/usr/bin/whups-convert-to-utf8 is in php-horde-whups 3.0.0-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | #!/usr/bin/env php
<?php
/**
* This script converts the data in an SQL backend from any supported charset
* to UTF-8.
*
* Copyright 2011-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsdl.php.
*
* @author Jan Schneider <jan@horde.org>
*/
if (file_exists(__DIR__ . '/../../whups/lib/Application.php')) {
$baseDir = __DIR__ . '/../';
} else {
require_once 'PEAR/Config.php';
$baseDir = PEAR_Config::singleton()
->get('horde_dir', null, 'pear.horde.org') . '/whups/';
}
require_once $baseDir . 'lib/Application.php';
Horde_Registry::appInit('whups', array('cli' => true));
if ($conf['tickets']['driver'] != 'Sql') {
exit("You must have an SQL backend configured.\n");
}
// Get current charset.
$charset = $cli->prompt('Please specify the current charset of the data',
null, 'ISO-8859-1');
$dbFactory = $injector->getInstance('Horde_Core_Factory_Db');
$config = $dbFactory->getConfig('tickets');
$config['charset'] = $charset;
$dbin = $dbFactory->create('whups', $config);
$config['charset'] = 'UTF-8';
$dbout = $dbFactory->create('whups', $config);
$mysql = stristr($dbout->adapterName(), 'mysql');
// Convert queues.
try {
$results = $dbin->select('SELECT queue_id, queue_name, queue_description FROM whups_queues');
$sth = 'UPDATE whups_queues SET queue_name = ?, queue_description = ?'
. ' WHERE queue_id = ?';
echo 'Converting queues';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['queue_name'], $row['queue_description']),
$charset, 'UTF-8');
$values[] = $row['queue_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert types.
try {
$results = $dbin->select('SELECT type_id, type_name, type_description FROM whups_types');
$sth = 'UPDATE whups_types SET type_name = ?, type_description = ?'
. ' WHERE type_id = ?';
echo 'Converting types';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['type_name'], $row['type_description']),
$charset, 'UTF-8');
$values[] = $row['type_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert states.
try {
$results = $dbin->select('SELECT state_id, state_name, state_description, state_category FROM whups_states');
$sth = 'UPDATE whups_states SET state_name = ?, state_description = ?, state_category = ?'
. ' WHERE state_id = ?';
echo 'Converting states';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['state_name'], $row['state_description'], $row['state_category']),
$charset, 'UTF-8');
$values[] = $row['state_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert priorities.
try {
$results = $dbin->select('SELECT priority_id, priority_name, priority_description FROM whups_priorities');
$sth = 'UPDATE whups_priorities SET priority_name = ?, priority_description = ?'
. ' WHERE priority_id = ?';
echo 'Converting priorities';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['priority_name'], $row['priority_description']),
$charset, 'UTF-8');
$values[] = $row['priority_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert versions.
try {
$results = $dbin->select('SELECT version_id, version_name, version_description FROM whups_versions');
$sth = 'UPDATE whups_versions SET version_name = ?, version_description = ?'
. ' WHERE version_id = ?';
echo 'Converting versions';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['version_name'], $row['version_description']),
$charset, 'UTF-8');
$values[] = $row['version_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert replies.
try {
$results = $dbin->select('SELECT reply_id, reply_name, reply_text FROM whups_replies');
$sth = 'UPDATE whups_replies SET reply_name = ?, reply_text = ?'
. ' WHERE reply_id = ?';
echo 'Converting replies';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['reply_name'], $row['reply_text']),
$charset, 'UTF-8');
$values[] = $row['reply_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert tickets.
try {
$results = $dbin->select('SELECT ticket_id, ticket_summary FROM whups_tickets');
$sth = 'UPDATE whups_tickets SET ticket_summary = ?'
. ' WHERE ticket_id = ?';
echo 'Converting tickets';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['ticket_summary']),
$charset, 'UTF-8');
$values[] = $row['ticket_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert comments.
try {
$results = $dbin->select('SELECT comment_id, comment_text FROM whups_comments');
$sth = 'UPDATE whups_comments SET comment_text = ?'
. ' WHERE comment_id = ?';
echo 'Converting comments';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['comment_text']),
$charset, 'UTF-8');
$values[] = $row['comment_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert queries.
try {
$results = $dbin->select('SELECT query_id, query_parameters, query_object FROM whups_queries');
$sth = 'UPDATE whups_queries SET query_parameters = ?, query_object = ?'
. ' WHERE query_id = ?';
echo 'Converting queries';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['query_parameters'], $row['query_object']),
$charset, 'UTF-8');
$values[] = $row['query_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert attributes.
try {
echo 'Converting attributes';
$results = $dbin->select('SELECT attribute_id, attribute_name, attribute_description, attribute_params FROM whups_attributes_desc');
$sth = 'UPDATE whups_attributes_desc SET attribute_name = ?, attribute_description = ?, attribute_params = ?'
. ' WHERE attribute_id = ?';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['attribute_name'], $row['attribute_description']),
$charset, 'UTF-8');
$values[] = serialize(Horde_String::convertCharset(unserialize($row['attribute_params']), $charset, 'UTF-8'));
$values[] = $row['attribute_id'];
$dbout->update($sth, $values);
echo '.';
}
$results = $dbin->select('SELECT ticket_id, attribute_id, attribute_value FROM whups_attributes');
$sth = 'UPDATE whups_attributes SET attribute_value = ?'
. ' WHERE ticket_id = ? AND attribute_id = ?';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['attribute_value']),
$charset, 'UTF-8');
$values[] = $row['ticket_id'];
$values[] = $row['attribute_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
// Convert logs.
try {
$results = $dbin->select('SELECT log_id, log_value FROM whups_logs');
$sth = 'UPDATE whups_logs SET log_value = ?'
. ' WHERE log_id = ?';
echo 'Converting logs';
foreach ($results as $row) {
$values = Horde_String::convertCharset(
array($row['log_value']),
$charset, 'UTF-8');
$values[] = $row['log_id'];
$dbout->update($sth, $values);
echo '.';
}
$cli->writeln($cli->green('Done'));
} catch (Horde_Db_Exception $e) {
$cli->fatal($e->getMessage());
}
|