From: Chuck Hagenbuch Date: Sun, 3 Oct 2010 18:03:39 +0000 (-0400) Subject: Re-add convert_to_utf8 as a script and convert it to Horde_Db X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7716741d68b67da7eb56717e18ad93bf5d209072;p=horde.git Re-add convert_to_utf8 as a script and convert it to Horde_Db --- diff --git a/wicked/scripts/convert_to_utf8.php b/wicked/scripts/convert_to_utf8.php new file mode 100755 index 000000000..9ef9704e3 --- /dev/null +++ b/wicked/scripts/convert_to_utf8.php @@ -0,0 +1,103 @@ +#!/usr/bin/php + + */ + +require_once dirname(__FILE__) . '/../lib/Application.php'; +Horde_Registry::appInit('wicked', array('authentication' => 'none', 'cli' => true)); + +// Create driver instance. +if ($conf['storage']['driver'] != 'sql') { + exit("You must have an SQL backend configured.\n"); +} +$db = $wicked->_db; + +// Get current charset. +$charset = $cli->prompt('Please specify the current charset of the data', + null, 'ISO-8859-1'); + +// Read existing attachments. +echo 'Converting attachments'; +$rows = $db->selectAll( + 'SELECT page_id, attachment_name, change_log FROM ' + . $conf['storage']['params']['attachmenttable']); +$updateSql = + 'UPDATE ' . $conf['storage']['params']['attachmenttable'] + . ' SET attachment_name = ?, change_log = ?' + . ' WHERE page_id = ? AND attachment_name = ?'; +foreach ($rows as $row) { + $values = Horde_String::convertCharset( + array($row['attachment_name'], $row['change_log']), + $charset, 'UTF-8'); + $values[] = $row['page_id']; + $values[] = $row['attachment_name']; + $db->update($updateSql, $values); + echo '.'; +} + +$rows = $db->selectAll( + 'SELECT page_id, attachment_name, change_log FROM ' + . $conf['storage']['params']['attachmenthistorytable']); +$updateSql = + 'UPDATE ' . $conf['storage']['params']['attachmenthistorytable'] + . ' SET attachment_name = ?, change_log = ?' + . ' WHERE page_id = ? AND attachment_name = ?'; +foreach ($rows as $row) { + $values = Horde_String::convertCharset( + array($row['attachment_name'], $row['change_log']), + $charset, 'UTF-8'); + $values[] = $row['page_id']; + $values[] = $row['attachment_name']; + $db->update($updateSql, $values); + echo '.'; +} +$cli->writeln($cli->green('Done')); + +// Read existing history. +$rows = $db->selectAll( + 'SELECT page_id, page_majorversion, page_minorversion, page_name, page_text, change_log FROM ' + . $conf['storage']['params']['historytable']); +$updateSql = + 'UPDATE ' . $conf['storage']['params']['historytable'] + . ' SET page_name = ?, page_text = ?, change_log = ?' + . ' WHERE page_id = ? AND page_majorversion = ? AND page_minorversion = ?'; +echo 'Converting history'; +foreach ($rows as $row) { + $values = Horde_String::convertCharset( + array($row['page_name'], $row['page_text'], $row['change_log']), + $charset, 'UTF-8'); + $values[] = $row['page_id']; + $values[] = $row['page_majorversion']; + $values[] = $row['page_minorversion']; + $db->update($updateSql, $values); +} +$cli->writeln($cli->green('Done')); + +// Read existing pages. +$rows = $db->selectAll( + 'SELECT page_id, page_name, page_text, change_log FROM ' + . $conf['storage']['params']['table']); +$updateSql = + 'UPDATE ' . $conf['storage']['params']['table'] + . ' SET page_name = ?, page_text = ?, change_log = ?' + . ' WHERE page_id = ?'); +echo 'Converting pages'; +foreach ($rows as $row) { + $values = Horde_String::convertCharset( + array($row['page_name'], $row['page_text'], $row['change_log']), + $charset, 'UTF-8'); + $values[] = $row['page_id']; + $db->update($updateSql, $values); + echo '.'; +} + +$cli->writeln($cli->green('Done'));