Chris@0: select('system', 's', [ Chris@0: 'fetch' => \PDO::FETCH_ASSOC, Chris@0: ]) Chris@0: ->fields('s') Chris@0: ->execute(); Chris@0: foreach ($results as $result) { Chris@0: $system_data[$result['type']][$result['name']] = $result; Chris@0: } Chris@0: } Chris@18: catch (DatabaseExceptionWrapper $e) { Chris@0: // The table might not exist for example in tests. Chris@0: } Chris@0: return $system_data; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates the necessary state entries for SqlBase::getDatabase() to work. Chris@0: * Chris@0: * The state entities created here have to exist before migration plugin Chris@0: * instances are created so that derivers such as Chris@0: * \Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver can access the source Chris@0: * database. Chris@0: * Chris@0: * @param array $database Chris@0: * The source database settings. Chris@0: * @param string $drupal_version Chris@0: * The Drupal version. Chris@0: * Chris@0: * @see \Drupal\migrate\Plugin\migrate\source\SqlBase::getDatabase() Chris@0: */ Chris@0: protected function createDatabaseStateSettings(array $database, $drupal_version) { Chris@0: $database_state['key'] = 'upgrade'; Chris@0: $database_state['database'] = $database; Chris@0: $database_state_key = 'migrate_drupal_' . $drupal_version; Chris@0: \Drupal::state()->set($database_state_key, $database_state); Chris@0: \Drupal::state()->set('migrate.fallback_state_key', $database_state_key); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the migrations for import. Chris@0: * Chris@0: * @param string $database_state_key Chris@0: * The state key. Chris@0: * @param int $drupal_version Chris@0: * The version of Drupal we're getting the migrations for. Chris@0: * Chris@0: * @return \Drupal\migrate\Plugin\MigrationInterface[] Chris@0: * The migrations for import. Chris@0: */ Chris@0: protected function getMigrations($database_state_key, $drupal_version) { Chris@0: $version_tag = 'Drupal ' . $drupal_version; Chris@0: $plugin_manager = \Drupal::service('plugin.manager.migration'); Chris@0: /** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */ Chris@0: $all_migrations = $plugin_manager->createInstancesByTag($version_tag); Chris@0: $migrations = []; Chris@0: foreach ($all_migrations as $migration) { Chris@16: // Skip migrations tagged with any of the follow-up migration tags. They Chris@16: // will be derived and executed after the migrations on which they depend Chris@16: // have been successfully executed. Chris@16: // @see Drupal\migrate_drupal\Plugin\MigrationWithFollowUpInterface Chris@16: if (!empty(array_intersect($migration->getMigrationTags(), $this->getFollowUpMigrationTags()))) { Chris@16: continue; Chris@16: } Chris@17: // Multilingual migrations require migrate_drupal_multilingual. Chris@17: $tags = $migration->getMigrationTags() ?: []; Chris@17: if (in_array('Multilingual', $tags, TRUE) && (!\Drupal::service('module_handler')->moduleExists('migrate_drupal_multilingual'))) { Chris@17: throw new RequirementsException(sprintf("Install migrate_drupal_multilingual to run migration '%s'.", $migration->getPluginId())); Chris@17: } Chris@17: Chris@0: try { Chris@0: // @todo https://drupal.org/node/2681867 We should be able to validate Chris@0: // the entire migration at this point. Chris@0: $source_plugin = $migration->getSourcePlugin(); Chris@0: if ($source_plugin instanceof RequirementsInterface) { Chris@0: $source_plugin->checkRequirements(); Chris@0: } Chris@0: $destination_plugin = $migration->getDestinationPlugin(); Chris@0: if ($destination_plugin instanceof RequirementsInterface) { Chris@0: $destination_plugin->checkRequirements(); Chris@0: } Chris@0: $migrations[] = $migration; Chris@0: } Chris@0: catch (RequirementsException $e) { Chris@0: // Migrations which are not applicable given the source and destination Chris@0: // site configurations (e.g., what modules are enabled) will be silently Chris@0: // ignored. Chris@0: } Chris@0: } Chris@0: Chris@0: return $migrations; Chris@0: } Chris@0: Chris@0: /** Chris@16: * Returns the follow-up migration tags. Chris@16: * Chris@16: * @return string[] Chris@16: */ Chris@16: protected function getFollowUpMigrationTags() { Chris@16: if ($this->followUpMigrationTags === NULL) { Chris@16: $this->followUpMigrationTags = \Drupal::configFactory() Chris@16: ->get('migrate_drupal.settings') Chris@16: ->get('follow_up_migration_tags') ?: []; Chris@16: } Chris@16: return $this->followUpMigrationTags; Chris@16: } Chris@16: Chris@16: /** Chris@0: * Determines what version of Drupal the source database contains. Chris@0: * Chris@0: * @param \Drupal\Core\Database\Connection $connection Chris@0: * The database connection object. Chris@0: * Chris@14: * @return string|false Chris@14: * A string representing the major branch of Drupal core (e.g. '6' for Chris@0: * Drupal 6.x), or FALSE if no valid version is matched. Chris@0: */ Chris@0: protected function getLegacyDrupalVersion(Connection $connection) { Chris@0: // Don't assume because a table of that name exists, that it has the columns Chris@0: // we're querying. Catch exceptions and report that the source database is Chris@0: // not Drupal. Chris@0: // Drupal 5/6/7 can be detected by the schema_version in the system table. Chris@0: if ($connection->schema()->tableExists('system')) { Chris@0: try { Chris@0: $version_string = $connection Chris@0: ->query('SELECT schema_version FROM {system} WHERE name = :module', [':module' => 'system']) Chris@0: ->fetchField(); Chris@0: if ($version_string && $version_string[0] == '1') { Chris@0: if ((int) $version_string >= 1000) { Chris@0: $version_string = '5'; Chris@0: } Chris@0: else { Chris@0: $version_string = FALSE; Chris@0: } Chris@0: } Chris@0: } Chris@0: catch (\PDOException $e) { Chris@0: $version_string = FALSE; Chris@0: } Chris@0: } Chris@0: // For Drupal 8 (and we're predicting beyond) the schema version is in the Chris@0: // key_value store. Chris@0: elseif ($connection->schema()->tableExists('key_value')) { Chris@18: try { Chris@18: $result = $connection Chris@18: ->query("SELECT value FROM {key_value} WHERE collection = :system_schema and name = :module", [ Chris@18: ':system_schema' => 'system.schema', Chris@18: ':module' => 'system', Chris@18: ]) Chris@18: ->fetchField(); Chris@18: $version_string = unserialize($result); Chris@18: } Chris@18: catch (DatabaseExceptionWrapper $e) { Chris@18: $version_string = FALSE; Chris@18: } Chris@0: } Chris@0: else { Chris@0: $version_string = FALSE; Chris@0: } Chris@0: Chris@0: return $version_string ? substr($version_string, 0, 1) : FALSE; Chris@0: } Chris@0: Chris@0: }