simplesitemap.install 4.38 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Module install and update procedures.
6 7 8 9 10 11 12 13 14
 */

/**
 * Implements hook_schema().
 */
function simplesitemap_schema() {
  $schema['simplesitemap'] = array(
    'description' => 'Holds XML sitemaps as strings for quick retrieval.',
    'fields' => array(
15 16
      'id' => array(
        'description' => 'Sitemap chunk unique identifier.',
17 18
        'type' => 'int',
        'size' => 'small',
19 20 21
        'not null' => TRUE,
      ),
      'sitemap_string' => array(
22
        'description' => 'XML sitemap chunk string.',
23 24 25 26
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
27
      'sitemap_created' => array(
28 29 30 31 32
        'description' => 'Timestamp of sitemap chunk generation.',
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
      ),
33
    ),
34
    'primary key' => array('id'),
35 36 37
  );
  return $schema;
}
38

39 40 41 42 43
/**
 * Implements hook_install().
 */
function simplesitemap_install() {
  $base_url = $GLOBALS['base_url'];
44
  drupal_set_message(t("You can now include content into the <a href='@sitemap_url' target='_blank'>XML sitemap</a> by visiting the corresponding entity type edit pages (e.g. <a href='@content_type_url' target='_blank'>content type</a>, <a href='@taxonomy_vocabulary_url' target='_blank'>taxonomy vocabulary</a>, <a href='@menu_url' target='_blank'>menu</a> and <a href='@user_url' target='_blank'>user</a> pages.)<br/>Custom links can be added on <a href='@config_url' target='_blank'>this configuration page</a>.", array('@sitemap_url' => "$base_url/sitemap.xml", '@content_type_url' => "$base_url/admin/structure/types", '@taxonomy_vocabulary_url' => "$base_url/admin/structure/taxonomy", '@menu_url' => "$base_url/admin/structure/menu", '@user_url' => "$base_url/admin/config/people/accounts", '@config_url' => "$base_url/admin/config/search/simplesitemap/custom")));
45 46
}

47
/**
48
 * Update: Altering the {simplesitemap} language_code table field to hold longer strings.
49 50 51 52 53 54 55
 */
function simplesitemap_update_8101() {
  db_change_field('simplesitemap', 'language_code', 'language_code', array(
    'type' => 'varchar',
    'not null' => TRUE,
    'length' => 12,));
}
56 57

/**
58
 * Changing config settings according to new config structure.
59 60 61 62 63 64 65 66 67 68 69 70
 */
function simplesitemap_update_8102() {
  $entity_types = \Drupal::config('simplesitemap.settings')->get('entity_types');
  $entity_types = is_array($entity_types) ? $entity_types : array();
  if (isset($entity_types['node'])) {
    $entity_types['node_type'] = $entity_types['node'];
    unset($entity_types['node']);
  }
  if (isset($entity_types['taxonomy_term'])) {
    $entity_types['taxonomy_vocabulary'] = $entity_types['taxonomy_term'];
    unset($entity_types['taxonomy_term']);
  }
71 72
  \Drupal::service('config.factory')->getEditable('simplesitemap.settings')
    ->set('entity_types', $entity_types)->save();
73
}
74 75 76 77 78 79 80 81 82 83 84

/**
 * Modifying database structure to hold one multilingual sitemap.
 */
function simplesitemap_update_8103() {
  db_truncate('simplesitemap')->execute();
  db_drop_primary_key('simplesitemap');
  db_change_field('simplesitemap', 'language_code', 'id', array(
    'type' => 'serial',
    'not null' => TRUE
  ), array('primary key' => array('id')));
gbyte.co's avatar
gbyte.co committed
85
  return t('Before the sitemap can be accessed, it must be regenerated manually or via cron run.');
86
}
87 88 89 90 91 92 93 94 95 96 97

/**
 * Modifying database structure to accommodate sitemap chunks.
 */
function simplesitemap_update_8104() {
  db_truncate('simplesitemap')->execute();
  db_change_field('simplesitemap', 'id', 'id', array(
    'type' => 'int',
    'size' => 'small',
    'not null' => TRUE,
  ));
98 99
  \Drupal::service('config.factory')->getEditable('simplesitemap.settings')
    ->set('settings', array('max_links' => 2000))->save();
100 101
  return t('Before the sitemap can be accessed, it must be regenerated manually or via cron run.');
}
102 103 104 105 106 107 108 109 110 111 112 113

/**
 * Modifying database structure to accommodate sitemap chunk timestamps.
 */
function simplesitemap_update_8105() {
  db_add_field('simplesitemap', 'generated', array(
    'description' => 'Timestamp of sitemap chunk generation.',
    'type' => 'int',
    'default' => 0,
    'not null' => TRUE,
  ));
}
114 115 116 117 118

/**
 * Changing column name to 'sitemap_created', as 'generated' is a reserved word since MySQL 5.7.6.
 */
function simplesitemap_update_8106() {
119 120 121
  // Omitting the high level DB API to be able to escape the column name.
  Drupal\Core\Database\Database::getConnection()
    ->query("alter table {simplesitemap} CHANGE `generated` sitemap_created int(11) NOT NULL");
122 123
}