diff --git a/core/modules/image/image.install b/core/modules/image/image.install index ac12b7e..eee45b8 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -114,6 +114,61 @@ function image_requirements($phase) { */ /** + * Load all the effects for an image style. + * + * Helper function for retrieving image effects from the image_effects database + * table for a given image style. This is a combination of the + * image_style_effects() and image_effects() functions from Drupal 7. + * + * @see image_update_8000() + */ +function _image_upgrade_style_effects($style) { + $effects = &drupal_static(__FUNCTION__); + + if (!isset($effects)) { + $effects = array(); + + // Get image effects. + $result = db_select('image_effects', NULL, array('fetch' => PDO::FETCH_ASSOC)) + ->fields('image_effects') + ->orderBy('image_effects.weight', 'ASC') + ->execute(); + foreach ($result as $effect) { + $effect['data'] = unserialize($effect['data']); + $definition = image_effect_definition_load($effect['name']); + // Do not load image effects whose definition cannot be found. + if ($definition) { + $effect = array_merge($definition, $effect); + // Generate machine name for each effect. + $effect['ieid'] = $effect['name']; + foreach ($effect['data'] as $key => $value) { + $effect['ieid'] .= '_' . $value; + } + $effect['ieid'] = preg_replace('@[^a-zA-Z0-9_-]@', '', $effect['ieid']); + // Remove deprecated items from the effect. + $deprecated = array('effect callback', 'dimensions callback', 'form callback', 'summary theme', 'help', 'label', 'dimensions passthrough', 'module'); + foreach ($effect as $key => $value) { + if (in_array($key, $deprecated)) { + unset($effect[$key]); + } + } + $effects[$effect['ieid']] = $effect; + } + } + } + + $style_effects = array(); + foreach ($effects as $effect) { + if ($style['isid'] == $effect['isid']) { + unset($effect['isid']); + $style_effects[$effect['ieid']] = $effect; + } + } + + return $style_effects; +} + +/** * Convert existing image styles to the new config system. */ function image_update_8000() { @@ -129,7 +184,7 @@ function image_update_8000() { ->fetchAllAssoc('name', PDO::FETCH_ASSOC); foreach ($user_styles as $style_name => $style) { - $style['effects'] = image_style_effects($style); // need to remake this + $style['effects'] = _image_upgrade_style_effects($style); if (isset($styles[$style_name]['module'])) { $style['module'] = $styles[$style_name]['module']; } @@ -140,7 +195,13 @@ function image_update_8000() { foreach ($styles as $name => $style) { $config = config('image.styles.' . $name); - // Generate machine name for each effect + $config->set('name', $name); + if (isset($style['effects'])) { + $config->set('effects', $style['effects']); + } + else { + $config->set('effects', array()); + } $config->save(); } @@ -150,3 +211,4 @@ function image_update_8000() { * @} End of "defgroup updates-7.x-to-8.x" * The next series of updates should start at 9000. */ + diff --git a/core/modules/system/tests/upgrade/upgrade.image.test b/core/modules/system/tests/upgrade/upgrade.image.test index 2a784fe..a4675be 100644 --- a/core/modules/system/tests/upgrade/upgrade.image.test +++ b/core/modules/system/tests/upgrade/upgrade.image.test @@ -31,5 +31,50 @@ class ImageUpgradePathTestCase extends UpgradePathTestCase { */ public function testImageStyleUpgrade() { $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + + // Test that overridden and custom image styles are properly upgraded. + $styles = array( + 'test-custom' => array( + 'name' => 'test-custom', + 'effects' => array( + 'image_rotate_90_FFFFFF_1' => array( + 'name' => 'image_rotate', + 'data' => array( + 'degrees' => '90', + 'bgcolor' => '#FFFFFF', + 'random' => '1', + ), + 'ieid' => 'image_rotate_90_FFFFFF_1', + 'weight' => '1', + ), + 'image_desaturate' => array( + 'name' => 'image_desaturate', + 'data' => array(), + 'ieid' => 'image_desaturate', + 'weight' => '2', + ), + ), + ), + 'thumbnail' => array( + 'name' => 'thumbnail', + 'effects' => array ( + 'image_scale_177_177_0' => array( + 'name' => 'image_scale', + 'data' => array ( + 'width' => '177', + 'height' => '177', + 'upscale' => '0', + ), + 'ieid' => 'image_scale_177_177_0', + 'weight' => '0', + ), + ), + ), + ); + + foreach ($styles as $name => $style) { + $config = config('image.styles.' . $name)->get(); + $this->assertEqual($style, $config, t('Upgraded image style %name successfully.', array('%name' => $name))); + } } -} \ No newline at end of file +}