From 0e1a6fc40bf78f4c7089e167c4b399eb01881f7b Mon Sep 17 00:00:00 2001 From: Keith Dechant Date: Mon, 4 May 2015 23:52:10 -0700 Subject: [PATCH] D7 migrations --- .../config/install/migrate.migration.d7_field.yml | 41 ++++++++ .../migrate.migration.d7_field_instance.yml | 32 +++++++ .../config/install/migrate.migration.d7_file.yml | 20 ++++ .../migrate.migration.d7_image_settings.yml | 12 +++ .../migrate.migration.d7_system_authorize.yml | 10 ++ .../install/migrate.migration.d7_system_menu.yml | 10 ++ .../install/migrate.migration.d7_taxonomy_term.yml | 28 ++++++ .../migrate.migration.d7_taxonomy_vocabulary.yml | 24 +++++ .../config/install/migrate.migration.d7_user.yml | 32 +++++++ .../install/migrate.migration.d7_user_flood.yml | 18 ++++ .../migrate/process/d7/FieldInstanceDefaults.php | 42 +++++++++ .../migrate/process/d7/FieldInstanceSettings.php | 56 +++++++++++ .../src/Plugin/migrate/source/d7/Field.php | 99 ++++++++++++++++++++ .../src/Plugin/migrate/source/d7/FieldInstance.php | 103 +++++++++++++++++++++ .../src/Plugin/migrate/source/d7/File.php | 90 ++++++++++++++++++ .../src/Plugin/migrate/source/d7/Term.php | 78 ++++++++++++++++ .../src/Plugin/migrate/source/d7/User.php | 94 +++++++++++++++++++ .../src/Plugin/migrate/source/d7/Vocabulary.php | 66 +++++++++++++ 18 files changed, 855 insertions(+) create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_field.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_field_instance.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_file.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_image_settings.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_system_authorize.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_system_menu.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_taxonomy_term.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_taxonomy_vocabulary.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_user.yml create mode 100755 core/modules/migrate_drupal/config/install/migrate.migration.d7_user_flood.yml create mode 100755 core/modules/migrate_drupal/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php create mode 100755 core/modules/migrate_drupal/src/Plugin/migrate/process/d7/FieldInstanceSettings.php create mode 100755 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Field.php create mode 100755 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldInstance.php create mode 100755 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/File.php create mode 100755 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Term.php create mode 100755 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/User.php create mode 100755 core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Vocabulary.php diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_field.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_field.yml new file mode 100755 index 0000000..115cec2 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_field.yml @@ -0,0 +1,41 @@ +id: d7_field + +source: + plugin: d7_field + constants: + status: true + langcode: und +process: + entity_type: entity_type + status: constants.status + langcode: constants.langcode + name: field_name + type: + plugin: static_map + source: + - type + map: + number_integer: integer + number_decimal: decimal + number_float: float + file: file + image: image + text: text + text_long: text_long + text_with_summary: text_with_summary + email: email + link_field: link + date: datetime + datestamp: datetime + datetime: datetime + phone: telephone + cardinality: cardinality + settings: settings + +destination: + plugin: entity:field_config +dependencies: + # It is not possible to make this a requirement as d6_field_settings has no + # source id. However it also has no requirements so it will always run so a + # dependency is enough. + - d6_field_settings: false diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_field_instance.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_field_instance.yml new file mode 100755 index 0000000..0168023 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_field_instance.yml @@ -0,0 +1,32 @@ +id: d7_field_instance + +source: + plugin: d7_field_instance + constants: + status: true + +process: + entity_type: entity_type + field_name: field_name + bundle: bundle + label: label + description: description + required: required + status: constants.status + settings: + plugin: d7_field_instance_settings + source: + - instance_settings + - widget_settings + + default_value_function: '' + default_value: + plugin: d7_field_instance_defaults + source: + - default_value + - widget_settings + +destination: + plugin: entity:field_instance_config +migration_dependencies: + - d7_field diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_file.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_file.yml new file mode 100755 index 0000000..17757f7 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_file.yml @@ -0,0 +1,20 @@ +# Every migration that saves into {file_managed} must have the d7_file +# migration as an optional dependency to ensure d7_file runs first. +id: d7_file +label: Drupal 7 files +migration_groups: + - Drupal 7 +source: + plugin: d7_file +process: + fid: fid + filename: filename + uid: uid + uri: uri + filemime: filemime + filesize: filesize + status: status + created: timestamp + changed: timestamp +destination: + plugin: entity:file diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_image_settings.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_image_settings.yml new file mode 100755 index 0000000..8f55c15 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_image_settings.yml @@ -0,0 +1,12 @@ +id: d7_image_settings +source: + plugin: variable + variables: + - allow_insecure_derivatives + - suppress_itok_output +process: + suppress_itok_output: suppress_itok_output + allow_insecure_derivatives: allow_insecure_derivatives +destination: + plugin: config + config_name: image.settings diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_system_authorize.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_system_authorize.yml new file mode 100755 index 0000000..fa58548 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_system_authorize.yml @@ -0,0 +1,10 @@ +id: d7_system_authorize +source: + plugin: variable + variables: + - authorize_filetransfer_default +process: + filetransfer_default: authorize_filetransfer_default +destination: + plugin: config + config_name: system.authorize diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_system_menu.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_system_menu.yml new file mode 100755 index 0000000..b905f65 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_system_menu.yml @@ -0,0 +1,10 @@ +id: d7_system_menu +source: + plugin: variable + variables: + - menu_default_active_menus +process: + active_menus_default: menu_default_active_menus +destination: + plugin: config + config_name: system.menu diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_taxonomy_term.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_taxonomy_term.yml new file mode 100755 index 0000000..721dc34 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_taxonomy_term.yml @@ -0,0 +1,28 @@ +id: d7_taxonomy_term +label: Drupal 7 taxonomy terms +migration_groups: + - Drupal 7 +source: + plugin: d7_taxonomy_term +process: + tid: tid + vid: + plugin: migration + migration: d7_taxonomy_vocabulary + source: vid + name: name + description: description + weight: weight + parent: + - + plugin: skip_process_on_empty + source: parent + - + plugin: migration + migration: d7_taxonomy_term + changed: timestamp +destination: + plugin: entity:taxonomy_term +migration_dependencies: + required: + - d7_taxonomy_vocabulary diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_taxonomy_vocabulary.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_taxonomy_vocabulary.yml new file mode 100755 index 0000000..1b42ae0 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_taxonomy_vocabulary.yml @@ -0,0 +1,24 @@ +id: d7_taxonomy_vocabulary +label: Drupal 7 taxonomy vocabularies +migration_groups: + - Drupal 7 +source: + plugin: d7_taxonomy_vocabulary +process: + vid: + - + plugin: machine_name + source: machine_name + - + plugin: dedupe_entity + entity_type: taxonomy_vocabulary + field: vid + length: 32 + label: name + name: name + description: description + hierarchy: hierarchy + module: module + weight: weight +destination: + plugin: entity:taxonomy_vocabulary diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_user.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_user.yml new file mode 100755 index 0000000..268017c --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_user.yml @@ -0,0 +1,32 @@ +id: d7_user +source: + plugin: d7_user +destination: + plugin: entity:user +process: + uid: uid + name: name + pass: pass + mail: mail + status: status + signature: signature + # TODO: whe the d7 text format migration is written, uncomment the following. +# signature_format: +# plugin: migration +# migration: d6_filter_format +# source: signature_format +# no_stub: 1 + created: created + changed: changed + access: access + login: login + timezone: timezone + langcode: language + preferred_langcode: language + preferred_admin_langcode: language + init: init + # d7 user roles migration is not written yet. +# roles: +# plugin: migration +# migration: d7_user_role +# source: roles \ No newline at end of file diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d7_user_flood.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d7_user_flood.yml new file mode 100755 index 0000000..8309395 --- /dev/null +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d7_user_flood.yml @@ -0,0 +1,18 @@ +id: d7_user_flood +source: + plugin: variable + variables: + - user_failed_login_identifier_uid_only + - user_failed_login_ip_limit + - user_failed_login_ip_window + - user_failed_login_user_window + - user_failed_login_user_limit +process: + uid_only: user_failed_login_identifier_uid_only + ip_limit: user_failed_login_ip_limit + ip_window: user_failed_login_ip_window + user_limit: user_failed_login_user_limit + user_window: user_failed_login_user_window +destination: + plugin: config + config_name: user.flood diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php new file mode 100755 index 0000000..84938d2 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php @@ -0,0 +1,42 @@ + $instance_settings['default_image'], + 'alt' => '', + 'title' => '', + 'width' => NULL, + 'height' => NULL, + ); + break; + + // @todo Add here other special conversions, if case. + + default: + $settings = $instance_settings; + } + + // Remove 'user_register_form'. + // @see https://drupal.org/node/2049485' + unset($settings['user_register_form']); + + return $settings; + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Field.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Field.php new file mode 100755 index 0000000..edc6b6f --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Field.php @@ -0,0 +1,99 @@ +select('field_config', 'fc') + ->fields('fc', array( + 'field_name', + 'type', + 'module', + 'storage_type', + 'storage_module', + 'locked', + 'data', + 'cardinality', + 'translatable', + )) + ->fields('fci', array( + 'entity_type', + )) + ->condition('fc.active', 1) + ->condition('fc.deleted', 0) + ->condition('fc.storage_active', 1); + $query->join('field_config_instance', 'fci', 'fc.id = fci.field_id'); + $query->orderBy('fc.field_name'); + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'field_name' => $this->t('The name of this field.'), + 'type' => $this->t('The type of this field.'), + 'module' => $this->t('The module that implements the field type.') , + 'storage' => $this->t('The field stoerage.'), + 'locked' => $this->t( 'Locked'), + 'cardinality' => $this->t('Cardinality'), + 'translatable' => $this->t('translatable'), + ); + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row, $keep = TRUE) { + // The logic is from field_read_fields() in Drupal 7. + $field = unserialize($row->getSourceProperty('data')); + $field['field_name'] = $row->getSourceProperty('field_name'); + $field['type'] = $row->getSourceProperty('type'); + $field['module'] = $row->getSourceProperty('module'); + $field['storage']['type'] = $row->getSourceProperty('storage_type'); + $field['storage']['module'] = $row->getSourceProperty('storage_module'); + $field['locked'] = $row->getSourceProperty('locked'); + $field['cardinality'] = $row->getSourceProperty('cardinality'); + $field['translatable'] = $row->getSourceProperty('translatable'); + foreach ($field as $key => $data) { + $row->setSourceProperty($key, $data); + } + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['field_name']['type'] = 'string'; + $ids['field_name']['alias'] = 'fc'; + $ids['entity_type']['type'] = 'string'; + $ids['entity_type']['alias'] = 'fci'; + return $ids; + } +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldInstance.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldInstance.php new file mode 100755 index 0000000..7b8bc92 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/FieldInstance.php @@ -0,0 +1,103 @@ +select('field_config_instance', 'fci') + ->fields('fci', array('field_name', 'entity_type', 'bundle', 'data')) + ->condition('fci.deleted', 0) + ->condition('fc.active', 1) + ->condition('fc.deleted', 0) + ->condition('fc.storage_active', 1); + $query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id'); + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'field_name' => $this->t('The machine name of field.'), + 'entity_type' => $this->t('The entity type.'), + 'bundle' => $this->t('The entity bundle.'), + 'default_value' => $this->t('Default value'), + 'instance_settings' => $this->t('Field instance settings.'), + 'widget_settings' => $this->t('Widget settings.'), + 'display_settings' => $this->t('Display settings.'), + + /* + 'weight' => $this->t('Weight.'), + 'label' => $this->t('A name to show.'), + 'widget_type' => $this->t('Widget type.'), + 'description' => $this->t('A description of field.'), + 'widget_module' => $this->t('Module that implements widget.'), + 'widget_active' => $this->t('Status of widget'), + 'module' => $this->t('The module that provides the field.'), + */ + + ); + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row, $keep = TRUE) { + $data = unserialize($row->getSourceProperty('data')); + + $row->setSourceProperty('label', $data['label']); + $row->setSourceProperty('description', $data['description']); + $row->setSourceProperty('required', $data['required']); + + $default_value = !empty($data['default_value']) ? $data['default_value'] : array(); + $row->setSourceProperty('default_value', $default_value); + + // Settings. + $row->setSourceProperty('instance_settings', $data['settings']); + $row->setSourceProperty('widget_settings', $data['widget']); + $row->setSourceProperty('display_settings', $data['display']); + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return array( + 'entity_type' => array( + 'type' => 'string', + 'alias' => 'fci', + ), + 'bundle' => array( + 'type' => 'string', + 'alias' => 'fci', + ), + 'field_name' => array( + 'type' => 'string', + 'alias' => 'fci', + ), + ); + } +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/File.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/File.php new file mode 100755 index 0000000..e5fd782 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/File.php @@ -0,0 +1,90 @@ +select('file_managed', 'f')->fields('f', array( + 'fid', + 'uid', + 'filename', + 'uri', + 'filemime', + 'filesize', + 'status', + 'timestamp', + 'type' + )); + return $query; + } + + + /** + * {@inheritdoc} + */ + protected function runQuery() { + $conf_path = isset($this->configuration['conf_path']) ? $this->configuration['conf_path'] : 'sites/default'; + $this->filePath = $this->variableGet('file_directory_path', $conf_path . '/files') . '/'; + + // FILE_DOWNLOADS_PUBLIC == 1 and FILE_DOWNLOADS_PRIVATE == 2. + $this->isPublic = $this->variableGet('file_downloads', 1) == 1; + return parent::runQuery(); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'fid' => $this->t('File ID'), + 'uid' => $this->t('The {users}.uid who added the file. If set to 0, this file was added by an anonymous user.'), + 'filename' => $this->t('File name'), + 'uri' => $this->t('File URI'), + 'filemime' => $this->t('File Mime Type'), + 'status' => $this->t('The published status of a file.'), + 'created' => $this->t('The time that the file was added.'), + 'changed' => $this->t('The time that the file was last changed.'), + ); + } + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['fid']['type'] = 'integer'; + return $ids; + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Term.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Term.php new file mode 100755 index 0000000..157ec5b --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Term.php @@ -0,0 +1,78 @@ +select('taxonomy_term_data', 'td') + ->fields('td', array('tid', 'vid', 'name', 'description', 'weight', 'format')) + // This works, but we cannot test that, because there is no support for + // distinct() in FakeSelect, yet. + ->distinct(); + if (isset($this->configuration['vocabulary'])) { + $query->condition('vid', $this->configuration['vocabulary'], 'IN'); + } + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'tid' => $this->t('The term ID.'), + 'vid' => $this->t('Existing term VID'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'weight' => $this->t('Weight'), + 'parent' => $this->t("The Drupal term IDs of the term's parents."), + ); + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + // Find parents for this row. + $parents = $this->select('taxonomy_term_hierarchy', 'th') + ->fields('th', array('parent', 'tid')) + ->condition('tid', $row->getSourceProperty('tid')) + ->execute() + ->fetchCol(); + $row->setSourceProperty('parent', $parents); + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['tid']['type'] = 'integer'; + return $ids; + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/User.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/User.php new file mode 100755 index 0000000..c2801f6 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/User.php @@ -0,0 +1,94 @@ +select('users', 'u') + ->fields('u', array_keys($this->baseFields())) + ->condition('uid', 0, '>') + ->orderBy('uid'); + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = $this->baseFields(); + return $fields; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return array( + 'uid' => array( + 'type' => 'integer', + 'alias' => 'u', + ), + ); + } + + /** + * Returns the user base fields to be migrated. + * + * @return array + * Associative array having field name as key and description as value. + */ + protected function baseFields() { + $fields = array( + 'uid' => $this->t('User ID'), + 'name' => $this->t('Username'), + 'pass' => $this->t('Password'), + 'mail' => $this->t('Email address'), + 'signature' => $this->t('Signature'), + 'signature_format' => $this->t('Signature format'), + 'created' => $this->t('Registered timestamp'), + 'access' => $this->t('Last access timestamp'), + 'login' => $this->t('Last login timestamp'), + 'status' => $this->t('Status'), + 'timezone' => $this->t('Timezone'), + 'language' => $this->t('Language'), + 'picture' => $this->t('Picture'), + 'init' => $this->t('Init'), + ); + return $fields; + +} + + /** + * {@inheritdoc} + */ + public function bundleMigrationRequired() { + return FALSE; + } + + /** + * {@inheritdoc} + */ + public function entityTypeId() { + return 'user'; + } + +} \ No newline at end of file diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Vocabulary.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Vocabulary.php new file mode 100755 index 0000000..929009e --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d7/Vocabulary.php @@ -0,0 +1,66 @@ +select('taxonomy_vocabulary', 'v') + ->fields('v', array( + 'vid', + 'name', + 'description', + 'hierarchy', + 'module', + 'weight', + 'machine_name' + )); + $query->condition('vid', array(5,6), 'NOT IN'); + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + return array( + 'vid' => $this->t('The vocabulary ID.'), + 'name' => $this->t('The name of the vocabulary.'), + 'description' => $this->t('The description of the vocabulary.'), + 'help' => $this->t('Help text to display for the vocabulary.'), + 'relations' => $this->t('Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)'), + 'hierarchy' => $this->t('The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)'), + 'weight' => $this->t('The weight of the vocabulary in relation to other vocabularies.'), + 'parents' => $this->t("The Drupal term IDs of the term's parents."), + 'node_types' => $this->t('The names of the node types the vocabulary may be used with.'), + ); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['vid']['type'] = 'integer'; + return $ids; + } + +} -- 2.3.5