Changeset 1174
- Timestamp:
- Apr 14, 2006, 11:25:49 PM (19 years ago)
- Location:
- branches/branch-1_6
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/branch-1_6/include/config_default.inc.php
r1157 r1174 334 334 $conf['debug_l10n'] = false; 335 335 336 // die_on_sql_error: if an SQL query fails, should everything stop? 337 $conf['die_on_sql_error'] = true; 338 336 339 // +-----------------------------------------------------------------------+ 337 340 // | authentication | -
branches/branch-1_6/include/functions.inc.php
r1161 r1174 652 652 function my_error($header) 653 653 { 654 global $conf; 655 654 656 $error = '<pre>'; 655 657 $error.= $header; … … 657 659 $error.= mysql_error(); 658 660 $error.= '</pre>'; 659 die ($error); 661 662 if ($conf['die_on_sql_error']) 663 { 664 die($error); 665 } 666 else 667 { 668 echo $error; 669 } 660 670 } 661 671 -
branches/branch-1_6/template/yoga/upgrade.tpl
r859 r1174 8 8 9 9 <body> 10 <!-- BEGIN choices-->10 <!-- BEGIN introduction --> 11 11 <h1>Welcome to PhpWebGallery upgrade page.</h1> 12 <p>This page proposes to upgrade your database corresponding to your old version13 of PhpWebGallery to the current version. Select the version you wish to upgrade14 :</p>15 12 16 <ul> 17 <!-- BEGIN choice --> 18 <li><a href="{choices.choice.URL}">{choices.choice.VERSION}</a></li> 19 <!-- END choice --> 20 </ul> 21 <!-- END choices --> 13 <p>This page proposes to upgrade your database corresponding to your old 14 version of PhpWebGallery to the current version. The upgrade assistant 15 thinks you are currently running a 16 <strong>release {introduction.CURRENT_RELEASE}</strong> (or equivalent).</p> 17 18 <p><a href="{introduction.RUN_UPGRADE_URL}">Upgrade from release 19 {introduction.CURRENT_RELEASE} to {RELEASE}</a></p> 20 <!-- END introduction --> 22 21 23 22 <!-- BEGIN upgrade --> -
branches/branch-1_6/upgrade.php
r1075 r1174 30 30 include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); 31 31 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 32 include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php'); 32 33 include(PHPWG_ROOT_PATH.'include/template.php'); 33 34 34 35 include(PHPWG_ROOT_PATH.'include/mysql.inc.php'); 35 36 // +-----------------------------------------------------------------------+ 37 // | Check Access and exit when it is not ok | 38 // +-----------------------------------------------------------------------+ 36 include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); 37 @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); 38 39 39 check_upgrade(); 40 40 … … 44 44 include_once(PHPWG_ROOT_PATH.'include/constants.php'); 45 45 define('PREFIX_TABLE', $prefixeTable); 46 47 $conf['show_queries'] = false;48 46 49 47 // Database connection … … 69 67 70 68 /** 71 * l oads an sql file and executes all queries69 * list all tables in an array 72 70 * 73 * Before executing a query, $replaced is... replaced by $replacing. This is 74 * useful when the SQL file contains generic words. Drop table queries are 75 * not executed. 71 * @return array 72 */ 73 function get_tables() 74 { 75 $tables = array(); 76 77 $query = ' 78 SHOW TABLES 79 ;'; 80 $result = mysql_query($query); 81 82 while ($row = mysql_fetch_row($result)) 83 { 84 array_push( 85 $tables, 86 preg_replace('/^'.PREFIX_TABLE.'/', '', $row[0]) 87 ); 88 } 89 90 return $tables; 91 } 92 93 /** 94 * list all columns of each given table 76 95 * 77 * @param string filepath 78 * @param string replaced 79 * @param string replacing 96 * @return array of array 97 */ 98 function get_columns_of($tables) 99 { 100 $columns_of = array(); 101 102 foreach ($tables as $table) 103 { 104 $query = ' 105 DESC '.PREFIX_TABLE.$table.' 106 ;'; 107 $result = mysql_query($query); 108 109 $columns_of[$table] = array(); 110 111 while ($row = mysql_fetch_row($result)) 112 { 113 array_push($columns_of[$table], $row[0]); 114 } 115 } 116 117 return $columns_of; 118 } 119 120 /** 121 */ 122 function print_time($message) 123 { 124 global $last_time; 125 126 $new_time = get_moment(); 127 echo '<pre>['.get_elapsed_time($last_time, $new_time).']'; 128 echo ' '.$message; 129 echo '</pre>'; 130 flush(); 131 $last_time = $new_time; 132 } 133 134 /** 135 * replace old style #images.keywords by #tags. Requires a big data 136 * migration. 137 * 80 138 * @return void 81 139 */ 82 function execute_sqlfile($filepath, $replaced, $replacing) 83 { 84 $sql_lines = file($filepath); 85 $query = ''; 86 foreach ($sql_lines as $sql_line) 87 { 88 $sql_line = trim($sql_line); 89 if (preg_match('/(^--|^$)/', $sql_line)) 90 { 91 continue; 92 } 93 $query.= ' '.$sql_line; 94 // if we reached the end of query, we execute it and reinitialize the 95 // variable "query" 96 if (preg_match('/;$/', $sql_line)) 97 { 98 $query = trim($query); 99 $query = str_replace($replaced, $replacing, $query); 100 // we don't execute "DROP TABLE" queries 101 if (!preg_match('/^DROP TABLE/i', $query)) 140 function tag_replace_keywords() 141 { 142 // code taken from upgrades 19 and 22 143 144 $query = ' 145 CREATE TABLE '.PREFIX_TABLE.'tags ( 146 id smallint(5) UNSIGNED NOT NULL auto_increment, 147 name varchar(255) BINARY NOT NULL, 148 url_name varchar(255) BINARY NOT NULL, 149 PRIMARY KEY (id) 150 ) 151 ;'; 152 pwg_query($query); 153 154 $query = ' 155 CREATE TABLE '.PREFIX_TABLE.'image_tag ( 156 image_id mediumint(8) UNSIGNED NOT NULL, 157 tag_id smallint(5) UNSIGNED NOT NULL, 158 PRIMARY KEY (image_id,tag_id) 159 ) 160 ;'; 161 pwg_query($query); 162 163 // 164 // Move keywords to tags 165 // 166 167 // each tag label is associated to a numeric identifier 168 $tag_id = array(); 169 // to each tag id (key) a list of image ids (value) is associated 170 $tag_images = array(); 171 172 $current_id = 1; 173 174 $query = ' 175 SELECT id, keywords 176 FROM '.PREFIX_TABLE.'images 177 WHERE keywords IS NOT NULL 178 ;'; 179 $result = pwg_query($query); 180 while ($row = mysql_fetch_array($result)) 181 { 182 foreach(preg_split('/[,]+/', $row['keywords']) as $keyword) 183 { 184 if (!isset($tag_id[$keyword])) 102 185 { 103 mysql_query($query);186 $tag_id[$keyword] = $current_id++; 104 187 } 105 $query = ''; 106 } 107 } 108 } 188 189 if (!isset($tag_images[ $tag_id[$keyword] ])) 190 { 191 $tag_images[ $tag_id[$keyword] ] = array(); 192 } 193 194 array_push( 195 $tag_images[ $tag_id[$keyword] ], 196 $row['id'] 197 ); 198 } 199 } 200 201 $datas = array(); 202 foreach ($tag_id as $tag_name => $tag_id) 203 { 204 array_push( 205 $datas, 206 array( 207 'id' => $tag_id, 208 'name' => $tag_name, 209 'url_name' => str2url($tag_name), 210 ) 211 ); 212 } 213 214 if (!empty($datas)) 215 { 216 mass_inserts( 217 PREFIX_TABLE.'tags', 218 array_keys($datas[0]), 219 $datas 220 ); 221 } 222 223 $datas = array(); 224 foreach ($tag_images as $tag_id => $images) 225 { 226 foreach (array_unique($images) as $image_id) 227 { 228 array_push( 229 $datas, 230 array( 231 'tag_id' => $tag_id, 232 'image_id' => $image_id, 233 ) 234 ); 235 } 236 } 237 238 if (!empty($datas)) 239 { 240 mass_inserts( 241 PREFIX_TABLE.'image_tag', 242 array_keys($datas[0]), 243 $datas 244 ); 245 } 246 247 // 248 // Delete images.keywords 249 // 250 $query = ' 251 ALTER TABLE '.PREFIX_TABLE.'images DROP COLUMN keywords 252 ;'; 253 pwg_query($query); 254 255 // 256 // Add useful indexes 257 // 258 $query = ' 259 ALTER TABLE '.PREFIX_TABLE.'tags 260 ADD INDEX tags_i1(url_name) 261 ;'; 262 pwg_query($query); 263 264 265 $query = ' 266 ALTER TABLE '.PREFIX_TABLE.'image_tag 267 ADD INDEX image_tag_i1(tag_id) 268 ;'; 269 pwg_query($query); 270 271 print_time('tags have replaced keywords'); 272 } 273 274 // +-----------------------------------------------------------------------+ 275 // | playing zone | 276 // +-----------------------------------------------------------------------+ 277 278 // echo implode('<br>', get_tables()); 279 // echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>'; 280 109 281 // +-----------------------------------------------------------------------+ 110 282 // | template initialization | … … 116 288 117 289 // +-----------------------------------------------------------------------+ 118 // | versions upgradable |119 // +-----------------------------------------------------------------------+120 $versions = array();121 $path = PHPWG_ROOT_PATH.'install';122 if ($contents = opendir($path))123 {124 while (($node = readdir($contents)) !== false)125 {126 if (is_file($path.'/'.$node)127 and preg_match('/^upgrade_(.*?)\.php$/', $node, $match))128 {129 array_push($versions, $match[1]);130 }131 }132 }133 natcasesort($versions);134 // +-----------------------------------------------------------------------+135 290 // | upgrade choice | 136 291 // +-----------------------------------------------------------------------+ 292 137 293 if (!isset($_GET['version'])) 138 294 { 139 $template->assign_block_vars('choices', array()); 140 foreach ($versions as $version) 141 { 142 $template->assign_block_vars( 143 'choices.choice', 144 array( 145 'URL' => PHPWG_ROOT_PATH.'upgrade.php?version='.$version, 146 'VERSION' => $version 147 )); 148 } 149 } 295 // find the current release 296 $tables = get_tables(); 297 $columns_of = get_columns_of($tables); 298 299 if (!in_array('param', $columns_of['config'])) 300 { 301 // we're in branch 1.3, important upgrade, isn't it? 302 if (in_array('user_category', $tables)) 303 { 304 $current_release = '1.3.1'; 305 } 306 else 307 { 308 $current_release = '1.3.0'; 309 } 310 } 311 else if (!in_array('user_cache', $tables)) 312 { 313 $current_release = '1.4.0'; 314 } 315 else if (!in_array('tags', $tables)) 316 { 317 $current_release = '1.5.0'; 318 } 319 else 320 { 321 die('You are already on branch 1.6, no upgrade required'); 322 } 323 324 $template->assign_block_vars( 325 'introduction', 326 array( 327 'CURRENT_RELEASE' => $current_release, 328 'RUN_UPGRADE_URL' => 329 PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release, 330 ) 331 ); 332 } 333 150 334 // +-----------------------------------------------------------------------+ 151 335 // | upgrade launch | 152 336 // +-----------------------------------------------------------------------+ 337 153 338 else 154 339 { 155 $upgrade_file = $path.'/upgrade_'.$_GET['version'].'.php';340 $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php'; 156 341 if (is_file($upgrade_file)) 157 342 { 158 343 $page['upgrade_start'] = get_moment(); 344 $conf['die_on_sql_error'] = false; 159 345 include($upgrade_file); 160 346 $page['upgrade_end'] = get_moment(); … … 164 350 array( 165 351 'VERSION' => $_GET['version'], 166 'TOTAL_TIME' => get_elapsed_time($page['upgrade_start'], 167 $page['upgrade_end']), 168 'SQL_TIME' => number_format($page['queries_time'], 3, '.', ' ').' s', 352 'TOTAL_TIME' => get_elapsed_time( 353 $page['upgrade_start'], 354 $page['upgrade_end'] 355 ), 356 'SQL_TIME' => number_format( 357 $page['queries_time'], 358 3, 359 '.', 360 ' ' 361 ).' s', 169 362 'NB_QUERIES' => $page['count_queries'] 170 )); 363 ) 364 ); 171 365 172 366 if (!isset($infos)) … … 198 392 foreach ($infos as $info) 199 393 { 200 $template->assign_block_vars('upgrade.infos.info', 201 array('CONTENT' => $info)); 394 $template->assign_block_vars( 395 'upgrade.infos.info', 396 array( 397 'CONTENT' => $info, 398 ) 399 ); 202 400 } 203 401 } … … 207 405 } 208 406 } 407 408 $query = ' 409 UPDATE '.USER_CACHE_TABLE.' 410 SET need_update = \'true\' 411 ;'; 412 pwg_query($query); 413 209 414 // +-----------------------------------------------------------------------+ 210 415 // | sending html code | 211 416 // +-----------------------------------------------------------------------+ 417 212 418 $template->pparse('upgrade'); 213 419 ?>
Note: See TracChangeset
for help on using the changeset viewer.