From 3532cd0490a70b54a92108549de6042459fd8469 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 28 May 2009 18:19:22 -0400 Subject: Only enqueue inbox-dependent transports after inboxes have been filled --- scripts/inboxqueuehandler.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/inboxqueuehandler.php b/scripts/inboxqueuehandler.php index 73d31e854..c7aab4fe1 100755 --- a/scripts/inboxqueuehandler.php +++ b/scripts/inboxqueuehandler.php @@ -41,7 +41,7 @@ class InboxQueueHandler extends QueueHandler } function start() { - $this->log(LOG_INFO, "INITIALIZE"); + $this->log(LOG_INFO, "Initialize inbox queue handler"); return true; } @@ -49,11 +49,19 @@ class InboxQueueHandler extends QueueHandler { $this->log(LOG_INFO, "Distributing notice to inboxes for $notice->id"); $notice->addToInboxes(); + $notice->saveGroups(); $notice->blowSubsCache(); + $transports = common_post_inbox_transports(); + + foreach ($transports as $transport) { + common_enqueue_notice_transport($notice, $transport); + } + return true; } function finish() { + $this->log(LOG_INFO, "Terminating inbox queue handler"); } } -- cgit v1.2.3-54-g00ecf From 76ee1fd5daa6ab1999224d8e93df1b7116f24c36 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 30 May 2009 04:40:47 -0400 Subject: Removing inbox and memcached daemon handling --- classes/Notice.php | 54 ++------------------------- lib/util.php | 13 +------ scripts/getvaliddaemons.php | 5 --- scripts/inboxqueuehandler.php | 77 --------------------------------------- scripts/memcachedqueuehandler.php | 70 ----------------------------------- scripts/stopdaemons.sh | 3 +- 6 files changed, 6 insertions(+), 216 deletions(-) delete mode 100755 scripts/inboxqueuehandler.php delete mode 100755 scripts/memcachedqueuehandler.php (limited to 'scripts') diff --git a/classes/Notice.php b/classes/Notice.php index 3a90d18b4..b4c86ebeb 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -196,12 +196,8 @@ class Notice extends Memcached_DataObject $notice->saveReplies(); $notice->saveTags(); - if (common_config('queue', 'enabled')) { - $notice->addToAuthorInbox(); - } else { - $notice->addToInboxes(); - $notice->saveGroups(); - } + $notice->addToInboxes(); + $notice->saveGroups(); $notice->query('COMMIT'); @@ -211,13 +207,7 @@ class Notice extends Memcached_DataObject # Clear the cache for subscribed users, so they'll update at next request # XXX: someone clever could prepend instead of clearing the cache - if (common_config('memcached', 'enabled')) { - if (common_config('queue', 'enabled')) { - $notice->blowAuthorCaches(); - } else { - $notice->blowCaches(); - } - } + $notice->blowCaches(); return $notice; } @@ -280,17 +270,6 @@ class Notice extends Memcached_DataObject $this->blowGroupCache($blowLast); } - function blowAuthorCaches($blowLast=false) - { - // Clear the user's cache - $cache = common_memcache(); - if (!empty($cache)) { - $cache->delete(common_cache_key('notice_inbox:by_user:'.$this->profile_id)); - } - $this->blowNoticeCache($blowLast); - $this->blowPublicCache($blowLast); - } - function blowGroupCache($blowLast=false) { $cache = common_memcache(); @@ -709,33 +688,6 @@ class Notice extends Memcached_DataObject return; } - function addToAuthorInbox() - { - $enabled = common_config('inboxes', 'enabled'); - - if ($enabled === true || $enabled === 'transitional') { - $user = User::staticGet('id', $this->profile_id); - if (empty($user)) { - return; - } - $inbox = new Notice_inbox(); - $UT = common_config('db','type')=='pgsql'?'"user"':'user'; - $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' . - "SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " . - "FROM $UT " . - "WHERE $UT.id = " . $this->profile_id . ' ' . - 'AND NOT EXISTS (SELECT user_id, notice_id ' . - 'FROM notice_inbox ' . - "WHERE user_id = " . $this->profile_id . ' '. - 'AND notice_id = ' . $this->id . ' )'; - if ($enabled === 'transitional') { - $qry .= " AND $UT.inboxed = 1"; - } - $inbox->query($qry); - } - return; - } - function saveGroups() { $enabled = common_config('inboxes', 'enabled'); diff --git a/lib/util.php b/lib/util.php index 214c33279..22308f432 100644 --- a/lib/util.php +++ b/lib/util.php @@ -884,16 +884,12 @@ function common_enqueue_notice($notice) // If inboxes are enabled, wait till inboxes are filled // before doing inbox-dependent broadcasts - if (common_config('inboxes', 'enabled') === true || - common_config('inboxes', 'enabled') === 'transitional') { - $transports[] = 'inbox'; - } else { - $transports = array_merge($transports, common_post_inbox_transports()); - } + $transports = array_merge($transports, common_post_inbox_transports()); foreach ($transports as $transport) { common_enqueue_notice_transport($notice, $transport); } + return $result; } @@ -905,11 +901,6 @@ function common_post_inbox_transports() $transports = array_merge($transports, array('jabber', 'public')); } - if (common_config('memcached', 'enabled')) { - // Note: limited to 8 chars - $transports[] = 'memcache'; - } - return $transports; } diff --git a/scripts/getvaliddaemons.php b/scripts/getvaliddaemons.php index 482e63af7..0996ba9f4 100755 --- a/scripts/getvaliddaemons.php +++ b/scripts/getvaliddaemons.php @@ -25,7 +25,6 @@ * daemon names. */ - # Abort if called from a web server if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { print "This script must be run from the command line\n"; @@ -41,12 +40,8 @@ if(common_config('xmpp','enabled')) { echo "xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php "; echo "xmppconfirmhandler.php "; } -if(common_config('memcached','enabled')) { - echo "memcachedqueuehandler.php "; -} echo "ombqueuehandler.php "; echo "twitterqueuehandler.php "; echo "facebookqueuehandler.php "; echo "pingqueuehandler.php "; -echo "inboxqueuehandler.php "; echo "smsqueuehandler.php "; diff --git a/scripts/inboxqueuehandler.php b/scripts/inboxqueuehandler.php deleted file mode 100755 index c7aab4fe1..000000000 --- a/scripts/inboxqueuehandler.php +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env php -. - */ - -// Abort if called from a web server - -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); - -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); - -set_error_handler('common_error_handler'); - -class InboxQueueHandler extends QueueHandler -{ - function transport() - { - return 'inbox'; - } - - function start() { - $this->log(LOG_INFO, "Initialize inbox queue handler"); - return true; - } - - function handle_notice($notice) - { - $this->log(LOG_INFO, "Distributing notice to inboxes for $notice->id"); - $notice->addToInboxes(); - $notice->saveGroups(); - $notice->blowSubsCache(); - $transports = common_post_inbox_transports(); - - foreach ($transports as $transport) { - common_enqueue_notice_transport($notice, $transport); - } - - return true; - } - - function finish() { - $this->log(LOG_INFO, "Terminating inbox queue handler"); - } -} - -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$id = ($argc > 1) ? $argv[1] : null; - -$handler = new InboxQueueHandler($id); - -$handler->runOnce(); diff --git a/scripts/memcachedqueuehandler.php b/scripts/memcachedqueuehandler.php deleted file mode 100755 index 185b781f7..000000000 --- a/scripts/memcachedqueuehandler.php +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env php -. - */ - -// Abort if called from a web server - -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); -} - -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('LACONICA', true); - -require_once(INSTALLDIR . '/lib/common.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); - -set_error_handler('common_error_handler'); - -class MemcachedQueueHandler extends QueueHandler -{ - function transport() - { - return 'memcache'; - } - - function start() { - $this->log(LOG_INFO, "INITIALIZE"); - return true; - } - - function handle_notice($notice) - { - // XXX: fork here - $this->log(LOG_INFO, "Blowing memcached for $notice->id"); - $notice->blowCaches(); - return true; - } - - function finish() { - } - -} - -ini_set("max_execution_time", "0"); -ini_set("max_input_time", "0"); -set_time_limit(0); -mb_internal_encoding('UTF-8'); - -$id = ($argc > 1) ? $argv[1] : null; - -$handler = new MemcachedQueueHandler($id); - -$handler->runOnce(); diff --git a/scripts/stopdaemons.sh b/scripts/stopdaemons.sh index f6d71eddf..2134b4ab0 100755 --- a/scripts/stopdaemons.sh +++ b/scripts/stopdaemons.sh @@ -24,8 +24,7 @@ SDIR=`dirname $0` DIR=`php $SDIR/getpiddir.php` for f in jabberhandler ombhandler publichandler smshandler pinghandler \ - xmppconfirmhandler xmppdaemon twitterhandler facebookhandler \ - memcachehandler inboxhandler; do + xmppconfirmhandler xmppdaemon twitterhandler facebookhandler; do FILES="$DIR/$f.*.pid" for ff in "$FILES" ; do -- cgit v1.2.3-54-g00ecf From 7b1a72da307694bee40a2278482003855a2a2ab1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 30 May 2009 11:52:35 -0400 Subject: take a max and min argument for fixup_utf8 --- scripts/fixup_utf8.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php index e5021ff34..67f9c4623 100644 --- a/scripts/fixup_utf8.php +++ b/scripts/fixup_utf8.php @@ -35,7 +35,7 @@ define('LACONICA', true); require_once(INSTALLDIR . '/lib/common.php'); require_once('DB.php'); -function fixup_utf8($id) { +function fixup_utf8($max_id, $min_id) { $dbl = doConnect('latin1'); @@ -61,8 +61,12 @@ function fixup_utf8($id) { $sql = 'SELECT id, content, rendered FROM notice ' . 'WHERE LENGTH(content) != CHAR_LENGTH(content)'; - if (!empty($id)) { - $sql .= ' AND id < ' . $id; + if (!empty($max_id)) { + $sql .= ' AND id <= ' . $max_id; + } + + if (!empty($min_id)) { + $sql .= ' AND id >= ' . $min_id; } $sql .= ' ORDER BY id DESC'; @@ -136,6 +140,7 @@ function doConnect($charset) return $db; } -$id = ($argc > 1) ? $argv[1] : null; +$max_id = ($argc > 1) ? $argv[1] : null; +$min_id = ($argc > 2) ? $argv[2] : null; -fixup_utf8($id); +fixup_utf8($max_id, $min_id); -- cgit v1.2.3-54-g00ecf From a262f83210f6a405bfe79148b52387d1dbdd9a5d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 30 May 2009 12:20:42 -0400 Subject: use mysqli_set_charset instead of set names --- scripts/fixup_utf8.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php index 67f9c4623..925da2484 100644 --- a/scripts/fixup_utf8.php +++ b/scripts/fixup_utf8.php @@ -121,10 +121,14 @@ function doConnect($charset) return NULL; } - $result = $db->query("SET NAMES $charset"); +// $result = $db->query("SET NAMES $charset"); - if (PEAR::isError($result)) { - echo "ERROR: " . $result->getMessage() . "\n"; + $conn = $db->connection; + + $succ = mysqli_set_charset($conn, $charset); + + if (!$succ) { + echo "ERROR: couldn't set charset\n"; $db->disconnect(); return NULL; } -- cgit v1.2.3-54-g00ecf From da0d2a9745ea072cd261990e152d08198331a415 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 30 May 2009 20:58:29 -0400 Subject: make fixup_utf8.php handle profiles and groups too --- scripts/fixup_utf8.php | 299 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 228 insertions(+), 71 deletions(-) (limited to 'scripts') diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php index 925da2484..2046d2b77 100644 --- a/scripts/fixup_utf8.php +++ b/scripts/fixup_utf8.php @@ -35,116 +35,273 @@ define('LACONICA', true); require_once(INSTALLDIR . '/lib/common.php'); require_once('DB.php'); -function fixup_utf8($max_id, $min_id) { +class UTF8FixerUpper +{ + var $dbl = null; + var $dbu = null; + var $args = array(); + + function __construct($args) + { + $this->args = $args; + + if (array_key_exists('max_date', $args)) { + $this->max_date = strftime('%Y-%m-%d %H:%M:%S', strtotime($args['max_date'])); + } else { + $this->max_date = strftime('%Y-%m-%d %H:%M:%S', time()); + } - $dbl = doConnect('latin1'); + $this->dbl = $this->doConnect('latin1'); - if (empty($dbl)) { - return; - } + if (empty($this->dbl)) { + return; + } - $dbu = doConnect('utf8'); + $this->dbu = $this->doConnect('utf8'); - if (empty($dbu)) { - return; + if (empty($this->dbu)) { + return; + } } - // Do a separate DB connection + function doConnect($charset) + { + $db = DB::connect(common_config('db', 'database'), + array('persistent' => false)); - $sth = $dbu->prepare("UPDATE notice SET content = UNHEX(?), rendered = UNHEX(?) WHERE id = ?"); + if (PEAR::isError($db)) { + echo "ERROR: " . $db->getMessage() . "\n"; + return NULL; + } - if (PEAR::isError($sth)) { - echo "ERROR: " . $sth->getMessage() . "\n"; - return; - } + $conn = $db->connection; - $sql = 'SELECT id, content, rendered FROM notice ' . - 'WHERE LENGTH(content) != CHAR_LENGTH(content)'; + $succ = mysqli_set_charset($conn, $charset); - if (!empty($max_id)) { - $sql .= ' AND id <= ' . $max_id; - } + if (!$succ) { + echo "ERROR: couldn't set charset\n"; + $db->disconnect(); + return NULL; + } - if (!empty($min_id)) { - $sql .= ' AND id >= ' . $min_id; - } + $result = $db->autoCommit(true); - $sql .= ' ORDER BY id DESC'; + if (PEAR::isError($result)) { + echo "ERROR: " . $result->getMessage() . "\n"; + $db->disconnect(); + return NULL; + } - $rn = $dbl->query($sql); + return $db; + } - if (PEAR::isError($rn)) { - echo "ERROR: " . $rn->getMessage() . "\n"; - return; + function fixup() + { + $this->fixupNotices($this->args['max_notice'], + $this->args['min_notice']); + $this->fixupProfiles(); + $this->fixupGroups(); } - echo "Number of rows: " . $rn->numRows() . "\n"; + function fixupNotices($max_id, $min_id) { - $notice = array(); + // Do a separate DB connection - while (DB_OK == $rn->fetchInto($notice)) { + $sth = $this->dbu->prepare("UPDATE notice SET content = UNHEX(?), rendered = UNHEX(?) WHERE id = ?"); - $id = ($notice[0])+0; - $content = bin2hex($notice[1]); - $rendered = bin2hex($notice[2]); + if (PEAR::isError($sth)) { + echo "ERROR: " . $sth->getMessage() . "\n"; + return; + } - echo "$id..."; + $sql = 'SELECT id, content, rendered FROM notice ' . + 'WHERE LENGTH(content) != CHAR_LENGTH(content) '. + 'AND modified < "'.$this->max_date.'" '; - $result =& $dbu->execute($sth, array($content, $rendered, $id)); + if (!empty($max_id)) { + $sql .= ' AND id <= ' . $max_id; + } - if (PEAR::isError($result)) { - echo "ERROR: " . $result->getMessage() . "\n"; - continue; + if (!empty($min_id)) { + $sql .= ' AND id >= ' . $min_id; } - $cnt = $dbu->affectedRows(); + $sql .= ' ORDER BY id DESC'; + + $rn = $this->dbl->query($sql); - if ($cnt != 1) { - echo "ERROR: 0 rows affected\n"; - continue; + if (PEAR::isError($rn)) { + echo "ERROR: " . $rn->getMessage() . "\n"; + return; } - $notice = Notice::staticGet('id', $id); - $notice->decache(); + echo "Number of rows: " . $rn->numRows() . "\n"; - echo "OK\n"; - } -} + $notice = array(); -function doConnect($charset) -{ - $db = DB::connect(common_config('db', 'database'), - array('persistent' => false)); + while (DB_OK == $rn->fetchInto($notice)) { - if (PEAR::isError($db)) { - echo "ERROR: " . $db->getMessage() . "\n"; - return NULL; - } + $id = ($notice[0])+0; + $content = bin2hex($notice[1]); + $rendered = bin2hex($notice[2]); + + echo "$id..."; + + $result =& $this->dbu->execute($sth, array($content, $rendered, $id)); + + if (PEAR::isError($result)) { + echo "ERROR: " . $result->getMessage() . "\n"; + continue; + } -// $result = $db->query("SET NAMES $charset"); + $cnt = $this->dbu->affectedRows(); - $conn = $db->connection; + if ($cnt != 1) { + echo "ERROR: 0 rows affected\n"; + continue; + } - $succ = mysqli_set_charset($conn, $charset); + $notice = Notice::staticGet('id', $id); + $notice->decache(); - if (!$succ) { - echo "ERROR: couldn't set charset\n"; - $db->disconnect(); - return NULL; + echo "OK\n"; + } } - $result = $db->autoCommit(true); + function fixupProfiles() + { + // Do a separate DB connection + + $sth = $this->dbu->prepare("UPDATE profile SET ". + "fullname = UNHEX(?),". + "location = UNHEX(?), ". + "bio = UNHEX(?) ". + "WHERE id = ?"); + + if (PEAR::isError($sth)) { + echo "ERROR: " . $sth->getMessage() . "\n"; + return; + } + + $sql = 'SELECT id, fullname, location, bio FROM profile ' . + 'WHERE (LENGTH(fullname) != CHAR_LENGTH(fullname) '. + 'OR LENGTH(location) != CHAR_LENGTH(location) '. + 'OR LENGTH(bio) != CHAR_LENGTH(bio)) '. + 'AND modified < "'.$this->max_date.'" '. + ' ORDER BY modified DESC'; + + $rn = $this->dbl->query($sql); + + if (PEAR::isError($rn)) { + echo "ERROR: " . $rn->getMessage() . "\n"; + return; + } - if (PEAR::isError($result)) { - echo "ERROR: " . $result->getMessage() . "\n"; - $db->disconnect(); - return NULL; + echo "Number of rows: " . $rn->numRows() . "\n"; + + $profile = array(); + + while (DB_OK == $rn->fetchInto($profile)) { + + $id = ($profile[0])+0; + $fullname = bin2hex($profile[1]); + $location = bin2hex($profile[2]); + $bio = bin2hex($profile[3]); + + echo "$id..."; + + $result =& $this->dbu->execute($sth, array($fullname, $location, $bio, $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; + } + + $profile = Profile::staticGet('id', $id); + $profile->decache(); + + echo "OK\n"; + } } - return $db; + function fixupGroups() + { + // Do a separate DB connection + + $sth = $this->dbu->prepare("UPDATE user_group SET ". + "fullname = UNHEX(?),". + "location = UNHEX(?), ". + "description = UNHEX(?) ". + "WHERE id = ?"); + + if (PEAR::isError($sth)) { + echo "ERROR: " . $sth->getMessage() . "\n"; + return; + } + + $sql = 'SELECT id, fullname, location, description FROM user_group ' . + 'WHERE LENGTH(fullname) != CHAR_LENGTH(fullname) '. + 'OR LENGTH(location) != CHAR_LENGTH(location) '. + 'OR LENGTH(description) != CHAR_LENGTH(description) '; + 'AND modified < "'.$this->max_date.'" '. + 'ORDER BY modified DESC'; + + $rn = $this->dbl->query($sql); + + if (PEAR::isError($rn)) { + echo "ERROR: " . $rn->getMessage() . "\n"; + return; + } + + echo "Number of rows: " . $rn->numRows() . "\n"; + + $user_group = array(); + + while (DB_OK == $rn->fetchInto($user_group)) { + + $id = ($user_group[0])+0; + $fullname = bin2hex($user_group[1]); + $location = bin2hex($user_group[2]); + $description = bin2hex($user_group[3]); + + echo "$id..."; + + $result =& $this->dbu->execute($sth, array($fullname, $location, $description, $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; + } + + $user_group = User_group::staticGet('id', $id); + $user_group->decache(); + + echo "OK\n"; + } + } } -$max_id = ($argc > 1) ? $argv[1] : null; -$min_id = ($argc > 2) ? $argv[2] : null; +$max_date = ($argc > 1) ? $argv[1] : null; +$max_id = ($argc > 2) ? $argv[2] : null; +$min_id = ($argc > 3) ? $argv[3] : null; + +$fixer = new UTF8FixerUpper(array('max_date' => $max_date, + 'max_notice' => $max_id, + 'min_notice' => $min_id)); + +$fixer->fixup(); -fixup_utf8($max_id, $min_id); -- cgit v1.2.3-54-g00ecf From f134ba68ab6a7e9f94579d2a4e1f02eca2a7ebc0 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 30 May 2009 21:04:35 -0400 Subject: free memory for each iteration DB_DataObject in fixup_utf8 --- scripts/fixup_utf8.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'scripts') diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php index 2046d2b77..f9debd3ec 100644 --- a/scripts/fixup_utf8.php +++ b/scripts/fixup_utf8.php @@ -163,6 +163,7 @@ class UTF8FixerUpper $notice = Notice::staticGet('id', $id); $notice->decache(); + $notice->free(); echo "OK\n"; } @@ -226,6 +227,7 @@ class UTF8FixerUpper $profile = Profile::staticGet('id', $id); $profile->decache(); + $profile->free(); echo "OK\n"; } @@ -289,6 +291,7 @@ class UTF8FixerUpper $user_group = User_group::staticGet('id', $id); $user_group->decache(); + $user_group->free(); echo "OK\n"; } -- cgit v1.2.3-54-g00ecf From d15fdac3d348eda7314a206c2403494e9a096c98 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 6 Jun 2009 09:54:40 -0700 Subject: add fixup messages for utf8 --- scripts/fixup_utf8.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'scripts') 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; -- cgit v1.2.3-54-g00ecf From 265e2bd58de2a01e0d7840310eb44b21b70e3914 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 8 Jun 2009 10:57:35 -0700 Subject: remember to convert messages --- scripts/fixup_utf8.php | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php index 83e485021..169376091 100644 --- a/scripts/fixup_utf8.php +++ b/scripts/fixup_utf8.php @@ -101,6 +101,7 @@ class UTF8FixerUpper $this->args['min_notice']); $this->fixupProfiles(); $this->fixupGroups(); + $this->fixupMessages(); } function fixupNotices($max_id, $min_id) { -- cgit v1.2.3-54-g00ecf