From 281694bd1796a10a5cd4022725fed35d3a6cfd7f Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Mon, 5 Mar 2012 13:06:00 -0800
Subject: [PATCH 01/12] Added config directory checking to
 install_verify_settings()

---
 core/includes/install.core.inc |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 493246c..6f8aead 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -841,18 +841,25 @@ function install_verify_completed_task() {
  * Verifies the existing settings in settings.php.
  */
 function install_verify_settings() {
-  global $databases;
+  global $databases, $config_directory_name;
 
-  // Verify existing settings (if any).
+  // Verify database settings, if they have been pre-filled in settings.php.
   if (!empty($databases) && install_verify_pdo()) {
     $database = $databases['default']['default'];
     drupal_static_reset('conf_path');
     $settings_file = './' . conf_path(FALSE) . '/settings.php';
     $errors = install_database_errors($database, $settings_file);
-    if (empty($errors)) {
-      return TRUE;
-    }
   }
+
+  // Verify config settings, if they have been pre-filled in settings.php.
+  if (!empty($config_directory_name)) {
+    $errors += install_config_directory_errors(conf_path() . '/files/' . $config_directory_name);
+  }
+
+  if (empty($errors)) {
+    return TRUE;
+  }
+
   return FALSE;
 }
 
@@ -959,6 +966,20 @@ function install_settings_form_validate($form, &$form_state) {
 }
 
 /**
+ * Checks a configuration directory and returns any errors.
+ */
+function install_config_directory_errors($dir) {
+  $errors = array();
+
+  // Check that the specified config directory exists.
+  if (!file_prepare_directory($dir, 0)) {
+    $errors['config_directory'] = st("Your config directory, specified as %dir, does not exist or is not writeable. Please create this directory and set it to be writeable by the web server.", array('%dir' => $dir));
+  }
+
+  return $errors;
+}
+
+/**
  * Checks a database connection and returns any errors.
  */
 function install_database_errors($database, $settings_file) {
-- 
1.7.5.4


From bf81303670a6326a8c2827a99a4a90476c8d8015 Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Mon, 5 Mar 2012 13:14:59 -0800
Subject: [PATCH 02/12] Moved config directory creation to
 install_system_module() so it isn't reliant on the
 installer settings form being submitted

---
 core/includes/install.core.inc |   50 ++++++++++++++++++---------------------
 1 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 6f8aead..f844d18 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -793,6 +793,29 @@ function install_verify_requirements(&$install_state) {
  *   An array of information about the current installation state.
  */
 function install_system_module(&$install_state) {
+  $settings['config_signature_key'] = array(
+    'value'    => drupal_hash_base64(drupal_random_bytes(55)),
+    'required' => TRUE,
+  );
+
+  // This duplicates drupal_get_token() because that function can't work yet.
+  $settings['config_directory_name'] = array(
+    'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value'] . $settings['drupal_hash_salt']['value']),
+    'required'  => TRUE,
+  );
+
+  drupal_rewrite_settings($settings);
+
+  // Actually create the config directory named above.
+  $config_path = conf_path() . '/files/' . $settings['config_directory_name']['value'];
+  if (!file_prepare_directory($config_path, FILE_CREATE_DIRECTORY)) {
+    // How best to handle errors here?
+  };
+
+  // Write out a .htaccess file that will protect the config directory from
+  // prying eyes.
+  file_save_htaccess($config_path, TRUE);
+
   // Install system.module.
   drupal_install_system();
 
@@ -1032,34 +1055,7 @@ function install_settings_form_submit($form, &$form_state) {
     'required' => TRUE,
   );
 
-  $settings['config_signature_key'] = array(
-    'value'    => drupal_hash_base64(drupal_random_bytes(55)),
-    'required' => TRUE,
-  );
-
-  // This duplicates drupal_get_token() because that function can't work yet.
-  // Wondering if it makes sense to move this later in the process, but its
-  // nice having all the settings stuff here.
-  //
-  // @todo This is actually causing a bug right now, because you can install
-  // without hitting install_settings_form_submit() if your settings.php
-  // already has the db stuff in it, and right now in that case your
-  // config directory never gets created. So this needs to be moved elsewhere.
-  $settings['config_directory_name'] = array(
-    'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value'] . $settings['drupal_hash_salt']['value']),
-    'required'  => TRUE,
-  );
-
   drupal_rewrite_settings($settings);
-  // Actually create the config directory named above.
-  $config_path = conf_path() . '/files/' . $settings['config_directory_name']['value'];
-  if (!file_prepare_directory($config_path, FILE_CREATE_DIRECTORY)) {
-    // How best to handle errors here?
-  };
-
-  // Write out a .htaccess file that will protect the config directory from
-  // prying eyes.
-  file_save_htaccess($config_path, TRUE);
 
   // Indicate that the settings file has been verified, and check the database
   // for the last completed task, now that we have a valid connection. This
-- 
1.7.5.4


From 5f0093073f730255312618ac4181e01163a0857e Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Wed, 7 Mar 2012 15:14:00 -0800
Subject: [PATCH 03/12] Removing all code for a test

---
 core/includes/install.core.inc |   56 +++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index f844d18..cfd0356 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -793,28 +793,28 @@ function install_verify_requirements(&$install_state) {
  *   An array of information about the current installation state.
  */
 function install_system_module(&$install_state) {
-  $settings['config_signature_key'] = array(
-    'value'    => drupal_hash_base64(drupal_random_bytes(55)),
-    'required' => TRUE,
-  );
-
-  // This duplicates drupal_get_token() because that function can't work yet.
-  $settings['config_directory_name'] = array(
-    'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value'] . $settings['drupal_hash_salt']['value']),
-    'required'  => TRUE,
-  );
-
-  drupal_rewrite_settings($settings);
-
-  // Actually create the config directory named above.
-  $config_path = conf_path() . '/files/' . $settings['config_directory_name']['value'];
-  if (!file_prepare_directory($config_path, FILE_CREATE_DIRECTORY)) {
-    // How best to handle errors here?
-  };
-
-  // Write out a .htaccess file that will protect the config directory from
-  // prying eyes.
-  file_save_htaccess($config_path, TRUE);
+  // $settings['config_signature_key'] = array(
+  //   'value'    => drupal_hash_base64(drupal_random_bytes(55)),
+  //   'required' => TRUE,
+  // );
+  //
+  // // This duplicates drupal_get_token() because that function can't work yet.
+  // $settings['config_directory_name'] = array(
+  //   'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value']),
+  //   'required'  => TRUE,
+  // );
+  //
+  // drupal_rewrite_settings($settings);
+  //
+  // // Actually create the config directory named above.
+  // $config_path = conf_path() . '/files/' . $settings['config_directory_name']['value'];
+  // if (!file_prepare_directory($config_path, FILE_CREATE_DIRECTORY)) {
+  //   // How best to handle errors here?
+  // };
+  //
+  // // Write out a .htaccess file that will protect the config directory from
+  // // prying eyes.
+  // file_save_htaccess($config_path, TRUE);
 
   // Install system.module.
   drupal_install_system();
@@ -865,6 +865,7 @@ function install_verify_completed_task() {
  */
 function install_verify_settings() {
   global $databases, $config_directory_name;
+  $errors = array();
 
   // Verify database settings, if they have been pre-filled in settings.php.
   if (!empty($databases) && install_verify_pdo()) {
@@ -873,12 +874,15 @@ function install_verify_settings() {
     $settings_file = './' . conf_path(FALSE) . '/settings.php';
     $errors = install_database_errors($database, $settings_file);
   }
-
-  // Verify config settings, if they have been pre-filled in settings.php.
-  if (!empty($config_directory_name)) {
-    $errors += install_config_directory_errors(conf_path() . '/files/' . $config_directory_name);
+  else {
+    return FALSE;
   }
 
+  // // Verify config settings, if they have been pre-filled in settings.php.
+  // if (!empty($config_directory_name)) {
+  //   $errors += install_config_directory_errors(conf_path() . '/files/' . $config_directory_name);
+  // }
+
   if (empty($errors)) {
     return TRUE;
   }
-- 
1.7.5.4


From 1c1698e7ebeb875e420be907e9862c5b00abc0bd Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Wed, 7 Mar 2012 15:50:50 -0800
Subject: [PATCH 04/12] Moved writing of settings file back to
 install_form_submit(), things kind of working now

---
 core/includes/install.core.inc |   56 +++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index cfd0356..ba4c265 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -793,28 +793,17 @@ function install_verify_requirements(&$install_state) {
  *   An array of information about the current installation state.
  */
 function install_system_module(&$install_state) {
-  // $settings['config_signature_key'] = array(
-  //   'value'    => drupal_hash_base64(drupal_random_bytes(55)),
-  //   'required' => TRUE,
-  // );
-  //
-  // // This duplicates drupal_get_token() because that function can't work yet.
-  // $settings['config_directory_name'] = array(
-  //   'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value']),
-  //   'required'  => TRUE,
-  // );
-  //
-  // drupal_rewrite_settings($settings);
-  //
-  // // Actually create the config directory named above.
-  // $config_path = conf_path() . '/files/' . $settings['config_directory_name']['value'];
-  // if (!file_prepare_directory($config_path, FILE_CREATE_DIRECTORY)) {
-  //   // How best to handle errors here?
-  // };
-  //
-  // // Write out a .htaccess file that will protect the config directory from
-  // // prying eyes.
-  // file_save_htaccess($config_path, TRUE);
+  global $config_directory_name;
+
+  // Actually create the config directory named above.
+  $config_path = conf_path() . '/files/' . $config_directory_name;
+  if (!file_prepare_directory($config_path, FILE_CREATE_DIRECTORY)) {
+    // How best to handle errors here?
+  };
+
+  // Write out a .htaccess file that will protect the config directory from
+  // prying eyes.
+  file_save_htaccess($config_path, TRUE);
 
   // Install system.module.
   drupal_install_system();
@@ -878,10 +867,13 @@ function install_verify_settings() {
     return FALSE;
   }
 
-  // // Verify config settings, if they have been pre-filled in settings.php.
-  // if (!empty($config_directory_name)) {
-  //   $errors += install_config_directory_errors(conf_path() . '/files/' . $config_directory_name);
-  // }
+  // Verify config settings, if they have been pre-filled in settings.php.
+  if (!empty($config_directory_name)) {
+    $errors += install_config_directory_errors(conf_path() . '/files/' . $config_directory_name);
+    if (!empty($errors)) {
+      throw new Exception(implode("\n", $errors));
+    }
+  }
 
   if (empty($errors)) {
     return TRUE;
@@ -1059,6 +1051,18 @@ function install_settings_form_submit($form, &$form_state) {
     'required' => TRUE,
   );
 
+  // Create the config directory name while we're at it.
+  $settings['config_signature_key'] = array(
+    'value'    => drupal_hash_base64(drupal_random_bytes(55)),
+    'required' => TRUE,
+  );
+
+  // This duplicates drupal_get_token() because that function can't work yet.
+  $settings['config_directory_name'] = array(
+    'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value'] . $settings['drupal_hash_salt']['value']),
+    'required'  => TRUE,
+  );
+
   drupal_rewrite_settings($settings);
 
   // Indicate that the settings file has been verified, and check the database
-- 
1.7.5.4


From ce3cf8bb3a334bdf330c30447dd58492f53ccb1e Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Thu, 8 Mar 2012 17:11:52 -0800
Subject: [PATCH 05/12] Fixed situation where someone had coded a config
 directory but no their database settings

---
 core/includes/install.core.inc |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index ba4c265..ce03d4d 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -1039,7 +1039,7 @@ function install_database_errors($database, $settings_file) {
  * Form API submit for install_settings form.
  */
 function install_settings_form_submit($form, &$form_state) {
-  global $install_state;
+  global $install_state, $config_directory_name;
 
   // Update global settings array and save.
   $settings['databases'] = array(
@@ -1051,17 +1051,20 @@ function install_settings_form_submit($form, &$form_state) {
     'required' => TRUE,
   );
 
-  // Create the config directory name while we're at it.
   $settings['config_signature_key'] = array(
     'value'    => drupal_hash_base64(drupal_random_bytes(55)),
     'required' => TRUE,
   );
 
-  // This duplicates drupal_get_token() because that function can't work yet.
-  $settings['config_directory_name'] = array(
-    'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value'] . $settings['drupal_hash_salt']['value']),
-    'required'  => TRUE,
-  );
+  // If someone had already set a config directory in settings.php, don't
+  // create a new one.
+  if (empty($config_directory_name)) {
+    // This duplicates drupal_get_token() because that function can't work yet.
+    $settings['config_directory_name'] = array(
+      'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value'] . $settings['drupal_hash_salt']['value']),
+      'required'  => TRUE,
+    );
+  }
 
   drupal_rewrite_settings($settings);
 
-- 
1.7.5.4


From de5cd762856d7366c49b769ffcd39ed000061b59 Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Sun, 11 Mar 2012 16:19:12 -0700
Subject: [PATCH 06/12] First pass at a system module upgrade path

---
 core/modules/system/system.install |   66 +++++++++++++++++++++++++++++++++++-
 1 files changed, 65 insertions(+), 1 deletions(-)

diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index 2cbb615..ff67891 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -1697,9 +1697,11 @@ function system_update_8002() {
 }
 
 /**
- * Adds {config} table for new Configuration system.
+ * Adds {config} table and create directory for the new Configuration system.
  */
 function system_update_8003() {
+  global $config_directory_name;
+
   // @todo Temporary.
   if (db_table_exists('config')) {
     db_drop_table('config');
@@ -1724,6 +1726,68 @@ function system_update_8003() {
     ),
     'primary key' => array('name'),
   ));
+
+  $settings['config_signature_key'] = array(
+    'value'    => drupal_hash_base64(drupal_random_bytes(55)),
+    'required' => TRUE,
+  );
+
+  // If someone had already set a config directory in settings.php, don't
+  // create a new one.
+  if (empty($config_directory_name)) {
+    // This duplicates drupal_get_token() because that function can't work yet.
+    $settings['config_directory_name'] = array(
+      'value'     => 'config_' . drupal_hmac_base64('', session_id() . $settings['config_signature_key']['value'] . $settings['drupal_hash_salt']['value']),
+      'required'  => TRUE,
+    );
+  }
+
+  drupal_rewrite_settings($settings);
+
+  // Actually create the config directory named above.
+  $config_path = conf_path() . '/files/' . $config_directory_name;
+  if (!file_prepare_directory($config_path, FILE_CREATE_DIRECTORY)) {
+    // How best to handle errors here?
+  };
+
+  // Write out a .htaccess file that will protect the config directory from
+  // prying eyes.
+  file_save_htaccess($config_path, TRUE);
+
+  // Install the default configuration for the system module.
+  config_install_default_config('system');
+
+  // Move the values of any existing variables into the config system, and
+  // delete the variables.
+  $config = config('system.performance');
+  foreach (_system_get_variables_and_defaults() as $key => $default) {
+    $config->set($key, variable_get($key, $default));
+    variable_del($key);
+  }
+  $config->save();
+}
+
+/**
+ * Get all variables managed by the system module, and their defaults.
+ *
+ * This is a helper function used in the upgrade of the existing variable
+ * system to the new config system. As new variables are converted, they
+ * can just be added to this array and they will become part of the upgrade
+ * path. The format is
+ *
+ * variable_name => default value
+ *
+ * @see system_upgrade_8003()
+ */
+function _system_get_variables_and_defaults() {
+  return array(
+    'cache' => 0,
+    'cache_lifetime' => 0,
+    'page_cache_maximum_age' => 0,
+    'page_compression' => 0,
+    'preprocess_css' => 0,
+    'preprocess_js' => 0,
+  )
 }
 
 /**
-- 
1.7.5.4


From 6f36b7b3dc6787d570783394e8e7f7b160de824f Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Sun, 11 Mar 2012 17:15:43 -0700
Subject: [PATCH 07/12] Shelling in the image converstion

---
 core/modules/image/image.install   |   59 ++++++++++++++++++++++++++++++++++++
 core/modules/system/system.install |   27 ++++++++++-------
 2 files changed, 75 insertions(+), 11 deletions(-)

diff --git a/core/modules/image/image.install b/core/modules/image/image.install
index 91349a9..70540a4 100644
--- a/core/modules/image/image.install
+++ b/core/modules/image/image.install
@@ -106,3 +106,62 @@ function image_requirements($phase) {
 
   return $requirements;
 }
+
+/**
+ * @defgroup updates-7.x-to-8.x Updates from 7.x to 8.x
+ * @{
+ * Update functions from 7.x to 8.x.
+ */
+
+/**
+ * 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()
+
+  $module_styles = module_invoke('image', 'image_default_styles');
+  foreach ($module_styles as $style_name => $style) {
+    $style['name'] = $style_name;
+    foreach ($style['effects'] as $key => $effect) {
+      $definition = image_effect_definition_load($effect['name']); // Need to remake this
+      $effect = array_merge($definition, $effect);
+      $style['effects'][$key] = $effect;
+    }
+    $styles[$style_name] = $style;
+  }
+
+  // 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))
+    ->fields('image_styles')
+    ->orderBy('name')
+    ->execute()
+    ->fetchAllAssoc('name', PDO::FETCH_ASSOC);
+
+  foreach ($user_styles as $style_name => $style) {
+    $style['effects'] = image_style_effects($style); // need to remake this
+    if (isset($styles[$style_name]['module'])) {
+      $style['module'] = $styles[$style_name]['module'];
+    }
+    $styles[$style_name] = $style;
+  }
+
+  // Convert styles to the config system
+  foreach ($styles as $name => $style) {
+    $config = config('image.styles.' . $name);
+
+
+
+    $config->save();
+  }
+}
+
+/**
+ * @} End of "defgroup updates-7.x-to-8.x"
+ * The next series of updates should start at 9000.
+ */
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index ff67891..095ffd9 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -1759,12 +1759,15 @@ function system_update_8003() {
 
   // Move the values of any existing variables into the config system, and
   // delete the variables.
-  $config = config('system.performance');
-  foreach (_system_get_variables_and_defaults() as $key => $default) {
-    $config->set($key, variable_get($key, $default));
-    variable_del($key);
+  $variables = _system_get_variables_and_defaults();
+  foreach ($variables as $file => $values) {
+    $config = config($file);
+    foreach ($values as $key => $default) {
+      $config->set($key, variable_get($key, $default));
+      variable_del($key);
+    }
+    $config->save();
   }
-  $config->save();
 }
 
 /**
@@ -1781,12 +1784,14 @@ function system_update_8003() {
  */
 function _system_get_variables_and_defaults() {
   return array(
-    'cache' => 0,
-    'cache_lifetime' => 0,
-    'page_cache_maximum_age' => 0,
-    'page_compression' => 0,
-    'preprocess_css' => 0,
-    'preprocess_js' => 0,
+    'system.performance' =? array(
+      'cache' => 0,
+      'cache_lifetime' => 0,
+      'page_cache_maximum_age' => 0,
+      'page_compression' => 0,
+      'preprocess_css' => 0,
+      'preprocess_js' => 0,
+    )
   )
 }
 
-- 
1.7.5.4


From 79084292b90e10a25efdcfb90fb281d83e92f975 Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Sun, 11 Mar 2012 17:54:11 -0700
Subject: [PATCH 08/12] Removed default style code since we don't actually
 need it

---
 core/modules/image/image.install |   19 ++-----------------
 1 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/core/modules/image/image.install b/core/modules/image/image.install
index 70540a4..ddcd26d 100644
--- a/core/modules/image/image.install
+++ b/core/modules/image/image.install
@@ -120,23 +120,8 @@ function image_update_8000() {
   // Install default config for the image module
   config_install_default_config('image');
 
-  // Get the image module-defined styles.
-  $styles = array()
-
-  $module_styles = module_invoke('image', 'image_default_styles');
-  foreach ($module_styles as $style_name => $style) {
-    $style['name'] = $style_name;
-    foreach ($style['effects'] as $key => $effect) {
-      $definition = image_effect_definition_load($effect['name']); // Need to remake this
-      $effect = array_merge($definition, $effect);
-      $style['effects'][$key] = $effect;
-    }
-    $styles[$style_name] = $style;
-  }
-
-  // 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.
+  // Get the user generated styles. Note some of these may be overrides
+  // of styles supplied by the image module.
   $user_styles = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC))
     ->fields('image_styles')
     ->orderBy('name')
-- 
1.7.5.4


From cb33c52be3c1c6ee9b9cce63de436d07bac8c2b9 Mon Sep 17 00:00:00 2001
From: Greg Dunlap <gdd@heyrocker.com>
Date: Sun, 11 Mar 2012 17:55:49 -0700
Subject: [PATCH 09/12] Adding a reminder

---
 core/modules/image/image.install |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/core/modules/image/image.install b/core/modules/image/image.install
index ddcd26d..ac12b7e 100644
--- a/core/modules/image/image.install
+++ b/core/modules/image/image.install
@@ -140,7 +140,7 @@ function image_update_8000() {
   foreach ($styles as $name => $style) {
     $config = config('image.styles.' . $name);
 
-
+    // Generate machine name for each effect
 
     $config->save();
   }
-- 
1.7.5.4


From 10e904895360fb4b0220d4c267c664ee6ef0a610 Mon Sep 17 00:00:00 2001
From: Jonathan Hedstrom <jhedstrom@gmail.com>
Date: Wed, 18 Apr 2012 09:08:02 -0700
Subject: [PATCH 10/12] Fixing typos in system.install.

---
 core/modules/system/system.install |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index 0bb742d..a6b97d3 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -1778,7 +1778,7 @@ function system_update_8003() {
  */
 function _system_get_variables_and_defaults() {
   return array(
-    'system.performance' =? array(
+    'system.performance' => array(
       'cache' => 0,
       'cache_lifetime' => 0,
       'page_cache_maximum_age' => 0,
@@ -1786,7 +1786,7 @@ function _system_get_variables_and_defaults() {
       'preprocess_css' => 0,
       'preprocess_js' => 0,
     )
-  )
+  );
 }
 
 /**
-- 
1.7.5.4


From cf4d7f6ac8c28f59528b573249e667f9429d9dd8 Mon Sep 17 00:00:00 2001
From: Jonathan Hedstrom <jhedstrom@gmail.com>
Date: Wed, 18 Apr 2012 10:06:01 -0700
Subject: [PATCH 11/12] Issue #1464554: adding upgrade databases for image and
 system modules, and corresponding tests.

---
 core/modules/system/system.info                    |    2 +
 .../tests/upgrade/drupal-7.image.database.php      |   66 ++++++++++++++++++++
 .../tests/upgrade/drupal-7.system.database.php     |   42 ++++++++++++
 .../system/tests/upgrade/upgrade.image.test        |   35 ++++++++++
 .../system/tests/upgrade/upgrade.system.test       |   54 ++++++++++++++++
 5 files changed, 199 insertions(+), 0 deletions(-)
 create mode 100644 core/modules/system/tests/upgrade/drupal-7.image.database.php
 create mode 100644 core/modules/system/tests/upgrade/drupal-7.system.database.php
 create mode 100644 core/modules/system/tests/upgrade/upgrade.image.test
 create mode 100644 core/modules/system/tests/upgrade/upgrade.system.test

diff --git a/core/modules/system/system.info b/core/modules/system/system.info
index 41495f3..29a9c00 100644
--- a/core/modules/system/system.info
+++ b/core/modules/system/system.info
@@ -42,4 +42,6 @@ files[] = tests/xmlrpc.test
 files[] = tests/upgrade/upgrade.test
 files[] = tests/upgrade/upgrade_bare.test
 files[] = tests/upgrade/upgrade_filled.test
+files[] = tests/upgrade/upgrade.image.test
 files[] = tests/upgrade/upgrade.language.test
+files[] = tests/upgrade/upgrade.system.test
diff --git a/core/modules/system/tests/upgrade/drupal-7.image.database.php b/core/modules/system/tests/upgrade/drupal-7.image.database.php
new file mode 100644
index 0000000..9a5dc7f
--- /dev/null
+++ b/core/modules/system/tests/upgrade/drupal-7.image.database.php
@@ -0,0 +1,66 @@
+<?php
+
+/**
+ * @file
+ * Database additions for image tests. Used in upgrade.image.test.
+ *
+ * This dump only contains data and schema components relevant for image
+ * functionality. The drupal-7.bare.database.php file is imported before
+ * this dump, so the two form the database structure expected in tests
+ * altogether.
+ */
+
+// Add image effects.
+db_insert('image_effects')->fields(array(
+  'ieid',
+  'isid',
+  'weight',
+  'name',
+  'data',
+))
+->values(array(
+  'ieid' => '1',
+  'isid' => '1',
+  'weight' => '0',
+  'name' => 'image_scale',
+  'data' => 'a:3:{s:5:"width";s:3:"177";s:6:"height";s:3:"177";s:7:"upscale";i:0;}',
+))
+->values(array(
+  'ieid' => '2',
+  'isid' => '1',
+  'weight' => '2',
+  'name' => 'image_desaturate',
+  'data' => 'a:0:{}',
+))
+->values(array(
+  'ieid' => '3',
+  'isid' => '2',
+  'weight' => '1',
+  'name' => 'image_rotate',
+  'data' => 'a:3:{s:7:"degrees";s:2:"90";s:7:"bgcolor";s:7:"#FFFFFF";s:6:"random";i:1;}',
+))
+->values(array(
+  'ieid' => '4',
+  'isid' => '2',
+  'weight' => '2',
+  'name' => 'image_desaturate',
+  '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();
diff --git a/core/modules/system/tests/upgrade/drupal-7.system.database.php b/core/modules/system/tests/upgrade/drupal-7.system.database.php
new file mode 100644
index 0000000..e3d0fb4
--- /dev/null
+++ b/core/modules/system/tests/upgrade/drupal-7.system.database.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @file
+ * Database additions for system tests. Used in upgrade.system.test.
+ *
+ * This dump only contains data and schema components relevant for system
+ * functionality. The drupal-7.filled.bare.php file is imported before
+ * this dump, so the two form the database structure expected in tests
+ * altogether.
+ */
+
+// Add non-default system settings.
+db_insert('variable')->fields(array(
+  'name',
+  'value',
+))
+->values(array(
+  'name' => 'cache',
+  'value'=> 'i:1;',
+))
+->values(array(
+    'name' => 'cache_lifetime',
+    'value' => 's:5:"10800";',
+  ))
+->values(array(
+    'name' => 'page_cache_maximum_age',
+    'value' => 's:4:"1800";',
+  ))
+->values(array(
+    'name' => 'page_compression',
+    'value' => 'i:1;',
+  ))
+->values(array(
+    'name' => 'preprocess_css',
+    'value' => 'i:1;',
+  ))
+->values(array(
+    'name' => 'preprocess_js',
+    'value' => 'i:1;',
+  ))
+->execute();
\ No newline at end of file
diff --git a/core/modules/system/tests/upgrade/upgrade.image.test b/core/modules/system/tests/upgrade/upgrade.image.test
new file mode 100644
index 0000000..2a784fe
--- /dev/null
+++ b/core/modules/system/tests/upgrade/upgrade.image.test
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @file
+ * Upgrade tests for Image module.
+ */
+
+/**
+ * Test upgrade of overridden and custom image styles.
+ */
+class ImageUpgradePathTestCase extends UpgradePathTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Image upgrade test',
+      'description' => 'Upgrade tests for overridden and custom image styles.',
+      'group' => 'Upgrade path',
+    );
+  }
+
+  public function setUp() {
+    // Path to the database dump files.
+    $path = drupal_get_path('module', 'system') . '/tests/upgrade';
+    $this->databaseDumpFiles = array(
+      $path . '/drupal-7.bare.database.php.gz',
+      $path . '/drupal-7.image.database.php',
+    );
+    parent::setUp();
+  }
+
+  /**
+   * Tests that custom and overridden image styles have been upgraded.
+   */
+  public function testImageStyleUpgrade() {
+    $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
+  }
+}
\ No newline at end of file
diff --git a/core/modules/system/tests/upgrade/upgrade.system.test b/core/modules/system/tests/upgrade/upgrade.system.test
new file mode 100644
index 0000000..d621067
--- /dev/null
+++ b/core/modules/system/tests/upgrade/upgrade.system.test
@@ -0,0 +1,54 @@
+<?php
+/**
+ * @file
+ * Upgrade tests for the System module.
+ */
+
+/**
+ * Test upgrade of non-default values for system variables.
+ */
+class SystemUpgradePathTestCase extends UpgradePathTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'System upgrade test',
+      'description' => 'Upgrade tests for non-default values of system variables.',
+      'group' => 'Upgrade path',
+    );
+  }
+
+  public function setUp() {
+    // Path to the database dump files.
+    $path = drupal_get_path('module', 'system') . '/tests/upgrade';
+    $this->databaseDumpFiles = array(
+      $path . '/drupal-7.bare.database.php.gz',
+      $path . '/drupal-7.system.database.php',
+    );
+    parent::setUp();
+  }
+
+  /**
+   * Tests that custom and overridden image styles have been upgraded.
+   */
+  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,
+        'cache_lifetime' => '10800',
+        'page_cache_maximum_age' => '1800',
+        'page_compression' => 1,
+        'preprocess_css' => 1,
+        'preprocess_js' => 1,
+      ),
+    );
+    foreach ($overrides 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)));
+      }
+    }
+  }
+}
\ No newline at end of file
-- 
1.7.5.4


From 7b334d1a7a98145a21326523b773677bda993934 Mon Sep 17 00:00:00 2001
From: Jonathan Hedstrom <jhedstrom@gmail.com>
Date: Thu, 19 Apr 2012 17:47:13 -0700
Subject: [PATCH 12/12] Adding update functionality for image styles.

---
 core/modules/image/image.install                   |   66 +++++++++++++++++++-
 .../system/tests/upgrade/upgrade.image.test        |   47 ++++++++++++++-
 2 files changed, 110 insertions(+), 3 deletions(-)

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
+}
-- 
1.7.5.4

