📜 ⬆️ ⬇️

Importing information blocks from 1C-Bitrix to MODx Revolution

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:


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:

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:


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:
  1. Install MODx Revo.
  2. Create containers for import, assign TV to pictures.
  3. Upload dump bitrix db.
  4. Download the archive and unzip to the root of the site.
  5. Configure config.inc.php, specify table prefix and information block settings.
  6. Start importing information blocks in process.php from the console - there is a possibility of arbitrary launch.
  7. 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 Agency

UPD. 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?

Source: https://habr.com/ru/post/142430/


All Articles