You are here

function simple_sitemap_update_8208 in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 simple_sitemap.install \simple_sitemap_update_8208()
  2. 8.2 simple_sitemap.install \simple_sitemap_update_8208()

Adding changefreq setting to all existing bundle and entity instance settings.

File

./simple_sitemap.install, line 398
Module install and update procedures.

Code

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();
    }
  }
  return t('You may now want to configure the new changefreq setting for the XML sitemap entities and custom links.');
}