Simple PHP script to migrate articles from Radiant (Rails CMS) to Joomla (PHP CMS)

I was working on migrating data from Radient 0.8.1 (Ruby on Rails CMS) to Joomla 2.5.6 (PHP CMS), and it was a bit silly but interesting task. So, I wrote the following simple php script to migrate articles, but you should adjust some variables first.

<?php

// First, update the following variables with your database privileges.
// Joomla MySQL server and database
$db_joomla = mysql_connect('DB_HOST', 'DB_USER_NAME', 'DB_PASSWORD'); 
mysql_select_db('joomla_db', $db_joomla) or die("Cant select joomla DB, " . mysql_error());

// Radiant MySQL server and database
$db_radiant = mysql_connect('DB_HOST', 'DB_USER_NAME', 'DB_PASSWORD', true); 
mysql_select_db('radiant_db', $db_radiant) or die("Cant select radiant DB, " . mysql_error());

// Second, In the following query, update parent_id with your radiant category ID
$result = mysql_query("SELECT *, `pages`.`id` AS `page_id`, `page_parts`.`id` AS `page_part_id` 
									FROM `pages`,`page_parts` 
									WHERE `pages`.`id` = `page_parts`.`page_id`
									AND `pages`.`status_id` = '100'
									AND `pages`.`parent_id` = '8'
									AND `page_parts`.`name` IN ('body', 'extended')"
        , $db_radiant) or die(mysql_error());

$last_page_id = '';
$last_insert_id = '';

while ($row = mysql_fetch_assoc($result)) {
    if ($row['page_id'] == $last_page_id && $row['name'] == 'extended') {
        mysql_query("UPDATE `qm3be_content` SET `fulltext`='" . mysql_real_escape_string($row['content']) . "' WHERE `id`='" . $last_insert_id . "'", $db_joomla) or die('can not update : ' . mysql_error());
    } else {

// Finally, Update catid with your Joomla category ID.

// Replace qm3be_content with your joomla content table
        mysql_query("INSERT INTO `qm3be_content` SET
		title = '" . mysql_real_escape_string($row['title']) . "',
		alias = '" . mysql_real_escape_string($row['slug']) . "',
		created = '" . mysql_real_escape_string($row['created_at']) . "', 
		modified = '" . mysql_real_escape_string($row['updated_at']) . "',
		publish_up = '" . mysql_real_escape_string($row['published_at']) . "',
		introtext = '" . mysql_real_escape_string($row['content']) . "',
		access ='1',
		language ='*',
		catid = '16',
		state = '1',
		created_by = '42',
		images = '{\"image_intro\":\"\",\"float_intro\":\"\",\"image_intro_alt\":\"\",\"image_intro_caption\":\"\",\"image_fulltext\":\"\",\"float_fulltext\":\"\",\"image_fulltext_alt\":\"\",\"image_fulltext_caption\":\"\"}',
		urls = '{\"urla\":null,\"urlatext\":\"\",\"targeta\":\"\",\"urlb\":null,\"urlbtext\":\"\",\"targetb\":\"\",\"urlc\":null,\"urlctext\":\"\",\"targetc\":\"\"}',
		attribs = '{\"show_title\":\"\",\"link_titles\":\"\",\"show_intro\":\"\",\"show_category\":\"\",\"link_category\":\"\",\"show_parent_category\":\"\",\"link_parent_category\":\"\",\"show_author\":\"\",\"link_author\":\"\",\"show_create_date\":\"\",\"show_modify_date\":\"\",\"show_publish_date\":\"\",\"show_item_navigation\":\"\",\"show_icons\":\"\",\"show_print_icon\":\"\",\"show_email_icon\":\"\",\"show_vote\":\"\",\"show_hits\":\"\",\"show_noauth\":\"\",\"urls_position\":\"\",\"alternative_readmore\":\"\",\"article_layout\":\"\",\"show_publishing_options\":\"\",\"show_article_options\":\"\",\"show_urls_images_backend\":\"\",\"show_urls_images_frontend\":\"\"}',
		metadata = '{\"robots\":\"\",\"author\":\"\",\"rights\":\"\",\"xreference\":\"\"}'
		", $db_joomla) or die(mysql_error());
    }

    $last_page_id = $row['page_id'];
    $last_insert_id = mysql_insert_id();
}

Leave a comment

 

WP-SpamFree by Pole Position Marketing