Import of information blocks from 1C-Bitrix into MODx Revolution

    On the third day they set the task - to write a script to move from Bitrix to MODx. The task seemed interesting, especially since I had never really worked with Bitrix.

    I can’t write anything about the system itself, since I didn’t even go to the admin panel - it worked only with the database. By the way, these are 322 tables, against 68 for MODx.

    Of course, there was no talk of the complete transfer of everything, the task was to import the contents of certain information blocks (articles and news), with authors and some properties (pictures, publication date).
    And of course, keep all urls 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 there is an archive for download, but for now I will tell you a little how the script works.

    3 files:
    • - an array with a specific structure, which contains the settings for each info block
    • import.class.php - class with methods
    • process.php - file to run, connects the config and class


    All the data necessary for work is added to 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 blocks array contains the import settings for specific info blocks:
    • id - parent resource number for importing all information block pages. Need to create in advance.
    • cat_tpl - template identifier for containers (categories)
    • tpl - template identifier for regular resources
    • uri_override - freeze uri pages, you need to save old links.
    • preview_picture - TV parameter for saving a small picture of the page, optional
    • detail_picture - TV parameter for a large picture, optional

    The settings also indicate the prefix of the Bitrix tables. I believe that they are in the same database as MODx tables.

    Available Methods

    Now you need to look into the proccess.php file.

    There MODx itself is connected, the import class and the necessary methods for import are called:
    • truncateTable - takes the resource id, and removes all resources after it. Useful for experimentation.
    • importBlock - directly imports the infoblock, takes its name (and looks for settings in the config array)
    • linkToAuthors - a method personally necessary for my situation, links the pages of authors of articles with articles. Useful as an example.
    • getProps - takes the name of the infoblock section and returns 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 returns its properties (address, name). Files are grabbed by Bitrex through a separate table in the database.
    • makeURI - create uri for the MODx resource (we need to save it) according to the template from the section properties
    • getProperty - additional elements of the infoblock element. Something like TV in MODx.

    In general, almost all methods are written to work in importBlock.
    When it starts, the section properties are obtained, its subcategories are created, then resources are imported into them and the pictures are saved in TV boxes.

    Uri pages

    Most importantly, all uri work when using the following plugin, of course:
    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]))) {

    Since in Bitrix (I don’t know, always, or only in my case) these are the addresses - news / detail.php? News = 6868, you also need to force the web server to send them to index.php in the root of the site. That is, it is as if we have such friendly urls coming out.

    The plugin even makes pagination work with getPage. That is, news / detail.php? News = 6868 & page = 5 - will work correctly.


    I tried to write the script as versatile as possible, but not to the detriment of the main work. In any case, those who want to move from Bitrix to MODx now have something to start from.

    It works quite quickly, importing 5000 resources and linking to each other via TV parameters takes about 4 - 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 ask me to transfer another site from Bitrix to Revo. In general, I give it back as it is.

    Finally, briefly:
    1. Install MODx Revo.
    2. Create containers for import, assign TV for pictures.
    3. Fill the dump of the Bitrix database.
    4. Download the archive and unzip to the root of the site.
    5. Configure, specify the table prefix and settings for info blocks.
    6. Start importing information blocks in process.php from the console - there is a possibility of arbitrary launch.
    7. If something is wrong - dig into the code and edit for yourself.

    I beg you not to deploy regular holivars on the topic of "the best CMS in the world"!

    PS The guys from Webmaster Agency

    UPD ordered, paid, and allowed to share . It's not nice to get cons in post and karma for, it seems to me, a useful script. If only someone would unsubscribe - what doesn’t suit you?

    Also popular now: