summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-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;