Answer the question
In order to leave comments, you need to log in
Creating a large number of documents in MODX Revo?
There is a task to create 3-4 thousand documents (regular catalog import). There is already a ready-made associative array.
I tried to work with the processor 'create': $modx->runProcessor($processor,$line);
- it's very slow.
I tried to create objects like: $object = $modx->newObject('modResource');
- it's faster than processors, but not fast enough.
I'm running out of time, apparently due to a large number of queries to MySQL.
I'm looking for a way to solve this problem.
There is an idea to collect requests in groups (“packs” of 50-100 pieces, for example) and then send (save).
With the help of objects it will not work, right?
For xPDO, I did not find a way to create resources (documents) - there is little written about this on the Internet.
Any ideas?
Answer the question
In order to leave comments, you need to log in
Found a solution, works very fast. I got it like this:
$table = $modx->getTableName('modResource');
$sql = "INSERT INTO {$table} (pagetitle, longtitle, menutitle, alias, parent, isfolder, template, published, hidemenu, content, createdby, createdon, editedby, editedon) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$q = $modx->prepare($sql);
$q->bindValue(1, $line['pagetitle']);
$q->bindValue(2, $line['longtitle']);
$q->bindValue(3, $line['menutitle']);
$q->bindValue(4, $line['alias']);
$q->bindValue(5, $line['parent']);
$q->bindValue(6, $line['isfolder']);
$q->bindValue(7, $line['template']);
$q->bindValue(8, '1');
$q->bindValue(9, $line['hidemenu']);
$q->bindValue(10, $line['content']);
$q->bindValue(11, 1);
$q->bindValue(12, date());
$q->bindValue(13, 1);
$q->bindValue(14, date());
$q->execute();
Thanks to the internets:
forums.modx.com/thread/71759/populate-large-data-in-xpdo-solved
All these ORM add-ons are made for the convenience of the programmer, and not for speed. So if you want to add quickly, it means bare SQL, and it is desirable to combine queries. In order not to spend a lot of time picking in the structure, enable the query log in MySQL on the local, and do the necessary action in MODx, after which you already see what queries the CMS used, and based on them make a template for your queries.
Never worked with MODx, but the task is close to me.
In my opinion, you have two options:
- Increase the script's running time ( set_time_limit ) so that there are no time limits. Perhaps the script also does not have enough memory, I worked with a similar problem on Kohana and Doctrine as an ORM, there was a catastrophic lack of memory ( ini_set('memory_limit', '512M') )
- Do everything with “handles” and write “bare” SQL queries to the base. There are a lot of disadvantages in this option - from a greater chance of making a mistake to losing a lot of time to analyze the structure and connections in the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question