You are here

function xmlsitemap_taxonomy_update_6198 in XML sitemap 6.2

Migrate 6.x-1.x taxonomy data.

File

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

Code

function xmlsitemap_taxonomy_update_6198(&$context) {
  $ret = array();
  if (!db_table_exists('xmlsitemap_taxonomy')) {

    // 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(tid) FROM {xmlsitemap_taxonomy} WHERE priority_override <> -2 AND tid > %d", $context['last']));
  }
  drupal_load('module', 'xmlsitemap_taxonomy');
  drupal_load('module', 'xmlsitemap');
  $query = db_query_range("SELECT tid, priority_override FROM {xmlsitemap_taxonomy} WHERE priority_override <> -2 AND tid > %d ORDER BY tid", $context['last'], 0, 10);
  while ($record = db_fetch_object($query)) {
    if ($term = taxonomy_get_term($record->tid)) {
      $link = xmlsitemap_taxonomy_create_link($term);
      $link['status'] = variable_get('xmlsitemap_taxonomy_status_' . $term->vid, 0);
      $link['priority'] = variable_get('xmlsitemap_taxonomy_priority_' . $term->vid, 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->tid;
    $context['progress']++;
  }
  $ret['#finished'] = empty($context['count']) ? 1 : $context['progress'] / $context['count'];
  return $ret;
}