summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-04-10 12:20:17 (GMT)
committerAlex Pott2018-04-10 12:20:17 (GMT)
commitd25a77e0ec33bcdc3a2dbf36edf3238999102441 (patch)
tree0d891ab153bdb276b92497ce36c92e5dacf907be
parent5550b7650f9e58e57ae7eccb677bf4861e673149 (diff)
Issue #2500495 by quietone, Jo Fitzgerald, phenaproxima, maxocub, alexpott, mikeryan, chx: Upgrade path for Color 7.x
-rw-r--r--core/modules/color/migrations/d7_color.yml54
-rw-r--r--core/modules/color/src/Plugin/migrate/destination/Color.php90
-rw-r--r--core/modules/color/src/Plugin/migrate/source/d7/Color.php98
-rw-r--r--core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php61
-rw-r--r--core/modules/color/tests/src/Kernel/Plugin/migrate/source/d7/ColorTest.php129
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal7.php40
-rw-r--r--core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php2
-rw-r--r--core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php2
-rw-r--r--core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php2
9 files changed, 476 insertions, 2 deletions
diff --git a/core/modules/color/migrations/d7_color.yml b/core/modules/color/migrations/d7_color.yml
new file mode 100644
index 0000000..9bc7af6
--- /dev/null
+++ b/core/modules/color/migrations/d7_color.yml
@@ -0,0 +1,54 @@
+id: d7_color
+label: Color
+migration_tags:
+ - Drupal 7
+ - Configuration
+source:
+ plugin: d7_color
+ constants:
+ config_prefix: 'color.theme.'
+process:
+ # Skip if theme not installed on destination.
+ theme_installed:
+ plugin: skip_on_empty
+ source: theme_installed
+ method: row
+ element_name:
+ -
+ plugin: explode
+ source: name
+ delimiter: _
+ -
+ plugin: extract
+ index:
+ - 2
+ # Skip if the variable name ends in 'screenshot'.
+ screenshot:
+ -
+ plugin: static_map
+ source: '@element_name'
+ bypass: true
+ map:
+ screenshot: false
+ -
+ plugin: skip_on_empty
+ method: row
+ # Build the configuration name from the variable name, i.e.
+ # 'color_themename_element' becomes 'color.theme.themename'
+ theme_name:
+ -
+ plugin: explode
+ source: name
+ delimiter: _
+ -
+ plugin: extract
+ index:
+ - 1
+ configuration_name:
+ plugin: concat
+ source:
+ - constants/config_prefix
+ - '@theme_name'
+ value: value
+destination:
+ plugin: color
diff --git a/core/modules/color/src/Plugin/migrate/destination/Color.php b/core/modules/color/src/Plugin/migrate/destination/Color.php
new file mode 100644
index 0000000..4fe62b7
--- /dev/null
+++ b/core/modules/color/src/Plugin/migrate/destination/Color.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace Drupal\color\Plugin\migrate\destination;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\migrate\Row;
+use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
+
+/**
+ * Persist color data to the config system.
+ *
+ * @MigrateDestination(
+ * id = "color"
+ * )
+ */
+class Color extends DestinationBase implements ContainerFactoryPluginInterface {
+
+ /**
+ * The configuration factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
+ * Constructs a Color object.
+ *
+ * @param array $configuration
+ * Plugin configuration.
+ * @param string $plugin_id
+ * The plugin ID.
+ * @param mixed $plugin_definition
+ * The plugin definition.
+ * @param \Drupal\migrate\Plugin\MigrationInterface $migration
+ * The current migration.
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The configuration factory.
+ */
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ConfigFactoryInterface $config_factory) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
+ $this->configFactory = $config_factory;
+ }
+
+ /**
+ * {@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('config.factory')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function import(Row $row, array $old_destination_id_values = []) {
+ $imported = FALSE;
+ $value = $row->getDestinationProperty('value');
+ if (isset($value)) {
+ $this->configFactory->getEditable($row->getDestinationProperty('configuration_name'))
+ ->set($row->getDestinationProperty('element_name'), $row->getDestinationProperty('value'))
+ ->save();
+ $imported = TRUE;
+ }
+ return $imported;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIds() {
+ $ids['name']['type'] = 'string';
+ return $ids;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields(MigrationInterface $migration = NULL) {
+ return [];
+ }
+
+}
diff --git a/core/modules/color/src/Plugin/migrate/source/d7/Color.php b/core/modules/color/src/Plugin/migrate/source/d7/Color.php
new file mode 100644
index 0000000..e713f0e
--- /dev/null
+++ b/core/modules/color/src/Plugin/migrate/source/d7/Color.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Drupal\color\Plugin\migrate\source\d7;
+
+use Drupal\Core\Extension\ThemeHandler;
+use Drupal\migrate\Row;
+use Drupal\migrate_drupal\Plugin\migrate\source\VariableMultiRow;
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\State\StateInterface;
+use Drupal\migrate\Plugin\MigrationInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Drupal 7 color source from database.
+ *
+ * @MigrateSource(
+ * id = "d7_color",
+ * source_module = "color"
+ * )
+ */
+class Color extends VariableMultiRow {
+
+ /**
+ * The theme handler.
+ *
+ * @var \Drupal\Core\Extension\ThemeHandler
+ */
+ protected $themeHandler;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ThemeHandler $theme_handler) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
+ $this->themeHandler = $theme_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('theme_handler')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function query() {
+ // Get color data for all themes.
+ $query = $this->select('variable', 'v')
+ ->fields('v', ['name', 'value'])
+ ->condition('name', 'color_%', 'LIKE');
+ return $query;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function prepareRow(Row $row) {
+ $themes = $this->themeHandler->listInfo();
+ $themes_installed = [];
+ /** @var \Drupal\Core\Extension\Extension $theme */
+ foreach ($themes as $theme) {
+ if ($theme->status) {
+ $themes_installed[] = $theme->getName();
+ }
+ }
+
+ // The name is of the form 'color_theme_variable'.
+ $name = explode('_', $row->getSourceProperty('name'));
+
+ // Set theme_installed if this source theme is installed.
+ if (in_array($name[1], $themes_installed)) {
+ $row->setSourceProperty('theme_installed', TRUE);
+ }
+
+ return parent::prepareRow($row);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields() {
+ return [
+ 'name' => $this->t('A color variable for a theme.'),
+ 'value' => $this->t('The value of a color variable.'),
+ ];
+ }
+
+}
diff --git a/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php b/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php
new file mode 100644
index 0000000..946d1e3
--- /dev/null
+++ b/core/modules/color/tests/src/Kernel/Migrate/d7/MigrateColorTest.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Drupal\Tests\color\Kernel\Migrate\d7;
+
+use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
+
+/**
+ * Tests migration of Color variables to configuration.
+ *
+ * @group color
+ */
+class MigrateColorTest extends MigrateDrupal7TestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['color'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+ // Install the themes used for this test.
+ $this->container->get('theme_installer')->install(['bartik']);
+ $this->executeMigration('d7_color');
+ }
+
+ /**
+ * Tests migration of color's variables to configuration.
+ */
+ public function testMigrateColor() {
+ // Test Bartik migration.
+ $config = $this->config('color.theme.bartik');
+ $files = [
+ 'public://color/bartik-e0e23ad7/logo.png',
+ 'public://color/bartik-e0e23ad7/colors.css',
+ ];
+ $this->assertSame($files, $config->get('files'));
+ $this->assertSame('public://color/bartik-e0e23ad7/logo.png', $config->get('logo'));
+ $palette = [
+ 'top' => '#d0d0d0',
+ 'bottom' => '#c2c4c5',
+ 'bg' => '#ffffff',
+ 'sidebar' => '#ffffff',
+ 'sidebarborders' => '#cccccc',
+ 'footer' => '#24272c',
+ 'titleslogan' => '#000000',
+ 'text' => '#4a4a4a',
+ 'link' => '#019dbf',
+ ];
+ $this->assertSame($palette, $config->get('palette'));
+ $this->assertSame(['public://color/bartik-e0e23ad7/colors.css'], $config->get('stylesheets'));
+ // Test that the screenshot was not migrated.
+ $this->assertNull($config->get('screenshot'));
+
+ // Test that garland was not migrated.
+ $this->assertEmpty(\Drupal::config('color.theme.garland')->get());
+ }
+
+}
diff --git a/core/modules/color/tests/src/Kernel/Plugin/migrate/source/d7/ColorTest.php b/core/modules/color/tests/src/Kernel/Plugin/migrate/source/d7/ColorTest.php
new file mode 100644
index 0000000..cb634a9
--- /dev/null
+++ b/core/modules/color/tests/src/Kernel/Plugin/migrate/source/d7/ColorTest.php
@@ -0,0 +1,129 @@
+<?php
+
+namespace Drupal\Tests\color\Kernel\Plugin\migrate\source\d7;
+
+use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
+
+/**
+ * Tests D7 color source plugin.
+ *
+ * @covers \Drupal\color\Plugin\migrate\source\d7\Color
+ *
+ * @group color
+ */
+class ColorTest extends MigrateSqlSourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['color', 'migrate_drupal'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function providerSource() {
+ $tests = [];
+
+ // The source data.
+ $tests[0]['database']['variable'] = [
+ [
+ 'name' => 'color_bartik_palette',
+ 'value' => [
+ 'top' => '#cd2d2d',
+ 'bottom' => '#d64e4e',
+ 'bg' => '#ffffff',
+ 'sidebar' => '#f1f4f0',
+ 'sidebarborders' => '#ededed',
+ 'footer' => '#1f1d1c',
+ 'titleslogan' => '#fffeff',
+ 'text' => '#888888',
+ 'link' => '#d6121f',
+ ],
+ ],
+ [
+ 'name' => 'color_bartik_logo',
+ 'value' => 'public://color/bartik-e0e23ad7/logo.png',
+ ],
+ [
+ 'name' => 'color_bartik_stylesheets',
+ 'value' => ['public://color/bartik-1d249313/colors.css'],
+ ],
+ [
+ 'name' => 'color_bartik_files',
+ 'value' => [
+ 'public://color/bartik-e0e23ad7/logo.png',
+ 'public://color/bartik-e0e23ad7/colors.css',
+ ],
+ ],
+ [
+ 'name' => 'color_bartik_screenshot',
+ 'value' => ['public:://color/bartik-b69cfcec/screenshot.png'],
+ ],
+ [
+ 'name' => 'color_custom_stylesheets',
+ 'value' => ['public:://color/custom-beadedff/colors.css'],
+ ],
+ ];
+
+ foreach ($tests[0]['database']['variable'] as $key => $expected) {
+ $tests[0]['database']['variable'][$key]['value'] = serialize($expected['value']);
+ }
+
+ $tests[0]['database']['system'] = [
+ [
+ 'name' => 'bartik',
+ 'type' => 'theme',
+ 'status' => '1',
+ ],
+ [
+ 'name' => 'custom',
+ 'type' => 'theme',
+ 'status' => '0',
+ ],
+ ];
+
+ // Expected results are the same as the source.
+ $tests[0]['expected_results'] = [
+ [
+ 'name' => 'color_bartik_palette',
+ 'value' => [
+ 'top' => '#cd2d2d',
+ 'bottom' => '#d64e4e',
+ 'bg' => '#ffffff',
+ 'sidebar' => '#f1f4f0',
+ 'sidebarborders' => '#ededed',
+ 'footer' => '#1f1d1c',
+ 'titleslogan' => '#fffeff',
+ 'text' => '#888888',
+ 'link' => '#d6121f',
+ ],
+ ],
+ [
+ 'name' => 'color_bartik_logo',
+ 'value' => 'public://color/bartik-e0e23ad7/logo.png',
+ ],
+ [
+ 'name' => 'color_bartik_stylesheets',
+ 'value' => ['public://color/bartik-1d249313/colors.css'],
+ ],
+ [
+ 'name' => 'color_bartik_files',
+ 'value' => [
+ 'public://color/bartik-e0e23ad7/logo.png',
+ 'public://color/bartik-e0e23ad7/colors.css',
+ ],
+ ],
+ [
+ 'name' => 'color_bartik_screenshot',
+ 'value' => ['public:://color/bartik-b69cfcec/screenshot.png'],
+ ],
+ [
+ 'name' => 'color_custom_stylesheets',
+ 'value' => ['public:://color/custom-beadedff/colors.css'],
+ ],
+ ];
+
+ return $tests;
+ }
+
+}
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
index 23dd81e..6f61f67 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
@@ -46862,6 +46862,46 @@ $connection->insert('variable')
'value' => 's:1:"1";',
))
->values(array(
+ 'name' => 'color_bartik_files',
+ 'value' => 'a:2:{i:0;s:39:"public://color/bartik-e0e23ad7/logo.png";i:1;s:41:"public://color/bartik-e0e23ad7/colors.css";}',
+))
+->values(array(
+ 'name' => 'color_bartik_logo',
+ 'value' => 's:39:"public://color/bartik-e0e23ad7/logo.png";',
+))
+->values(array(
+ 'name' => 'color_bartik_palette',
+ 'value' => 'a:9:{s:3:"top";s:7:"#d0d0d0";s:6:"bottom";s:7:"#c2c4c5";s:2:"bg";s:7:"#ffffff";s:7:"sidebar";s:7:"#ffffff";s:14:"sidebarborders";s:7:"#cccccc";s:6:"footer";s:7:"#24272c";s:11:"titleslogan";s:7:"#000000";s:4:"text";s:7:"#4a4a4a";s:4:"link";s:7:"#019dbf";}',
+))
+->values(array(
+ 'name' => 'color_bartik_stylesheets',
+ 'value' => 'a:1:{i:0;s:41:"public://color/bartik-e0e23ad7/colors.css";}',
+))
+->values(array(
+ 'name' => 'color_bartik_screenshot',
+ 'value' => 's:72:"/var/www/drupal/sites/default/files/color/bartik-b69cfcec/screenshot.png";'
+))
+->values(array(
+ 'name' => 'color_garland_files',
+ 'value' => 'a:19:{i:0;s:50:"public://color/garland-b69cfcec/menu-collapsed.gif";i:1;s:54:"public://color/garland-b69cfcec/menu-collapsed-rtl.gif";i:2;s:49:"public://color/garland-b69cfcec/menu-expanded.gif";i:3;s:45:"public://color/garland-b69cfcec/menu-leaf.gif";i:4;s:67:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/body.png";i:5;s:69:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-bar.png";i:6;s:75:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-bar-white.png";i:7;s:69:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-tab.png";i:8;s:76:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-navigation.png";i:9;s:78:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-content-left.png";i:10;s:79:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-content-right.png";i:11;s:73:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-content.png";i:12;s:81:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-navigation-item.png";i:13;s:87:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/bg-navigation-item-hover.png";i:14;s:77:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/gradient-inner.png";i:15;s:67:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/logo.png";i:16;s:73:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/screenshot.png";i:17;s:41:"public://color/garland-b69cfcec/style.css";i:18;s:45:"public://color/garland-b69cfcec/style-rtl.css";}',
+))
+->values(array(
+ 'name' => 'color_garland_logo',
+ 'value' => 's:40:"public://color/garland-b69cfcec/logo.png";'
+))
+->values(array(
+ 'name' => 'color_garland_palette',
+ 'value' => 'a:5:{s:4:"base";s:7:"#d0cb9a";s:4:"link";s:7:"#917803";s:3:"top";s:7:"#efde01";s:6:"bottom";s:7:"#e6fb2d";s:4:"text";s:7:"#494949";}',
+))
+->values(array(
+ 'name' => 'color_garland_screenshot',
+ 'value' => 's:73:"/var/www/drupal/sites/default/files/color/garland-b69cfcec/screenshot.png";'
+))
+->values(array(
+ 'name' => 'color_garland_stylesheets',
+ 'value' => 'a:2:{i:0;s:41:"public://color/garland-b69cfcec/style.css";i:1;s:45:"public://color/garland-b69cfcec/style-rtl.css";}',
+))
+->values(array(
'name' => 'comment_anonymous_article',
'value' => 'i:0;',
))
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php
index 0ff29fd..dde4d7d 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/DestinationCategoryTest.php
@@ -3,6 +3,7 @@
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate;
use Drupal\ban\Plugin\migrate\destination\BlockedIP;
+use Drupal\color\Plugin\migrate\destination\Color;
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
use Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase;
use Drupal\migrate\Plugin\migrate\destination\Config;
@@ -98,6 +99,7 @@ class DestinationCategoryTest extends MigrateDrupalTestBase {
*/
protected function getConfigurationClasses() {
return [
+ Color::class,
Config::class,
EntityConfigBase::class,
ThemeSettings::class,
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php
index be048f9..12b6616 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7ReviewPageTest.php
@@ -35,6 +35,7 @@ class MigrateUpgrade7ReviewPageTest extends MigrateUpgradeReviewPageTestBase {
'aggregator',
'block',
'book',
+ 'color',
'comment',
'contact',
'date',
@@ -116,7 +117,6 @@ class MigrateUpgrade7ReviewPageTest extends MigrateUpgradeReviewPageTestBase {
*/
protected function getMissingPaths() {
return [
- 'color',
'rdf',
'views',
];
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php
index 27cc4cf..4df392f 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php
@@ -119,6 +119,7 @@ class MigrateUpgrade7Test extends MigrateUpgradeExecuteTestBase {
'aggregator',
'block',
'book',
+ 'color',
'comment',
'contact',
'date',
@@ -170,7 +171,6 @@ class MigrateUpgrade7Test extends MigrateUpgradeExecuteTestBase {
*/
protected function getMissingPaths() {
return [
- 'color',
'rdf',
// These modules are in the missing path list because they are installed
// on the source site but they are not installed on the destination site.