simple_sitemap.install 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. <?php
  2. /**
  3. * @file
  4. * Module install and update procedures.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. *
  9. * @param $phase
  10. * @return array
  11. */
  12. function simple_sitemap_requirements($phase) {
  13. $requirements = [];
  14. if (!extension_loaded('xmlwriter')) {
  15. $requirements['simple_sitemap_php_extensions'] = [
  16. 'title' => t('Simple XML sitemap PHP extensions'),
  17. 'value' => t('Missing PHP xmlwriter extension'),
  18. '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.'),
  19. 'severity' => REQUIREMENT_ERROR,
  20. ];
  21. }
  22. switch ($phase) {
  23. case 'runtime':
  24. // todo Implement for 3.x
  25. // /** @var \Drupal\simple_sitemap\Simplesitemap $generator */
  26. // $generator = \Drupal::service('simple_sitemap.generator');
  27. // $generated_ago = $generator->getGeneratedAgo();
  28. // $cron_generation = $generator->getSetting('cron_generate');
  29. //
  30. // if (!$generated_ago) {
  31. // $value = t('Not available');
  32. // $description = t($cron_generation
  33. // ? 'Run cron, or <a href="@generate">generate</a> the sitemap manually.'
  34. // : 'Generation on cron run is disabled. <a href="@generate">Generate</a> the sitemap manually.', [
  35. // '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
  36. // ]
  37. // );
  38. // $severity = REQUIREMENT_WARNING;
  39. // }
  40. // else {
  41. // $value = t('XML sitemaps are available');
  42. // $description = t('The last generation finished @ago ago.'
  43. // . ' ' . ($cron_generation
  44. // ? 'Run cron, or <a href="@generate">regenerate</a> the sitemaps manually.'
  45. // : 'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemaps manually.'), [
  46. // '@ago' => $generated_ago,
  47. // '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'
  48. // ]
  49. // );
  50. // $severity = REQUIREMENT_INFO;
  51. // }
  52. //
  53. // $requirements['simple_sitemap_generated'] = [
  54. // 'title' => 'Simple XML sitemap',
  55. // 'value' => $value,
  56. // 'description' => $description,
  57. // 'severity' => $severity,
  58. // ];
  59. break;
  60. }
  61. return $requirements;
  62. }
  63. /**
  64. * Implements hook_uninstall().
  65. */
  66. function simple_sitemap_uninstall() {
  67. \Drupal::service('state')->deleteMultiple([
  68. 'simple_sitemap.last_cron_generate',
  69. 'simple_sitemap.queue_items_initial_amount',
  70. 'simple_sitemap.queue_stashed_results',
  71. ]);
  72. \Drupal::service('queue')
  73. ->get('simple_sitemap_elements')
  74. ->deleteQueue();
  75. }
  76. /**
  77. * Implements hook_schema().
  78. */
  79. function simple_sitemap_schema() {
  80. $schema['simple_sitemap'] = [
  81. 'description' => 'Holds XML sitemaps as strings for quick retrieval.',
  82. 'fields' => [
  83. 'id' => [
  84. 'description' => 'Sitemap chunk unique identifier.',
  85. 'type' => 'int',
  86. 'size' => 'small',
  87. 'not null' => TRUE,
  88. 'unsigned' => TRUE,
  89. ],
  90. 'type' => [
  91. 'description' => 'Type of sitemap this chunk belongs to.',
  92. 'type' => 'varchar',
  93. 'length' => 50,
  94. 'not null' => TRUE,
  95. 'default' => '',
  96. ],
  97. 'delta' => [
  98. 'description' => 'Delta of the chunk within the type scope.',
  99. 'type' => 'int',
  100. 'size' => 'small',
  101. 'not null' => TRUE,
  102. 'unsigned' => TRUE,
  103. ],
  104. 'sitemap_string' => [
  105. 'description' => 'XML sitemap chunk string.',
  106. 'type' => 'text',
  107. 'size' => 'big',
  108. 'not null' => TRUE,
  109. ],
  110. 'sitemap_created' => [
  111. 'description' => 'Timestamp of sitemap chunk generation.',
  112. 'type' => 'int',
  113. 'not null' => TRUE,
  114. 'unsigned' => TRUE,
  115. 'default' => 0,
  116. ],
  117. 'status' => [
  118. 'description' => "Flag indicating the publishing status of the chunk.",
  119. 'type' => 'int',
  120. 'size' => 'tiny',
  121. 'not null' => TRUE,
  122. 'unsigned' => TRUE,
  123. 'default' => 0,
  124. ],
  125. ],
  126. 'primary key' => ['id'],
  127. ];
  128. $schema['simple_sitemap_entity_overrides'] = [
  129. 'description' => 'Holds sitemap settings overridden by entities.',
  130. 'fields' => [
  131. 'id' => [
  132. 'description' => 'Override unique identifier.',
  133. 'type' => 'serial',
  134. 'not null' => TRUE,
  135. 'unsigned' => TRUE,
  136. ],
  137. 'type' => [
  138. 'description' => 'Type of sitemap this override belongs to.',
  139. 'type' => 'varchar',
  140. 'length' => 50,
  141. 'not null' => TRUE,
  142. ],
  143. 'entity_type' => [
  144. 'description' => 'Entity type of the overriding entity.',
  145. 'type' => 'varchar',
  146. 'length' => 32,
  147. 'not null' => TRUE,
  148. ],
  149. 'entity_id' => [
  150. 'description' => 'ID of the overriding entity.',
  151. 'type' => 'varchar',
  152. 'length' => 32,
  153. 'not null' => TRUE,
  154. ],
  155. 'inclusion_settings' => [
  156. 'description' => 'Setting for the overriding entity.',
  157. 'type' => 'blob',
  158. ],
  159. ],
  160. 'primary key' => ['id'],
  161. ];
  162. return $schema;
  163. }
  164. function _simple_sitemap_update_8216_get_default_variant() {
  165. $config_factory = \Drupal::service('config.factory');
  166. $default_variant = $config_factory->get('simple_sitemap.settings')->get('default_variant');
  167. if (empty($default_variant)) {
  168. $default_variant = 'default';
  169. $config_factory->getEditable('simple_sitemap.settings')
  170. ->set('default_variant', $default_variant)
  171. ->save();
  172. }
  173. /** @var \Drupal\simple_sitemap\SimplesitemapManager $manager */
  174. $manager = \Drupal::service('simple_sitemap.manager');
  175. $variants = $manager->getSitemapVariants();
  176. if (!isset($variants[$default_variant])) {
  177. $manager->addSitemapVariant($default_variant);
  178. }
  179. return $default_variant;
  180. }
  181. /**
  182. * Changing the data structure of the module's configuration.
  183. */
  184. function simple_sitemap_update_8201() {
  185. $entity_types = \Drupal::config('simple_sitemap.settings')->get('entity_types');
  186. $entity_types = is_array($entity_types) ? $entity_types : [];
  187. $naming_changes = [
  188. 'node_type' => 'node',
  189. 'taxonomy_vocabulary' => 'taxonomy_term',
  190. 'menu' => 'menu_link_content',
  191. 'commerce_product_type' => 'commerce_product',
  192. 'media_bundle' => 'media',
  193. ];
  194. foreach ($entity_types as $entity_type_name => $settings) {
  195. if (isset($naming_changes[$entity_type_name])) {
  196. $entity_types[$naming_changes[$entity_type_name]] = $entity_types[$entity_type_name];
  197. unset($entity_types[$entity_type_name]);
  198. }
  199. }
  200. \Drupal::service('config.factory')->getEditable('simple_sitemap.settings')
  201. ->set('entity_types', $entity_types)->save();
  202. }
  203. /**
  204. * Moving entity overrides from configuration to database table.
  205. */
  206. function simple_sitemap_update_8202() {
  207. $database = \Drupal::database();
  208. // Create database table.
  209. if (!$database->schema()->tableExists('simple_sitemap_entity_overrides')) {
  210. $database->schema()->createTable('simple_sitemap_entity_overrides', [
  211. 'description' => 'Holds sitemap settings overridden by entities.',
  212. 'fields' => [
  213. 'id' => [
  214. 'description' => 'Override unique identifier.',
  215. 'type' => 'serial',
  216. 'unsigned' => TRUE,
  217. 'not null' => TRUE,
  218. ],
  219. 'entity_type' => [
  220. 'description' => 'Entity type of the overriding entity.',
  221. 'type' => 'varchar',
  222. 'length' => 32,
  223. 'not null' => TRUE,
  224. ],
  225. 'entity_id' => [
  226. 'description' => 'ID of the overriding entity.',
  227. 'type' => 'int',
  228. 'unsigned' => TRUE,
  229. 'not null' => TRUE,
  230. ],
  231. 'inclusion_settings' => [
  232. 'description' => 'Setting for the overriding entity.',
  233. 'type' => 'blob',
  234. ],
  235. ],
  236. 'primary key' => ['id'],
  237. ]);
  238. }
  239. // Populate database table with config values.
  240. $entity_types = \Drupal::config('simple_sitemap.settings')->get('entity_types');
  241. $entity_types = is_array($entity_types) ? $entity_types : [];
  242. foreach ($entity_types as $entity_type_name => &$entity_type) {
  243. if (is_array($entity_type)) {
  244. foreach ($entity_type as $bundle_name => &$bundle) {
  245. if (isset($bundle['entities'])) {
  246. foreach ($bundle['entities'] as $entity_id => $entity_settings) {
  247. $database->insert('simple_sitemap_entity_overrides')
  248. ->fields([
  249. 'entity_type' => $entity_type_name,
  250. 'entity_id' => $entity_id,
  251. 'inclusion_settings' => serialize($entity_settings),
  252. ])
  253. ->execute();
  254. }
  255. // Remove entity overrides from configuration.
  256. unset($bundle['entities']);
  257. }
  258. }
  259. }
  260. }
  261. \Drupal::service('config.factory')->getEditable('simple_sitemap.settings')
  262. ->set('entity_types', $entity_types)->save();
  263. }
  264. /**
  265. * Splitting simple_sitemap.settings configuration into simple_sitemap.settings,
  266. * simple_sitemap.entity_types and simple_sitemap.custom.
  267. */
  268. function simple_sitemap_update_8203() {
  269. $old_config = $config = \Drupal::config('simple_sitemap.settings');
  270. foreach (['entity_types', 'custom'] as $config_name) {
  271. if (!$config = $old_config->get($config_name)) {
  272. continue;
  273. }
  274. \Drupal::service('config.factory')->getEditable("simple_sitemap.$config_name")
  275. ->setData($config)->save();
  276. }
  277. $settings = $old_config->get('settings');
  278. \Drupal::service('config.factory')->getEditable("simple_sitemap.settings")
  279. ->setData($settings)->save();
  280. }
  281. /**
  282. * Removing entity type settings for entity types which do not have the canonical
  283. * link template.
  284. */
  285. function simple_sitemap_update_8204() {
  286. $sitemap_entity_types = \Drupal::service('entity_type.manager')->getDefinitions();
  287. $entity_types = \Drupal::config('simple_sitemap.entity_types')->get();
  288. unset($entity_types['_core']);
  289. foreach ($entity_types as $entity_type_id => $entity_type) {
  290. if (!isset($sitemap_entity_types[$entity_type_id])
  291. || !$sitemap_entity_types[$entity_type_id]->hasLinkTemplate('canonical')) {
  292. // Delete entity overrides.
  293. \Drupal::database()->delete('simple_sitemap_entity_overrides')
  294. ->condition('entity_type', $entity_type_id)
  295. ->execute();
  296. // Delete entity type settings.
  297. unset($entity_types[$entity_type_id]);
  298. }
  299. }
  300. \Drupal::service('config.factory')->getEditable("simple_sitemap.entity_types")
  301. ->setData($entity_types)->save();
  302. }
  303. /**
  304. * Splitting simple_sitemap.entity_types into individual configuration objects
  305. * for each bundle.
  306. */
  307. function simple_sitemap_update_8205() {
  308. $entity_types = \Drupal::config('simple_sitemap.entity_types')->get();
  309. unset($entity_types['_core']);
  310. $enabled_entity_types = [];
  311. foreach ($entity_types as $entity_type_id => $bundles) {
  312. $enabled_entity_types[] = $entity_type_id;
  313. foreach ($bundles as $bundle_name => $bundle_settings) {
  314. \Drupal::service('config.factory')
  315. ->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle_name")
  316. ->setData($bundle_settings)->save();
  317. }
  318. }
  319. // Add enabled entity type settings.
  320. \Drupal::service('config.factory')
  321. ->getEditable('simple_sitemap.settings')
  322. ->set('enabled_entity_types', $enabled_entity_types)
  323. ->save();
  324. // Remove old configuration object.
  325. \Drupal::service('config.factory')
  326. ->getEditable('simple_sitemap.entity_types')
  327. ->delete();
  328. }
  329. /**
  330. * Placing custom links in a subkey of simple_sitemap.custom configuration.
  331. */
  332. function simple_sitemap_update_8206() {
  333. $custom_links = \Drupal::config('simple_sitemap.custom')->get();
  334. foreach ($custom_links as $i => $custom_link) {
  335. if (!isset($custom_link['path'])) {
  336. unset($custom_links[$i]);
  337. }
  338. }
  339. \Drupal::service('config.factory')->getEditable('simple_sitemap.custom')
  340. ->setData(['links' => $custom_links])->save();
  341. }
  342. /**
  343. * Updating entity_id field of simple_sitemap_entity_overrides table to varchar(32).
  344. */
  345. function simple_sitemap_update_8207() {
  346. \Drupal::database()->schema()->changeField(
  347. 'simple_sitemap_entity_overrides',
  348. 'entity_id',
  349. 'entity_id', [
  350. 'description' => 'ID of the overriding entity.',
  351. 'type' => 'varchar',
  352. 'length' => 32,
  353. 'not null' => TRUE,
  354. ]
  355. );
  356. }
  357. /**
  358. * Adding changefreq setting to all existing bundle and entity instance settings.
  359. */
  360. function simple_sitemap_update_8208() {
  361. // Update existing bundle settings.
  362. $config_factory = \Drupal::service('config.factory');
  363. $entity_types = $config_factory->listAll('simple_sitemap.bundle_settings.');
  364. foreach ($entity_types as $entity_type) {
  365. $config = $config_factory->get($entity_type)->get();
  366. if (!isset($config['changefreq'])) {
  367. $config_factory->getEditable($entity_type)
  368. ->setData($config + ['changefreq' => ''])
  369. ->save();
  370. }
  371. }
  372. // Update existing entity override data.
  373. $results = \Drupal::database()->select('simple_sitemap_entity_overrides', 'o')
  374. ->fields('o', ['id', 'inclusion_settings'])
  375. ->execute()->fetchAll(\PDO::FETCH_OBJ);
  376. foreach ($results as $row) {
  377. $settings = unserialize($row->inclusion_settings);
  378. if (!isset($settings['changefreq'])) {
  379. \Drupal::database()->update('simple_sitemap_entity_overrides')
  380. ->fields(['inclusion_settings' => serialize($settings + ['changefreq' => '']),])
  381. ->condition('id', $row->id)
  382. ->execute();
  383. }
  384. }
  385. return t('You may now want to configure the new changefreq setting for the XML sitemap entities and custom links.');
  386. }
  387. /**
  388. * Adding image inclusion setting to all existing bundle and entity instance settings.
  389. */
  390. function simple_sitemap_update_8209() {
  391. // Update existing bundle settings.
  392. $config_factory = \Drupal::service('config.factory');
  393. $all_bundle_settings = $config_factory->listAll('simple_sitemap.bundle_settings.');
  394. foreach ($all_bundle_settings as $bundle_settings) {
  395. $config = $config_factory->get($bundle_settings)->get();
  396. if (!isset($config['include_images'])) {
  397. $config_factory->getEditable($bundle_settings)
  398. ->setData($config + ['include_images' => 0])
  399. ->save();
  400. }
  401. }
  402. // Update existing entity override data.
  403. $results = \Drupal::database()->select('simple_sitemap_entity_overrides', 'o')
  404. ->fields('o', ['id', 'inclusion_settings'])
  405. ->execute()->fetchAll(\PDO::FETCH_OBJ);
  406. foreach ($results as $row) {
  407. $settings = unserialize($row->inclusion_settings);
  408. if (!isset($settings['include_images'])) {
  409. \Drupal::database()->update('simple_sitemap_entity_overrides')
  410. ->fields(['inclusion_settings' => serialize($settings + ['include_images' => 0]),])
  411. ->condition('id', $row->id)
  412. ->execute();
  413. }
  414. }
  415. return t('You may now want to configure your XML sitemap entities to include images.');
  416. }
  417. /**
  418. * Adding 'type' and 'delta' fields to simple_sitemap table.
  419. */
  420. function simple_sitemap_update_8210() {
  421. $database = \Drupal::database();
  422. $database->truncate('simple_sitemap')->execute();
  423. if (!$database->schema()->fieldExists('simple_sitemap', 'type')) {
  424. $database->schema()->addField(
  425. 'simple_sitemap',
  426. 'type', [
  427. 'description' => 'Type of sitemap this chunk belongs to.',
  428. 'type' => 'varchar',
  429. 'length' => 50,
  430. 'not null' => TRUE,
  431. 'default' => '',
  432. ]
  433. );
  434. }
  435. if (!$database->schema()->fieldExists('simple_sitemap', 'delta')) {
  436. $database->schema()->addField(
  437. 'simple_sitemap',
  438. 'delta', [
  439. 'description' => 'Delta of the chunk within the type scope.',
  440. 'type' => 'int',
  441. 'size' => 'small',
  442. 'not null' => TRUE,
  443. 'unsigned' => TRUE,
  444. ]
  445. );
  446. }
  447. }
  448. /**
  449. * Adding simple_sitemap.variants and simple_sitemap.types to configuration.
  450. */
  451. function simple_sitemap_update_8211() {
  452. $config_factory = \Drupal::service('config.factory');
  453. // Add simple_sitemap.types.
  454. $config_factory
  455. ->getEditable('simple_sitemap.types.default_hreflang')
  456. ->setData([
  457. 'label' => 'Default hreflang',
  458. 'description' => 'The default hreflang sitemap type.',
  459. 'sitemap_generator' => 'default',
  460. 'url_generators' => [
  461. 'custom',
  462. 'entity',
  463. 'entity_menu_link_content',
  464. 'arbitrary',
  465. ],
  466. ])->save();
  467. // Add simple_sitemap.variants.
  468. $config_factory
  469. ->getEditable('simple_sitemap.variants')
  470. ->set('variants', [
  471. 'default' => [
  472. 'label' => 'Default',
  473. 'type' => 'default_hreflang',
  474. ]
  475. ])->save();
  476. }
  477. /**
  478. * Changing storage data type of 'index' and 'include_images' from integer to boolean.
  479. */
  480. function simple_sitemap_update_8212() {
  481. // Update existing bundle settings.
  482. $config_factory = \Drupal::service('config.factory');
  483. $all_bundle_settings = $config_factory->listAll('simple_sitemap.bundle_settings.');
  484. foreach ($all_bundle_settings as $bundle_settings) {
  485. $config = $config_factory->get($bundle_settings)->get();
  486. $config['include_images'] = isset($config['include_images'])
  487. ? (bool) $config['include_images']
  488. : FALSE;
  489. $config['index'] = isset($config['index'])
  490. ? (bool) $config['index']
  491. : FALSE;
  492. $config_factory->getEditable($bundle_settings)->setData($config)->save();
  493. }
  494. // Update existing entity override data.
  495. $results = \Drupal::database()->select('simple_sitemap_entity_overrides', 'o')
  496. ->fields('o', ['id', 'inclusion_settings'])
  497. ->execute()->fetchAll(\PDO::FETCH_OBJ);
  498. foreach ($results as $row) {
  499. $settings = unserialize($row->inclusion_settings);
  500. if (isset($settings['index'])) {
  501. $settings['index'] = (bool) $settings['index'];
  502. }
  503. if (isset($settings['include_images'])) {
  504. $settings['include_images'] = (bool) $settings['include_images'];
  505. }
  506. \Drupal::database()->update('simple_sitemap_entity_overrides')
  507. ->fields(['inclusion_settings' => serialize($settings)])
  508. ->condition('id', $row->id)
  509. ->execute();
  510. }
  511. }
  512. /**
  513. * Altering the configuration storage of variants.
  514. */
  515. function simple_sitemap_update_8213() {
  516. $config_factory = \Drupal::service('config.factory');
  517. $new_variants = [];
  518. foreach ($config_factory->get('simple_sitemap.variants')->get('variants') as $variant_name => $variant_definition) {
  519. $new_variants[$variant_definition['type']][$variant_name] = ['label' => $variant_definition['label']];
  520. }
  521. // Create new configuration objects.
  522. foreach ($new_variants as $type => $variants) {
  523. $config_factory
  524. ->getEditable('simple_sitemap.variants.' . $type)
  525. ->set('variants', $variants)
  526. ->save();
  527. }
  528. // Remove old configuration object.
  529. $config_factory->getEditable('simple_sitemap.variants')->delete();
  530. }
  531. /**
  532. * Removing sitemap types from configuration as they are to be stored as plugins in code.
  533. */
  534. function simple_sitemap_update_8214() {
  535. $config_factory = \Drupal::service('config.factory');
  536. $sitemap_types = $config_factory->listAll('simple_sitemap.types.');
  537. // Remove sitemap type configuration objects.
  538. foreach ($sitemap_types as $type) {
  539. $config_factory->getEditable($type)->delete();
  540. }
  541. }
  542. /**
  543. * Adding 'status' field to simple_sitemap table and weight to variants.
  544. */
  545. function simple_sitemap_update_8215() {
  546. $database = \Drupal::database();
  547. $database->truncate('simple_sitemap')->execute();
  548. if (!$database->schema()->fieldExists('simple_sitemap', 'status')) {
  549. $database->schema()->addField(
  550. 'simple_sitemap',
  551. 'status', [
  552. 'description' => "Flag indicating the publishing status of the chunk.",
  553. 'type' => 'int',
  554. 'size' => 'tiny',
  555. 'not null' => TRUE,
  556. 'unsigned' => TRUE,
  557. 'default' => 0,
  558. ]
  559. );
  560. }
  561. $config_factory = \Drupal::service('config.factory');
  562. foreach ($config_factory->listAll('simple_sitemap.variants.') as $type) {
  563. $type = $config_factory->getEditable($type);
  564. $variants = $type->get('variants');
  565. foreach($variants as $i => $variant) {
  566. $variants[$i]['weight'] = 0;
  567. }
  568. $type->set('variants', $variants)->save();
  569. }
  570. }
  571. /**
  572. * Adding per-variant bundle and entity override configuration.
  573. */
  574. function simple_sitemap_update_8216() {
  575. $config_factory = \Drupal::service('config.factory');
  576. foreach ($config_factory->listAll('simple_sitemap.bundle_settings.') as $bundle_config_name) {
  577. $config = $config_factory->getEditable($bundle_config_name);
  578. $config_name_parts = explode('.', $bundle_config_name);
  579. $config_factory->getEditable($config_name_parts[0] . '.' . $config_name_parts[1]
  580. . '.' . _simple_sitemap_update_8216_get_default_variant() . '.' . $config_name_parts[2] . '.' . $config_name_parts[3])
  581. ->setData($config->get())->save();
  582. $config->delete();
  583. }
  584. $database = \Drupal::database();
  585. if (!$database->schema()->fieldExists('simple_sitemap_entity_overrides', 'type')) {
  586. $database->schema()->addField(
  587. 'simple_sitemap_entity_overrides',
  588. 'type', [
  589. 'description' => 'Type of sitemap this override belongs to.',
  590. 'type' => 'varchar',
  591. 'length' => 50,
  592. 'not null' => TRUE,
  593. 'initial' => 'default',
  594. ]
  595. );
  596. }
  597. }
  598. /**
  599. * Adding per-variant custom link configuration.
  600. */
  601. function simple_sitemap_update_8217() {
  602. $config_factory = \Drupal::service('config.factory');
  603. $old_config = $config_factory->getEditable('simple_sitemap.custom');
  604. $config_factory->getEditable('simple_sitemap.custom_links.' . _simple_sitemap_update_8216_get_default_variant())
  605. ->setData($old_config->get())->save();
  606. $old_config->delete();
  607. return t('The XML sitemaps need to be regenerated.');
  608. }