예제 #1
0
 /**
  * @return array
  *
  * @see update_batch()
  */
 public function listMigrations()
 {
     // Resolve any update dependencies to determine the actual updates that will
     // be run and the order they will be run in.
     require_once DRUPAL_ROOT . '/includes/update.inc';
     $startingUpdates = $this->listUpdates();
     $updates = update_resolve_dependencies($startingUpdates);
     // Store the dependencies for each update function in an array which the
     // batch API can pass in to the batch operation each time it is called. (We
     // do not store the entire update dependency array here because it is
     // potentially very large.)
     $dependencyMap = array();
     foreach ($updates as $function => $update) {
         $dependencyMap[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();
     }
     $migrations = array();
     foreach ($updates as $update) {
         if ($update['allowed']) {
             // Set the installed version of each module so updates will start at the
             // correct place. (The updates are already sorted, so we can simply base
             // this on the first one we come across in the above foreach loop.)
             if (isset($startingUpdates[$update['module']])) {
                 drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
                 unset($startingUpdates[$update['module']]);
             }
             // Add this update function to the batch.
             $function = $update['module'] . '_update_' . $update['number'];
             $migrations[] = array('module' => $update['module'], 'number' => $update['number'], 'dependencyMap' => $dependencyMap[$function]);
         }
     }
     return $migrations;
 }
예제 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /*      drupal_set_installed_schema_version('sample', '8000');
             exit();*/
     include_once DRUPAL_ROOT . '/core/includes/install.inc';
     include_once DRUPAL_ROOT . '/core/includes/update.inc';
     $module = $input->getArgument('module');
     $update_n = $input->getArgument('update-n');
     $module_handler = $this->getModuleHandler();
     drupal_load_updates();
     update_fix_compatibility();
     $updates = update_get_update_list();
     if ($module != 'all') {
         if (!isset($updates[$module])) {
             $output->writeln('[-] <error>' . sprintf($this->trans('commands.update.execute.messages.no-module-updates'), $module) . '</error>');
             return;
         } else {
             // filter to execute only a specific module updates
             $updates = [$module => $updates[$module]];
             if ($update_n && !isset($updates[$module]['pending'][$update_n])) {
                 $output->writeln('[-] <info>' . sprintf($this->trans('commands.update.execute.messages.module-update-function-not-found'), $module, $update_n) . '</info>');
             }
         }
     }
     $output->writeln('[-] <info>' . $this->trans('commands.site.maintenance.description') . '</info>');
     \Drupal::state()->set('system.maintenance_mode', true);
     foreach ($updates as $module_name => $module_updates) {
         foreach ($module_updates['pending'] as $update_number => $update) {
             if ($module != 'all' && $update_n != null and $update_n != $update_number) {
                 continue;
             }
             //Executing all pending updates
             if ($update_n > $module_updates['start']) {
                 $output->writeln('[-] <info>' . $this->trans('commands.update.execute.messages.executing-required-previous-updates') . '</info>');
             }
             for ($update_index = $module_updates['start']; $update_index <= $update_number; $update_index++) {
                 $output->writeln('[-] <info>' . sprintf($this->trans('commands.update.execute.messages.executing-update'), $update_index, $module_name) . '</info>');
                 try {
                     $module_handler->invoke($module_name, 'update_' . $update_index);
                 } catch (\Exception $e) {
                     watchdog_exception('update', $e);
                     $output->writeln('<error>' . $e->getMessage() . '</error>');
                 }
                 //Update module schema version
                 drupal_set_installed_schema_version($module_name, $update_index);
             }
         }
     }
     \Drupal::state()->set('system.maintenance_mode', false);
     $output->writeln('[-] <info>' . $this->trans('commands.site.maintenance.messages.maintenance-off') . '</info>');
     $this->getHelper('chain')->addCommand('cache:rebuild', ['cache' => 'all']);
 }
예제 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $this->getDrupalHelper()->loadLegacyFile('/core/includes/install.inc');
     $this->getDrupalHelper()->loadLegacyFile('/core/includes/update.inc');
     $module = $input->getArgument('module');
     $update_n = $input->getArgument('update-n');
     $module_handler = $this->getModuleHandler();
     drupal_load_updates();
     update_fix_compatibility();
     $updates = update_get_update_list();
     if ($module != 'all') {
         if (!isset($updates[$module])) {
             $io->error(sprintf($this->trans('commands.update.execute.messages.no-module-updates'), $module));
             return;
         } else {
             // filter to execute only a specific module updates
             $updates = [$module => $updates[$module]];
             if ($update_n && !isset($updates[$module]['pending'][$update_n])) {
                 $io->info(sprintf($this->trans('commands.update.execute.messages.module-update-function-not-found'), $module, $update_n));
             }
         }
     }
     $io->info($this->trans('commands.site.maintenance.description'));
     $state = $this->getService('state');
     $state->set('system.maintenance_mode', true);
     foreach ($updates as $module_name => $module_updates) {
         foreach ($module_updates['pending'] as $update_number => $update) {
             if ($module != 'all' && $update_n !== null && $update_n != $update_number) {
                 continue;
             }
             //Executing all pending updates
             if ($update_n > $module_updates['start']) {
                 $io->info($this->trans('commands.update.execute.messages.executing-required-previous-updates'));
             }
             for ($update_index = $module_updates['start']; $update_index <= $update_number; $update_index++) {
                 $io->info(sprintf($this->trans('commands.update.execute.messages.executing-update'), $update_index, $module_name));
                 try {
                     $module_handler->invoke($module_name, 'update_' . $update_index);
                 } catch (\Exception $e) {
                     watchdog_exception('update', $e);
                     $io->error($e->getMessage());
                 }
                 //Update module schema version
                 drupal_set_installed_schema_version($module_name, $update_index);
             }
         }
     }
     $state->set('system.maintenance_mode', false);
     $io->info($this->trans('commands.site.maintenance.messages.maintenance-off'));
     $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']);
 }
예제 #4
0
 function testWith7x()
 {
     // Ensure that the minimum schema version is 8000, despite 7200 update
     // hooks and a 7XXX hook_update_last_removed().
     $this->assertEqual(drupal_get_installed_schema_version('update_test_with_7x'), 8000);
     // Try to manually set the schema version to 7110 and ensure that no
     // updates are allowed.
     drupal_set_installed_schema_version('update_test_with_7x', 7110);
     // Click through update.php with 'administer software updates' permission.
     $this->drupalLogin($this->update_user);
     $this->drupalPostForm($this->update_url, array(), t('Continue'), array('external' => TRUE));
     $this->assertText(t('Some of the pending updates cannot be applied because their dependencies were not met.'));
 }
예제 #5
0
function update_batch()
{
    global $base_url;
    $operations = array();
    // Set the installed version so updates start at the correct place.
    foreach ($_POST['start'] as $module => $version) {
        drupal_set_installed_schema_version($module, $version - 1);
        $updates = drupal_get_schema_versions($module);
        $max_version = max($updates);
        if ($version <= $max_version) {
            foreach ($updates as $update) {
                if ($update >= $version) {
                    $operations[] = array('update_do_one', array($module, $update));
                }
            }
        }
    }
    $batch = array('operations' => $operations, 'title' => 'Updating', 'init_message' => 'Starting updates', 'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.', 'finished' => 'update_finished');
    batch_set($batch);
    batch_process($base_url . '/update.php?op=results', $base_url . '/update.php');
}
예제 #6
0
 /**
  * Tests that the status page returns.
  */
 public function testStatusPage()
 {
     // Go to Administration.
     $this->drupalGet('admin/reports/status');
     $this->assertResponse(200, 'The status page is reachable.');
     $phpversion = phpversion();
     $this->assertText($phpversion, 'Php version is shown on the page.');
     // Checks if the suggestion to update to php 5.5.21 or 5.6.5 for disabling
     // multiple statements is present when necessary.
     if (\Drupal::database()->driver() === 'mysql' && !SystemRequirements::phpVersionWithPdoDisallowMultipleStatements($phpversion)) {
         $this->assertText(t('PHP (multiple statement disabling)'));
     } else {
         $this->assertNoText(t('PHP (multiple statement disabling)'));
     }
     if (function_exists('phpinfo')) {
         $this->assertLinkByHref(Url::fromRoute('system.php')->toString());
     } else {
         $this->assertNoLinkByHref(Url::fromRoute('system.php')->toString());
     }
     // If a module is fully installed no pending updates exists.
     $this->assertNoText(t('Out of date'));
     // The global $config_directories is not properly formed.
     $this->assertRaw(t('Your %file file must define the $config_directories variable as an array containing the names of directories in which configuration files can be found. It must contain a %sync_key key.', array('%file' => $this->siteDirectory . '/settings.php', '%sync_key' => CONFIG_SYNC_DIRECTORY)));
     // Set the schema version of update_test_postupdate to a lower version, so
     // update_test_postupdate_update_8001() needs to be executed.
     drupal_set_installed_schema_version('update_test_postupdate', 8000);
     $this->drupalGet('admin/reports/status');
     $this->assertText(t('Out of date'));
     // Now cleanup the executed post update functions.
     drupal_set_installed_schema_version('update_test_postupdate', 8001);
     /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
     $post_update_registry = \Drupal::service('update.post_update_registry');
     $post_update_registry->filterOutInvokedUpdatesByModule('update_test_postupdate');
     $this->drupalGet('admin/reports/status');
     $this->assertText(t('Out of date'));
     $this->drupalGet('admin/reports/status/php');
     $this->assertResponse(200, 'The phpinfo page is reachable.');
 }
예제 #7
0
 /**
  * Tests that the status page returns.
  */
 public function testStatusPage()
 {
     // Go to Administration.
     $this->drupalGet('admin/reports/status');
     $this->assertResponse(200, 'The status page is reachable.');
     $phpversion = phpversion();
     $this->assertText($phpversion, 'Php version is shown on the page.');
     // Checks if the suggestion to update to php 5.5.21 or 5.6.5 for disabling
     // multiple statements is present when necessary.
     if (\Drupal::database()->driver() === 'mysql' && !SystemRequirements::phpVersionWithPdoDisallowMultipleStatements($phpversion)) {
         $this->assertText(t('PHP (multiple statement disabling)'));
     } else {
         $this->assertNoText(t('PHP (multiple statement disabling)'));
     }
     if (function_exists('phpinfo')) {
         $this->assertLinkByHref(Url::fromRoute('system.php')->toString());
     } else {
         $this->assertNoLinkByHref(Url::fromRoute('system.php')->toString());
     }
     // If a module is fully installed no pending updates exists.
     $this->assertNoText(t('Out of date'));
     // Set the schema version of update_test_postupdate to a lower version, so
     // update_test_postupdate_update_8001() needs to be executed.
     drupal_set_installed_schema_version('update_test_postupdate', 8000);
     $this->drupalGet('admin/reports/status');
     $this->assertText(t('Out of date'));
     // Now cleanup the executed post update functions.
     drupal_set_installed_schema_version('update_test_postupdate', 8001);
     /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
     $post_update_registry = \Drupal::service('update.post_update_registry');
     $post_update_registry->filterOutInvokedUpdatesByModule('update_test_postupdate');
     $this->drupalGet('admin/reports/status');
     $this->assertText(t('Out of date'));
     $this->drupalGet('admin/reports/status/php');
     $this->assertResponse(200, 'The phpinfo page is reachable.');
 }
예제 #8
0
 /**
  * Helper function to run updates via the browser.
  */
 protected function updateScriptTest($maintenance_mode)
 {
     $schema_version = drupal_get_installed_schema_version('update_script_test');
     $this->assertEqual($schema_version, 8001, 'update_script_test is initially installed with schema version 8001.');
     // Set the installed schema version to one less than the current update.
     drupal_set_installed_schema_version('update_script_test', $schema_version - 1);
     $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
     $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.');
     // Click through update.php with 'administer software updates' permission.
     $this->drupalLogin($this->updateUser);
     if ($maintenance_mode) {
         $this->assertText('Operating in maintenance mode.');
     } else {
         $this->assertNoText('Operating in maintenance mode.');
     }
     $this->drupalGet($this->updateUrl, array('external' => TRUE));
     $this->clickLink(t('Continue'));
     $this->clickLink(t('Apply pending updates'));
     // Verify that updates were completed successfully.
     $this->assertText('Updates were attempted.');
     $this->assertLink('site');
     $this->assertText('The update_script_test_update_8001() update was executed successfully.');
     // Verify that no 7.x updates were run.
     $this->assertNoText('The update_script_test_update_7200() update was executed successfully.');
     $this->assertNoText('The update_script_test_update_7201() update was executed successfully.');
     // Verify that there are no links to different parts of the workflow.
     $this->assertNoLink('Administration pages');
     $this->assertNoLinkByHrefInMainRegion('update.php', 0);
     $this->assertNoLink('logged');
     // Verify the front page can be visited following the upgrade.
     $this->clickLink('Front page');
     $this->assertResponse(200);
 }
 /**
  * {@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;
 }
예제 #10
0
 /**
  * Tests update.php after performing a successful update.
  */
 function testSuccessfulUpdateFunctionality()
 {
     $schema_version = drupal_get_installed_schema_version('update_script_test');
     $this->assertEqual($schema_version, 8001, 'update_script_test is initially installed with schema version 8001.');
     // Set the installed schema version to one less than the current update.
     drupal_set_installed_schema_version('update_script_test', $schema_version - 1);
     $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
     $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.');
     // Click through update.php with 'administer software updates' permission.
     $this->drupalLogin($this->updateUser);
     $this->drupalGet($this->updateUrl, array('external' => TRUE));
     $this->clickLink(t('Continue'));
     $this->clickLink(t('Apply pending updates'));
     // Verify that updates were completed successfully.
     $this->assertText('Updates were attempted.');
     $this->assertLink('site');
     $this->assertText('The update_script_test_update_8001() update was executed successfully.');
     // Verify that no 7.x updates were run.
     $this->assertNoText('The update_script_test_update_7200() update was executed successfully.');
     $this->assertNoText('The update_script_test_update_7201() update was executed successfully.');
     // Verify that there are no links to different parts of the workflow.
     $this->assertNoLink('Administration pages');
     $this->assertNoLinkByHref('update.php', 0);
     $this->assertNoLink('logged');
     // Verify the front page can be visited following the upgrade.
     $this->clickLink('Front page');
     $this->assertResponse(200);
     // Reset the static cache to ensure we have the most current setting.
     $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
     $this->assertEqual($schema_version, 8001, 'update_script_test schema version is 8001 after updating.');
     // Set the installed schema version to one less than the current update.
     drupal_set_installed_schema_version('update_script_test', $schema_version - 1);
     $schema_version = drupal_get_installed_schema_version('update_script_test', TRUE);
     $this->assertEqual($schema_version, 8000, 'update_script_test schema version overridden to 8000.');
     // Click through update.php with 'access administration pages' and
     // 'access site reports' permissions.
     $admin_user = $this->drupalCreateUser(array('administer software updates', 'access administration pages', 'access site reports', 'access site in maintenance mode'));
     $this->drupalLogin($admin_user);
     $this->drupalGet($this->updateUrl, array('external' => TRUE));
     $this->clickLink(t('Continue'));
     $this->clickLink(t('Apply pending updates'));
     $this->assertText('Updates were attempted.');
     $this->assertLink('logged');
     $this->assertLink('Administration pages');
     $this->assertNoLinkByHref('update.php', 1);
     $this->clickLink('Administration pages');
     $this->assertResponse(200);
 }
예제 #11
0
function update_batch()
{
    global $base_url;
    // During the update, toggle site maintenance so that schema changes do not
    // affect visiting users.
    $_SESSION['site_offline'] = variable_get('site_offline', FALSE);
    if ($_SESSION['site_offline'] == FALSE) {
        variable_set('site_offline', TRUE);
    }
    $operations = array();
    // Set the installed version so updates start at the correct place.
    foreach ($_POST['start'] as $module => $version) {
        drupal_set_installed_schema_version($module, $version - 1);
        $updates = drupal_get_schema_versions($module);
        $max_version = max($updates);
        if ($version <= $max_version) {
            foreach ($updates as $update) {
                if ($update >= $version) {
                    $operations[] = array('update_do_one', array($module, $update));
                }
            }
        }
    }
    $batch = array('operations' => $operations, 'title' => 'Updating', 'init_message' => 'Starting updates', 'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.', 'finished' => 'update_finished');
    batch_set($batch);
    batch_process($base_url . '/update.php?op=results', $base_url . '/update.php');
}
예제 #12
0
 /**
  * @param \Drupal\Console\Style\DrupalStyle $io
  * @param $updates
  */
 private function runUpdates(DrupalStyle $io, $updates)
 {
     $module_handler = $this->getDrupalService('module_handler');
     foreach ($updates as $module_name => $module_updates) {
         $modulePath = $this->getApplication()->getSite()->getModulePath($this->module);
         $this->get('site')->loadLegacyFile($modulePath . '/' . $this->module . '.install', false);
         foreach ($module_updates['pending'] as $update_number => $update) {
             if ($this->module != 'all' && $this->update_n !== null && $this->update_n != $update_number) {
                 continue;
             }
             if ($this->update_n > $module_updates['start']) {
                 $io->info($this->trans('commands.update.execute.messages.executing-required-previous-updates'));
             }
             for ($update_index = $module_updates['start']; $update_index <= $update_number; $update_index++) {
                 $io->info(sprintf($this->trans('commands.update.execute.messages.executing-update'), $update_index, $module_name));
                 try {
                     $module_handler->invoke($module_name, 'update_' . $update_index);
                 } catch (\Exception $e) {
                     watchdog_exception('update', $e);
                     $io->error($e->getMessage());
                 }
                 drupal_set_installed_schema_version($module_name, $update_index);
             }
         }
     }
 }
예제 #13
0
 /**
  * Starts the database update batch process.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  */
 protected function triggerBatch(Request $request)
 {
     // During the update, bring the site offline so that schema changes do not
     // affect visiting users.
     $maintenance_mode = $this->config('system.maintenance')->get('enabled');
     if (isset($maintenance_mode)) {
         $_SESSION['maintenance_mode'] = $maintenance_mode;
     }
     if (empty($_SESSION['maintenance_mode'])) {
         $this->state->set('system.maintenance_mode', TRUE);
     }
     $operations = array();
     // First of all perform entity definition updates, which will update
     // storage schema if needed, so that module update functions work with
     // the correct entity schema.
     if ($this->entityDefinitionUpdateManager->needsUpdates()) {
         $operations[] = array('update_entity_definitions', array('system', '0 - Update entity definitions'));
     }
     // Resolve any update dependencies to determine the actual updates that will
     // be run and the order they will be run in.
     $start = $this->getModuleUpdates();
     $updates = update_resolve_dependencies($start);
     // Store the dependencies for each update function in an array which the
     // batch API can pass in to the batch operation each time it is called. (We
     // do not store the entire update dependency array here because it is
     // potentially very large.)
     $dependency_map = array();
     foreach ($updates as $function => $update) {
         $dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();
     }
     // Determine updates to be performed.
     foreach ($updates as $update) {
         if ($update['allowed']) {
             // Set the installed version of each module so updates will start at the
             // correct place. (The updates are already sorted, so we can simply base
             // this on the first one we come across in the above foreach loop.)
             if (isset($start[$update['module']])) {
                 drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
                 unset($start[$update['module']]);
             }
             // Add this update function to the batch.
             $function = $update['module'] . '_update_' . $update['number'];
             $operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));
         }
     }
     $batch['operations'] = $operations;
     $batch += array('title' => $this->t('Updating'), 'init_message' => $this->t('Starting updates'), 'error_message' => $this->t('An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.'), 'finished' => array('\\Drupal\\system\\Controller\\DbUpdateController', 'batchFinished'));
     batch_set($batch);
     return batch_process('update.php/results', Url::fromRoute('system.db_update', array('op' => 'start')));
 }
예제 #14
0
function update_update_page()
{
    // Set the installed version so updates start at the correct place.
    foreach ($_POST['start'] as $module => $version) {
        drupal_set_installed_schema_version($module, $version - 1);
        $updates = drupal_get_schema_versions($module);
        $max_version = max($updates);
        if ($version <= $max_version) {
            foreach ($updates as $update) {
                if ($update >= $version) {
                    $_SESSION['update_remaining'][] = array('module' => $module, 'version' => $update);
                }
            }
        }
    }
    // Keep track of total number of updates
    $_SESSION['update_total'] = count($_SESSION['update_remaining']);
    if ($_POST['has_js']) {
        return update_progress_page();
    } else {
        return update_progress_page_nojs();
    }
}
예제 #15
0
 /**
  * {@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;
 }
예제 #16
0
 /**
  * Starts the database update batch process.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  */
 protected function triggerBatch(Request $request)
 {
     $maintenance_mode = $this->state->get('system.maintenance_mode', FALSE);
     // Store the current maintenance mode status in the session so that it can
     // be restored at the end of the batch.
     $_SESSION['maintenance_mode'] = $maintenance_mode;
     // During the update, always put the site into maintenance mode so that
     // in-progress schema changes do not affect visiting users.
     if (empty($maintenance_mode)) {
         $this->state->set('system.maintenance_mode', TRUE);
     }
     $operations = array();
     // Resolve any update dependencies to determine the actual updates that will
     // be run and the order they will be run in.
     $start = $this->getModuleUpdates();
     $updates = update_resolve_dependencies($start);
     // Store the dependencies for each update function in an array which the
     // batch API can pass in to the batch operation each time it is called. (We
     // do not store the entire update dependency array here because it is
     // potentially very large.)
     $dependency_map = array();
     foreach ($updates as $function => $update) {
         $dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();
     }
     // Determine updates to be performed.
     foreach ($updates as $function => $update) {
         if ($update['allowed']) {
             // Set the installed version of each module so updates will start at the
             // correct place. (The updates are already sorted, so we can simply base
             // this on the first one we come across in the above foreach loop.)
             if (isset($start[$update['module']])) {
                 drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
                 unset($start[$update['module']]);
             }
             $operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));
         }
     }
     $post_updates = $this->postUpdateRegistry->getPendingUpdateFunctions();
     if ($post_updates) {
         // Now we rebuild all caches and after that execute the hook_post_update()
         // functions.
         $operations[] = ['drupal_flush_all_caches', []];
         foreach ($post_updates as $function) {
             $operations[] = ['update_invoke_post_update', [$function]];
         }
     }
     $batch['operations'] = $operations;
     $batch += array('title' => $this->t('Updating'), 'init_message' => $this->t('Starting updates'), 'error_message' => $this->t('An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.'), 'finished' => array('\\Drupal\\system\\Controller\\DbUpdateController', 'batchFinished'));
     batch_set($batch);
     // @todo Revisit once https://www.drupal.org/node/2548095 is in.
     return batch_process(Url::fromUri('base://results'), Url::fromUri('base://start'));
 }
예제 #17
0
 /**
  * Starts the database update batch process.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request object.
  */
 protected function triggerBatch(Request $request)
 {
     $maintenance_mode = $this->state->get('system.maintenance_mode', FALSE);
     // Store the current maintenance mode status in the session so that it can
     // be restored at the end of the batch.
     $_SESSION['maintenance_mode'] = $maintenance_mode;
     // During the update, always put the site into maintenance mode so that
     // in-progress schema changes do not affect visiting users.
     if (empty($maintenance_mode)) {
         $this->state->set('system.maintenance_mode', TRUE);
     }
     $operations = array();
     // Resolve any update dependencies to determine the actual updates that will
     // be run and the order they will be run in.
     $start = $this->getModuleUpdates();
     $updates = update_resolve_dependencies($start);
     // Store the dependencies for each update function in an array which the
     // batch API can pass in to the batch operation each time it is called. (We
     // do not store the entire update dependency array here because it is
     // potentially very large.)
     $dependency_map = array();
     foreach ($updates as $function => $update) {
         $dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : array();
     }
     // Determine updates to be performed.
     foreach ($updates as $function => $update) {
         if ($update['allowed']) {
             // Set the installed version of each module so updates will start at the
             // correct place. (The updates are already sorted, so we can simply base
             // this on the first one we come across in the above foreach loop.)
             if (isset($start[$update['module']])) {
                 drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
                 unset($start[$update['module']]);
             }
             $operations[] = array('update_do_one', array($update['module'], $update['number'], $dependency_map[$function]));
         }
     }
     // Lastly, perform entity definition updates, which will update storage
     // schema if needed. If module update functions need to work with specific
     // entity schema they should call the entity update service for the specific
     // update themselves.
     // @see \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::applyEntityUpdate()
     // @see \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::applyFieldUpdate()
     if ($this->entityDefinitionUpdateManager->needsUpdates()) {
         $operations[] = array('update_entity_definitions', array());
     }
     $batch['operations'] = $operations;
     $batch += array('title' => $this->t('Updating'), 'init_message' => $this->t('Starting updates'), 'error_message' => $this->t('An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.'), 'finished' => array('\\Drupal\\system\\Controller\\DbUpdateController', 'batchFinished'));
     batch_set($batch);
     return batch_process(Url::fromUri($request->getUriForPath('/results')), Url::fromUri($request->getUriForPath('/start')));
 }