Commit be0beb18 authored by slashrsm's avatar slashrsm

Issue #2658422 by slashrsm: Complete migration from D7 to D8.

parent c1ef848c
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
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
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
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
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
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
<?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;
}
}
<?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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment