/**
  * {@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;
 }
 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.');
 }
Exemple #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)
 {
     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');
     }
 }