You are here

function xmlsitemap_update_6202 in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap.install \xmlsitemap_update_6202()

Create the {xmlsitemap_sitemap} table and add the sitemap context data.

File

./xmlsitemap.install, line 561
Install, update and uninstall functions for the xmlsitemap module.

Code

function xmlsitemap_update_6202() {
  $ret = array();
  if (!db_table_exists('xmlsitemap_sitemap')) {
    $schema['xmlsitemap_sitemap'] = array(
      'fields' => array(
        'smid' => array(
          'description' => 'Sitemap ID',
          'type' => 'serial',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'context_hash' => array(
          'description' => 'The MD5 hash of the context field.',
          'type' => 'varchar',
          'length' => 32,
          'not null' => TRUE,
          'default' => '',
        ),
        'context' => array(
          'description' => 'Serialized array with the sitemaps context',
          'type' => 'text',
          'not null' => TRUE,
        ),
        'updated' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'links' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'chunks' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'primary key' => array(
        'smid',
      ),
      'unique keys' => array(
        'context_hash' => array(
          'context_hash',
        ),
      ),
    );
    db_create_table($ret, 'xmlsitemap_sitemap', $schema['xmlsitemap_sitemap']);
  }

  // Add the default sitemap(s) and use language contexts if possible.
  if (!db_result(db_query("SELECT COUNT(smid) FROM {xmlsitemap_sitemap}"))) {

    // Refresh the schema and load the module if it's disabled.
    drupal_get_schema(NULL, TRUE);
    drupal_load('module', 'xmlsitemap');
    if (module_exists('xmlsitemap_i18n') && ($languages = variable_get('xmlsitemap_languages', array()))) {
      foreach ($languages as $language) {
        $sitemap = new stdClass();
        $sitemap->context = array(
          'language' => $language,
        );
        xmlsitemap_sitemap_save($sitemap);
      }
    }
    else {
      $sitemap = new stdClass();
      $sitemap->context = array();
      xmlsitemap_sitemap_save($sitemap);
    }
  }

  // Language variable is no longer needed, so go ahead and delete it.
  variable_del('xmlsitemap_languages');

  // Ensure that the sitemaps will be refreshed on next cron.
  variable_set('xmlsitemap_generated_last', 0);
  variable_set('xmlsitemap_regenerate_needed', TRUE);
  return $ret;
}