simplenews installed, configured. Simplenews migrated (missing status) missing subscribers
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
id: d7_simplenews_nodes
|
||||
migration_group: d7_materio
|
||||
dependencies:
|
||||
module:
|
||||
- migrate_drupal
|
||||
- simplenews
|
||||
label: Simplenews newsletters nodes
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
- Materio
|
||||
|
||||
source:
|
||||
plugin: d7_simplenews_nodes
|
||||
node_type: simplenews
|
||||
high_water_property:
|
||||
name: changed
|
||||
alias: n
|
||||
|
||||
destination:
|
||||
plugin: entity:node
|
||||
|
||||
process:
|
||||
# nid
|
||||
type:
|
||||
plugin: default_value
|
||||
default_value: simplenews_issue
|
||||
title: title
|
||||
created: created
|
||||
changed: changed
|
||||
|
||||
uid:
|
||||
plugin: migration_lookup
|
||||
migration: d7_users
|
||||
source: uid
|
||||
|
||||
field_migration:
|
||||
plugin: default_value
|
||||
default_value: 'migration_imported'
|
||||
body:
|
||||
plugin: iterator
|
||||
source: body
|
||||
process:
|
||||
value: value
|
||||
format:
|
||||
plugin: default_value
|
||||
default_value: wysiwyg
|
||||
langcode: language
|
||||
|
||||
field_workflow:
|
||||
-
|
||||
plugin: default_value
|
||||
source: workflow
|
||||
default_value: 2
|
||||
-
|
||||
plugin: static_map
|
||||
default_value: 2
|
||||
map:
|
||||
1: "workflow_creation"
|
||||
2: "workflow_hidden"
|
||||
3: "workflow_visible"
|
||||
4: "workflow_imported"
|
||||
5: "workflow_edited"
|
||||
|
||||
simplenews_issue:
|
||||
-
|
||||
plugin: extract
|
||||
source: field_simplenews_term
|
||||
index:
|
||||
- 0
|
||||
- tid
|
||||
-
|
||||
plugin: static_map
|
||||
map:
|
||||
6585: "test"
|
||||
6374: "ze_daily_materio_"
|
||||
6274: "materio_newsletter"
|
||||
7881: "companies"
|
||||
|
||||
# Sent status
|
||||
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_allpublicfiles
|
||||
- d7_users
|
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\materio_migrate\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandler;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Drupal 7 node source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_simplenews_nodes",
|
||||
* source_module = "node"
|
||||
* )
|
||||
*/
|
||||
class D7SimplenewsNodes extends FieldableEntity {
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('state'),
|
||||
$container->get('entity.manager'),
|
||||
$container->get('module_handler')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The join options between the node and the node_revisions table.
|
||||
*/
|
||||
const JOIN = 'n.vid = nr.vid';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
// Select node in its last revision.
|
||||
$query = $this->select('node_revision', 'nr')
|
||||
->fields('n', [
|
||||
'nid',
|
||||
'type',
|
||||
'uid',
|
||||
'language',
|
||||
'status',
|
||||
'created',
|
||||
'changed',
|
||||
'comment',
|
||||
'promote',
|
||||
'sticky',
|
||||
'tnid',
|
||||
'translate',
|
||||
])
|
||||
->fields('nr', [
|
||||
'vid',
|
||||
'title',
|
||||
'log',
|
||||
'timestamp',
|
||||
])
|
||||
->orderBy('changed');
|
||||
|
||||
$query->addField('n', 'uid', 'node_uid');
|
||||
$query->addField('nr', 'uid', 'revision_uid');
|
||||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
|
||||
if (isset($this->configuration['node_type'])) {
|
||||
$query->condition('n.type', $this->configuration['node_type']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$nid = $row->getSourceProperty('nid');
|
||||
$vid = $row->getSourceProperty('vid');
|
||||
$type = $row->getSourceProperty('type');
|
||||
$title = $row->getSourceProperty('title');
|
||||
// drush_print('-- '.$nid."\t".$title);
|
||||
|
||||
// Get Field API field values.
|
||||
foreach ($this->getFields('node', $type) as $field_name => $field) {
|
||||
$row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, 'und'));
|
||||
}
|
||||
|
||||
// workflow
|
||||
$query = $this->select('workflow_node', 'wn');
|
||||
$query->fields('wn', ['sid']);
|
||||
$query->condition('wn.nid', $nid);
|
||||
$results = $query->execute()->fetchField();
|
||||
if(!$results){
|
||||
$results = 2;
|
||||
drush_print('WARNING: no workflow');
|
||||
}
|
||||
$row->setSourceProperty('workflow', $results);
|
||||
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = [
|
||||
'nid' => $this->t('Node ID'),
|
||||
'type' => $this->t('Type'),
|
||||
'title' => $this->t('Title'),
|
||||
'node_uid' => $this->t('Node authored by (uid)'),
|
||||
'revision_uid' => $this->t('Revision authored by (uid)'),
|
||||
'created' => $this->t('Created timestamp'),
|
||||
'changed' => $this->t('Modified timestamp'),
|
||||
'status' => $this->t('Published'),
|
||||
'promote' => $this->t('Promoted to front page'),
|
||||
'sticky' => $this->t('Sticky at top of lists'),
|
||||
'revision' => $this->t('Create new revision'),
|
||||
'language' => $this->t('Language (fr, en, ...)'),
|
||||
'tnid' => $this->t('The translation set id for this node'),
|
||||
'timestamp' => $this->t('The timestamp the latest revision of this node was created.'),
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['nid']['type'] = 'integer';
|
||||
$ids['nid']['alias'] = 'n';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user