summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-06-06 09:54:40 -0700
committerEvan Prodromou <evan@controlyourself.ca>2009-06-06 09:54:40 -0700
commitd15fdac3d348eda7314a206c2403494e9a096c98 (patch)
treecd44af660137c4cff955f31cccc6e0e5597ea262
parent2c81d8db76135af2e4343316f67a2f535971d013 (diff)
add fixup messages for utf8
-rw-r--r--scripts/fixup_utf8.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php
index f9debd3ec..83e485021 100644
--- a/scripts/fixup_utf8.php
+++ b/scripts/fixup_utf8.php
@@ -296,6 +296,63 @@ class UTF8FixerUpper
echo "OK\n";
}
}
+
+ function fixupMessages() {
+
+ // Do a separate DB connection
+
+ $sth = $this->dbu->prepare("UPDATE message SET content = UNHEX(?), rendered = UNHEX(?) WHERE id = ?");
+
+ if (PEAR::isError($sth)) {
+ echo "ERROR: " . $sth->getMessage() . "\n";
+ return;
+ }
+
+ $sql = 'SELECT id, content, rendered FROM message ' .
+ 'WHERE LENGTH(content) != CHAR_LENGTH(content) '.
+ 'AND modified < "'.$this->max_date.'" '.
+ 'ORDER BY id DESC';
+
+ $rn = $this->dbl->query($sql);
+
+ if (PEAR::isError($rn)) {
+ echo "ERROR: " . $rn->getMessage() . "\n";
+ return;
+ }
+
+ echo "Number of rows: " . $rn->numRows() . "\n";
+
+ $message = array();
+
+ while (DB_OK == $rn->fetchInto($message)) {
+
+ $id = ($message[0])+0;
+ $content = bin2hex($message[1]);
+ $rendered = bin2hex($message[2]);
+
+ echo "$id...";
+
+ $result =& $this->dbu->execute($sth, array($content, $rendered, $id));
+
+ if (PEAR::isError($result)) {
+ echo "ERROR: " . $result->getMessage() . "\n";
+ continue;
+ }
+
+ $cnt = $this->dbu->affectedRows();
+
+ if ($cnt != 1) {
+ echo "ERROR: 0 rows affected\n";
+ continue;
+ }
+
+ $message = Message::staticGet('id', $id);
+ $message->decache();
+ $message->free();
+
+ echo "OK\n";
+ }
+ }
}
$max_date = ($argc > 1) ? $argv[1] : null;