pm-enable and pm-disable are not working for themes in v3.0 head.

If I take the functionality in the old theme add on and make it available as a standalone command (not all the functionality of pm-enable/disable wrapped around it, it works.

Debugging information:
the drush_theme_enable/disable functions in environment_6.inc are actually working. When I checked pre/post dbquery values, the db was correct.

On moving back into pm.drush.inc pre/post values to the drush_theme_enable/disable function calls were correct.

Further debug shows that the call (line 415) '$project_info = drush_get_projects();' seems to reset the database back to the original state.

I have not had time to debug this further.

CommentFileSizeAuthor
#7 756228.patch5.01 KBjonhattan
#4 environment_6.inc_.patch1.82 KBmarcus_gbs

Comments

marcus_gbs’s picture

In environment_6.inc in function drush_get_themes, the call to system_theme_data seems to be what causes the enable/disable theme to revert. Inspection of DB before the call shows the new value and after the call shows the old value.

That is why this worked prior to merging into pm-enable as the old implementation didn't have the system_theme_data call.

marcus_gbs’s picture

call order:
pm-enable/disable (pm.drush.inc)
drush_get_projects (update_6.inc)
drush_get_themes (environment_6.inc)
system_theme_data() (drupal core's system.module)

The values set in the DB are correct up through the initial part of the system_theme_data function.

There is a call to system_get_file_database. On return from that, the database still has the correct information in it. However, the $themes array that was returned does not. system_theme_data then deletes the theme information from the system table and inserts the information from the $themes array.

That is how this is being overwritten.

marcus_gbs’s picture

I am not sure what system_get_files_database is supposed to do, but I am not sure if the logic is correct.

750  function system_get_files_database(&$files, $type) {
751    // Extract current files from database.
752    $result = db_query("SELECT filename, name, type, status, throttle, schema_version FROM {system} WHERE type = '%s'", $type);
753    while ($file = db_fetch_object($result)) {
754      if (isset($files[$file->name]) && is_object($files[$file->name])) {
755        $file->old_filename = $file->filename;
756        foreach ($file as $key => $value) {
757          if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
758            $files[$file->name]->$key = $value;
759          }
760        }
761      }
762    }
763  }

The question I have is regarding line 757. To begin with first condition is always going to be false as you passed the condition in 754. What 754 is saying is that if you don't have an array item with that file name or if you don't have that key in the array, then you set the key.

In our scenario, pm_enable/disable theme, we come through system_get_files_database twice (via calls to drush_get_projects), first when it gets the initial list and then afterwards when they get the list in preparation for giving the final status. The problem arises in that in the second call, the key is already in the list. With the check on line 757, as the status key exists, it does not write it. However, it contains the old value. In this case at least, it would need to update the status key.

At this point, I am hitting system module functionality. I don't know if it should skip the existing keys or update them. If the system module is wrong, then we can have it fixed so that pm-enable/disable theme would work. If not, we need to figure out what to do instead of that second call to drush_get_projects.

marcus_gbs’s picture

StatusFileSize
new1.82 KB

If system.module is correct, then we need to set status differently. We can't set it directly in the db as it will just be overwritten. I think the answer would be to set it in the list of 'files'/themes that is returned by system_theme_data().

If that approach is acceptable, then I have a proposed patch for the Drupal 6.x environment. The patch is to the environment_6.inc file.

greg.1.anderson’s picture

Status: Active » Needs review

Don't have time to review this now, but setting status to 'needs review'.

jonhattan’s picture

EDIT: I've tried to explain it a bit better.

@marcus_gbs patch in #4 is not valid because it relies on the second call to drush_get_projects() in drush_pm_enable(). This mean any drush command calling drush_theme_enable() on its own will not work, or will need to also call drush_get_projects(). As a side note you use tabs instead of 2 whitespaces that is the drupal coding standard.

I've not tested but it seems your patch plus db_query('UPDATE..') is a valid solution (i.e. a valid workaround).

In #3 you hit a bug in drupal core. Are you submitting an issue? It happens to work for drupal because it doesn't call system_theme_data() twice in the same request.

Although incomplete, current implementation of drush_theme_enable/disable() should be valid if line 757 did it right.

In the meanwhile we have two workarounds here: yours or a rework of drush_get_projects() that also will help improve drush performance in some pm commands. The possible rework is to add an argument: drush_get_projects($status) where $status is one of enabled|disabled. If $status=='enabled' it is faster to call module_list() and list_themes() or querying the system table. This way the second call will ask only for enabled modules and we avoid calling system_theme_data() again.

Going further. The implementation of drush_theme_enable/disable() is incomplete. In drupal 7 we have theme_enable() that completely enable a theme and perform all subsequent actions related (rebuild cache, invoke hooks). We need this for D5 and D6 to be fully compliant.
D6 does it in system_themes_form_submit() and D5 in system_themes_submit().

jonhattan’s picture

StatusFileSize
new5.01 KB

Proposed solution: remove the second call to drush_get_projects() and query the system table.

This patch also fix errors in drush_db_select() and minor typos in related code comments.

marcus_gbs’s picture

Created an issue against core: http://drupal.org/node/759766 (call to system_get_files_database via system_theme_data overwrites changes made directly to database).

jonhattan’s picture

This is also related to #305653: Themes disabled during update. When backported to D6 we'll get rid of this failure. Anyway my proposal in #7 is a lightweight solution and the proper one as we don't need to rebuild anything to just check a theme/module is already enabled.

izkreny’s picture

Subscribing.

moshe weitzman’s picture

Can anyone verify the fix here?

moshe weitzman’s picture

Status: Needs review » Fixed

committed. please reopen if you see any problems.

Status: Fixed » Closed (fixed)

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