You are here

function simple_sitemap_update_8209 in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 8.2 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 439
Module install and update procedures.

Code

function simple_sitemap_update_8209() {

  // 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();
    if (!isset($config['include_images'])) {
      $config_factory
        ->getEditable($bundle_settings)
        ->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 XML sitemap entities to include images.');
}