diff --git a/migration_templates/d7_disqus_comment_status.yml b/migration_templates/d7_disqus_comment_status.yml new file mode 100644 index 0000000000000000000000000000000000000000..79f9763a367326ce5cfdb4bce250633a4dacddc9 --- /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 0000000000000000000000000000000000000000..abf2f6d7d2a613b170609bfb4c6cdd6ca741b056 --- /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 0000000000000000000000000000000000000000..338dd1a162fd48ea4faad6c4b8a197ba88d59c51 --- /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 0000000000000000000000000000000000000000..64b9ea4ea5e0ffabda609a93e7c48f3346848ed6 --- /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 0000000000000000000000000000000000000000..73fd8d484539fbaec3719c3efbd53c169535050f --- /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 0000000000000000000000000000000000000000..abed6a94bb497ff39ef47ed83090633f40861d75 --- /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 0000000000000000000000000000000000000000..64105a83a33329ad3898c0e29bc943770ac6e176 --- /dev/null +++ b/src/Plugin/migrate/source/DisqusCommentsStatus.php @@ -0,0 +1,98 @@ + $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 0000000000000000000000000000000000000000..3cb48659b87043102d92e59a8fa9b191edfb2a61 --- /dev/null +++ b/src/Plugin/migrate/source/DisqusEnabledNodeTypes.php @@ -0,0 +1,91 @@ +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; + } + +}