comparison core/lib/Drupal/Core/Extension/ModuleInstaller.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
91 // Nothing to do. All modules already installed. 91 // Nothing to do. All modules already installed.
92 return TRUE; 92 return TRUE;
93 } 93 }
94 94
95 // Add dependencies to the list. The new modules will be processed as 95 // Add dependencies to the list. The new modules will be processed as
96 // the while loop continues. 96 // the foreach loop continues.
97 while (list($module) = each($module_list)) { 97 foreach ($module_list as $module => $value) {
98 foreach (array_keys($module_data[$module]->requires) as $dependency) { 98 foreach (array_keys($module_data[$module]->requires) as $dependency) {
99 if (!isset($module_data[$dependency])) { 99 if (!isset($module_data[$dependency])) {
100 // The dependency does not exist. 100 // The dependency does not exist.
101 throw new MissingDependencyException("Unable to install modules: module '$module' is missing its dependency module $dependency."); 101 throw new MissingDependencyException("Unable to install modules: module '$module' is missing its dependency module $dependency.");
102 } 102 }
302 } 302 }
303 } 303 }
304 304
305 // If any modules were newly installed, invoke hook_modules_installed(). 305 // If any modules were newly installed, invoke hook_modules_installed().
306 if (!empty($modules_installed)) { 306 if (!empty($modules_installed)) {
307 \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old')); 307 // If the container was rebuilt during hook_install() it might not have
308 // the 'router.route_provider.old' service.
309 if (\Drupal::hasService('router.route_provider.old')) {
310 \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old'));
311 }
308 if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) { 312 if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) {
309 // Rebuild routes after installing module. This is done here on top of 313 // Rebuild routes after installing module. This is done here on top of
310 // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on 314 // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
311 // fastCGI which executes ::destruct() after the module installation 315 // fastCGI which executes ::destruct() after the module installation
312 // page was sent already. 316 // page was sent already.
338 return TRUE; 342 return TRUE;
339 } 343 }
340 344
341 if ($uninstall_dependents) { 345 if ($uninstall_dependents) {
342 // Add dependent modules to the list. The new modules will be processed as 346 // Add dependent modules to the list. The new modules will be processed as
343 // the while loop continues. 347 // the foreach loop continues.
344 $profile = drupal_get_profile(); 348 $profile = drupal_get_profile();
345 while (list($module) = each($module_list)) { 349 foreach ($module_list as $module => $value) {
346 foreach (array_keys($module_data[$module]->required_by) as $dependent) { 350 foreach (array_keys($module_data[$module]->required_by) as $dependent) {
347 if (!isset($module_data[$dependent])) { 351 if (!isset($module_data[$dependent])) {
348 // The dependent module does not exist. 352 // The dependent module does not exist.
349 return FALSE; 353 return FALSE;
350 } 354 }
413 foreach ($entity_manager->getDefinitions() as $entity_type) { 417 foreach ($entity_manager->getDefinitions() as $entity_type) {
414 if ($entity_type->getProvider() == $module) { 418 if ($entity_type->getProvider() == $module) {
415 $update_manager->uninstallEntityType($entity_type); 419 $update_manager->uninstallEntityType($entity_type);
416 } 420 }
417 elseif ($entity_type->entityClassImplements(FieldableEntityInterface::CLASS)) { 421 elseif ($entity_type->entityClassImplements(FieldableEntityInterface::CLASS)) {
418 // The module being installed may be adding new fields to existing 422 // The module being uninstalled might have added new fields to
419 // entity types. Field definitions for any entity type defined by 423 // existing entity types. This will add them to the deleted fields
420 // the module are handled in the if branch. 424 // repository so their data will be purged on cron.
421 $entity_type_id = $entity_type->id(); 425 foreach ($entity_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) {
422 /** @var \Drupal\Core\Entity\FieldableEntityStorageInterface $storage */ 426 if ($storage_definition->getProvider() == $module) {
423 $storage = $entity_manager->getStorage($entity_type_id);
424 foreach ($entity_manager->getFieldStorageDefinitions($entity_type_id) as $storage_definition) {
425 // @todo We need to trigger field purging here.
426 // See https://www.drupal.org/node/2282119.
427 if ($storage_definition->getProvider() == $module && !$storage->countFieldData($storage_definition, TRUE)) {
428 $update_manager->uninstallFieldStorageDefinition($storage_definition); 427 $update_manager->uninstallFieldStorageDefinition($storage_definition);
429 } 428 }
430 } 429 }
431 } 430 }
432 } 431 }