diff --git a/core/modules/image/image.install b/core/modules/image/image.install index c3505e9..5cdf997 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -104,100 +104,67 @@ function image_requirements($phase) { return $requirements; } -/* - * Load all the effects for an image style. +/** + * Loads all 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. + * @param array $style + * The image style (array) to retrieve effects for. * * @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; - } +function _image_update_get_style_with_effects(array $style) { + // Retrieve image effects. + // @todo Module updates are not able to invoke module hooks and API functions; + // additional information previously supplied via hook_image_effect_info() + // is not and cannot be taken into account. + $effects = array(); + $result = db_select('image_effects', NULL, array('fetch' => PDO::FETCH_ASSOC)) + ->fields('image_effects') + ->condition('isid', $style['isid']) + ->execute(); + foreach ($result as $effect) { + unset($effect['isid']); + $effect['data'] = unserialize($effect['data']); + + // Generate new key 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']); - $style_effects = array(); - foreach ($effects as $effect) { - if ($style['isid'] == $effect['isid']) { - unset($effect['isid']); - $style_effects[$effect['ieid']] = $effect; - } + $effects[$effect['ieid']] = $effect; } - - return $style_effects; + return $effects; } /** * Convert existing image styles to the new config system. */ function image_update_8000() { - // Install default config for the image module - config_install_default_config('image'); - - // Get the image module-defined styles. $styles = array(); - - // Get the user generated styles. If there are overrides of any of - // the image module's default styles, then they will overwrite the - // default style. - $user_styles = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC)) + $result = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC)) ->fields('image_styles') - ->orderBy('name') ->execute() ->fetchAllAssoc('name', PDO::FETCH_ASSOC); - - foreach ($user_styles as $style_name => $style) { - $style['effects'] = _image_upgrade_style_effects($style); - if (isset($styles[$style_name]['module'])) { - $style['module'] = $styles[$style_name]['module']; - } + foreach ($result as $style_name => $style) { + $style['effects'] = _image_update_get_style_with_effects($style); $styles[$style_name] = $style; } - // Convert styles to the config system + // Convert each style into a configuration object. foreach ($styles as $name => $style) { $config = config('image.style.' . $name); - $config->set('name', $name); - if (isset($style['effects'])) { - $config->set('effects', $style['effects']); - } - else { - $config->set('effects', array()); - } - + $config->set('effects', $style['effects']); $config->save(); } } + +/** + * Remove the {image_styles} and {image_effects} tables. + */ +function image_update_8001() { + db_drop_table('image_styles'); + db_drop_table('image_effects'); +} 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 fa9fe41..9e72305 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/ImageUpgradePathTest.php @@ -20,7 +20,6 @@ class ImageUpgradePathTest extends UpgradePathTestBase { } public function setUp() { - // Path to the database dump files. $this->databaseDumpFiles = array( drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz', drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.image.database.php', @@ -34,49 +33,46 @@ class ImageUpgradePathTest extends UpgradePathTestBase { 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', + // Verify that image styles were properly upgraded. + $expected_styles['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', + ); + $expected_styles['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) { + foreach ($expected_styles as $name => $style) { $config = config('image.style.' . $name)->get(); - $this->assertEqual($style, $config, t('Upgraded image style %name successfully.', array('%name' => $name))); + $this->assertEqual($style, $config, format_string('Expected image style %name found.', array('%name' => $name))); } } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php index cab0b7f..3643a84 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php @@ -8,19 +8,18 @@ namespace Drupal\system\Tests\Upgrade; /** - * Test upgrade of non-default values for system variables. + * Tests upgrade of system variables. */ class SystemUpgradePathTest extends UpgradePathTestBase { public static function getInfo() { return array( 'name' => 'System upgrade test', - 'description' => 'Upgrade tests for non-default values of system variables.', + 'description' => 'Tests upgrade of system variables.', 'group' => 'Upgrade path', ); } public function setUp() { - // Path to the database dump files. $this->databaseDumpFiles = array( drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz', drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.system.database.php', @@ -29,26 +28,24 @@ class SystemUpgradePathTest extends UpgradePathTestBase { } /** - * Tests that custom and overridden image styles have been upgraded. + * Tests upgrade of system variables. */ public function testSystemVariableUpgrade() { $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); - // Test that the overridden values were properly converted. - $overrides = array( - 'system.performance' => array( - 'cache' => 1, - 'page_cache_maximum_age' => '1800', - 'page_compression' => 1, - 'preprocess_css' => 1, - 'preprocess_js' => 1, - ), + // Verify that variables were properly upgraded. + $expected_config['system.performance'] = array( + 'cache' => 1, + 'page_cache_maximum_age' => '1800', + 'page_compression' => 1, + 'preprocess_css' => 1, + 'preprocess_js' => 1, ); - foreach ($overrides as $file => $values) { + foreach ($expected_config as $file => $values) { $config = config($file); foreach ($values as $name => $value) { $stored = $config->get($name); - $this->assertEqual($value, $stored, t('Stored value %stored for %name matches old value %value.', array('%stored' => $stored, '%name' => $name, '%value' => $value))); + $this->assertEqual($value, $stored, format_string('Expected value for %name found: %stored (previously: %value).', array('%stored' => $stored, '%name' => $name, '%value' => $value))); } } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 797078e..cf67428 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1998,11 +1998,11 @@ function system_update_8014() { } /** - * Moves performance system settings from variable to config. + * Moves system performance settings from variable to config. * * @ingroup config_upgrade */ -function system_update_8014() { +function system_update_8015() { update_variables_to_config('system.performance', array( 'cache' => 'cache', 'page_cache_maximum_age' => 'page_cache_maximum_age', 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 3cc99c0..c03ecf0 100644 --- a/core/modules/system/tests/upgrade/drupal-7.image.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.image.database.php @@ -10,6 +10,23 @@ * altogether. */ +// Add image styles. +db_insert('image_styles')->fields(array( + 'isid', + 'name', +)) +// Override thumbnail style. +->values(array( + 'isid' => '1', + 'name' => 'thumbnail', +)) +// Custom style. +->values(array( + 'isid' => '2', + 'name' => 'test-custom', +)) +->execute(); + // Add image effects. db_insert('image_effects')->fields(array( 'ieid', @@ -47,20 +64,3 @@ db_insert('image_effects')->fields(array( 'data' => 'a:0:{}', )) ->execute(); - -// Add image styles. -db_insert('image_styles')->fields(array( - 'isid', - 'name', -)) -// Custom style. -->values(array( - 'isid' => '2', - 'name' => 'test-custom', -)) -// Override thumbnail style. -->values(array( - 'isid' => '1', - 'name' => 'thumbnail', -)) -->execute();