From 3a1626fb95fdb239644532ceefceca04eb11088e Mon Sep 17 00:00:00 2001
From: James Gilliland <jgilliland@apqc.org>
Date: Mon, 27 Feb 2012 10:08:07 -0600
Subject: [PATCH] Remove nodewords data from user.data

---
 nodewords.install |   36 ++++++++++++++++++++++++++++++++++++
 nodewords.module  |    2 +-
 2 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/nodewords.install b/nodewords.install
index 1224180..06a09fd 100644
--- a/nodewords.install
+++ b/nodewords.install
@@ -1586,6 +1586,42 @@ function nodewords_update_6181() {
 }
 
 /**
+ * Remove fields accidently stashed on users.data.
+ */
+function nodewords_update_6182(&$sandbox) {
+  $ret = array();
+  $update_size = 250;
+
+  if (!isset($sandbox['progress'])) {
+    $sandbox['progress'] = 0;
+    $sandbox['current_uid'] = 0;
+    // We'll -1 to disregard the uid 0...
+    $sandbox['max'] = db_result(db_query('SELECT MAX(uid) FROM {users}'));
+  }
+
+  $users = db_query_range("SELECT uid, data FROM {users}
+    WHERE uid > %d
+    ORDER BY uid ASC", $sandbox['current_uid'], 0, $update_size);
+  while ($user = db_fetch_object($users)) {
+
+    $data = unserialize($user->data);
+    if (isset($data['nodewords'])) {
+      unset($data['nodewords']);
+
+      // db_query because we're likely to update a lot of users.
+      db_query("UPDATE {users}
+          SET data = '%s' WHERE uid = %d", serialize($data), $user->uid);
+    }
+
+    $sandbox['current_uid'] = $user->uid;
+  }
+
+  $ret['#finished'] = (empty($sandbox['max']) || $sandbox['current_uid'] > $sandbox['max']) ? 1 : ($sandbox['current_uid'] / $sandbox['max']);
+
+  return $ret;
+}
+
+/**
  * Implements hook_uninstall().
  */
 function nodewords_uninstall() {
diff --git a/nodewords.module b/nodewords.module
index a4ee404..2701a57 100644
--- a/nodewords.module
+++ b/nodewords.module
@@ -670,7 +670,7 @@ function nodewords_user($op, &$edit, &$account, $category = NULL) {
         nodewords_save_tags(NODEWORDS_TYPE_USER, $account->uid, $edit['nodewords'], TRUE);
       }
 
-      unset($edit['nodewords']);
+      $edit['nodewords'] = NULL;
       break;
 
     case 'form':
-- 
1.7.5.4

