Issue #2621500 by quietone, mikeryan, phenaproxima, chx: Configuration source plugin
parent
7522a3d9e8
commit
0ea5ff66b1
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\migrate_drupal\Plugin\migrate\source\d8;
|
||||||
|
|
||||||
|
use Drupal\migrate\Row;
|
||||||
|
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drupal config source from database.
|
||||||
|
*
|
||||||
|
* @MigrateSource(
|
||||||
|
* id = "d8_config"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class Config extends DrupalSqlBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function query() {
|
||||||
|
$query = $this->select('config', 'c')
|
||||||
|
->fields('c', array('collection', 'name', 'data'));
|
||||||
|
if (!empty($this->configuration['collections'])) {
|
||||||
|
$query->condition('collection', (array) $this->configuration['collections'], 'IN');
|
||||||
|
}
|
||||||
|
if (!empty($this->configuration['names'])) {
|
||||||
|
$query->condition('name', (array) $this->configuration['names'], 'IN');
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function prepareRow(Row $row) {
|
||||||
|
$row->setSourceProperty('data', unserialize($row->getSourceProperty('data')));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function fields() {
|
||||||
|
return [
|
||||||
|
'collection' => $this->t('The config object collection.'),
|
||||||
|
'name' => $this->t('The config object name.'),
|
||||||
|
'data' => $this->t('Serialized configuration object data.'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getIds() {
|
||||||
|
$ids['collection']['type'] = 'string';
|
||||||
|
$ids['name']['type'] = 'string';
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8;
|
||||||
|
|
||||||
|
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the config source plugin.
|
||||||
|
*
|
||||||
|
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d8\Config
|
||||||
|
* @group migrate_drupal
|
||||||
|
*/
|
||||||
|
class ConfigTest extends MigrateSqlSourceTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static $modules = ['migrate_drupal'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function providerSource() {
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
// The source database tables.
|
||||||
|
$data[0]['source_data'] = [
|
||||||
|
'config' => [
|
||||||
|
[
|
||||||
|
'collection' => 'language.af',
|
||||||
|
'name' => 'user.settings',
|
||||||
|
'data' => 'a:1:{s:9:"anonymous";s:14:"af - Anonymous";}',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'collection' => '',
|
||||||
|
'name' => 'user.settings',
|
||||||
|
'data' => 'a:1:{s:9:"anonymous";s:9:"Anonymous";}',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'collection' => 'language.de',
|
||||||
|
'name' => 'user.settings',
|
||||||
|
'data' => 'a:1:{s:9:"anonymous";s:14:"de - Anonymous";}',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'collection' => 'language.af',
|
||||||
|
'name' => 'bar',
|
||||||
|
'data' => 'b:0;',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// The expected results.
|
||||||
|
$data[0]['expected_results'] = [
|
||||||
|
[
|
||||||
|
'collection' => 'language.af',
|
||||||
|
'name' => 'user.settings',
|
||||||
|
'data' => [
|
||||||
|
'anonymous' => 'af - Anonymous',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'collection' => 'language.af',
|
||||||
|
'name' => 'bar',
|
||||||
|
'data' => FALSE,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$data[0]['expected_count'] = NULL;
|
||||||
|
$data[0]['configuration'] = [
|
||||||
|
'names' => [
|
||||||
|
'user.settings',
|
||||||
|
'bar',
|
||||||
|
],
|
||||||
|
'collections' => [
|
||||||
|
'language.af',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// Test with name and no collection in configuration.
|
||||||
|
$data[1]['source_data'] = $data[0]['source_data'];
|
||||||
|
$data[1]['expected_results'] = [
|
||||||
|
[
|
||||||
|
'collection' => 'language.af',
|
||||||
|
'name' => 'bar',
|
||||||
|
'data' => FALSE,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$data[1]['expected_count'] = NULL;
|
||||||
|
$data[1]['configuration'] = [
|
||||||
|
'names' => [
|
||||||
|
'bar',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// Test with collection and no name in configuration.
|
||||||
|
$data[2]['source_data'] = $data[0]['source_data'];
|
||||||
|
$data[2]['expected_results'] = [
|
||||||
|
[
|
||||||
|
'collection' => 'language.de',
|
||||||
|
'name' => 'user.settings',
|
||||||
|
'data' => [
|
||||||
|
'anonymous' => 'de - Anonymous',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$data[2]['expected_count'] = NULL;
|
||||||
|
$data[2]['configuration'] = [
|
||||||
|
'collections' => [
|
||||||
|
'language.de',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue