add fixup messages for utf8

This commit is contained in:
Evan Prodromou 2009-06-06 09:54:40 -07:00
parent 2c81d8db76
commit d15fdac3d3

View File

@ -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;