Import iblock from 1C-Bitrix to MODx Revolution

the Third day asked the task is to write a script for moving from Bitrix to MODx. The task seemed interesting, especially since Beatrix really never worked.



Can not write anything about the system itself, as even in admin area did not go — worked only with the database. By the way, is 322 table against 68 MODx.


On a full migration of everything to the speech of course did not go, the task was to import the contents of specified iblock (articles and news), with the authors and some properties (image, date of publication).
And of course, save all URLs are well indexed by search engines.

I think that with some effort the script could be finished to work with other CMS, like Joomla or Drupal.

At the end of a topic file for download, and I'll talk a little how the script works.

3 file:
the

    config.inc.php — an array with a specific structure, which contains the settings for each information block

    import.class.php class methods

    process.php — the file to run, connect and config class



Configuration


Everything you need is the data insertion in array:
the
 '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 array blocks are stored import settings specific iblock:
the

    id is the number of the parent of the resource to import all pages of information block. You need to create in advance.

    cat_tpl — the ID of the template for containers (categories)

    tpl — the ID of the template for a generic resource

    uri_override — freeze the uri of the page, you need to preserve old links.

    preview_picture — TV option to store small pictures of the pages, optional

    detail_picture — TV option for a large picture, optional


Also the settings specify a table prefix Bitrix. I believe they are in the same database tables MODx.

Available methods


Now we need to look at that file proccess.php.

There connects itself MODx, class imports, and calls the necessary methods to import:
the

    truncateTable — takes the id of the resource, and removes all resources after it. Useful for experimentation.

    importBlock — directly import of the information block, takes its name (and searches in the array config settings)

    linkToAuthors method is needed, personally for my situation, binds the pages of authors with articles. Useful as an example.

    getProps — takes the name of the section of the information block, and outputs it properties (the rules for constructing a uri and the like) the

  • getElements — takes a section id and displays all of its child pages
  • getSections — builds a tree of categories (sections), puts them at each other, as on the original website. Takes properties from getProps and configuration

    getFile — accepts a file id and gives out its properties (address, name). The file cling Bitrex using a separate table in the database.

    makeURI creates a uri for a resource in MODx (we need to save it) using the template from the properties section

    getProperty — additional elements of element of the information block. Something like a TV in MODx.



In General, almost all methods are written to work in importBlock.
When it starts to get the properties of a partition, its subcategories are created, then imported into their resources and saved the pictures in Turecki.

Uri of the page


Most importantly — all URIs with the following plugin, of course:
the
<?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'));
}
}

As in Bitrix (don't know, always, or only in my case) here such — news/detail.php?news=6868, still need to get the web server to give them to index.php at the root of the website. That is, it is as if we are friendly urls out.
The plugin even makes the pagination work with getPage. That is, news/detail.php?news=6868&page=5 — it will work correctly.

Conclusion.


The script I tried to write as more versatile, but not at the expense of substantive work. In any case, wish to move with Bitriks on MODx now have something to go by.

Works pretty quickly, import 5000 resources and linking each other via the TV settings takes about 4 — 5 minutes on a normal home computer. Linking is my specific task, do not know will be useful to anyone else.


To add, to modify and develop this script, I will not — only if you ask to reschedule another site with Bitriks on Revo. In General, give as is.

Finally, briefly:
    the
  1. to Install MODx Revo.
  2. the
  3. to Create containers for import to designate your TV for the pictures.
  4. the
  5. to Fill the database dump Bitrix.
  6. the
  7. Download archive and unzip to the root of the site.
  8. the
  9. Configure config.inc.php to specify a table prefix and configuration of the iblock.
  10. the
  11. to Start the import of the iblock in process.php from the console, there is a possibility of any start.
  12. the
  13. If something is wrong is to dig into the code and edit by yourself.


I beg you not to deploy another holivary on the topic of "the world's best CMS"!

PS Ordered, paid, and allowed to share the guys from Webmaster Agency

UPD. is Not pleasant to cons in a post and a karma for, I think, useful script. Even if someone unsubscribed — what's not to like?
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Briefly on how to make your Qt geoservice plugin

Database replication PostgreSQL-based SymmetricDS

Yandex.Widget + adjustIFrameHeight + MooTools