summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanez Urevc2016-01-31 18:38:33 (GMT)
committerJanez Urevc2016-01-31 18:38:33 (GMT)
commitbe0beb18637c1fbc6d7a246b385ef2ab8f586c8b (patch)
treea74015025f9f6f64740f7430dafccfab479bf820
parentc1ef848ce09260eb1729b2d225d5aa315fd3f4e9 (diff)
Issue #2658422 by slashrsm: Complete migration from D7 to D8.
-rw-r--r--migration_templates/d7_disqus_comment_status.yml20
-rw-r--r--migration_templates/d7_disqus_entity_display.yml29
-rw-r--r--migration_templates/d7_disqus_entity_form_display.yml20
-rw-r--r--migration_templates/d7_disqus_field.yml24
-rw-r--r--migration_templates/d7_disqus_field_storage.yml18
-rw-r--r--migration_templates/d7_disqus_settings.yml35
-rw-r--r--src/Plugin/migrate/source/DisqusCommentsStatus.php98
-rw-r--r--src/Plugin/migrate/source/DisqusEnabledNodeTypes.php91
8 files changed, 335 insertions, 0 deletions
diff --git a/migration_templates/d7_disqus_comment_status.yml b/migration_templates/d7_disqus_comment_status.yml
new file mode 100644
index 0000000..79f9763
--- /dev/null
+++ b/migration_templates/d7_disqus_comment_status.yml
@@ -0,0 +1,20 @@
+id: d7_disqus_comment_status
+label: D7 Disqus comment status
+migration_tags:
+ - Drupal 7
+source:
+ plugin: disqus_comments_status
+process:
+ nid: nid
+ 'disqus/status':
+ plugin: get
+ source: status
+ 'disqus/identifier':
+ plugin: get
+ source: identifier
+destination:
+ plugin: entity:node
+migration_dependencies:
+ required:
+ - d7_node:*
+ - d7_disqus_field
diff --git a/migration_templates/d7_disqus_entity_display.yml b/migration_templates/d7_disqus_entity_display.yml
new file mode 100644
index 0000000..abf2f6d
--- /dev/null
+++ b/migration_templates/d7_disqus_entity_display.yml
@@ -0,0 +1,29 @@
+langcode: en
+status: true
+id: d7_disqus_entity_display
+migration_tags:
+ - 'Drupal 7'
+label: 'Disqus display configuration'
+source:
+ plugin: disqus_enabled_content_types
+ constants:
+ entity_type: node
+ view_mode: default
+ name: disqus
+ type: disqus_comment
+ options:
+ label: hidden
+ type: disqus_comment
+ weight: 20
+process:
+ entity_type: 'constants/entity_type'
+ bundle: type
+ options: 'constants/options'
+ view_mode: 'constants/view_mode'
+ field_name: 'constants/name'
+ type: constants/type
+destination:
+ plugin: component_entity_display
+migration_dependencies:
+ required:
+ - d7_disqus_field
diff --git a/migration_templates/d7_disqus_entity_form_display.yml b/migration_templates/d7_disqus_entity_form_display.yml
new file mode 100644
index 0000000..338dd1a
--- /dev/null
+++ b/migration_templates/d7_disqus_entity_form_display.yml
@@ -0,0 +1,20 @@
+id: d7_disqus_entity_form_display
+label: 'Disqus form display configuration'
+migration_tags:
+ - Drupal 7
+source:
+ plugin: disqus_enabled_content_types
+ constants:
+ entity_type: node
+ field_name: disqus
+ form_mode: default
+process:
+ entity_type: 'constants/entity_type'
+ field_name: 'constants/field_name'
+ form_mode: 'constants/form_mode'
+ bundle: type
+destination:
+ plugin: component_entity_form_display
+migration_dependencies:
+ required:
+ - d7_disqus_field
diff --git a/migration_templates/d7_disqus_field.yml b/migration_templates/d7_disqus_field.yml
new file mode 100644
index 0000000..64b9ea4
--- /dev/null
+++ b/migration_templates/d7_disqus_field.yml
@@ -0,0 +1,24 @@
+id: d7_disqus_field
+label: Drupal 7 Disqus fields
+migration_tags:
+ - Drupal 7
+source:
+ plugin: disqus_enabled_content_types
+ constants:
+ entity_type: node
+ name: disqus
+ label: 'Disqus'
+ default_identifier: ''
+process:
+ entity_type: 'constants/entity_type'
+ bundle: type
+ label: 'constants/label'
+ field_name: 'constants/name'
+ 'default_value/0/status': default
+ 'default_value/0/identifier': 'constants/default_identifier'
+destination:
+ plugin: entity:field_config
+migration_dependencies:
+ required:
+ - d7_disqus_field_storage
+ - d7_node_type
diff --git a/migration_templates/d7_disqus_field_storage.yml b/migration_templates/d7_disqus_field_storage.yml
new file mode 100644
index 0000000..73fd8d4
--- /dev/null
+++ b/migration_templates/d7_disqus_field_storage.yml
@@ -0,0 +1,18 @@
+id: d7_disqus_field_storage
+label: Drupal 7 Disqus field storage
+migration_tags:
+ - Drupal 7
+source:
+ plugin: md_empty
+ constants:
+ entity_type: node
+ type: disqus_comment
+ name: disqus
+ cardinality: 1
+process:
+ entity_type: 'constants/entity_type'
+ field_name: 'constants/name'
+ type: 'constants/type'
+ cardinality: 'constants/cardinality'
+destination:
+ plugin: md_entity:field_storage_config
diff --git a/migration_templates/d7_disqus_settings.yml b/migration_templates/d7_disqus_settings.yml
new file mode 100644
index 0000000..abed6a9
--- /dev/null
+++ b/migration_templates/d7_disqus_settings.yml
@@ -0,0 +1,35 @@
+id: d7_disqus_settings
+label: Disqus settings
+migration_tags:
+ - Drupal 7
+source:
+ plugin: variable
+ variables:
+ - disqus_domain
+ - disqus_localization
+ - disqus_inherit_login
+ - disqus_track_newcomment_ga
+ - disqus_useraccesstoken
+ - disqus_publickey
+ - disqus_secretkey
+ - disqus_api_update
+ - disqus_api_delete
+ - disqus_sso
+ - disqus_use_site_logo
+ - disqus_logo
+process:
+ 'disqus_domain': disqus_domain
+ 'behavior/disqus_localization': disqus_localization
+ 'behavior/disqus_inherit_login': disqus_inherit_login
+ 'behavior/disqus_track_newcomment_ga': disqus_track_newcomment_ga
+ 'advanced/disqus_useraccesstoken': disqus_useraccesstoken
+ 'advanced/disqus_publickey': disqus_publickey
+ 'advanced/disqus_secretkey': disqus_secretkey
+ 'advanced/api/disqus_api_update': disqus_api_update
+ 'advanced/api/disqus_api_update': disqus_api_delete
+ 'advanced/sso/disqus_sso': disqus_sso
+ 'advanced/sso/disqus_use_site_logo': disqus_use_site_logo
+ 'advanced/sso/disqus_logo':
+destination:
+ plugin: config
+ config_name: disqus.settings
diff --git a/src/Plugin/migrate/source/DisqusCommentsStatus.php b/src/Plugin/migrate/source/DisqusCommentsStatus.php
new file mode 100644
index 0000000..64105a8
--- /dev/null
+++ b/src/Plugin/migrate/source/DisqusCommentsStatus.php
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\disqus\Plugin\migrate\source\DisqusCommentsStatus.
+ */
+
+namespace Drupal\disqus\Plugin\migrate\source;
+
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\State\StateInterface;
+use Drupal\migrate\Entity\MigrationInterface;
+use Drupal\migrate\Row;
+use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
+
+/**
+ * Disqus comments status.
+ *
+ * @MigrateSource(
+ * id = "disqus_comments_status"
+ * )
+ */
+class DisqusCommentsStatus extends DrupalSqlBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields() {
+ return [
+ 'nid' => $this->t('ID of Node this status belongs to'),
+ 'status' => $this->t('Disqus comments status'),
+ 'identifier' => $this->t('Disqus thread identifier'),
+ ];
+ }
+
+ /**
+ * Gets content types Disqus is enabled for.
+ *
+ * @return array
+ * Array of content type machine names.
+ */
+ protected function getEnabledTypes() {
+ $enabled = $this->getDatabase()
+ ->select('variable', 'v')
+ ->fields('v', ['value'])
+ ->condition('v.name', 'disqus_nodetypes')
+ ->execute()
+ ->fetchField();
+ return array_filter(unserialize($enabled));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function query() {
+ /** @var \Drupal\Core\Database\Query\SelectInterface $query */
+ $query = $this->select('node', 'n');
+ $query->condition('n.type', $this->getEnabledTypes(), 'IN');
+ $query->orderBy('n.nid');
+ $query->leftJoin('disqus', 'd', 'd.nid=n.nid');
+ $query->addField('n', 'nid', 'nid');
+ # No entry in {disqus} table means status == 1.
+ $query->addExpression('IF(d.status IS NULL, 1, d.status)', 'status');
+ return $query;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function count() {
+ return $this->getDatabase()
+ ->select('node', 'n')
+ ->condition('n.type', $this->getEnabledTypes(), 'IN')
+ ->countQuery()
+ ->execute()
+ ->fetchField();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function prepareRow(Row $row) {
+ parent::prepareRow($row);
+ $status = $row->getSourceProperty('status');
+ $nid = $row->getSourceProperty('nid');
+ $row->setSourceProperty('identifier', 'node/' . $nid);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIds() {
+ $ids['nid']['type'] = 'integer';
+ $ids['nid']['alias'] = 'n';
+ return $ids;
+ }
+
+}
diff --git a/src/Plugin/migrate/source/DisqusEnabledNodeTypes.php b/src/Plugin/migrate/source/DisqusEnabledNodeTypes.php
new file mode 100644
index 0000000..3cb4865
--- /dev/null
+++ b/src/Plugin/migrate/source/DisqusEnabledNodeTypes.php
@@ -0,0 +1,91 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\disqus\Plugin\migrate\source\DisqusEnabledNodeType.
+ */
+
+namespace Drupal\disqus\Plugin\migrate\source;
+
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\State\StateInterface;
+use Drupal\migrate\Entity\MigrationInterface;
+use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
+
+/**
+ * Disqus enabled content types migration source.
+ *
+ * @MigrateSource(
+ * id = "disqus_enabled_content_types"
+ * )
+ */
+class DisqusEnabledNodeTypes extends DrupalSqlBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function initializeIterator() {
+ return new \ArrayIterator($this->values());
+ }
+
+ /**
+ * Return the values of the variables specified in the plugin configuration.
+ *
+ * @return array
+ * An associative array where the keys are the variables specified in the
+ * plugin configuration and the values are the values found in the source.
+ * Only those values are returned that are actually in the database.
+ */
+ protected function values() {
+ $values = [];
+ if($result = $this->prepareQuery()->execute()->fetchAllKeyed()) {
+ $enabled_types = unserialize($result['disqus_nodetypes']);
+ $enabled_types = array_filter($enabled_types);
+ $defaults = unserialize($result['disqus_nodetypes_default']);
+ $defaults = array_filter($defaults);
+ foreach ($enabled_types as $type) {
+ $values[] = [
+ 'type' => $type,
+ 'default' => !empty($defaults[$type]),
+ ];
+ }
+ }
+ return $values;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function count() {
+ return count($this->values());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields() {
+ return [
+ 'type' => $this->t('Content type with enabled Disqus'),
+ 'default' => $this->t('Default Disqus status for node type'),
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function query() {
+ return $this->getDatabase()
+ ->select('variable', 'v')
+ ->fields('v', ['name', 'value'])
+ ->condition('v.name', ['disqus_nodetypes', 'disqus_nodetypes_default'], 'IN');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIds() {
+ $ids['type']['type'] = 'string';
+ return $ids;
+ }
+
+}