From a7d345d7a70de3e5fd596bfeef3d8300574b211c Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Thu, 15 May 2008 21:15:10 +0000
Subject: [PATCH] - Patch #200824 by sammys, Arancaytar et al: fixed bug in
 drupal_write_record().

---
 includes/common.inc | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/includes/common.inc b/includes/common.inc
index 046e1bd50bc4..fdb51571a58d 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3232,6 +3232,11 @@ function drupal_write_record($table, &$object, $update = array()) {
     $update = array($update);
   }
 
+  $schema = drupal_get_schema($table);
+  if (empty($schema)) {
+    return FALSE;
+  }
+
   // Convert to an object if needed.
   if (is_array($object)) {
     $object = (object) $object;
@@ -3241,11 +3246,6 @@ function drupal_write_record($table, &$object, $update = array()) {
     $array = FALSE;
   }
 
-  $schema = drupal_get_schema($table);
-  if (empty($schema)) {
-    return FALSE;
-  }
-
   $fields = $defs = $values = $serials = $placeholders = array();
 
   // Go through our schema, build SQL, and when inserting, fill in defaults for
@@ -3326,16 +3326,17 @@ function drupal_write_record($table, &$object, $update = array()) {
         $object->$field = db_last_insert_id($table, $field);
       }
     }
+  }
+  else {
+    $return = FALSE;
+  }
 
-    // If we began with an array, convert back so we don't surprise the caller.
-    if ($array) {
-      $object = (array) $object;
-    }
-
-    return $return;
+  // If we began with an array, convert back so we don't surprise the caller.
+  if ($array) {
+    $object = (array) $object;
   }
 
-  return FALSE;
+  return $return;
 }
 
 /**
-- 
GitLab