Changeset 1209 for branches/branch-1_6/upgrade.php
- Timestamp:
- Apr 19, 2006, 10:54:13 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/branch-1_6/upgrade.php
r1174 r1209 132 132 } 133 133 134 /**135 * replace old style #images.keywords by #tags. Requires a big data136 * migration.137 *138 * @return void139 */140 function tag_replace_keywords()141 {142 // code taken from upgrades 19 and 22143 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 tags165 //166 167 // each tag label is associated to a numeric identifier168 $tag_id = array();169 // to each tag id (key) a list of image ids (value) is associated170 $tag_images = array();171 172 $current_id = 1;173 174 $query = '175 SELECT id, keywords176 FROM '.PREFIX_TABLE.'images177 WHERE keywords IS NOT NULL178 ;';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]))185 {186 $tag_id[$keyword] = $current_id++;187 }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 $datas220 );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 $datas244 );245 }246 247 //248 // Delete images.keywords249 //250 $query = '251 ALTER TABLE '.PREFIX_TABLE.'images DROP COLUMN keywords252 ;';253 pwg_query($query);254 255 //256 // Add useful indexes257 //258 $query = '259 ALTER TABLE '.PREFIX_TABLE.'tags260 ADD INDEX tags_i1(url_name)261 ;';262 pwg_query($query);263 264 265 $query = '266 ALTER TABLE '.PREFIX_TABLE.'image_tag267 ADD INDEX image_tag_i1(tag_id)268 ;';269 pwg_query($query);270 271 print_time('tags have replaced keywords');272 }273 274 134 // +-----------------------------------------------------------------------+ 275 135 // | playing zone | … … 278 138 // echo implode('<br>', get_tables()); 279 139 // echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>'; 140 141 // foreach (get_available_upgrade_ids() as $upgrade_id) 142 // { 143 // echo $upgrade_id, '<br>'; 144 // } 280 145 281 146 // +-----------------------------------------------------------------------+ … … 341 206 if (is_file($upgrade_file)) 342 207 { 208 $page['infos'] = array(); 343 209 $page['upgrade_start'] = get_moment(); 344 210 $conf['die_on_sql_error'] = false; 345 211 include($upgrade_file); 212 213 // Available upgrades must be ignored after a fresh installation. To 214 // make PWG avoid upgrading, we must tell it upgrades have already been 215 // made. 216 list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); 217 define('CURRENT_DATE', $dbnow); 218 $datas = array(); 219 foreach (get_available_upgrade_ids() as $upgrade_id) 220 { 221 array_push( 222 $datas, 223 array( 224 'id' => $upgrade_id, 225 'applied' => CURRENT_DATE, 226 'description' => 'upgrade included in upgrade', 227 ) 228 ); 229 } 230 mass_inserts( 231 UPGRADE_TABLE, 232 array_keys($datas[0]), 233 $datas 234 ); 235 346 236 $page['upgrade_end'] = get_moment(); 347 237 … … 364 254 ); 365 255 366 if (!isset($infos))367 {368 $infos = array();369 }370 256 array_push( 371 $ infos,257 $page['infos'], 372 258 '[security] delete files "upgrade.php", "install.php" and "install" 373 259 directory' … … 375 261 376 262 array_push( 377 $ infos,263 $page['infos'], 378 264 'in include/mysql.inc.php, remove 379 265 <pre style="background-color:lightgray"> … … 383 269 384 270 array_push( 385 $ infos,271 $page['infos'], 386 272 'Perform a maintenance check in [Administration>General>Maintenance] 387 273 if you encounter any problem.' … … 390 276 $template->assign_block_vars('upgrade.infos', array()); 391 277 392 foreach ($ infosas $info)278 foreach ($page['infos'] as $info) 393 279 { 394 280 $template->assign_block_vars( … … 399 285 ); 400 286 } 401 } 402 else 403 { 404 die('Hacking attempt'); 405 } 406 } 407 408 $query = ' 287 288 $query = ' 409 289 UPDATE '.USER_CACHE_TABLE.' 410 290 SET need_update = \'true\' 411 291 ;'; 412 pwg_query($query); 292 pwg_query($query); 293 } 294 else 295 { 296 die('Hacking attempt'); 297 } 298 } 413 299 414 300 // +-----------------------------------------------------------------------+
Note: See TracChangeset
for help on using the changeset viewer.