public static function UpdateKernel::fixSerializedExtensionObjects in Drupal 8
Fixes caches and theme info if they contain old Extension objects.
@internal This function is only to be called by the Drupal core update process. Additionally, this function will be removed in minor release of Drupal.
@todo https://www.drupal.org/project/drupal/issues/3031322 Remove once Drupal 8.6.x is not supported.
Parameters
\Symfony\Component\DependencyInjection\ContainerInterface $container: The container.
2 calls to UpdateKernel::fixSerializedExtensionObjects()
- UpdateKernel::loadLegacyIncludes in core/
lib/ Drupal/ Core/ Update/ UpdateKernel.php - Helper method that loads legacy Drupal include files.
- update_fix_compatibility in core/
includes/ update.inc - Disables any extensions that are incompatible with the current core version.
File
- core/
lib/ Drupal/ Core/ Update/ UpdateKernel.php, line 215
Class
- UpdateKernel
- Defines a kernel which is used primarily to run the update of Drupal.
Namespace
Drupal\Core\UpdateCode
public static function fixSerializedExtensionObjects(ContainerInterface $container) {
// Create a custom error handler that will clear caches if a warning occurs
// while getting 'system.theme.data' from state. If this state value was
// created by Drupal <= 8.6.7 then when it is read by Drupal >= 8.6.8 there
// will be PHP warnings. This silently fixes Drupal so that the update can
// continue.
$clear_caches = FALSE;
$callable = function ($errno, $errstr) use ($container, &$clear_caches) {
if ($errstr === 'Class Drupal\\Core\\Extension\\Extension has no unserializer') {
$clear_caches = TRUE;
}
};
set_error_handler($callable, E_ERROR | E_WARNING);
$container
->get('state')
->get('system.theme.data', []);
restore_error_handler();
if ($clear_caches) {
// Reset static caches in profile list so the module list is rebuilt
// correctly.
$container
->get('extension.list.profile')
->reset();
foreach ($container
->getParameter('cache_bins') as $service_id => $bin) {
$container
->get($service_id)
->deleteAll();
}
// The system.theme.data key is no longer used in Drupal 8.7.x.
$container
->get('state')
->delete('system.theme.data');
// Also rebuild themes because it uses state as cache.
$container
->get('theme_handler')
->refreshInfo();
}
}