function elysia_cron_check_version_update() { $ver = variable_get('elysia_cron_version', 0); if ($ver < 20111012) { $ver = _ec_variable_get('elysia_cron_version', 0); } if (!$ver || $ver < 20090218) { $unchanged = array('elysia_cron_last_context', 'elysia_cron_last_run', 'elysia_cron_disabled', 'elysia_cron_semaphore', 'elysia_cron_key', 'elysia_cron_allowed_hosts', 'elysia_cron_default_rule', 'elysia_cron_script', 'elysia_cron_runtime_replacement', 'elysia_cron_version'); $rs = db_query('select * from {variable} where name like "elysia_cron_%%"'); while ($v = db_fetch_object($rs)) { if (!in_array($v->name, $unchanged)) { $vn = false; if (preg_match('/^elysia_cron_ctx_(.*)_(running|disabled|last_run|last_aborted|abort_count|execution_count|last_execution_time|avg_execution_time|max_execution_time|last_shutdown_time|last_abort_function)/', $v->name, $r)) { switch ($r[2]) { case 'running': $vn = 'ecc_' . _ec_get_name($r[1]) . '_r'; break; case 'disabled': $vn = 'ecc_' . _ec_get_name($r[1]) . '_d'; break; case 'last_run': $vn = 'ecc_' . _ec_get_name($r[1]) . '_lr'; break; case 'last_aborted': $vn = 'ecc_' . _ec_get_name($r[1]) . '_la'; break; case 'abort_count': $vn = 'ecc_' . _ec_get_name($r[1]) . '_ac'; break; case 'execution_count': $vn = 'ecc_' . _ec_get_name($r[1]) . '_ec'; break; case 'last_execution_time': $vn = 'ecc_' . _ec_get_name($r[1]) . '_let'; break; case 'avg_execution_time': $vn = 'ecc_' . _ec_get_name($r[1]) . '_aet'; break; case 'max_execution_time': $vn = 'ecc_' . _ec_get_name($r[1]) . '_met'; break; case 'last_shutdown_time': $vn = 'ecc_' . _ec_get_name($r[1]) . '_lst'; break; case 'last_abort_function': $vn = 'ecc_' . _ec_get_name($r[1]) . '_laf'; break; } } elseif (preg_match('/^elysia_cron_(.*)_(rule|disabled|context|running|last_run|last_execution_time|execution_count|avg_execution_time|max_execution_time)/', $v->name, $r)) { switch ($r[2]) { case 'rule': $vn = 'ec_' . _ec_get_name($r[1]) . '_rul'; break; case 'disabled': $vn = 'ec_' . _ec_get_name($r[1]) . '_d'; break; case 'context': $vn = 'ec_' . _ec_get_name($r[1]) . '_c'; break; case 'running': $vn = 'ec_' . _ec_get_name($r[1]) . '_r'; break; case 'last_run': $vn = 'ec_' . _ec_get_name($r[1]) . '_lr'; break; case 'last_execution_time': $vn = 'ec_' . _ec_get_name($r[1]) . '_let'; break; case 'execution_count': $vn = 'ec_' . _ec_get_name($r[1]) . '_ec'; break; case 'avg_execution_time': $vn = 'ec_' . _ec_get_name($r[1]) . '_aet'; break; case 'max_execution_time': $vn = 'ec_' . _ec_get_name($r[1]) . '_met'; break; } } if ($vn) { variable_set($vn, unserialize($v->value)); } else { _dco_watchdog('cron', 'Error in update, cant convert %name (value: %value)', array('%name' => $v->name, '%value' => $v->value), WATCHDOG_ERROR); } variable_del($v->name); } } variable_set('elysia_cron_version', 20090218); } if ($ver < 20090920) { variable_set('elysia_cron_version', 20090920); } if ($ver < 20100507) { if (EC_DRUPAL_VERSION >= 6) { // D6 drupal_install_schema('elysia_cron'); // In ver 20111020 disabled has been renamed to disable, revert it now if (EC_DRUPAL_VERSION >= 7) { // D7 // Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here) db_change_field($v = 'elysia_cron', 'disable', 'disabled', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE)); } elseif (EC_DRUPAL_VERSION >= 6) { // D6 $ret = array(); db_change_field($ret, 'elysia_cron', 'disable', 'disabled', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE)); } } else { // D5 switch ($GLOBALS['db_type']) { case 'mysqli': case 'mysql': db_query("create table if not exists {elysia_cron} (\r\n name varchar(120) not null,\r\n disabled tinyint(1) not null default '0',\r\n rule varchar(32),\r\n weight int(11) not null default '0',\r\n context varchar(32),\r\n running int(11) not null default '0',\r\n last_run int(11) not null default '0',\r\n last_aborted tinyint(1) not null default '0',\r\n abort_count int(11) not null default '0',\r\n last_abort_function varchar(32),\r\n last_execution_time int(11) not null default '0',\r\n execution_count int(11) not null default '0',\r\n avg_execution_time float(5,2) not null default '0',\r\n max_execution_time int(11) not null default '0',\r\n last_shutdown_time int(11) not null default '0',\r\n primary key (name)\r\n )"); break; case 'pgsql': db_query("create table {elysia_cron} (\r\n name varchar(120) not null,\r\n disabled smallint not null default '0',\r\n rule varchar(32),\r\n weight integer not null default '0',\r\n context varchar(32),\r\n running int not null default '0',\r\n last_run integer not null default '0',\r\n last_aborted smallint not null default '0',\r\n abort_count integer not null default '0',\r\n last_abort_function varchar(32),\r\n last_execution_time integer not null default '0',\r\n execution_count integer not null default '0',\r\n avg_execution_time float not null default '0',\r\n max_execution_time integer not null default '0',\r\n last_shutdown_time integer not null default '0',\r\n primary key (name)\r\n )"); } } $rs = db_query('select * from {variable} where name like "ec_%%" or name like "ecc_%%"'); $data = array(); $todelete = array(); while ($v = db_fetch_object($rs)) { $name = false; if (preg_match('/^ecc_(.+)_(r|d|lr|la|ac|ec|let|aet|met|lst|laf)/', $v->name, $r)) { $name = ':' . $r[1]; } elseif (preg_match('/^ec_(.+)_(rul|d|c|w|r|lr|let|ec|aet|met)/', $v->name, $r)) { $name = $r[1]; } if ($name) { if (!isset($data[$name])) { $data[$name] = array('name' => $name); } switch ($r[2]) { case 'r': $f = 'running'; break; case 'd': $f = 'disabled'; break; case 'rul': $f = 'rule'; break; case 'w': $f = 'weight'; break; case 'c': $f = 'context'; break; case 'lr': $f = 'last_run'; break; case 'la': $f = 'last_aborted'; break; case 'ac': $f = 'abort_count'; break; case 'laf': $f = 'last_abort_function'; break; case 'let': $f = 'last_execution_time'; break; case 'ec': $f = 'execution_count'; break; case 'aet': $f = 'avg_execution_time'; break; case 'met': $f = 'max_execution_time'; break; case 'lst': $f = 'last_shutdown_time'; break; } $data[$name][$f] = unserialize($v->value); $todelete[] = $v->name; } } $ifields = array('disabled', 'weight', 'running', 'last_run', 'last_aborted', 'abort_count', 'last_execution_time', 'execution_count', 'avg_execution_time', 'max_execution_time', 'last_shutdown_time'); foreach ($data as $v) { foreach ($ifields as $f) { if (empty($v[$f])) { $v[$f] = 0; } } db_query("insert into {elysia_cron} (name, disabled, rule, weight, context, running, last_run, last_aborted, abort_count, last_abort_function, last_execution_time, execution_count, avg_execution_time, max_execution_time, last_shutdown_time)\r\n values ('%s', %d, '%s', %d, '%s', %d, %d, %d, %d, '%s', %d, %d, %f, %d, %d)", $v['name'], $v['disabled'], $v['rule'], $v['weight'], $v['context'], $v['running'], $v['last_run'], $v['last_aborted'], $v['abort_count'], $v['last_abort_function'], $v['last_execution_time'], $v['execution_count'], $v['avg_execution_time'], $v['max_execution_time'], $v['last_shutdown_time']); } db_query("update {elysia_cron} set context = null where context = ''"); db_query("update {elysia_cron} set rule = null where rule = ''"); foreach ($todelete as $v) { variable_del($v); db_query("DELETE FROM {variable} WHERE name = '%s'", $v); } variable_set('elysia_cron_version', 20100507); unset($GLOBALS['_ec_variables']); } // D7 VERSION FROM NOW ON... if ($ver < 20110323) { if (EC_DRUPAL_VERSION >= 7) { // D7 // Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here) db_change_field($v = 'elysia_cron', 'weight', 'weight', array('type' => 'int', 'not null' => FALSE)); } elseif (EC_DRUPAL_VERSION >= 6) { // D6 $ret = array(); db_change_field($ret, 'elysia_cron', 'weight', 'weight', array('type' => 'int', 'not null' => FALSE)); } else { // D5 db_query("alter table {elysia_cron} change weight weight int(11)"); } variable_set('elysia_cron_version', 20110323); } if ($ver < 20111007) { $default_rules = variable_get('elysia_cron_default_rules', $GLOBALS['elysia_cron_default_rules']); if (!empty($default_rules['*/6 * * * *']) && $default_rules['*/6 * * * *'] == 'Every 6 hours') { unset($default_rules['*/6 * * * *']); $default_rules['0 */6 * * *'] = 'Every 6 hours'; variable_set('elysia_cron_default_rules', $default_rules); } variable_set('elysia_cron_version', 20111007); } if ($ver < 20111012) { // I only need to rebuild variable cache, so i just set the new version variable_set('elysia_cron_version', 20111012); } if ($ver < 20111020) { if (EC_DRUPAL_VERSION >= 7) { // D7 // Must use "$v" for PHP5.3 running D6 version (detect the error even if it doesn't pass here) db_change_field($v = 'elysia_cron', 'disabled', 'disable', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE)); } elseif (EC_DRUPAL_VERSION >= 6) { // D6 $ret = array(); db_change_field($ret, 'elysia_cron', 'disabled', 'disable', array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE)); } else { // D5 db_query("alter table {elysia_cron} change disabled disable tinyint(1)"); } db_query("update {elysia_cron} set disable = NULL where disable = 0"); variable_set('elysia_cron_version', 20111020); } }
/** * {@inheritdoc} */ public function install(array $module_list, $enable_dependencies = TRUE) { $extension_config = \Drupal::config('core.extension'); if ($enable_dependencies) { // Get all module data so we can find dependencies and sort. $module_data = system_rebuild_module_data(); $module_list = $module_list ? array_combine($module_list, $module_list) : array(); if (array_diff_key($module_list, $module_data)) { // One or more of the given modules doesn't exist. return FALSE; } // Only process currently uninstalled modules. $installed_modules = $extension_config->get('module') ?: array(); if (!($module_list = array_diff_key($module_list, $installed_modules))) { // Nothing to do. All modules already installed. return TRUE; } // Add dependencies to the list. The new modules will be processed as // the while loop continues. while (list($module) = each($module_list)) { foreach (array_keys($module_data[$module]->requires) as $dependency) { if (!isset($module_data[$dependency])) { // The dependency does not exist. return FALSE; } // Skip already installed modules. if (!isset($module_list[$dependency]) && !isset($installed_modules[$dependency])) { $module_list[$dependency] = $dependency; } } } // Set the actual module weights. $module_list = array_map(function ($module) use($module_data) { return $module_data[$module]->sort; }, $module_list); // Sort the module list by their weights (reverse). arsort($module_list); $module_list = array_keys($module_list); } // Required for module installation checks. include_once DRUPAL_ROOT . '/core/includes/install.inc'; /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */ $config_installer = \Drupal::service('config.installer'); $sync_status = $config_installer->isSyncing(); if ($sync_status) { $source_storage = $config_installer->getSourceStorage(); } $modules_installed = array(); foreach ($module_list as $module) { $enabled = $extension_config->get("module.{$module}") !== NULL; if (!$enabled) { // Throw an exception if the module name is too long. if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) { throw new ExtensionNameLengthException(format_string('Module name %name is over the maximum allowed length of @max characters.', array('%name' => $module, '@max' => DRUPAL_EXTENSION_NAME_MAX_LENGTH))); } $extension_config->set("module.{$module}", 0)->set('module', module_config_sort($extension_config->get('module')))->save(); // Prepare the new module list, sorted by weight, including filenames. // This list is used for both the ModuleHandler and DrupalKernel. It // needs to be kept in sync between both. A DrupalKernel reboot or // rebuild will automatically re-instantiate a new ModuleHandler that // uses the new module list of the kernel. However, DrupalKernel does // not cause any modules to be loaded. // Furthermore, the currently active (fixed) module list can be // different from the configured list of enabled modules. For all active // modules not contained in the configured enabled modules, we assume a // weight of 0. $current_module_filenames = $this->getModuleList(); $current_modules = array_fill_keys(array_keys($current_module_filenames), 0); $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module'))); $module_filenames = array(); foreach ($current_modules as $name => $weight) { if (isset($current_module_filenames[$name])) { $module_filenames[$name] = $current_module_filenames[$name]; } else { $module_path = drupal_get_path('module', $name); $pathname = "{$module_path}/{$name}.info.yml"; $filename = file_exists($module_path . "/{$name}.module") ? "{$name}.module" : NULL; $module_filenames[$name] = new Extension('module', $pathname, $filename); } } // Update the module handler in order to load the module's code. // This allows the module to participate in hooks and its existence to // be discovered by other modules. // The current ModuleHandler instance is obsolete with the kernel // rebuild below. $this->setModuleList($module_filenames); $this->load($module); module_load_install($module); // Clear the static cache of system_rebuild_module_data() to pick up the // new module, since it merges the installation status of modules into // its statically cached list. drupal_static_reset('system_rebuild_module_data'); // Update the kernel to include it. // This reboots the kernel to register the module's bundle and its // services in the service container. The $module_filenames argument is // taken over as %container.modules% parameter, which is passed to a // fresh ModuleHandler instance upon first retrieval. // @todo install_begin_request() creates a container without a kernel. if ($kernel = \Drupal::service('kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE)) { $kernel->updateModules($module_filenames, $module_filenames); } // Refresh the schema to include it. drupal_get_schema(NULL, TRUE); // Allow modules to react prior to the installation of a module. $this->invokeAll('module_preinstall', array($module)); // Now install the module's schema if necessary. drupal_install_schema($module); // Clear plugin manager caches and flag router to rebuild if requested. \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions(); \Drupal::service('router.builder_indicator')->setRebuildNeeded(); // Set the schema version to the number of the last update provided by // the module, or the minimum core schema version. $version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION; $versions = drupal_get_schema_versions($module); if ($versions) { $version = max(max($versions), $version); } // Notify the entity manager that this module's entity types are new, // so that it can notify all interested handlers. For example, a // SQL-based storage handler can use this as an opportunity to create // the necessary database tables. $entity_manager = \Drupal::entityManager(); foreach ($entity_manager->getDefinitions() as $entity_type) { if ($entity_type->getProvider() == $module) { $entity_manager->onEntityTypeCreate($entity_type); } } // Install default configuration of the module. $config_installer = \Drupal::service('config.installer'); if ($sync_status) { $config_installer->setSyncing(TRUE)->setSourceStorage($source_storage); } else { // If we're not in a config synchronisation reset the source storage // so that the extension install storage will pick up the new // configuration. $config_installer->resetSourceStorage(); } \Drupal::service('config.installer')->installDefaultConfig('module', $module); // If the module has no current updates, but has some that were // previously removed, set the version to the value of // hook_update_last_removed(). if ($last_removed = $this->invoke($module, 'update_last_removed')) { $version = max($version, $last_removed); } drupal_set_installed_schema_version($module, $version); // Record the fact that it was installed. $modules_installed[] = $module; // file_get_stream_wrappers() needs to re-register Drupal's stream // wrappers in case a module-provided stream wrapper is used later in // the same request. In particular, this happens when installing Drupal // via Drush, as the 'translations' stream wrapper is provided by // Interface Translation module and is later used to import // translations. \Drupal::service('stream_wrapper_manager')->register(); // Update the theme registry to include it. drupal_theme_rebuild(); // Modules can alter theme info, so refresh theme data. // @todo ThemeHandler cannot be injected into ModuleHandler, since that // causes a circular service dependency. // @see https://drupal.org/node/2208429 \Drupal::service('theme_handler')->refreshInfo(); // Allow the module to perform install tasks. $this->invoke($module, 'install'); // Record the fact that it was installed. \Drupal::logger('system')->info('%module module installed.', array('%module' => $module)); } } // If any modules were newly installed, invoke hook_modules_installed(). if (!empty($modules_installed)) { $this->invokeAll('modules_installed', array($modules_installed)); } return TRUE; }
/** * {@inheritdoc} */ public function setUp() { self::enableAutoload(); $this->prepareDrupalEnvironment(); $this->prepareClientManager(); parent::setUp(); drupal_install_schema('system'); drupal_install_schema('locale'); }
/** * Install the current version of the database schema, and any other setup tasks. * * The hook will be called the first time a module is installed, and the * module's schema version will be set to the module's greatest numbered update * hook. Because of this, anytime a hook_update_N() is added to the module, this * function needs to be updated to reflect the current version of the database * schema. * * See the Schema API documentation at * @link http://drupal.org/node/146843 http://drupal.org/node/146843 @endlink * for details on hook_schema, where a database tables are defined. * * Note that since this function is called from a full bootstrap, all functions * (including those in modules enabled by the current page request) are * available when this hook is called. Use cases could be displaying a user * message, or calling a module function necessary for initial setup, etc. * * Please be sure that anything added or modified in this function that can * be removed during uninstall should be removed with hook_uninstall(). * * @see hook_uninstall() */ function hook_install() { drupal_install_schema('upload'); }
/** * {@inheritdoc} */ public function install(array $module_list, $enable_dependencies = TRUE) { $extension_config = \Drupal::configFactory()->getEditable('core.extension'); if ($enable_dependencies) { // Get all module data so we can find dependencies and sort. $module_data = system_rebuild_module_data(); $module_list = $module_list ? array_combine($module_list, $module_list) : array(); if ($missing_modules = array_diff_key($module_list, $module_data)) { // One or more of the given modules doesn't exist. throw new MissingDependencyException(sprintf('Unable to install modules %s due to missing modules %s.', implode(', ', $module_list), implode(', ', $missing_modules))); } // Only process currently uninstalled modules. $installed_modules = $extension_config->get('module') ?: array(); if (!($module_list = array_diff_key($module_list, $installed_modules))) { // Nothing to do. All modules already installed. return TRUE; } // Add dependencies to the list. The new modules will be processed as // the while loop continues. while (list($module) = each($module_list)) { foreach (array_keys($module_data[$module]->requires) as $dependency) { if (!isset($module_data[$dependency])) { // The dependency does not exist. throw new MissingDependencyException("Unable to install modules: module '{$module}' is missing its dependency module {$dependency}."); } // Skip already installed modules. if (!isset($module_list[$dependency]) && !isset($installed_modules[$dependency])) { $module_list[$dependency] = $dependency; } } } // Set the actual module weights. $module_list = array_map(function ($module) use($module_data) { return $module_data[$module]->sort; }, $module_list); // Sort the module list by their weights (reverse). arsort($module_list); $module_list = array_keys($module_list); } // Required for module installation checks. include_once $this->root . '/core/includes/install.inc'; /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */ $config_installer = \Drupal::service('config.installer'); $sync_status = $config_installer->isSyncing(); if ($sync_status) { $source_storage = $config_installer->getSourceStorage(); } $modules_installed = array(); foreach ($module_list as $module) { $enabled = $extension_config->get("module.{$module}") !== NULL; if (!$enabled) { // Throw an exception if the module name is too long. if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) { throw new ExtensionNameLengthException("Module name '{$module}' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters'); } // Check the validity of the default configuration. This will throw // exceptions if the configuration is not valid. $config_installer->checkConfigurationToInstall('module', $module); // Save this data without checking schema. This is a performance // improvement for module installation. $extension_config->set("module.{$module}", 0)->set('module', module_config_sort($extension_config->get('module')))->save(TRUE); // Prepare the new module list, sorted by weight, including filenames. // This list is used for both the ModuleHandler and DrupalKernel. It // needs to be kept in sync between both. A DrupalKernel reboot or // rebuild will automatically re-instantiate a new ModuleHandler that // uses the new module list of the kernel. However, DrupalKernel does // not cause any modules to be loaded. // Furthermore, the currently active (fixed) module list can be // different from the configured list of enabled modules. For all active // modules not contained in the configured enabled modules, we assume a // weight of 0. $current_module_filenames = $this->moduleHandler->getModuleList(); $current_modules = array_fill_keys(array_keys($current_module_filenames), 0); $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module'))); $module_filenames = array(); foreach ($current_modules as $name => $weight) { if (isset($current_module_filenames[$name])) { $module_filenames[$name] = $current_module_filenames[$name]; } else { $module_path = drupal_get_path('module', $name); $pathname = "{$module_path}/{$name}.info.yml"; $filename = file_exists($module_path . "/{$name}.module") ? "{$name}.module" : NULL; $module_filenames[$name] = new Extension($this->root, 'module', $pathname, $filename); } } // Update the module handler in order to load the module's code. // This allows the module to participate in hooks and its existence to // be discovered by other modules. // The current ModuleHandler instance is obsolete with the kernel // rebuild below. $this->moduleHandler->setModuleList($module_filenames); $this->moduleHandler->load($module); module_load_install($module); // Clear the static cache of system_rebuild_module_data() to pick up the // new module, since it merges the installation status of modules into // its statically cached list. drupal_static_reset('system_rebuild_module_data'); // Update the kernel to include it. $this->updateKernel($module_filenames); // Allow modules to react prior to the installation of a module. $this->moduleHandler->invokeAll('module_preinstall', array($module)); // Now install the module's schema if necessary. drupal_install_schema($module); // Clear plugin manager caches. \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions(); // Set the schema version to the number of the last update provided by // the module, or the minimum core schema version. $version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION; $versions = drupal_get_schema_versions($module); if ($versions) { $version = max(max($versions), $version); } // Notify interested components that this module's entity types and // field storage definitions are new. For example, a SQL-based storage // handler can use this as an opportunity to create the necessary // database tables. // @todo Clean this up in https://www.drupal.org/node/2350111. $entity_manager = \Drupal::entityManager(); $update_manager = \Drupal::entityDefinitionUpdateManager(); foreach ($entity_manager->getDefinitions() as $entity_type) { if ($entity_type->getProvider() == $module) { $update_manager->installEntityType($entity_type); } elseif ($entity_type->isSubclassOf(FieldableEntityInterface::CLASS)) { // The module being installed may be adding new fields to existing // entity types. Field definitions for any entity type defined by // the module are handled in the if branch. foreach ($entity_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) { if ($storage_definition->getProvider() == $module) { // If the module being installed is also defining a storage key // for the entity type, the entity schema may not exist yet. It // will be created later in that case. try { $update_manager->installFieldStorageDefinition($storage_definition->getName(), $entity_type->id(), $module, $storage_definition); } catch (EntityStorageException $e) { watchdog_exception('system', $e, 'An error occurred while notifying the creation of the @name field storage definition: "!message" in %function (line %line of %file).', ['@name' => $storage_definition->getName()]); } } } } } // Install default configuration of the module. $config_installer = \Drupal::service('config.installer'); if ($sync_status) { $config_installer->setSyncing(TRUE)->setSourceStorage($source_storage); } \Drupal::service('config.installer')->installDefaultConfig('module', $module); // If the module has no current updates, but has some that were // previously removed, set the version to the value of // hook_update_last_removed(). if ($last_removed = $this->moduleHandler->invoke($module, 'update_last_removed')) { $version = max($version, $last_removed); } drupal_set_installed_schema_version($module, $version); // Ensure that all post_update functions are registered already. /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */ $post_update_registry = \Drupal::service('update.post_update_registry'); $post_update_registry->registerInvokedUpdates($post_update_registry->getModuleUpdateFunctions($module)); // Record the fact that it was installed. $modules_installed[] = $module; // Drupal's stream wrappers needs to be re-registered in case a // module-provided stream wrapper is used later in the same request. In // particular, this happens when installing Drupal via Drush, as the // 'translations' stream wrapper is provided by Interface Translation // module and is later used to import translations. \Drupal::service('stream_wrapper_manager')->register(); // Update the theme registry to include it. drupal_theme_rebuild(); // Modules can alter theme info, so refresh theme data. // @todo ThemeHandler cannot be injected into ModuleHandler, since that // causes a circular service dependency. // @see https://www.drupal.org/node/2208429 \Drupal::service('theme_handler')->refreshInfo(); // In order to make uninstalling transactional if anything uses routes. \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider')); \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder')); // Allow the module to perform install tasks. $this->moduleHandler->invoke($module, 'install'); // Record the fact that it was installed. \Drupal::logger('system')->info('%module module installed.', array('%module' => $module)); } } // If any modules were newly installed, invoke hook_modules_installed(). if (!empty($modules_installed)) { \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old')); if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) { // Rebuild routes after installing module. This is done here on top of // \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on // fastCGI which executes ::destruct() after the module installation // page was sent already. \Drupal::service('router.builder')->rebuild(); } $this->moduleHandler->invokeAll('modules_installed', array($modules_installed)); } return TRUE; }