comparison core/lib/Drupal/Core/Extension/ModuleInstaller.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 1fec387a4317
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
192 drupal_static_reset('system_rebuild_module_data'); 192 drupal_static_reset('system_rebuild_module_data');
193 193
194 // Update the kernel to include it. 194 // Update the kernel to include it.
195 $this->updateKernel($module_filenames); 195 $this->updateKernel($module_filenames);
196 196
197 // Replace the route provider service with a version that will rebuild
198 // if routes used during installation. This ensures that a module's
199 // routes are available during installation. This has to occur before
200 // any services that depend on it are instantiated otherwise those
201 // services will have the old route provider injected. Note that, since
202 // the container is rebuilt by updating the kernel, the route provider
203 // service is the regular one even though we are in a loop and might
204 // have replaced it before.
205 \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider'));
206 \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));
207
197 // Allow modules to react prior to the installation of a module. 208 // Allow modules to react prior to the installation of a module.
198 $this->moduleHandler->invokeAll('module_preinstall', [$module]); 209 $this->moduleHandler->invokeAll('module_preinstall', [$module]);
199 210
200 // Now install the module's schema if necessary. 211 // Now install the module's schema if necessary.
201 drupal_install_schema($module); 212 drupal_install_schema($module);
281 // @todo ThemeHandler cannot be injected into ModuleHandler, since that 292 // @todo ThemeHandler cannot be injected into ModuleHandler, since that
282 // causes a circular service dependency. 293 // causes a circular service dependency.
283 // @see https://www.drupal.org/node/2208429 294 // @see https://www.drupal.org/node/2208429
284 \Drupal::service('theme_handler')->refreshInfo(); 295 \Drupal::service('theme_handler')->refreshInfo();
285 296
286 // In order to make uninstalling transactional if anything uses routes.
287 \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider'));
288 \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder'));
289
290 // Allow the module to perform install tasks. 297 // Allow the module to perform install tasks.
291 $this->moduleHandler->invoke($module, 'install'); 298 $this->moduleHandler->invoke($module, 'install');
292 299
293 // Record the fact that it was installed. 300 // Record the fact that it was installed.
294 \Drupal::logger('system')->info('%module module installed.', ['%module' => $module]); 301 \Drupal::logger('system')->info('%module module installed.', ['%module' => $module]);
496 * 503 *
497 * @param string $module 504 * @param string $module
498 * The name of the module for which to remove all registered cache bins. 505 * The name of the module for which to remove all registered cache bins.
499 */ 506 */
500 protected function removeCacheBins($module) { 507 protected function removeCacheBins($module) {
501 // Remove any cache bins defined by a module.
502 $service_yaml_file = drupal_get_path('module', $module) . "/$module.services.yml"; 508 $service_yaml_file = drupal_get_path('module', $module) . "/$module.services.yml";
503 if (file_exists($service_yaml_file)) { 509 if (!file_exists($service_yaml_file)) {
504 $definitions = Yaml::decode(file_get_contents($service_yaml_file)); 510 return;
505 if (isset($definitions['services'])) { 511 }
506 foreach ($definitions['services'] as $id => $definition) { 512
507 if (isset($definition['tags'])) { 513 $definitions = Yaml::decode(file_get_contents($service_yaml_file));
508 foreach ($definition['tags'] as $tag) { 514
509 // This works for the default cache registration and even in some 515 $cache_bin_services = array_filter(
510 // cases when a non-default "super" factory is used. That should 516 isset($definitions['services']) ? $definitions['services'] : [],
511 // be extremely rare. 517 function ($definition) {
512 if ($tag['name'] == 'cache.bin' && isset($definition['factory_service']) && isset($definition['factory_method']) && !empty($definition['arguments'])) { 518 $tags = isset($definition['tags']) ? $definition['tags'] : [];
513 try { 519 foreach ($tags as $tag) {
514 $factory = \Drupal::service($definition['factory_service']); 520 if (isset($tag['name']) && ($tag['name'] == 'cache.bin')) {
515 if (method_exists($factory, $definition['factory_method'])) { 521 return TRUE;
516 $backend = call_user_func_array([$factory, $definition['factory_method']], $definition['arguments']); 522 }
517 if ($backend instanceof CacheBackendInterface) { 523 }
518 $backend->removeBin(); 524 return FALSE;
519 } 525 }
520 } 526 );
521 } 527
522 catch (\Exception $e) { 528 foreach (array_keys($cache_bin_services) as $service_id) {
523 watchdog_exception('system', $e, 'Failed to remove cache bin defined by the service %id.', ['%id' => $id]); 529 $backend = $this->kernel->getContainer()->get($service_id);
524 } 530 if ($backend instanceof CacheBackendInterface) {
525 } 531 $backend->removeBin();
526 }
527 }
528 }
529 } 532 }
530 } 533 }
531 } 534 }
532 535
533 /** 536 /**