You are here

function xmlsitemap_node_update_6198 in XML sitemap 6.2

Migrate 6.x-1.x node data.

File

xmlsitemap_node/xmlsitemap_node.install, line 44
Install and uninstall schema and functions for the xmlsitemap_node module.

Code

function xmlsitemap_node_update_6198(&$context) {
  $ret = array();
  if (!db_table_exists('xmlsitemap_node')) {

    // Skip if the 6.x-1.x table doesn't exist.
    return $ret;
  }
  elseif (db_column_exists('xmlsitemap', 'sid')) {

    // Skip if the main {xmlsitemap} table hasn't been upgraded yet.
    $ret['#abort'] = array(
      'success' => FALSE,
      'query' => 'The primary xmlsitemap table upgrade has not yet been completed. Re-run the upgrade script.',
    );
    return $ret;
  }
  if (!isset($context['progress'])) {
    $context['progress'] = $context['last'] = 0;
    $context['count'] = db_result(db_query("SELECT COUNT(nid) FROM {xmlsitemap_node} WHERE priority_override <> -2 AND nid > %d", $context['last']));
  }
  drupal_load('module', 'xmlsitemap_node');
  drupal_load('module', 'xmlsitemap');
  $query = db_query_range("SELECT nid, priority_override FROM {xmlsitemap_node} WHERE priority_override <> -2 AND nid > %d ORDER BY nid", $context['last'], 0, 10);
  while ($record = db_fetch_object($query)) {
    if ($node = node_load($record->nid, NULL, TRUE)) {
      $link = xmlsitemap_node_create_link($node);
      $link['status'] = variable_get('xmlsitemap_node_status_' . $node->type, 0);
      $link['priority'] = variable_get('xmlsitemap_node_priority_' . $node->type, 0.5);
      if ($record->priority_override == -1) {
        $link['status'] = 0;
        $link['status_override'] = 1;
      }
      elseif ($record->priority_override != -2) {
        $link['priority'] = $record->priority_override;
        $link['priority_override'] = 1;
      }
      xmlsitemap_link_save($link);
    }
    $context['last'] = $record->nid;
    $context['progress']++;
  }
  $ret['#finished'] = empty($context['count']) ? 1 : $context['progress'] / $context['count'];
  return $ret;
}