email_changelog-8.x-1.0-alpha1/src/Plugin/migrate/source/EmailChangelog.php
src/Plugin/migrate/source/EmailChangelog.php
<?php
namespace Drupal\email_changelog\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Serialization\PhpSerialize;
use Drupal\migrate\Row;
/**
* Drupal 7 email changelog from database.
*
* @MigrateSource(
* id = "email_changelog",
* source_module = "email_changelog"
* )
*/
class EmailChangelog extends SqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('email_changelog', 'ec');
return $query->fields('ec');
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'id' => $this->t('id'),
'uid' => $this->t('Uid'),
'old_email_address' => $this->t('Old Email'),
'new_email_address' => $this->t('New Email'),
'data' => $this->t('Data'),
'logged_in_uid' => $this->t('logged in user'),
'stamp' => $this->t('Date'),
'location' => $this->t('Location'),
];
return $fields;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$data = Json::decode($row->getSourceProperty('data'));
$row->setSourceProperty('location', $data['url']);
unset($data['url']);
$row->setSourceProperty('data', PhpSerialize::encode($data));
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'id' => [
'type' => 'integer',
'alias' => 'ec',
],
];
}
}
