diff --git a/core/modules/image/image.install b/core/modules/image/image.install index 58cf110..6069712 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -146,22 +146,23 @@ function _image_update_get_style_with_effects(array $style) { * Convert existing image styles to the new config system. */ function image_update_8000() { - $styles = array(); + $language = language_default(); + $uuid = new Uuid(); + $result = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC)) ->fields('image_styles') - ->execute() - ->fetchAllAssoc('name', PDO::FETCH_ASSOC); - foreach ($result as $style_name => $style) { - $style['effects'] = _image_update_get_style_with_effects($style); - $styles[$style_name] = $style; - } - - // Convert each style into a configuration object. - foreach ($styles as $name => $style) { - $config = config('image.style.' . $name); - $config->set('name', $name); - $config->set('effects', $style['effects']); - $config->save(); + ->execute(); + foreach ($result as $style) { + // Convert image style into a configuration object. + Drupal::config('image.style.' . $style['name']) + ->set('name', $style['name']) + // Labels for image styles added in Drupal 7.23. + ->set('label', $style['label']) + ->set('uuid', $uuid->generate()) + ->set('status', 1) + ->set('langcode', $language->id) + ->set('effects', _image_update_get_style_with_effects($style)) + ->save(); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php index cc5979a..48535c0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php @@ -36,6 +36,9 @@ public function testImageStyleUpgrade() { // Verify that image styles were properly upgraded. $expected_styles['test-custom'] = array( 'name' => 'test-custom', + 'label' => 'Test custom', + 'status' => '1', + 'langcode' => 'en', 'effects' => array( 'image_rotate' => array( 'id' => 'image_rotate', @@ -55,6 +58,9 @@ public function testImageStyleUpgrade() { ); $expected_styles['thumbnail'] = array( 'name' => 'thumbnail', + 'label' => 'Thumbnail (100x100)', + 'status' => '1', + 'langcode' => 'en', 'effects' => array ( 'image_scale' => array( 'id' => 'image_scale', @@ -67,11 +73,12 @@ public function testImageStyleUpgrade() { ), ), ); + $config_factory = $this->container->get('config.factory'); foreach ($expected_styles as $name => $style) { - $config = config('image.style.' . $name); + $configured_style = $config_factory->get('image.style.' . $name)->get(); // Replace placeholder with image effect name keys with UUID's generated // during by the image style upgrade functions. - foreach ($config->get('effects') as $uuid => $effect) { + foreach ($configured_style['effects'] as $uuid => $effect) { // Copy placeholder data. $style['effects'][$uuid] = $style['effects'][$effect['id']]; // Set the missing uuid key as this is unknown because it is a UUID. @@ -79,9 +86,13 @@ public function testImageStyleUpgrade() { // Remove the placeholder data. unset($style['effects'][$effect['id']]); } - $this->assertEqual($this->sortByKey($style), $config->get(), format_string('@first is equal to @second.', array( + // Make sure UUID assigned to new style. + $this->assertTrue($configured_style['uuid'], 'UUID assigned to converted style.'); + // Copy generated UUID to compared style. + $style['uuid'] = $configured_style['uuid']; + $this->assertEqual($this->sortByKey($style), $this->sortByKey($configured_style), format_string('@first is equal to @second.', array( '@first' => var_export($this->sortByKey($style), TRUE), - '@second' => var_export($config->get(), TRUE), + '@second' => var_export($this->sortByKey($configured_style), TRUE), ))); } } @@ -102,7 +113,7 @@ public function sortByKey(array $data) { ksort($data); foreach ($data as &$value) { if (is_array($value)) { - $this->sortByKey($value); + $value = $this->sortByKey($value); } } return $data; diff --git a/core/modules/system/tests/upgrade/drupal-7.image.database.php b/core/modules/system/tests/upgrade/drupal-7.image.database.php index 3033858..df97c68 100644 --- a/core/modules/system/tests/upgrade/drupal-7.image.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.image.database.php @@ -14,16 +14,19 @@ db_insert('image_styles')->fields(array( 'isid', 'name', + 'label' )) // Override thumbnail style. ->values(array( 'isid' => '1', 'name' => 'thumbnail', + 'label' => 'Thumbnail (100x100)', )) // Custom style. ->values(array( 'isid' => '2', 'name' => 'test-custom', + 'label' => 'Test custom', )) ->execute();