system.post_update.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * @file
  4. * Post update functions for System.
  5. */
  6. /**
  7. * @addtogroup updates-8.0.0-beta
  8. * @{
  9. */
  10. /**
  11. * Re-save all configuration entities to recalculate dependencies.
  12. */
  13. function system_post_update_recalculate_configuration_entity_dependencies(&$sandbox = NULL) {
  14. if (!isset($sandbox['config_names'])) {
  15. $sandbox['config_names'] = \Drupal::configFactory()->listAll();
  16. $sandbox['count'] = count($sandbox['config_names']);
  17. }
  18. /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
  19. $config_manager = \Drupal::service('config.manager');
  20. $count = 0;
  21. foreach ($sandbox['config_names'] as $key => $config_name) {
  22. if ($entity = $config_manager->loadConfigEntityByName($config_name)) {
  23. $entity->save();
  24. }
  25. unset($sandbox['config_names'][$key]);
  26. $count++;
  27. // Do 50 at a time.
  28. if ($count == 50) {
  29. break;
  30. }
  31. }
  32. $sandbox['#finished'] = empty($sandbox['config_names']) ? 1 : ($sandbox['count'] - count($sandbox['config_names'])) / $sandbox['count'];
  33. return t('Configuration dependencies recalculated');
  34. }
  35. /**
  36. * @} End of "addtogroup updates-8.0.0-beta".
  37. */