You are here

function xmlsitemap_update_6202 in XML sitemap 7.2

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

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

1 call to xmlsitemap_update_6202()
xmlsitemap_update_7201 in ./xmlsitemap.install
Re-run xmlsitemap_update_6202() to ensure sitemap data has been added.

File

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

Code

function xmlsitemap_update_6202() {
  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('xmlsitemap_sitemap', $schema['xmlsitemap_sitemap']);
  }

  // Add the default sitemap(s) and use language contexts if possible.
  if (!db_query_range("SELECT 1 FROM {xmlsitemap_sitemap}", 0, 1)
    ->fetchField()) {

    // 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);
}