function joomla_import_content in Joomla to Drupal 6
Same name and namespace in other branches
- 7 joomla.module \joomla_import_content()
2 calls to joomla_import_content()
3 string references to 'joomla_import_content'
- joomla_cron in ./
joomla.module - joomla_import_form_checkboxes in ./
joomla.module - These checkboxes are used on both the admin and import forms
- joomla_uninstall in ./
joomla.install - Implementation of hook_uninstall().
File
- ./
joomla.module, line 651 - The joomla module used for migrate Joomla to Drupal.
Code
function joomla_import_content($joomla_update_duplicate = NULL) {
joomla_database_init();
if ($joomla_update_duplicate === NULL) {
$joomla_update_duplicate = variable_get('joomla_update_duplicate', JOOMLA_UPDATE_DUPLICATE);
}
$joomla_prefix = variable_get('joomla_prefix', JOOMLA_PREFIX);
$content_total = 0;
$content_updated = 0;
$content_new = 0;
$content_failed = 0;
$images = array();
db_set_active('joomla');
$results_joomla = db_query("SELECT c.*,cf.content_id FROM %scontent c LEFT JOIN %scontent_frontpage cf ON cf.content_id = c.id", $joomla_prefix, $joomla_prefix);
db_set_active();
while ($data_joomla = db_fetch_object($results_joomla)) {
$content_total++;
$content_map = db_fetch_object(db_query('SELECT n.nid,jcontentid,changed FROM {joomla_content} jc JOIN {node} n ON n.nid = jc.nid WHERE jc.jcontentid = %d', $data_joomla->id));
if ($content_map && !$joomla_update_duplicate) {
// Content item has already been imported and update is off
continue;
}
/**
* If the content item already exists, but has not been updated
* since the last import, skip it
*/
$joomla_changed = strtotime($data_joomla->modified);
if ($content_map && $joomla_changed == $content_map->changed) {
continue;
}
$node = new stdClass();
$node_revision = new stdClass();
if ($content_map) {
$node->nid = $content_map->nid;
$node_revision->nid = $content_map->nid;
}
$node->uid = db_result(db_query('SELECT uid FROM {joomla_users} WHERE juid = %d', $data_joomla->created_by));
$node_revision->uid = $node->uid;
$node->title = $data_joomla->title;
$node_revision->title = $data_joomla->title;
$node->status = $data_joomla->state;
$node_revision->status = $data_joomla->state;
$node->created = strtotime($data_joomla->created);
$node->changed = $joomla_changed;
$node_revision->timestamp = $joomla_changed;
$node_revision->format = variable_get('joomla_input_format', JOOMLA_INPUT_FORMAT);
// Set content type
if ($data_joomla->sectionid == 0) {
$joomla_type = variable_get('joomla_default_static_nodetype', JOOMLA_DEFAULT_STATIC_NODETYPE);
}
else {
$joomla_type = variable_get('joomla_default_blog_nodetype', JOOMLA_DEFAULT_BLOG_NODETYPE);
}
$node->type = $joomla_type;
if (!empty($data_joomla->introtext)) {
$joomla_body = $data_joomla->introtext . "<!--break-->" . $data_joomla->fulltext;
$joomla_teaser = $data_joomla->introtext;
}
else {
$joomla_body = $data_joomla->fulltext;
$joomla_teaser = node_teaser($joomla_body, $node_revision->format);
}
$joomla_body = str_replace("{mospagebreak}", "", $joomla_body);
//images
if ($data_joomla->images) {
$joomla_teaser = joomla_replace_mos_image($data_joomla->images, $joomla_teaser);
$joomla_body = joomla_replace_mos_image($data_joomla->images, $joomla_body);
}
$joomla_teaser = joomla_replace_image_link($joomla_teaser);
$joomla_body = joomla_replace_image_link($joomla_body);
$node_revision->body = $joomla_body;
$node_revision->teaser = $joomla_teaser;
// This is used to make the taxonomy association
$term_node = new stdClass();
$term_node->tid = db_result(db_query('SELECT tid FROM {joomla_categories} WHERE jcategoryid = %d AND jsectionid = %d', $data_joomla->catid, $data_joomla->sectionid));
// Promote to front page?
if ($data_joomla->content_id) {
$joomla_promote = 1;
}
else {
$joomla_promote = 0;
}
$node->promote = $joomla_promote;
$status = FALSE;
if ($content_map) {
// Updating an existing node
$node_status = drupal_write_record('node', $node, 'nid');
/*
* Even though Joomla doesn't have revision info, no reason
* why we can't use Drupals revision system when making an update!
*/
$node_revision_status = drupal_write_record('node_revisions', $node_revision);
$node->vid = $node_revision->vid;
db_query('UPDATE {node} SET vid = %d WHERE nid = %d', $node_revision->vid, $node->nid);
if ($term_node->tid) {
$term_node->nid = $node->nid;
$term_node->vid = $node_revision->vid;
drupal_write_record('term_node', $term_node);
}
}
else {
// Creating a new node
$node_status = drupal_write_record('node', $node);
$node_revision->nid = $node->nid;
$node_revision_status = drupal_write_record('node_revisions', $node_revision);
$node->vid = $node_revision->vid;
db_query('UPDATE {node} SET vid = %d WHERE nid = %d', $node_revision->vid, $node->nid);
$joomla_content = new stdClass();
$joomla_content->nid = $node->nid;
$joomla_content->jcontentid = $data_joomla->id;
drupal_write_record('joomla_content', $joomla_content);
if ($term_node->tid) {
$term_node->nid = $node->nid;
$term_node->vid = $node_revision->vid;
drupal_write_record('term_node', $term_node);
}
}
if ($node_status == SAVED_NEW && $node_revision_status == SAVED_NEW) {
$content_new++;
}
elseif ($node_status == SAVED_UPDATED && $node_revision_status == SAVED_NEW) {
$content_updated++;
}
else {
$content_failed++;
}
// Hook to allow other modules to modufy the node
module_invoke_all('joomla', 'node', $node, $data_joomla->id);
joomla_sleep($content_total);
}
/*
* The node_comment_statistics table must be populated with a row for
* all of the created nodes, even if the nodes have no comments. This
* query is probably only valid on MySQL, but this module can currently
* only go from MySQL -> MySQL anyway.
*/
db_query('INSERT IGNORE INTO node_comment_statistics (nid,last_comment_timestamp,last_comment_uid) SELECT n.nid, n.created,1 FROM node n LEFT JOIN node_comment_statistics ncs ON n.nid = ncs.nid WHERE ISNULL(ncs.nid)');
drupal_set_message(t('Processed @total content items (@new new, @updated updated, @failed errors)', array(
'@total' => $content_total,
'@new' => $content_new,
'@updated' => $content_updated,
'@failed' => $content_failed,
)));
}