You are here

function simple_sitemap_update_8209 in Simple XML sitemap 8.2

Same name and namespace in other branches
  1. 8.3 simple_sitemap.install \simple_sitemap_update_8209()
  2. 4.x simple_sitemap.install \simple_sitemap_update_8209()

Adding image inclusion setting to all existing bundle and entity instance settings.

File

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

Code

function simple_sitemap_update_8209() {

  // 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['include_images'])) {
      $config_factory
        ->getEditable($entity_type)
        ->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();
    }
  }
  return t('You may now want to configure your sitemap entities to include images.');
}