From: Evan Prodromou Date: Sat, 6 Jun 2009 16:54:40 +0000 (-0700) Subject: add fixup messages for utf8 X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d15fdac3d348eda7314a206c2403494e9a096c98;p=quix0rs-gnu-social.git add fixup messages for utf8 --- diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php index f9debd3eca..83e4850217 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;