From ad7d3fd150591d64f1df0591361be1d15d5a3d35 Mon Sep 17 00:00:00 2001 From: Ted Cooper Date: Tue, 7 Feb 2012 01:04:17 +1000 Subject: [PATCH] Issue #1425868 by ELC: Return to old behaviour of deleting all theme entries to avoid dup key errors. --- modules/system/system.module | 24 ++++++++++-------------- 1 files changed, 10 insertions(+), 14 deletions(-) diff --git a/modules/system/system.module b/modules/system/system.module index 1a8d237..e9f6617 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -826,25 +826,21 @@ function system_theme_data() { // If lock not acquired, return $themes data without writing to database. if ($write_database) { - $names = array(); + + // Database is locked so no one else can change these settings, we are safe + // to delete everything and write out each of the records. + db_query("DELETE FROM {system} WHERE type = 'theme'"); foreach ($themes as $theme) { - // Record the name of each theme found in the file system. - $names[] = $theme->name; - // Update the contents of the system table. - if (isset($theme->status) && !(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE != 'install')) { - db_query("UPDATE {system} SET owner = '%s', info = '%s', filename = '%s' WHERE name = '%s' AND type = '%s'", $theme->owner, serialize($theme->info), $theme->filename, $theme->name, 'theme'); - } - else { + // If status is missing, set it based on this theme name matching the + // configured default theme. + if (!isset($theme->status)) { $theme->status = ($theme->name == variable_get('theme_default', 'garland')); - // This is a new theme. - db_query("INSERT INTO {system} (name, owner, info, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d)", $theme->name, $theme->owner, serialize($theme->info), 'theme', $theme->filename, $theme->status, 0, 0); } + // Insert records back into the system table + db_query("INSERT INTO {system} (name, owner, info, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d)", $theme->name, $theme->owner, serialize($theme->info), 'theme', $theme->filename, $theme->status, 0, 0); } - // Delete from the system table any themes missing from the file system. - if ($names) { - db_query("DELETE FROM {system} WHERE type = 'theme' AND name NOT IN (". db_placeholders($names, 'varchar') .")", $names); - } + lock_release('system_theme_data'); } return $themes; -- 1.7.2.5