Exemplo n.º 1
0
 /**
  * Returns all supported database driver installer objects.
  *
  * @return \Drupal\Core\Database\Install\Tasks[]
  *   An array of available database driver installer objects.
  */
 protected function getDatabaseTypes()
 {
     // Make sure the install API is available.
     include_once DRUPAL_ROOT . '/core/includes/install.inc';
     return drupal_get_database_types();
 }
Exemplo n.º 2
0
 /**
  * Returns all supported database driver installer objects.
  *
  * This wraps drupal_get_database_types() for use without a current container.
  *
  * @return \Drupal\Core\Database\Install\Tasks[]
  *   An array of available database driver installer objects.
  */
 protected function getDatabaseTypes()
 {
     \Drupal::setContainer($this->originalContainer);
     $database_types = drupal_get_database_types();
     \Drupal::unsetContainer();
     return $database_types;
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $driver = $form_state->getValue('driver');
     $database = $form_state->getValue($driver);
     $drivers = drupal_get_database_types();
     $reflection = new \ReflectionClass($drivers[$driver]);
     $install_namespace = $reflection->getNamespaceName();
     // Cut the trailing \Install from namespace.
     $database['namespace'] = substr($install_namespace, 0, strrpos($install_namespace, '\\'));
     $database['driver'] = $driver;
     $form_state->set('database', $database);
     $errors = install_database_errors($database, $form_state->getValue('settings_file'));
     foreach ($errors as $name => $message) {
         $form_state->setErrorByName($name, $message);
     }
 }
Exemplo n.º 4
0
 /**
  * Executes all steps of migrations upgrade.
  */
 protected function testMigrateUpgrade()
 {
     $connection_options = $this->sourceDatabase->getConnectionOptions();
     $this->drupalGet('/upgrade');
     $this->assertText('Upgrade a Drupal site by importing it into a clean and empty new install of Drupal 8. You will lose any existing configuration once you import your site into it. See the upgrading handbook for more detailed information.');
     $this->drupalPostForm(NULL, [], t('Continue'));
     $this->assertText('Provide credentials for the database of the Drupal site you want to upgrade.');
     $this->assertFieldByName('mysql[host]');
     $driver = $connection_options['driver'];
     $connection_options['prefix'] = $connection_options['prefix']['default'];
     // Use the driver connection form to get the correct options out of the
     // database settings. This supports all of the databases we test against.
     $drivers = drupal_get_database_types();
     $form = $drivers[$driver]->getFormOptions($connection_options);
     $connection_options = array_intersect_key($connection_options, $form + $form['advanced_options']);
     $edits = $this->translatePostValues(['driver' => $driver, $driver => $connection_options, 'source_base_path' => $this->getSourceBasePath()]);
     $this->drupalPostForm(NULL, $edits, t('Review upgrade'));
     $this->assertResponse(200);
     $this->assertText('Are you sure?');
     $this->drupalPostForm(NULL, [], t('Perform upgrade'));
     $this->assertText(t('Congratulations, you upgraded Drupal!'));
     // Have to reset all the statics after migration to ensure entities are
     // loadable.
     $this->resetAll();
     $expected_counts = $this->getEntityCounts();
     foreach (array_keys(\Drupal::entityTypeManager()->getDefinitions()) as $entity_type) {
         $real_count = count(\Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple());
         $expected_count = isset($expected_counts[$entity_type]) ? $expected_counts[$entity_type] : 0;
         $this->assertEqual($expected_count, $real_count, "Found {$real_count} {$entity_type} entities, expected {$expected_count}.");
     }
 }
Exemplo n.º 5
0
 /**
  * Executes all steps of migrations upgrade.
  */
 protected function testMigrateUpgrade()
 {
     $connection_options = $this->sourceDatabase->getConnectionOptions();
     $this->drupalGet('/upgrade');
     $this->assertText('Upgrade a Drupal site by importing it into a clean and empty new install of Drupal 8. You will lose any existing configuration once you import your site into it. See the upgrading handbook for more detailed information.');
     $this->drupalPostForm(NULL, [], t('Continue'));
     $this->assertText('Provide credentials for the database of the Drupal site you want to upgrade.');
     $this->assertFieldByName('mysql[host]');
     $driver = $connection_options['driver'];
     $connection_options['prefix'] = $connection_options['prefix']['default'];
     // Use the driver connection form to get the correct options out of the
     // database settings. This supports all of the databases we test against.
     $drivers = drupal_get_database_types();
     $form = $drivers[$driver]->getFormOptions($connection_options);
     $connection_options = array_intersect_key($connection_options, $form + $form['advanced_options']);
     $edit = [$driver => $connection_options, 'source_base_path' => $this->getSourceBasePath()];
     if (count($drivers) !== 1) {
         $edit['driver'] = $driver;
     }
     $edits = $this->translatePostValues($edit);
     // Ensure submitting the form with invalid database credentials gives us a
     // nice warning.
     $this->drupalPostForm(NULL, [$driver . '[database]' => 'wrong'] + $edits, t('Review upgrade'));
     $this->assertText('Resolve the issue below to continue the upgrade.');
     $this->drupalPostForm(NULL, $edits, t('Review upgrade'));
     $this->assertResponse(200);
     $this->assertText('Are you sure?');
     $this->drupalPostForm(NULL, [], t('Perform upgrade'));
     $this->assertText(t('Congratulations, you upgraded Drupal!'));
     // Have to reset all the statics after migration to ensure entities are
     // loadable.
     $this->resetAll();
     $expected_counts = $this->getEntityCounts();
     foreach (array_keys(\Drupal::entityTypeManager()->getDefinitions()) as $entity_type) {
         $real_count = count(\Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple());
         $expected_count = isset($expected_counts[$entity_type]) ? $expected_counts[$entity_type] : 0;
         $this->assertEqual($expected_count, $real_count, "Found {$real_count} {$entity_type} entities, expected {$expected_count}.");
     }
     $version_tag = 'Drupal ' . $this->getLegacyDrupalVersion($this->sourceDatabase);
     $plugin_manager = \Drupal::service('plugin.manager.migration');
     /** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
     $all_migrations = $plugin_manager->createInstancesByTag($version_tag);
     foreach ($all_migrations as $migration) {
         $id_map = $migration->getIdMap();
         foreach ($id_map as $source_id => $map) {
             // Convert $source_id into a keyless array so that
             // \Drupal\migrate\Plugin\migrate\id_map\Sql::getSourceHash() works as
             // expected.
             $source_id_values = array_values(unserialize($source_id));
             $row = $id_map->getRowBySource($source_id_values);
             $destination = serialize($id_map->currentDestination());
             $message = "Successful migration of {$source_id} to {$destination} as part of the {$migration->id()} migration. The source row status is " . $row['source_row_status'];
             // A completed migration should have maps with
             // MigrateIdMapInterface::STATUS_IGNORED or
             // MigrateIdMapInterface::STATUS_IMPORTED.
             if ($row['source_row_status'] == MigrateIdMapInterface::STATUS_FAILED || $row['source_row_status'] == MigrateIdMapInterface::STATUS_NEEDS_UPDATE) {
                 $this->fail($message);
             } else {
                 $this->pass($message);
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Returns the parameters that will be used when Simpletest installs Drupal.
  *
  * @see install_drupal()
  * @see install_state_defaults()
  */
 protected function installParameters()
 {
     $connection_info = Database::getConnectionInfo();
     $driver = $connection_info['default']['driver'];
     $connection_info['default']['prefix'] = $connection_info['default']['prefix']['default'];
     unset($connection_info['default']['driver']);
     unset($connection_info['default']['namespace']);
     unset($connection_info['default']['pdo']);
     unset($connection_info['default']['init_commands']);
     $parameters = array('interactive' => FALSE, 'parameters' => array('profile' => $this->profile, 'langcode' => 'en'), 'forms' => array('install_settings_form' => array('driver' => $driver, $driver => $connection_info['default']), 'install_configure_form' => array('site_name' => 'Drupal', 'site_mail' => '*****@*****.**', 'account' => array('name' => $this->root_user->name, 'mail' => $this->root_user->getEmail(), 'pass' => array('pass1' => $this->root_user->pass_raw, 'pass2' => $this->root_user->pass_raw)), 'update_status_module' => array(1 => NULL, 2 => NULL))));
     // If we only have one db driver available, we cannot set the driver.
     include_once DRUPAL_ROOT . '/core/includes/install.inc';
     if (count(drupal_get_database_types()) == 1) {
         unset($parameters['forms']['install_settings_form']['driver']);
     }
     return $parameters;
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, array &$form_state)
 {
     $driver = $form_state['values']['driver'];
     $database = $form_state['values'][$driver];
     $drivers = drupal_get_database_types();
     $reflection = new \ReflectionClass($drivers[$driver]);
     $install_namespace = $reflection->getNamespaceName();
     // Cut the trailing \Install from namespace.
     $database['namespace'] = substr($install_namespace, 0, strrpos($install_namespace, '\\'));
     $database['driver'] = $driver;
     $form_state['storage']['database'] = $database;
     $errors = install_database_errors($database, $form_state['values']['settings_file']);
     foreach ($errors as $name => $message) {
         $this->setFormError($name, $form_state, $message);
     }
 }