From 0ea5ff66b13daf13d1d6c6394b9cae4bb754a6d2 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 26 Oct 2016 11:59:24 -0700 Subject: [PATCH] Issue #2621500 by quietone, mikeryan, phenaproxima, chx: Configuration source plugin --- .../src/Plugin/migrate/source/d8/Config.php | 59 +++++++++ .../Plugin/migrate/source/d8/ConfigTest.php | 115 ++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 core/modules/migrate_drupal/src/Plugin/migrate/source/d8/Config.php create mode 100644 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/d8/Config.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/d8/Config.php new file mode 100644 index 000000000000..df3311f5fcd8 --- /dev/null +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d8/Config.php @@ -0,0 +1,59 @@ +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; + } + +} diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php new file mode 100644 index 000000000000..20b80957db32 --- /dev/null +++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php @@ -0,0 +1,115 @@ + [ + [ + '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; + } + +}