From 4f119c5f03e4ec4ddff78c66e67cb40fd44ba68f Mon Sep 17 00:00:00 2001
From: Ted Cooper <elc@784944.no-reply.drupal.org>
Date: Sat, 4 Feb 2012 09:27:44 +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 |   23 ++++++++---------------
 1 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/modules/system/system.module b/modules/system/system.module
index 1a8d237..9ad3fcc 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -828,23 +828,16 @@ function system_theme_data() {
   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 {
-        $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);
-      }
-    }
-    // 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);
+      // 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);
     }
+
     lock_release('system_theme_data');
   }
   return $themes;
-- 
1.7.2.5

