I've added some basic backwards compatibility for the users that may upgrade to version 2. The idea is to support the old variables but help transitioning to the new variable names (which are structurally different).

To do so I've mapped the old environment_indicator_enabled, environment_indicator_text, environment_indicator_color to the new names for the environment that is set through settings.php (called overritten_environment). Additionally if the users have permissions to see the overritten_environment they will be given a warning to change the settings.php variable names (and add the missing ones). In the status report there will be an error if there are old variable names while using version 2.

Can you help testing this? I'm not sure I'm covering all use cases or if you agree with the method I just described.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

Status: Needs review » Needs work

We at least need an upgrade path from 7.x to 2.x. 2.x introduces a database table, but there is no hopdate hook to create it.

e0ipso’s picture

Status: Needs work » Needs review
FileSize
3.88 KB

I totally forgot. Now we should be good to go.

(Already pushed to 7.x-2.x-dev, patch is for revision)

Stevel’s picture

The old variables still exist, causing it to show up as an overriden indicator, even if there are no variables in settings.php. (it checks for environment_indicator_enabled).

I propose an update function to modify the default configuration with the values from the old variables, and then removing these.

Stevel’s picture

Status: Needs review » Needs work
Stevel’s picture

Status: Needs work » Needs review
FileSize
4 KB

Here's a patch for the upgrade path. What is does:

  • Add an upgrade function to change the default environment with the old variables
  • Remove the old variables
  • Remove the requirements check for the old variables, as these are now removed
  • Remove the function that checks for old variables
  • Change the is_overwritten function to no longer check for the old variables
  • Change the load_overwritten function to no longer check for the old variables
mgifford’s picture

I couldn't get the last patch to work against the last release.. It rejected one piece of it, but can't see how that would have caused it to fail.. Maybe if I was using the git repo instead.

Upgrades should be easier, but when in doubt, this should also work:

DELETE FROM `variable` WHERE `variable`.`name` = 'environment_indicator_color';
DELETE FROM `variable` WHERE `variable`.`name` = 'environment_indicator_enabled';
DELETE FROM `variable` WHERE `variable`.`name` = 'environment_indicator_margin';
DELETE FROM `variable` WHERE `variable`.`name` = 'environment_indicator_position';
DELETE FROM `variable` WHERE `variable`.`name` = 'environment_indicator_text';

e0ipso’s picture

Status: Needs review » Fixed

@Stevel there are 2 key aspects here.

  1. Since the variables are in the settings.php there is no point in deleting them, they won't be removed unless the settings.php is edited.
  2. @mrfelton feels that there should be support for the settings.php style. Many people have build on top of the settings.php style and we should be supporting them in the 7.x version.
  1. +++ b/environment_indicator.install
    @@ -71,3 +71,36 @@
    +  $result = db_query("SELECT * FROM {variable} WHERE name LIKE 'environment_indicator_%'");
    

    This will wipe all variables, not just the old ones.

  2. +++ b/environment_indicator.install
    @@ -71,3 +71,36 @@
    +  $result = db_query("SELECT * FROM {variable} WHERE name LIKE 'environment_indicator_%'");
    +  if (result) {
    ...
    +        case 'environment_indicator_color':
    ...
    +        case 'environment_indicator_text':
    ...
    +        case 'environment_indicator_enabled':
    +        case 'environment_indicator_margin':
    +        case 'environment_indicator_position':
    

    This conditions will never happen since the settings.php variables are not in the database.

I'm sorry to see that your effort will not be fixed, but if you feel like it I can help you find a nice ticket in the issue queue.

Thanks for your contribution!

Stevel’s picture

Status: Fixed » Needs review

@e0ipso:

1. The variables can be defined in settings.php, but also set through the UI in 7.x-1.x (see http://drupalcode.org/project/environment_indicator.git/blob/739e2d71d2f...). When the user has configured the environment indicator via the UI, it would be nice if the behaviour is upgraded.

2. settings.php support is still in place. When an environment in settings.php is configured, this is displayed on the environment indicator overview page.

1. It doesn't remove all variables, only the variables that are no longer used in 7.x-2.x.
2. The variables are in the database if the settings form was saved at least once, which seem is very likely, so the cases will happen for most upgrades from 7.x-1.x. When the form was never saved, the upgrade function does nothing.

If I am misunderstanding something, please explain what is happening then, I'm happy to improve the patch.

Stevel’s picture

Rerolled patch after recent commits.

Stevel’s picture

I changed the patch to keep support for the old variable names in settings.php, but migrating the old 7.x-1.x variables to the default environment in 7.x-2.x (unless the default environment was already changed)

e0ipso’s picture

  1. +++ b/environment_indicator.install
    @@ -84,4 +84,45 @@ function environment_indicator_update_7201(&$sandbox) {
    +  $result = db_query("SELECT * FROM {variable} WHERE name LIKE 'environment_indicator_%'");
    +  if (result) {
    +    while ($row = $result->fetchAssoc()) {
    +      switch ($row['name']) {
    +        case 'environment_indicator_color':
    +          $default_environment->settings['color'] = unserialize($row['value']);
    +          variable_del($row['name']);
    +          break;
    +
    +        case 'environment_indicator_text':
    +          $default_environment->name = unserialize($row['value']);
    +          variable_del($row['name']);
    +          break;
    +
    +        case 'environment_indicator_enabled':
    +        case 'environment_indicator_margin':
    +        case 'environment_indicator_position':
    +          // This variable is no longer used. Remove it.
    +          variable_del($row['name']);
    +          break;
    +        case 'environment_indicator_suppress_pages':
    +          // This variable is still used, keep it.
    

    Instead do something like:

    $variable_names = array('environment_indicator_color', …);
    foreach ($variable_names as $variable_name) {
      $variable = variable_get($variable_name, NULL);
      if ($variable !== NULL) {
        …
      }
    }
    
  2. +++ b/environment_indicator.install
    @@ -84,4 +84,45 @@ function environment_indicator_update_7201(&$sandbox) {
    +  // Only save if the default environment was not edited yet.
    +  if (! ($defaut_environment->export_type & EXPORT_IN_DATABASE)) {
    +    ctools_export_crud_save('environment_indicator_environment', $default_environment);
    +  }
    

    Move this chunk to the top so we don't run the previous code if we are not going to save it.

    I'm concerned about a possible data loss in the following scenario: the user edits the default environment, exports it to code in a feature, then runs the DB updates.

Stevel’s picture

Status: Needs review » Needs work

1. The reason I didn't use variable_get is that it also uses values from settings.php, while the idea is to migrate the settings stored in the database, leaving those in settings.php alone. I'll update the comment to clarify this.

2. The variable_del statements still have to run to remove the old variables from the database, even if the default environment is already overridden. (otherwise the old variables will still override the ui-configured environment)

Stevel’s picture

Status: Needs work » Needs review
FileSize
3.71 KB
1.8 KB

Updated patch. In addition to the comment changes, it fixes a syntax error (forgotten }) and checks that the default_environment is the one defined in this module before saving.

e0ipso’s picture

Assigned: mrfelton » e0ipso
Status: Needs review » Fixed

Reviewed and committed (http://drupalcode.org/project/environment_indicator.git/commit/d7a5c5a).

I added some update notification and corrected a typo result => $result

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.