simple_sitemap.install 21.7 KB
Newer Older
gbyte.co's avatar
gbyte.co committed
1
<?php
gbyte.co's avatar
gbyte.co committed
2

gbyte.co's avatar
gbyte.co committed
3 4 5 6 7 8 9
/**
 * @file
 * Module install and update procedures.
 */

/**
 * Implements hook_requirements().
10 11 12
 *
 * @param $phase
 * @return array
gbyte.co's avatar
gbyte.co committed
13 14
 */
function simple_sitemap_requirements($phase) {
15
  $requirements = [];
gbyte.co's avatar
gbyte.co committed
16 17

  if (!extension_loaded('xmlwriter')) {
18
    $requirements['simple_sitemap_php_extensions'] = [
19
      'title' => t('Simple XML Sitemap PHP extensions'),
gbyte.co's avatar
gbyte.co committed
20
      'value' => t('Missing PHP xmlwriter extension'),
21
      'description' => t('In order to be able to generate sitemaps, the Simple XML Sitemap module requires the <em>xmlwriter</em> PHP extension to be enabled.'),
gbyte.co's avatar
gbyte.co committed
22
      'severity' => REQUIREMENT_ERROR,
23
    ];
gbyte.co's avatar
gbyte.co committed
24 25
  }

gbyte.co's avatar
gbyte.co committed
26
  switch ($phase) {
27

gbyte.co's avatar
gbyte.co committed
28
    case 'runtime':
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
      // todo Implement for 3.x
//      /** @var \Drupal\simple_sitemap\Simplesitemap $generator */
//      $generator = \Drupal::service('simple_sitemap.generator');
//      $generated_ago = $generator->getGeneratedAgo();
//      $cron_generation = $generator->getSetting('cron_generate');
//
//      if (!$generated_ago) {
//        $value = t('Not available');
//        $description = t($cron_generation
//          ? 'Run cron, or <a href="@generate">generate</a> the sitemap manually.'
//          : 'Generation on cron run is disabled. <a href="@generate">Generate</a> the sitemap manually.', [
//            '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
//          ]
//        );
//        $severity = REQUIREMENT_WARNING;
//      }
//      else {
//        $value = t('XML sitemaps are available');
//        $description = t('The last generation finished @ago ago.'
//          . ' ' . ($cron_generation
//            ? 'Run cron, or <a href="@generate">regenerate</a> the sitemaps manually.'
//            : 'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemaps manually.'), [
//              '@ago' => $generated_ago,
//              '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
//            ]
//          );
//        $severity = REQUIREMENT_INFO;
//      }
//
//      $requirements['simple_sitemap_generated'] = [
60
//        'title' => 'Simple XML Sitemap',
61 62 63 64
//        'value' => $value,
//        'description' => $description,
//        'severity' => $severity,
//      ];
gbyte.co's avatar
gbyte.co committed
65 66 67 68 69
      break;
  }
  return $requirements;
}

70 71 72 73 74 75 76 77 78
/**
 * Implements hook_uninstall().
 */
function simple_sitemap_uninstall() {
  \Drupal::service('state')->deleteMultiple([
    'simple_sitemap.last_cron_generate',
    'simple_sitemap.queue_items_initial_amount',
    'simple_sitemap.queue_stashed_results',
  ]);
gbyte.co's avatar
gbyte.co committed
79 80 81 82

  \Drupal::service('queue')
    ->get('simple_sitemap_elements')
    ->deleteQueue();
83 84
}

gbyte.co's avatar
gbyte.co committed
85 86 87 88
/**
 * Implements hook_schema().
 */
function simple_sitemap_schema() {
89
  $schema['simple_sitemap'] = [
gbyte.co's avatar
gbyte.co committed
90
    'description' => 'Holds XML sitemaps as strings for quick retrieval.',
91 92
    'fields' => [
      'id' => [
gbyte.co's avatar
gbyte.co committed
93 94 95
        'description' => 'Sitemap chunk unique identifier.',
        'type' => 'int',
        'not null' => TRUE,
96
        'unsigned' => TRUE,
97
      ],
98 99 100 101 102 103 104 105 106 107 108 109 110
      'type' => [
        'description' => 'Type of sitemap this chunk belongs to.',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ],
      'delta' => [
        'description' => 'Delta of the chunk within the type scope.',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ],
111
      'sitemap_string' => [
gbyte.co's avatar
gbyte.co committed
112 113 114 115
        'description' => 'XML sitemap chunk string.',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
116 117
      ],
      'sitemap_created' => [
gbyte.co's avatar
gbyte.co committed
118 119
        'description' => 'Timestamp of sitemap chunk generation.',
        'type' => 'int',
120 121
        'not null' => TRUE,
        'unsigned' => TRUE,
gbyte.co's avatar
gbyte.co committed
122
        'default' => 0,
123 124 125 126 127
      ],
      'status' => [
        'description' => "Flag indicating the publishing status of the chunk.",
        'type' => 'int',
        'size' => 'tiny',
gbyte.co's avatar
gbyte.co committed
128
        'not null' => TRUE,
129
        'unsigned' => TRUE,
130
        'default' => 0,
131 132 133 134 135 136 137 138 139 140 141 142
      ],
    ],
    'primary key' => ['id'],
  ];

  $schema['simple_sitemap_entity_overrides'] = [
    'description' => 'Holds sitemap settings overridden by entities.',
    'fields' => [
      'id' => [
        'description' => 'Override unique identifier.',
        'type' => 'serial',
        'not null' => TRUE,
143
        'unsigned' => TRUE,
144
      ],
145 146 147 148 149 150
      'type' => [
        'description' => 'Type of sitemap this override belongs to.',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
      ],
151 152 153 154 155 156 157 158
      'entity_type' => [
        'description' => 'Entity type of the overriding entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ],
      'entity_id' => [
        'description' => 'ID of the overriding entity.',
159 160
        'type' => 'varchar',
        'length' => 32,
161 162 163 164 165
        'not null' => TRUE,
      ],
      'inclusion_settings' => [
        'description' => 'Setting for the overriding entity.',
        'type' => 'blob',
166 167 168 169
      ],
    ],
    'primary key' => ['id'],
  ];
170

gbyte.co's avatar
gbyte.co committed
171 172 173
  return $schema;
}

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
function _simple_sitemap_update_8216_get_default_variant() {
  $config_factory = \Drupal::service('config.factory');
  $default_variant = $config_factory->get('simple_sitemap.settings')->get('default_variant');
  if (empty($default_variant)) {
    $default_variant = 'default';
    $config_factory->getEditable('simple_sitemap.settings')
      ->set('default_variant', $default_variant)
      ->save();
  }

  /** @var \Drupal\simple_sitemap\SimplesitemapManager $manager */
  $manager = \Drupal::service('simple_sitemap.manager');
  $variants = $manager->getSitemapVariants();
  if (!isset($variants[$default_variant])) {
    $manager->addSitemapVariant($default_variant);
  }

  return $default_variant;
}

194 195 196 197 198
/**
 * Changing the data structure of the module's configuration.
 */
function simple_sitemap_update_8201() {
  $entity_types = \Drupal::config('simple_sitemap.settings')->get('entity_types');
199
  $entity_types = is_array($entity_types) ? $entity_types : [];
200 201 202 203 204 205 206
  $naming_changes = [
    'node_type' => 'node',
    'taxonomy_vocabulary' => 'taxonomy_term',
    'menu' => 'menu_link_content',
    'commerce_product_type' => 'commerce_product',
    'media_bundle' => 'media',
  ];
gbyte.co's avatar
gbyte.co committed
207
  foreach ($entity_types as $entity_type_name => $settings) {
208 209 210 211 212 213 214
    if (isset($naming_changes[$entity_type_name])) {
      $entity_types[$naming_changes[$entity_type_name]] = $entity_types[$entity_type_name];
      unset($entity_types[$entity_type_name]);
    }
  }
  \Drupal::service('config.factory')->getEditable('simple_sitemap.settings')
    ->set('entity_types', $entity_types)->save();
gbyte.co's avatar
gbyte.co committed
215
}
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

/**
 * Moving entity overrides from configuration to database table.
 */
function simple_sitemap_update_8202() {
  $database = \Drupal::database();

  // Create database table.
  if (!$database->schema()->tableExists('simple_sitemap_entity_overrides')) {
    $database->schema()->createTable('simple_sitemap_entity_overrides', [
      'description' => 'Holds sitemap settings overridden by entities.',
      'fields' => [
        'id' => [
          'description' => 'Override unique identifier.',
          'type' => 'serial',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'entity_type' => [
          'description' => 'Entity type of the overriding entity.',
          'type' => 'varchar',
          'length' => 32,
          'not null' => TRUE,
        ],
        'entity_id' => [
          'description' => 'ID of the overriding entity.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'inclusion_settings' => [
          'description' => 'Setting for the overriding entity.',
          'type' => 'blob',
        ],
      ],
      'primary key' => ['id'],
    ]);
  }

  // Populate database table with config values.
  $entity_types = \Drupal::config('simple_sitemap.settings')->get('entity_types');
  $entity_types = is_array($entity_types) ? $entity_types : [];

  foreach ($entity_types as $entity_type_name => &$entity_type) {
    if (is_array($entity_type)) {
gbyte.co's avatar
gbyte.co committed
261
      foreach ($entity_type as $bundle_name => &$bundle) {
262
        if (isset($bundle['entities'])) {
gbyte.co's avatar
gbyte.co committed
263
          foreach ($bundle['entities'] as $entity_id => $entity_settings) {
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
            $database->insert('simple_sitemap_entity_overrides')
              ->fields([
                'entity_type' => $entity_type_name,
                'entity_id' => $entity_id,
                'inclusion_settings' => serialize($entity_settings),
              ])
              ->execute();
          }
          // Remove entity overrides from configuration.
          unset($bundle['entities']);
        }
      }
    }
  }

  \Drupal::service('config.factory')->getEditable('simple_sitemap.settings')
    ->set('entity_types', $entity_types)->save();
}

/**
 * Splitting simple_sitemap.settings configuration into simple_sitemap.settings,
 * simple_sitemap.entity_types and simple_sitemap.custom.
 */
function simple_sitemap_update_8203() {
288 289
  $old_config = $config = \Drupal::config('simple_sitemap.settings');
  foreach (['entity_types', 'custom'] as $config_name) {
290 291 292
    if (!$config = $old_config->get($config_name)) {
      continue;
    }
293 294 295 296 297 298
    \Drupal::service('config.factory')->getEditable("simple_sitemap.$config_name")
      ->setData($config)->save();
  }
  $settings = $old_config->get('settings');
  \Drupal::service('config.factory')->getEditable("simple_sitemap.settings")
    ->setData($settings)->save();
299
}
300 301

/**
302
 * Removing entity type settings for entity types which do not have the canonical
303 304 305 306 307 308
 * link template.
 */
function simple_sitemap_update_8204() {
  $sitemap_entity_types = \Drupal::service('entity_type.manager')->getDefinitions();
  $entity_types = \Drupal::config('simple_sitemap.entity_types')->get();
  unset($entity_types['_core']);
gbyte.co's avatar
gbyte.co committed
309
  foreach ($entity_types as $entity_type_id => $entity_type) {
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    if (!isset($sitemap_entity_types[$entity_type_id])
      || !$sitemap_entity_types[$entity_type_id]->hasLinkTemplate('canonical')) {

      // Delete entity overrides.
      \Drupal::database()->delete('simple_sitemap_entity_overrides')
        ->condition('entity_type', $entity_type_id)
        ->execute();

      // Delete entity type settings.
      unset($entity_types[$entity_type_id]);
    }
  }
  \Drupal::service('config.factory')->getEditable("simple_sitemap.entity_types")
    ->setData($entity_types)->save();
}
325 326 327 328 329 330 331 332 333

/**
 * Splitting simple_sitemap.entity_types into individual configuration objects
 * for each bundle.
 */
function simple_sitemap_update_8205() {
  $entity_types = \Drupal::config('simple_sitemap.entity_types')->get();
  unset($entity_types['_core']);
  $enabled_entity_types = [];
gbyte.co's avatar
gbyte.co committed
334
  foreach ($entity_types as $entity_type_id => $bundles) {
335
    $enabled_entity_types[] = $entity_type_id;
gbyte.co's avatar
gbyte.co committed
336
    foreach ($bundles as $bundle_name => $bundle_settings) {
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
      \Drupal::service('config.factory')
        ->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle_name")
        ->setData($bundle_settings)->save();
    }
  }

  // Add enabled entity type settings.
  \Drupal::service('config.factory')
    ->getEditable('simple_sitemap.settings')
    ->set('enabled_entity_types', $enabled_entity_types)
    ->save();

  // Remove old configuration object.
  \Drupal::service('config.factory')
    ->getEditable('simple_sitemap.entity_types')
    ->delete();
}
354 355 356 357 358 359

/**
 * Placing custom links in a subkey of simple_sitemap.custom configuration.
 */
function simple_sitemap_update_8206() {
  $custom_links = \Drupal::config('simple_sitemap.custom')->get();
gbyte.co's avatar
gbyte.co committed
360
  foreach ($custom_links as $i => $custom_link) {
361 362 363 364
    if (!isset($custom_link['path'])) {
      unset($custom_links[$i]);
    }
  }
gbyte.co's avatar
gbyte.co committed
365
  \Drupal::service('config.factory')->getEditable('simple_sitemap.custom')
366 367
    ->setData(['links' => $custom_links])->save();
}
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383

/**
 * Updating entity_id field of simple_sitemap_entity_overrides table to varchar(32).
 */
function simple_sitemap_update_8207() {
  \Drupal::database()->schema()->changeField(
    'simple_sitemap_entity_overrides',
    'entity_id',
    'entity_id', [
      'description' => 'ID of the overriding entity.',
      'type' => 'varchar',
      'length' => 32,
      'not null' => TRUE,
    ]
  );
}
384 385

/**
386
 * Adding changefreq setting to all existing bundle and entity instance settings.
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
 */
function simple_sitemap_update_8208() {

  // Update existing bundle settings.
  $config_factory = \Drupal::service('config.factory');
  $entity_types = $config_factory->listAll('simple_sitemap.bundle_settings.');

  foreach ($entity_types as $entity_type) {
    $config = $config_factory->get($entity_type)->get();
    if (!isset($config['changefreq'])) {
      $config_factory->getEditable($entity_type)
        ->setData($config + ['changefreq' => ''])
        ->save();
    }
  }

  // Update existing entity override data.
  $results = \Drupal::database()->select('simple_sitemap_entity_overrides', 'o')
    ->fields('o', ['id', 'inclusion_settings'])
    ->execute()->fetchAll(\PDO::FETCH_OBJ);

  foreach ($results as $row) {
    $settings = unserialize($row->inclusion_settings);
    if (!isset($settings['changefreq'])) {
      \Drupal::database()->update('simple_sitemap_entity_overrides')
        ->fields(['inclusion_settings' => serialize($settings + ['changefreq' => '']),])
        ->condition('id', $row->id)
        ->execute();
    }
  }
417

gbyte.co's avatar
gbyte.co committed
418
  return t('You may now want to configure the new changefreq setting for the XML sitemap entities and custom links.');
419 420 421 422 423 424 425 426 427
}

/**
 * Adding image inclusion setting to all existing bundle and entity instance settings.
 */
function simple_sitemap_update_8209() {

  // Update existing bundle settings.
  $config_factory = \Drupal::service('config.factory');
428
  $all_bundle_settings = $config_factory->listAll('simple_sitemap.bundle_settings.');
429

430 431
  foreach ($all_bundle_settings as $bundle_settings) {
    $config = $config_factory->get($bundle_settings)->get();
432
    if (!isset($config['include_images'])) {
433
      $config_factory->getEditable($bundle_settings)
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
        ->setData($config + ['include_images' => 0])
        ->save();
    }
  }

  // Update existing entity override data.
  $results = \Drupal::database()->select('simple_sitemap_entity_overrides', 'o')
    ->fields('o', ['id', 'inclusion_settings'])
    ->execute()->fetchAll(\PDO::FETCH_OBJ);

  foreach ($results as $row) {
    $settings = unserialize($row->inclusion_settings);
    if (!isset($settings['include_images'])) {
      \Drupal::database()->update('simple_sitemap_entity_overrides')
        ->fields(['inclusion_settings' => serialize($settings + ['include_images' => 0]),])
        ->condition('id', $row->id)
        ->execute();
    }
  }

gbyte.co's avatar
gbyte.co committed
454
  return t('You may now want to configure your XML sitemap entities to include images.');
455
}
456 457

/**
458
 * Adding 'type' and 'delta' fields to simple_sitemap table.
459 460 461 462
 */
function simple_sitemap_update_8210() {

  $database = \Drupal::database();
463
  $database->truncate('simple_sitemap')->execute();
464

465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
  if (!$database->schema()->fieldExists('simple_sitemap', 'type')) {
    $database->schema()->addField(
      'simple_sitemap',
      'type', [
        'description' => 'Type of sitemap this chunk belongs to.',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ]
    );
  }
  if (!$database->schema()->fieldExists('simple_sitemap', 'delta')) {
    $database->schema()->addField(
      'simple_sitemap',
      'delta', [
        'description' => 'Delta of the chunk within the type scope.',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ]
    );
  }
489 490
}

491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
/**
 * Adding simple_sitemap.variants and simple_sitemap.types to configuration.
 */
function simple_sitemap_update_8211() {
  $config_factory = \Drupal::service('config.factory');

  // Add simple_sitemap.types.
  $config_factory
    ->getEditable('simple_sitemap.types.default_hreflang')
    ->setData([
      'label' => 'Default hreflang',
      'description' => 'The default hreflang sitemap type.',
      'sitemap_generator' => 'default',
      'url_generators' => [
        'custom',
        'entity',
        'entity_menu_link_content',
        'arbitrary',
      ],
    ])->save();

  // Add simple_sitemap.variants.
  $config_factory
    ->getEditable('simple_sitemap.variants')
    ->set('variants', [
      'default' => [
        'label' => 'Default',
        'type' => 'default_hreflang',
      ]
    ])->save();
}

523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
/**
 * Changing storage data type of 'index' and 'include_images' from integer to boolean.
 */
function simple_sitemap_update_8212() {

  // Update existing bundle settings.
  $config_factory = \Drupal::service('config.factory');
  $all_bundle_settings = $config_factory->listAll('simple_sitemap.bundle_settings.');

  foreach ($all_bundle_settings as $bundle_settings) {
    $config = $config_factory->get($bundle_settings)->get();

    $config['include_images'] = isset($config['include_images'])
      ? (bool) $config['include_images']
      : FALSE;

    $config['index'] = isset($config['index'])
      ? (bool) $config['index']
      : FALSE;

    $config_factory->getEditable($bundle_settings)->setData($config)->save();
  }

  // Update existing entity override data.
  $results = \Drupal::database()->select('simple_sitemap_entity_overrides', 'o')
    ->fields('o', ['id', 'inclusion_settings'])
    ->execute()->fetchAll(\PDO::FETCH_OBJ);

  foreach ($results as $row) {
    $settings = unserialize($row->inclusion_settings);

    if (isset($settings['index'])) {
      $settings['index'] = (bool) $settings['index'];
    }

    if (isset($settings['include_images'])) {
      $settings['include_images'] = (bool) $settings['include_images'];
    }

    \Drupal::database()->update('simple_sitemap_entity_overrides')
      ->fields(['inclusion_settings' => serialize($settings)])
      ->condition('id', $row->id)
      ->execute();
  }
}

569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
/**
 * Altering the configuration storage of variants.
 */
function simple_sitemap_update_8213() {
  $config_factory = \Drupal::service('config.factory');
  $new_variants = [];
  foreach ($config_factory->get('simple_sitemap.variants')->get('variants') as $variant_name => $variant_definition) {
    $new_variants[$variant_definition['type']][$variant_name] = ['label' => $variant_definition['label']];
  }

  // Create new configuration objects.
  foreach ($new_variants as $type => $variants) {
    $config_factory
      ->getEditable('simple_sitemap.variants.' . $type)
      ->set('variants', $variants)
      ->save();
  }

  // Remove old configuration object.
  $config_factory->getEditable('simple_sitemap.variants')->delete();
}
590

591 592 593 594 595 596 597 598 599 600 601 602
/**
 * Removing sitemap types from configuration as they are to be stored as plugins in code.
 */
function simple_sitemap_update_8214() {
  $config_factory = \Drupal::service('config.factory');
  $sitemap_types = $config_factory->listAll('simple_sitemap.types.');

  // Remove sitemap type configuration objects.
  foreach ($sitemap_types as $type) {
    $config_factory->getEditable($type)->delete();
  }
}
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633

/**
 * Adding 'status' field to simple_sitemap table and weight to variants.
 */
function simple_sitemap_update_8215() {
  $database = \Drupal::database();
  $database->truncate('simple_sitemap')->execute();

  if (!$database->schema()->fieldExists('simple_sitemap', 'status')) {
    $database->schema()->addField(
      'simple_sitemap',
      'status', [
        'description' => "Flag indicating the publishing status of the chunk.",
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ]
    );
  }

  $config_factory = \Drupal::service('config.factory');
  foreach ($config_factory->listAll('simple_sitemap.variants.') as $type) {
    $type = $config_factory->getEditable($type);
    $variants = $type->get('variants');
    foreach($variants as $i => $variant) {
      $variants[$i]['weight'] = 0;
    }
    $type->set('variants', $variants)->save();
  }
634 635 636 637 638 639 640 641 642 643 644
}

/**
 * Adding per-variant bundle and entity override configuration.
 */
function simple_sitemap_update_8216() {
  $config_factory = \Drupal::service('config.factory');
  foreach ($config_factory->listAll('simple_sitemap.bundle_settings.') as $bundle_config_name) {
    $config = $config_factory->getEditable($bundle_config_name);
    $config_name_parts = explode('.', $bundle_config_name);
    $config_factory->getEditable($config_name_parts[0] . '.' . $config_name_parts[1]
645
      . '.' . _simple_sitemap_update_8216_get_default_variant() . '.' . $config_name_parts[2] . '.' . $config_name_parts[3])
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
      ->setData($config->get())->save();

    $config->delete();
  }

  $database = \Drupal::database();
  if (!$database->schema()->fieldExists('simple_sitemap_entity_overrides', 'type')) {
    $database->schema()->addField(
      'simple_sitemap_entity_overrides',
      'type', [
        'description' => 'Type of sitemap this override belongs to.',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'initial' => 'default',
      ]
    );
  }
664 665 666 667 668 669 670 671 672 673 674
}

/**
 * Adding per-variant custom link configuration.
 */
function simple_sitemap_update_8217() {
  $config_factory = \Drupal::service('config.factory');
  $old_config = $config_factory->getEditable('simple_sitemap.custom');
  $config_factory->getEditable('simple_sitemap.custom_links.' . _simple_sitemap_update_8216_get_default_variant())
    ->setData($old_config->get())->save();
  $old_config->delete();
675 676 677

  return t('The XML sitemaps need to be regenerated.');
}
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706

/**
 * Changing id and delta fields of simple_sitemap table from smallint to int.
 */
function simple_sitemap_update_8301() {
  $schema = \Drupal::database()->schema();

  $schema->changeField(
    'simple_sitemap',
    'id',
    'id', [
      'description' => 'Sitemap chunk unique identifier.',
      'type' => 'int',
      'not null' => TRUE,
      'unsigned' => TRUE,
    ]
  );

  $schema->changeField(
    'simple_sitemap',
    'delta',
    'delta', [
      'description' => 'Delta of the chunk within the variant scope.',
      'type' => 'int',
      'not null' => TRUE,
      'unsigned' => TRUE,
    ]
  );
}