From 919a50bb2222a2e01687ee8fc086b962e223dbd5 Mon Sep 17 00:00:00 2001
From: PatchRanger <Staratel@1209848.no-reply.drupal.org>
Date: Sat, 28 Sep 2013 14:47:48 +0700
Subject: [PATCH] Issue #2092963 by PatchRanger: Update 6100 failed

---
 boxes.install |   66 ++++++++++++++++++++++++---------------------------------
 1 file changed, 28 insertions(+), 38 deletions(-)

diff --git a/boxes.install b/boxes.install
index 9bf7f62..017e9cc 100644
--- a/boxes.install
+++ b/boxes.install
@@ -74,13 +74,14 @@ function boxes_uninstall() {
 }
 
 /**
- * Make boxes content pluggable, move body/format into a serialized options
+ * Make boxes content pluggable, move body|format into a serialized options
  * array, add plugin key field.
  */
 function boxes_update_6100() {
-  $ret = array();
-  $result = db_query("SELECT delta, body, format FROM {custom_block}");
-  while ($box = db_fetch_object($result)) {
+  $query = db_select('block_custom', 'bc');
+  $join_alias = $query->join('box', 'b', 'b.bid = bc.bid');
+  $result = $query->fields($join_alias, array('bid', 'body', 'format'))->execute();
+  while ($box = $result->fetchObject()) {
     $body = array(
       'body' => $box->body,
       'format' => $box->format,
@@ -104,27 +105,27 @@ function boxes_update_6100() {
     'description' => "The plugin responsible for this block.",
   );
   db_add_field('box', 'plugin_key', $spec);
-  // TODO Please review the conversion of this statement to the D7 database API syntax.
-  /* db_query("UPDATE {custom_block} SET plugin_key = 'simple'") */
-  db_update('custom_block')
-  ->fields(array(
-    'plugin_key' => 'simple',
-  ))
-  ->execute();
+  db_update('box')
+    ->fields(array(
+      'plugin_key' => 'simple',
+    ))
+    ->execute();
   // hook_update_N() no longer returns a $ret array. Instead, return
   // nothing or a translated string indicating the update ran successfully.
   // See http://drupal.org/node/224333#update_sql.
-  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
+  return t('Boxes content made pluggable, body|format moved into a serialized options array, plugin key field added.');
 }
 
 /**
  * If Spaces is installed update existing spaces overrides.
  */
 function boxes_update_6101() {
-  $ret = array();
   if (module_exists('spaces')) {
-    $result = db_query("SELECT * FROM {spaces_overrides} WHERE object_type = :object_type", array(':object_type' => 'boxes'));
-    while ($row = db_fetch_object($result)) {
+    $result = db_select('spaces_overrides', 'so')
+      ->fields('so')
+      ->condition('object_type', 'boxes')
+      ->execute();
+    while ($row = $result->fetchObject()) {
       $v = unserialize($row->value);
       $v->plugin_key = 'simple';
       $v->options = array(
@@ -136,23 +137,18 @@ function boxes_update_6101() {
       $row->value = (array) $v;
       drupal_write_record('spaces_overrides', $row, array('type', 'id', 'object_type', 'object_id'));
     }
-    $ret[] = array(
-      'success' => TRUE,
-      'query' => 'Updated Spaces overrides',
-    );
   }
   // hook_update_N() no longer returns a $ret array. Instead, return
   // nothing or a translated string indicating the update ran successfully.
   // See http://drupal.org/node/224333#update_sql.
-  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
+  return t('Successfully updated Spaces overrides.');
 }
 
 /**
- * Make the box.delta column definition match blocks.delta
+ * Make the box.delta column definition match block.delta.
  */
 function boxes_update_6102() {
-  $ret = array();
-  $result = db_query('SELECT delta FROM {custom_block} WHERE CHAR_LENGTH(delta) > :CHAR_LENGTH(delta)', array(':CHAR_LENGTH(delta)' => 32))->fetchField();
+  $result = db_query('SELECT delta FROM {block} WHERE CHAR_LENGTH(delta) > :CHAR_LENGTH(delta)', array(':CHAR_LENGTH(delta)' => 32))->fetchField();
   if (empty($result)) {
     db_drop_primary_key('box');
     $spec = array(
@@ -164,37 +160,31 @@ function boxes_update_6102() {
     db_change_field('box', 'delta', 'delta', $spec, $new_keys);
   }
   else {
-    $ret['#abort'] = array(
-      'success' => FALSE,
-      'query' => "Could not resize the `box.delta` field. Some entries are larger than 32 characters and must be manually truncated.",
-    );
+    throw new DrupalUpdateException(t("Could not resize the `box.delta` field. Some entries are larger than 32 characters and must be manually truncated."));
   }
   // hook_update_N() no longer returns a $ret array. Instead, return
   // nothing or a translated string indicating the update ran successfully.
   // See http://drupal.org/node/224333#update_sql.
-  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
+  return t('box.delta column definition now matches block.delta.');
 }
 
 /**
- * Ensure that Spaces overrides are stored as an object, not  an array.
+ * Ensure that Spaces overrides are stored as an object, not an array.
  */
 function boxes_update_6103() {
-  $ret = array();
   if (module_exists('spaces')) {
-    $result = db_query("SELECT * FROM {spaces_overrides} WHERE object_type = :object_type", array(':object_type' => 'boxes'));
-    while ($row = db_fetch_object($result)) {
+    $result = db_select('spaces_overrides', 'so')
+      ->fields('so')
+      ->condition('object_type', 'boxes')
+      ->execute();
+    while ($row = $result->fetchObject()) {
       $v = unserialize($row->value);
       $row->value = (object) $v;
       drupal_write_record('spaces_overrides', $row, array('type', 'id', 'object_type', 'object_id'));
     }
-    $ret[] = array(
-      'success' => TRUE,
-      'query' => 'Updated Spaces overrides',
-    );
   }
   // hook_update_N() no longer returns a $ret array. Instead, return
   // nothing or a translated string indicating the update ran successfully.
   // See http://drupal.org/node/224333#update_sql.
-  return t('TODO Add a descriptive string here to show in the UI.') /* $ret */;
+  return t('Successfully updated Spaces overrides.');
 }
-
-- 
1.7.9.5

