The third day we were asked to write a script to move from Bitrix to MODx. The task seemed interesting, especially since it never really worked with Bitrix.

I can’t write anything about the system itself, because I didn’t even enter the admin area - I only worked with the database. By the way, this is 322 tables, versus 68 for MODx.
')
Of course, there was no complete transfer of the entire speech, the task was to import the contents of certain information blocks (articles and news), with authors and some properties (pictures, date of publication).
And of course, save all url addresses well indexed by search engines.
I think that with some zeal this script can be finished to work with other CMS, such as Joomla or Drupal.
At the end of the topic is an archive for download, but for now I’ll tell you a little how the script works.
3 files:
- config.inc.php - an array with a certain structure in which the settings for each information block are located
- import.class.php - class with methods
- process.php - file to run, connects the config and class
Configuration
All the necessary data for work is entered into the array:
'table_prefix' => 'bitrix_' ,'blocks' => array( 'articles' => array( 'id' => 3 ,'cat_tpl' => 3 ,'tpl' => 3 ,'uri_override' => 1 ,'preview_picture' => 'preview_picture' ,'detail_picture' => 'detail_picture' )
The block array stores the import settings for specific information blocks:
- id is the number of the parent resource for importing all information block pages. Need to create in advance.
- cat_tpl - template identifier for containers (categories)
- tpl - template identifier for common resources
- uri_override - freeze uri pages, you need to save the old links.
- preview_picture - TV parameter for saving a small picture of the page, optional
- detail_picture - TV parameter for large images, optional
Also in the settings specified prefix tables Bitrix. I believe that they are in the same database with MODx tables.
Available methods
Now you need to look into the file proccess.php.
It connects MODx itself, the import class and the necessary methods to import are called:
- truncateTable - accepts resource id, and deletes all resources after it. Useful for experiments.
- importBlock - directly import the information block, accepts its name (and looks for settings in the configuration array)
- linkToAuthors - the method needed personally for my situation, links the pages of the authors of articles with articles. Useful as an example.
- getProps - takes the name of the information block section and displays its properties (rules for building uri and the like)
- getElements - takes a section id and displays all its child pages
- getSections - builds a tree of categories (from sections), puts them into each other, as on the original site. Accepts properties from getProps and config
- getFile - takes the id of the file and displays its properties (address, name). Files cling to Bitrex through a separate table in the database.
- makeURI - creating uri for a MODx resource (we need to save it) according to a template from the section properties
- getProperty - additional elements of the information block element. Something like TV in MODx.
In general, almost all methods are written to work in importBlock.
When it is launched, the properties of the section are obtained, its subcategories are created, then resources are imported into them and pictures are saved in TVshechki.
Uri pages
The most important thing is that all uri work, when using the following plugin, of course:
<?php if ($modx->event->name == 'OnPageNotFound') { $uri = parse_url(substr($_SERVER['REQUEST_URI'],1)); $query = explode('&', $uri['query']); $num1 = count($query); $query = array_unique($query); $num2 = count($query); if ($num1 != $num2) { $modx->sendRedirect($modx->getOption('site_url').$uri['path'].'?'.implode('&', $query)); } else if ($res = $modx->getObject('modResource', array('uri' => $uri['path'].'?'.$query[0]))) { $modx->sendForward($res->get('id')); } }
Since in Bitrix (I don’t know, always, or only in my case) these are the addresses / news / detail.php? News = 6868, you also have to force the web server to send them to index.php in the root of the site. That is, it’s like we have such friendly urls coming out.
The plugin even makes pagination work with getPage. That is, news / detail.php? News = 6868 & page = 5 - it will work correctly.
Conclusion
I tried to write the script as universally as possible, but not to the detriment of the main work. In any case, those wishing to move from Bitrix to MODx now have something to push off.
It works quite quickly, importing 5000 resources and linking to each other via TV parameters takes about 4 to 5 minutes on a regular home computer. Linking is my specific task, I don’t know if anyone else will come in handy.

I will not add, modify and develop this script - only if they are asked to transfer another site from Bitrix to Revo. In general, I give, as it is.
Finally, in short:
- Install MODx Revo.
- Create containers for import, assign TV to pictures.
- Upload dump bitrix db.
- Download the archive and unzip to the root of the site.
- Configure config.inc.php, specify table prefix and information block settings.
- Start importing information blocks in process.php from the console - there is a possibility of arbitrary launch.
- If something is wrong, dig in the code and edit for yourself.
I beg you not to deploy the next holivary on the theme of “the world's best CMS”!PS Ordered, paid, and allowed to share the guys from
Webmaster AgencyUPD. It is not pleasant to receive cons in a post and a karma for, as it seems to me, a useful script. If only someone unsubscribed - what does not suit?