[ Index ] |
|
Code source de Plume CMS 1.2.2 |
1 <?php 2 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 3 /* 4 # ***** BEGIN LICENSE BLOCK ***** 5 # This file is part of Plume CMS, a website management application. 6 # Copyright (C) 2001-2006 Loic d'Anterroches and contributors. 7 # 8 # Plume CMS is free software; you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation; either version 2 of the License, or 11 # (at your option) any later version. 12 # 13 # Plume CMS is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this program; if not, write to the Free Software 20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 # 22 # ***** END LICENSE BLOCK ***** */ 23 if (basename($_SERVER['SCRIPT_NAME']) == 'dbconvert.php') { 24 exit; 25 } 26 include_once dirname(__FILE__).'/../inc/lib.utils.php'; 27 /** 28 * Convert a table from latin1 to utf-8. 29 * 30 * The fields to be converted are in the array $fields. 31 * The primary key against which the update is performed is $primkey. 32 */ 33 function convert_table($table, $primkey, $fields) 34 { 35 $err = ''; 36 if (is_array($primkey)) { 37 $primstr = implode(', ', $primkey); 38 } else { 39 $primstr = $primkey; 40 } 41 $select = 'SELECT '.$primstr.', '.implode(', ', $fields).' FROM '.$table; 42 $con = &pxDBConnect(); 43 44 if (($rs = $con->select($select)) === false) { 45 $err = $con->error(); 46 return $select.' - '.$err; 47 } 48 while (!$rs->EOF()) { 49 $update = 'UPDATE '.$table.' SET '; 50 $u_fields = array(); 51 foreach ($fields as $k => $field) { 52 $u_fields[] = $field.'=\''.$con->esc(Misc::latin1_utf8($rs->f($field))).'\''; 53 } 54 $update .= implode(', ', $u_fields); 55 if (!is_array($primkey)) { 56 $update .= ' WHERE '.$primkey.' = \'' 57 .$con->esc(Misc::latin1_utf8($rs->f($primkey))).'\''; 58 } else { 59 $prims = array(); 60 foreach ($primkey as $k => $field) { 61 $prims[] = $field.'=\''.$con->esc(Misc::latin1_utf8($rs->f($field))).'\''; 62 } 63 $update .= ' WHERE '.implode(' AND ', $prims); 64 } 65 if ($con->execute($update) === false) { 66 $err = $con->error(); 67 $err = $update.' - '.$err; 68 break; 69 } 70 $rs->moveNext(); 71 } 72 return $err; 73 } 74 75 $tableconvert = __('The table %s has been converted to the utf-8 encoding.'); 76 $tableerrors = __('Errors occured when converting the table %s to the utf-8 encoding:'); 77 78 79 $con = pxDBConnect(); 80 81 $err = convert_table($con->pfx.'users', 82 'user_id', 83 array( 84 'user_username', 85 'user_realname', 86 'user_email', 87 'user_pubemail', 88 'user_website', 89 'user_company', 90 'lang_id', 91 'country_id', 92 'user_status', 93 'user_image', 94 'user_icq', 95 'user_aol', 96 'user_yahoo', 97 'user_msn', 98 'user_jabber', 99 'user_signature')); 100 $g_mess = sprintf($tableconvert, $con->pfx.'users'); 101 $b_mess = sprintf($tableerrors, $con->pfx.'users').' '.$err; 102 $checklist->addTest('convert-users', (strlen($err) == 0), $g_mess, $b_mess); 103 104 $err = convert_table($con->pfx.'articles', 105 'page_id', 106 array( 107 'page_title', 108 'page_content', 109 ) 110 ); 111 $g_mess = sprintf($tableconvert, $con->pfx.'articles'); 112 $b_mess = sprintf($tableerrors, $con->pfx.'articles').' '.$err; 113 $checklist->addTest('convert-articles', (strlen($err) == 0), $g_mess, $b_mess); 114 115 $err = convert_table($con->pfx.'categories', 116 'category_id', 117 array( 118 'website_id', 119 'category_name', 120 'category_description', 121 'category_keywords', 122 'category_path', 123 'category_template', 124 'category_type', 125 ) 126 ); 127 $g_mess = sprintf($tableconvert, $con->pfx.'categories'); 128 $b_mess = sprintf($tableerrors, $con->pfx.'categories').' '.$err; 129 $checklist->addTest('convert-categories', (strlen($err) == 0), $g_mess, $b_mess); 130 131 $err = convert_table($con->pfx.'categoryasso', 132 array('category_id', 'identifier'), 133 array( 134 'identifier', 135 'template', 136 ) 137 ); 138 $g_mess = sprintf($tableconvert, $con->pfx.'categoryasso'); 139 $b_mess = sprintf($tableerrors, $con->pfx.'categoryasso').' '.$err; 140 $checklist->addTest('convert-categoryasso', (strlen($err) == 0), $g_mess, $b_mess); 141 142 $err = convert_table($con->pfx.'comments', 143 'comment_id', 144 array( 145 'comment_author', 146 'comment_email', 147 'comment_website', 148 'comment_content', 149 'comment_ip', 150 ) 151 ); 152 $g_mess = sprintf($tableconvert, $con->pfx.'comments'); 153 $b_mess = sprintf($tableerrors, $con->pfx.'comments').' '.$err; 154 $checklist->addTest('convert-comments', (strlen($err) == 0), $g_mess, $b_mess); 155 156 $err = convert_table($con->pfx.'grants', 157 array('user_id', 'website_id'), 158 array( 159 'website_id', 160 ) 161 ); 162 $g_mess = sprintf($tableconvert, $con->pfx.'grants'); 163 $b_mess = sprintf($tableerrors, $con->pfx.'grants').' '.$err; 164 $checklist->addTest('convert-grants', (strlen($err) == 0), $g_mess, $b_mess); 165 166 $err = convert_table($con->pfx.'links', 167 'link_id', 168 array( 169 'website_id', 170 'href', 171 'label', 172 'title', 173 'lang', 174 'rel', 175 ) 176 ); 177 $g_mess = sprintf($tableconvert, $con->pfx.'links'); 178 $b_mess = sprintf($tableerrors, $con->pfx.'links').' '.$err; 179 $checklist->addTest('convert-links', (strlen($err) == 0), $g_mess, $b_mess); 180 181 $err = convert_table($con->pfx.'news', 182 'resource_id', 183 array( 184 'news_titlewebsite', 185 'news_linkwebsite', 186 ) 187 ); 188 $g_mess = sprintf($tableconvert, $con->pfx.'news'); 189 $b_mess = sprintf($tableerrors, $con->pfx.'news').' '.$err; 190 $checklist->addTest('convert-news', (strlen($err) == 0), $g_mess, $b_mess); 191 192 $err = convert_table($con->pfx.'resources', 193 'resource_id', 194 array( 195 'website_id', 196 'type_id', 197 'identifier', 198 'subject', 199 'creatorname', 200 'creatoremail', 201 'creatorwebsite', 202 'publisher', 203 'lang_id', 204 'title', 205 'description', 206 'path', 207 'size', 208 'version', 209 'metadata', 210 'comment', 211 'misc', 212 'format', 213 'dctype', 214 'dccoverage', 215 'rights', 216 ) 217 ); 218 $g_mess = sprintf($tableconvert, $con->pfx.'resources'); 219 $b_mess = sprintf($tableerrors, $con->pfx.'resources').' '.$err; 220 $checklist->addTest('convert-resources', (strlen($err) == 0), $g_mess, $b_mess); 221 $err = convert_table($con->pfx.'search', 222 array('resource_id', 'website_id'), 223 array( 224 'website_id', 225 ) 226 ); 227 $g_mess = sprintf($tableconvert, $con->pfx.'search'); 228 $b_mess = sprintf($tableerrors, $con->pfx.'search').' '.$err; 229 $checklist->addTest('convert-search', (strlen($err) == 0), $g_mess, $b_mess); 230 231 /* 232 $err = convert_table($con->pfx.'searchocc', 233 array('resource_id', 'website_id', 'word_id'), 234 array( 235 'website_id', 236 ) 237 ); 238 $g_mess = sprintf($tableconvert, $con->pfx.'searchocc'); 239 $b_mess = sprintf($tableerrors, $con->pfx.'searchocc').' '.$err; 240 $checklist->addTest('convert-searchocc', (strlen($err) == 0), $g_mess, $b_mess); 241 */ 242 /* 243 $err = convert_table($con->pfx.'searchwords', 244 'word_id', 245 array( 246 'word', 247 ) 248 ); 249 $g_mess = sprintf($tableconvert, $con->pfx.'searchwords'); 250 $b_mess = sprintf($tableerrors, $con->pfx.'searchwords').' '.$err; 251 $checklist->addTest('convert-searchwords', (strlen($err) == 0), $g_mess, $b_mess); 252 */ 253 254 $err = convert_table($con->pfx.'smart404', 255 array('website_id', 'oldpage'), 256 array( 257 'website_id', 258 'oldpage', 259 'newpage', 260 ) 261 ); 262 $g_mess = sprintf($tableconvert, $con->pfx.'smart404'); 263 $b_mess = sprintf($tableerrors, $con->pfx.'smart404').' '.$err; 264 $checklist->addTest('convert-smart404', (strlen($err) == 0), $g_mess, $b_mess); 265 266 $err = convert_table($con->pfx.'subtypes', 267 array('subtype_id', 'type_id', 'website_id'), 268 array( 269 'type_id', 270 'website_id', 271 'subtype_name', 272 'subtype_template', 273 'subtype_extra1', 274 'subtype_extra2', 275 ) 276 ); 277 $g_mess = sprintf($tableconvert, $con->pfx.'subtypes'); 278 $b_mess = sprintf($tableerrors, $con->pfx.'subtypes').' '.$err; 279 $checklist->addTest('convert-subtypes', (strlen($err) == 0), $g_mess, $b_mess); 280 281 282 $err = convert_table($con->pfx.'userprefs', 283 array('user_id', 'keyname', 'website_id'), 284 array( 285 'website_id', 286 'keyname', 287 'data', 288 ) 289 ); 290 $g_mess = sprintf($tableconvert, $con->pfx.'userprefs'); 291 $b_mess = sprintf($tableerrors, $con->pfx.'userprefs').' '.$err; 292 $checklist->addTest('convert-userprefs', (strlen($err) == 0), $g_mess, $b_mess); 293 $err = convert_table($con->pfx.'websites', 294 'website_id', 295 array( 296 'website_id', 297 'website_name', 298 'website_url', 299 'website_reurl', 300 'website_path', 301 'website_xmedia_reurl', 302 'website_xmedia_path', 303 'website_description', 304 'website_color', 305 ) 306 ); 307 $g_mess = sprintf($tableconvert, $con->pfx.'websites'); 308 $b_mess = sprintf($tableerrors, $con->pfx.'websites').' '.$err; 309 $checklist->addTest('convert-websites', (strlen($err) == 0), $g_mess, $b_mess); 310 311 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 11:57:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |