fixed simplenews subscribers without account migration
This commit is contained in:
@@ -24,9 +24,10 @@ process:
|
||||
mail: mail
|
||||
# uid: uid
|
||||
uid:
|
||||
plugin: migration
|
||||
plugin: migration_lookup
|
||||
migration: d7_users
|
||||
source: uid
|
||||
no_stub: true
|
||||
|
||||
langcode: language
|
||||
changes: changes
|
||||
|
@@ -0,0 +1,55 @@
|
||||
id: d7_simplenews_subscribers_notuser
|
||||
migration_group: d7_materio
|
||||
dependencies:
|
||||
# config:
|
||||
# - migrate.migration.d7_simplenews_newsletter
|
||||
module:
|
||||
- migrate_drupal
|
||||
- simplenews
|
||||
label: Simplenews subscribers (without user drupal accompte)
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
- Materio
|
||||
|
||||
source:
|
||||
plugin: d7_simplenews_subscribers_notuser
|
||||
# high_water_property:
|
||||
# name: changes
|
||||
# alias: s
|
||||
|
||||
process:
|
||||
id: snid
|
||||
status: activated
|
||||
mail: mail
|
||||
uid: uid
|
||||
|
||||
langcode: language
|
||||
changes: changes
|
||||
created: created
|
||||
|
||||
subscriptions:
|
||||
plugin: iterator
|
||||
source: subscriptions
|
||||
process:
|
||||
target_id:
|
||||
plugin: static_map
|
||||
source: newsletter_id
|
||||
map:
|
||||
6585: "test"
|
||||
6374: "ze_daily_materio_"
|
||||
6274: "materio_newsletter"
|
||||
7881: "companies"
|
||||
# plugin: migration
|
||||
# migration: d7_simplenews_newsletter
|
||||
# source: newsletter_id
|
||||
status: status
|
||||
timestamp: timestamp
|
||||
source: source
|
||||
|
||||
destination:
|
||||
plugin: entity:simplenews_subscriber
|
||||
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_users
|
@@ -43,6 +43,7 @@ class D7SimplenewsSubscribers extends DrupalSqlBase {
|
||||
public function query() {
|
||||
return $this->select('simplenews_subscriber', 's')
|
||||
->fields('s')
|
||||
->condition('s.uid', 0, '<>')
|
||||
->orderBy('snid');
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\materio_migrate\Plugin\migrate\source;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Migration source for Subscriber entries in D7.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_simplenews_subscribers_notuser",
|
||||
* source_module = "simplenews"
|
||||
* )
|
||||
*/
|
||||
class D7SimplenewsSubscribersNotUser extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'snid' => $this->t('Subscriber ID'),
|
||||
'activated' => $this->t('Activated'),
|
||||
'mail' => $this->t("Subscriber's e-mail address"),
|
||||
'uid' => $this->t('Corresponding user'),
|
||||
'language' => $this->t('Language'),
|
||||
'changes' => $this->t('Pending unconfirmed subscription changes'),
|
||||
'created' => $this->t('Time of creation'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return ['snid' => ['type' => 'integer']];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('simplenews_subscriber', 's')
|
||||
->fields('s')
|
||||
->condition('s.uid', 0)
|
||||
->orderBy('snid');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$result = parent::prepareRow($row);
|
||||
|
||||
$version = $this->getModuleSchemaVersion('simplenews');
|
||||
$newsletter_id_field = 'newsletter_id';
|
||||
if ($version >= 7000 & $version < 7200) {
|
||||
$newsletter_id_field = 'tid';
|
||||
}
|
||||
|
||||
// Add associated data from the subscriptions table.
|
||||
$q = $this->select('simplenews_subscription', 'sub');
|
||||
$q->addField('sub', $newsletter_id_field, 'newsletter_id');
|
||||
$q->fields('sub', ['status', 'timestamp', 'source']);
|
||||
$q->condition('sub.snid', $row->getSourceProperty('snid'));
|
||||
$subscriptions = $q->execute()->fetchAllAssoc('newsletter_id');
|
||||
$row->setSourceProperty('subscriptions', $subscriptions);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user