Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function installDependencies()
 {
     $modules = ['migrate', 'migrate_drupal'];
     foreach ($modules as $i => $module) {
         if ($this->moduleHandler->moduleExists($module)) {
             unset($modules[$i]);
         }
     }
     if (!empty($modules)) {
         $this->moduleInstaller->install($modules, TRUE);
     }
     return $this;
 }
Exemplo n.º 2
0
 public function testEnableWithExistingContent()
 {
     foreach ($this->entityTypes as $entity_type_id => $values) {
         $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id);
         if ($entity_type_id == 'user') {
             $this->createUser(['administer nodes']);
             // There should now be 3 users in total, including the initial anonymous
             // and admin users.
             $count = 3;
         } else {
             $count = 2;
             for ($i = 0; $i < $count; $i++) {
                 $storage->create($values)->save();
             }
         }
         $count_before[$entity_type_id] = $count;
     }
     // Installing Multiversion will trigger the migration of existing content.
     $this->moduleInstaller->install(['multiversion']);
     $this->multiversionManager = \Drupal::service('multiversion.manager');
     // Check if all updates have been applied.
     $this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates(), 'All compatible entity types have been updated.');
     $ids_after = [];
     // Now check that the previously created entities still exist, have the
     // right IDs and are multiversion enabled. That means profit. Big profit.
     foreach ($this->entityTypes as $entity_type_id => $values) {
         $manager = \Drupal::entityTypeManager();
         $entity_type = $manager->getDefinition($entity_type_id);
         $storage = $manager->getStorage($entity_type_id);
         $id_key = $entity_type->getKey('id');
         $this->assertTrue($this->multiversionManager->isEnabledEntityType($entity_type), "{$entity_type_id} was enabled for Multiversion.");
         $this->assertTrue($storage instanceof ContentEntityStorageInterface, "{$entity_type_id} got the correct storage handler assigned.");
         $this->assertTrue($storage->getQuery() instanceof QueryInterface, "{$entity_type_id} got the correct query handler assigned.");
         $ids_after[$entity_type_id] = $storage->getQuery()->execute();
         $this->assertEqual($count_before[$entity_type_id], count($ids_after[$entity_type_id]), "All {$entity_type_id}s were migrated.");
         foreach ($ids_after[$entity_type_id] as $revision_id => $entity_id) {
             $rev = (int) $storage->getQuery()->condition($id_key, $entity_id)->condition('_rev', 'NULL', '<>')->count()->execute();
             $workspace = (int) $storage->getQuery()->condition($id_key, $entity_id)->condition('workspace', 1)->count()->execute();
             $deleted = (int) $storage->getQuery()->condition($id_key, $entity_id)->condition('_deleted', 0)->count()->execute();
             $this->assertEqual($rev, 1, "{$entity_type_id} {$entity_id} has a revision hash in database");
             $this->assertEqual($workspace, 1, "{$entity_type_id} {$entity_id} has correct workspace in database");
             $this->assertEqual($deleted, 1, "{$entity_type_id} {$entity_id} is not marked as deleted in database");
         }
     }
     // Now install a module with an entity type AFTER the migration and assert
     // that is being returned as supported and enabled.
     $this->moduleInstaller->install(['taxonomy']);
     $entity_type = \Drupal::entityTypeManager()->getDefinition('taxonomy_term');
     $this->assertTrue($this->multiversionManager->isEnabledEntityType($entity_type), 'Newly installed entity types gets enabled as well.');
     $this->assertFalse(\Drupal::service('entity.definition_update_manager')->needsUpdates(), 'There are not new updates to apply.');
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->config('system.site')->set('name', (string) $form_state->getValue('site_name'))->set('mail', (string) $form_state->getValue('site_mail'))->save(TRUE);
     $this->config('system.date')->set('timezone.default', (string) $form_state->getValue('date_default_timezone'))->set('country.default', (string) $form_state->getValue('site_default_country'))->save(TRUE);
     $account_values = $form_state->getValue('account');
     // Enable update.module if this option was selected.
     $update_status_module = $form_state->getValue('update_status_module');
     if ($update_status_module[1]) {
         $this->moduleInstaller->install(array('file', 'update'), FALSE);
         // Add the site maintenance account's email address to the list of
         // addresses to be notified when updates are available, if selected.
         if ($update_status_module[2]) {
             // Reset the configuration factory so it is updated with the new module.
             $this->resetConfigFactory();
             $this->config('update.settings')->set('notification.emails', array($account_values['mail']))->save(TRUE);
         }
     }
     // We precreated user 1 with placeholder values. Let's save the real values.
     $account = $this->userStorage->load(1);
     $account->init = $account->mail = $account_values['mail'];
     $account->roles = $account->getRoles();
     $account->activate();
     $account->timezone = $form_state->getValue('date_default_timezone');
     $account->pass = $account_values['pass'];
     $account->name = $account_values['name'];
     $account->save();
     // Record when this install ran.
     $this->state->set('install_time', $_SERVER['REQUEST_TIME']);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Remove the key value store entry.
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->delete($account);
     if (!empty($this->modules['install'])) {
         // Don't catch the exception that this can throw for missing dependencies:
         // the form doesn't allow modules with unmet dependencies, so the only way
         // this can happen is if the filesystem changed between form display and
         // submit, in which case the user has bigger problems.
         try {
             // Install the given modules.
             $this->moduleInstaller->install(array_keys($this->modules['install']));
         } catch (PreExistingConfigException $e) {
             $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
             drupal_set_message($this->formatPlural(count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', array('%config_names' => implode(', ', $config_objects), '@extension' => $this->modules['install'][$e->getExtension()])), 'error');
             return;
         } catch (UnmetDependenciesException $e) {
             drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $this->modules['install'][$e->getExtension()]), 'error');
             return;
         }
         $module_names = array_values($this->modules['install']);
         drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', array('%name' => $module_names[0], '%names' => implode(', ', $module_names))));
     }
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Retrieve a list of modules to install and their dependencies.
     $modules = $this->buildModuleList($form_state);
     // Check if we have to install any dependencies. If there is one or more
     // dependencies that are not installed yet, redirect to the confirmation
     // form.
     if (!empty($modules['dependencies']) || !empty($modules['missing'])) {
         // Write the list of changed module states into a key value store.
         $account = $this->currentUser()->id();
         $this->keyValueExpirable->setWithExpire($account, $modules, 60);
         // Redirect to the confirmation form.
         $form_state->setRedirect('system.modules_list_confirm');
         // We can exit here because at least one modules has dependencies
         // which we have to prompt the user for in a confirmation form.
         return;
     }
     // Install the given modules.
     if (!empty($modules['install'])) {
         try {
             $this->moduleInstaller->install(array_keys($modules['install']));
             $module_names = array_values($modules['install']);
             drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', array('%name' => $module_names[0], '%names' => implode(', ', $module_names))));
         } catch (PreExistingConfigException $e) {
             $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
             drupal_set_message($this->formatPlural(count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', array('%config_names' => implode(', ', $config_objects), '@extension' => $modules['install'][$e->getExtension()])), 'error');
             return;
         } catch (UnmetDependenciesException $e) {
             drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $modules['install'][$e->getExtension()]), 'error');
             return;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Clear the key value store entry.
     $account = $this->currentUser()->id();
     $this->keyValueExpirable->delete($account);
     // Uninstall the modules.
     $this->moduleInstaller->uninstall($this->modules);
     drupal_set_message($this->t('The selected modules have been uninstalled.'));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     try {
         $modules = $form_state->getValue('reinstall');
         $reinstall = array_keys(array_filter($modules));
         $this->moduleInstaller->uninstall($reinstall, FALSE);
         $this->moduleInstaller->install($reinstall, FALSE);
         drupal_set_message($this->t('Uninstalled and installed: %names.', array('%names' => implode(', ', $reinstall))));
     } catch (\Exception $e) {
         drupal_set_message($this->t('Unable to reinstall modules. Error: %error.', array('%error' => $e->getMessage())), 'error');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Make sure the install API is available.
     include_once DRUPAL_ROOT . '/core/includes/install.inc';
     // Get a list of all available modules.
     $modules = system_rebuild_module_data();
     $uninstallable = array_filter($modules, function ($module) use($modules) {
         return empty($modules[$module->getName()]->info['required']) && $module->status;
     });
     // Include system.admin.inc so we can use the sort callbacks.
     $this->moduleHandler->loadInclude('system', 'inc', 'system.admin');
     $form['filters'] = array('#type' => 'container', '#attributes' => array('class' => array('table-filter', 'js-show')));
     $form['filters']['text'] = array('#type' => 'search', '#title' => $this->t('Search'), '#size' => 30, '#placeholder' => $this->t('Enter module name'), '#attributes' => array('class' => array('table-filter-text'), 'data-table' => '#system-modules-uninstall', 'autocomplete' => 'off', 'title' => $this->t('Enter a part of the module name or description to filter by.')));
     $form['modules'] = array();
     // Only build the rest of the form if there are any modules available to
     // uninstall;
     if (empty($uninstallable)) {
         return $form;
     }
     $profile = drupal_get_profile();
     // Sort all modules by their name.
     uasort($uninstallable, 'system_sort_modules_by_info_name');
     $validation_reasons = $this->moduleInstaller->validateUninstall(array_keys($uninstallable));
     $form['uninstall'] = array('#tree' => TRUE);
     foreach ($uninstallable as $module_key => $module) {
         $name = $module->info['name'] ?: $module->getName();
         $form['modules'][$module->getName()]['#module_name'] = $name;
         $form['modules'][$module->getName()]['name']['#markup'] = $name;
         $form['modules'][$module->getName()]['description']['#markup'] = $this->t($module->info['description']);
         $form['uninstall'][$module->getName()] = array('#type' => 'checkbox', '#title' => $this->t('Uninstall @module module', array('@module' => $name)), '#title_display' => 'invisible');
         // If a validator returns reasons not to uninstall a module,
         // list the reasons and disable the check box.
         if (isset($validation_reasons[$module_key])) {
             $form['modules'][$module->getName()]['#validation_reasons'] = $validation_reasons[$module_key];
             $form['uninstall'][$module->getName()]['#disabled'] = TRUE;
         }
         // All modules which depend on this one must be uninstalled first, before
         // we can allow this module to be uninstalled. (The installation profile
         // is excluded from this list.)
         foreach (array_keys($module->required_by) as $dependent) {
             if ($dependent != $profile && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) {
                 $name = isset($modules[$dependent]->info['name']) ? $modules[$dependent]->info['name'] : $dependent;
                 $form['modules'][$module->getName()]['#required_by'][] = $name;
                 $form['uninstall'][$module->getName()]['#disabled'] = TRUE;
             }
         }
     }
     $form['#attached']['library'][] = 'system/drupal.system.modules';
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Uninstall'));
     return $form;
 }