Changeset 486 for trunk/admin/update.php
- Timestamp:
- Aug 21, 2004, 2:52:43 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/update.php
r466 r486 27 27 28 28 include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); 29 30 define('CURRENT_DATE', "'".date('Y-m-d')."'"); 29 31 //------------------------------------------------------------------- functions 30 function ordering( $id_uppercat) 32 /** 33 * order categories (update categories.rank database field) 34 * 35 * the purpose of this function is to give a rank for all categories 36 * (insides its sub-category), even the newer that have none at te 37 * beginning. For this, ordering function selects all categories ordered by 38 * rank ASC then name ASC for each uppercat. 39 * 40 * @returns void 41 */ 42 function ordering() 31 43 { 32 $rank = 1; 44 $current_rank = 0; 45 $current_uppercat = ''; 33 46 34 $query = 'SELECT id'; 35 $query.= ' FROM '.CATEGORIES_TABLE; 36 if ( !is_numeric( $id_uppercat)) 37 { 38 $query.= ' WHERE id_uppercat IS NULL'; 39 } 40 else 41 { 42 $query.= ' WHERE id_uppercat = '.$id_uppercat; 43 } 44 $query.= ' ORDER BY rank ASC, dir ASC'; 45 $query.= ';'; 46 $result = mysql_query( $query); 47 while ( $row = mysql_fetch_array( $result)) 48 { 49 $query = 'UPDATE '.CATEGORIES_TABLE; 50 $query.= ' SET rank = '.$rank; 51 $query.= ' WHERE id = '.$row['id']; 52 $query.= ';'; 53 mysql_query( $query); 54 $rank++; 55 ordering( $row['id']); 47 $query = ' 48 SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat 49 FROM '.CATEGORIES_TABLE.' 50 ORDER BY id_uppercat,rank,name 51 ;'; 52 $result = mysql_query($query); 53 while ($row = mysql_fetch_array($result)) 54 { 55 if ($row['id_uppercat'] != $current_uppercat) 56 { 57 $current_rank = 0; 58 $current_uppercat = $row['id_uppercat']; 59 } 60 $query = ' 61 UPDATE '.CATEGORIES_TABLE.' 62 SET rank = '.++$current_rank.' 63 WHERE id = '.$row['id'].' 64 ;'; 65 mysql_query($query); 56 66 } 57 67 } … … 111 121 } 112 122 113 $ sub_dirs = get_category_directories($cat_directory);123 $fs_subdirs = get_category_directories($cat_directory); 114 124 115 125 $sub_category_dirs = array(); … … 137 147 138 148 // 3. we have to remove the categories of the database not present anymore 149 $to_delete_categories = array(); 139 150 foreach ($sub_category_dirs as $id => $dir) 140 151 { 141 if (!in_array($dir, $sub_dirs)) 142 { 143 delete_category($id); 144 } 152 if (!in_array($dir, $fs_subdirs)) 153 { 154 array_push($to_delete_categories,$id); 155 } 156 } 157 if (count($to_delete_categories) > 0) 158 { 159 delete_categories($to_delete_categories); 145 160 } 146 161 … … 148 163 $inserts = array(); 149 164 150 foreach ($ sub_dirs as $sub_dir)165 foreach ($fs_subdirs as $fs_subdir) 151 166 { 152 167 // 5. Is the category already existing ? we create a subcat if not 153 168 // existing 154 $category_id = array_search($ sub_dir, $sub_category_dirs);169 $category_id = array_search($fs_subdir, $sub_category_dirs); 155 170 if (!is_numeric($category_id)) 156 171 { 157 if (preg_match('/^[a-zA-Z0-9-_.]+$/', $ sub_dir))172 if (preg_match('/^[a-zA-Z0-9-_.]+$/', $fs_subdir)) 158 173 { 159 $name = str_replace('_', ' ', $ sub_dir);160 161 $value = "('".$ sub_dir."','".$name."',1";174 $name = str_replace('_', ' ', $fs_subdir); 175 176 $value = "('".$fs_subdir."','".$name."',1"; 162 177 if (!is_numeric($id_uppercat)) 163 178 { … … 174 189 else 175 190 { 176 $output.= '<span style="color:red;">"'.$ sub_dir.'" : ';191 $output.= '<span style="color:red;">"'.$fs_subdir.'" : '; 177 192 $output.= $lang['update_wrong_dirname'].'</span><br />'; 178 193 } … … 251 266 function insert_local_element($dir, $category_id) 252 267 { 253 global $lang,$conf,$count_new , $count_deleted;268 global $lang,$conf,$count_new; 254 269 255 270 $output = ''; … … 309 324 310 325 $to_delete_elements = array_unique($to_delete_elements); 311 $count_deleted+= count($to_delete_elements); 312 if ($count_deleted > 0) 326 if (count($to_delete_elements) > 0) 313 327 { 314 328 delete_elements($to_delete_elements); … … 326 340 } 327 341 328 // validated pictures are picture uploaded by users, validated by an admin 329 // and not registered (visible) yet 330 $validated_pictures = array(); 342 // unvalidated pictures are picture uploaded by users, but not validated 343 // by an admin (so not registered truly visible yet) 331 344 $unvalidated_pictures = array(); 332 345 333 346 $query = ' 334 SELECT file ,infos,validated347 SELECT file 335 348 FROM '.WAITING_TABLE.' 336 349 WHERE storage_category_id = '.$category_id.' 350 AND validated = \'false\' 337 351 ;'; 338 352 $result = mysql_query($query); 339 353 while ($row = mysql_fetch_array($result)) 340 354 { 341 if ($row['validated'] == 'true') 342 { 343 $validated_pictures[$row['file']] = $row['infos']; 344 } 345 else 346 { 347 array_push($unvalidated_pictures, $row['file']); 348 } 355 array_push($unvalidated_pictures, $row['file']); 349 356 } 350 357 … … 386 393 if ($tn_ext != '') 387 394 { 388 $image_size = @getimagesize($dir.$unregistered_element); 389 // (file, storage_category_id, date_available, tn_ext, filesize, 390 // width, height, name, author, comment, date_creation, 391 // representative_ext)' 392 $value = '('; 393 $value.= "'".$unregistered_element."'"; 394 $value.= ','.$category_id; 395 $value.= ",'".date('Y-m-d')."'"; 396 $value.= ",'".$tn_ext."'"; 397 $value.= ','.floor(filesize($dir.$unregistered_element) / 1024); 398 $value.= ','.$image_size[0]; 399 $value.= ','.$image_size[1]; 400 if (isset($validated_pictures[$unregistered_element])) 401 { 402 // retrieving infos from the XML description from waiting table 403 $infos = nl2br($validated_pictures[$unregistered_element]); 404 405 $unixtime = getAttribute($infos, 'date_creation'); 406 if ($unixtime != '') 407 { 408 $date_creation ="'".date('Y-m-d',$unixtime)."'"; 409 } 410 else 411 { 412 $date_creation = 'NULL'; 413 } 414 415 $value.= ",'".getAttribute($infos, 'name')."'"; 416 $value.= ",'".getAttribute($infos, 'author')."'"; 417 $value.= ",'".getAttribute($infos, 'comment')."'"; 418 $value.= ','.$date_creation; 419 420 // deleting the waiting element 421 $query = ' 422 DELETE FROM '.WAITING_TABLE.' 423 WHERE file = \''.$unregistered_element.'\' 424 AND storage_category_id = '.$category_id.' 425 ;'; 426 mysql_query($query); 427 } 428 else 429 { 430 $value.= ",'','','',NULL"; 431 } 432 $value.= ',NULL'; // representative_ext 433 $value.= ')'; 434 395 $insert = array(); 396 $insert['file'] = "'".$unregistered_element."'"; 397 $insert['storage_category_id'] = $category_id; 398 $insert['date_available'] = CURRENT_DATE; 399 $insert['tn_ext'] = "'".$tn_ext."'"; 400 435 401 $count_new++; 436 402 $output.= $unregistered_element; … … 439 405 $output.= ' ('.$lang['update_research_tn_ext'].' '.$tn_ext.')'; 440 406 $output.= '<br />'; 441 array_push($inserts, $ value);407 array_push($inserts, $insert); 442 408 } 443 409 else 444 410 { 445 $output.= '<span style="color: red;">';411 $output.= '<span style="color:orange;">'; 446 412 $output.= $lang['update_missing_tn'].' : '.$unregistered_element; 447 413 $output.= ' (<span style="font-weight:bold;">'; … … 471 437 } 472 438 473 // (file, storage_category_id, date_available, tn_ext, filesize, 474 // width, height, name, author, comment, date_creation, 475 // representative_ext)' 476 $value = '('; 477 $value.= "'".$unregistered_element."'"; 478 $value.= ','.$category_id; 479 $value.= ",'".date('Y-m-d')."'"; 439 $insert = array(); 440 $insert['file'] = "'".$unregistered_element."'"; 441 $insert['storage_category_id'] = $category_id; 442 $insert['date_available'] = CURRENT_DATE; 480 443 if ( $tn_ext != '' ) 481 444 { 482 $value.= ",'".$tn_ext."'"; 483 } 484 else 485 { 486 $value.= ',NULL'; 487 } 488 $value.= ','.floor(filesize($dir.$unregistered_element) / 1024); 489 $value.= ',NULL'; 490 $value.= ',NULL'; 491 $value.= ',NULL'; 492 $value.= ',NULL'; 493 $value.= ',NULL'; 494 $value.= ',NULL'; 445 $insert['tn_ext'] = "'".$tn_ext."'"; 446 } 495 447 if ( $representative_ext != '' ) 496 448 { 497 $value.= ",'".$representative_ext."'"; 498 } 499 else 500 { 501 $value.= ',NULL'; 502 } 503 $value.= ')'; 449 $insert['representative_ext'] = "'".$representative_ext."'"; 450 } 504 451 505 452 $count_new++; … … 508 455 $output.= $lang['update_research_added'].'</span>'; 509 456 $output.= '<br />'; 510 array_push($inserts, $ value);457 array_push($inserts, $insert); 511 458 } 512 459 } … … 521 468 { 522 469 // inserts all found pictures 470 $dbfields = array( 471 'file','storage_category_id','date_available','tn_ext' 472 ,'representative_ext' 473 ); 523 474 $query = ' 524 475 INSERT INTO '.IMAGES_TABLE.' 525 (file,storage_category_id,date_available,tn_ext,filesize,width,height 526 ,name,author,comment,date_creation,representative_ext) 476 ('.implode(',', $dbfields).') 527 477 VALUES 528 '.implode(',', $inserts).' 529 ;'; 478 '; 479 foreach ($inserts as $insert_id => $insert) 480 { 481 $query.= ' 482 '; 483 if ($insert_id > 0) 484 { 485 $query.= ','; 486 } 487 $query.= '('; 488 foreach ($dbfields as $field_id => $dbfield) 489 { 490 if ($field_id > 0) 491 { 492 $query.= ','; 493 } 494 495 if (!isset($insert[$dbfield]) or $insert[$dbfield] == '') 496 { 497 $query.= 'NULL'; 498 } 499 else 500 { 501 $query.= $insert[$dbfield]; 502 } 503 } 504 $query.=')'; 505 } 506 $query.= ' 507 ;'; 508 530 509 mysql_query($query); 531 510 … … 576 555 'L_NEW_CATEGORY'=>$lang['update_research_conclusion'], 577 556 'L_DEL_CATEGORY'=>$lang['update_deletion_conclusion'], 557 'L_UPDATE_SYNC_METADATA_QUESTION'=>$lang['update_sync_metadata_question'], 578 558 579 559 'U_CAT_UPDATE'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=update&update=cats'), 580 560 'U_ALL_UPDATE'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=update&update=all') 581 561 )); 582 583 562 //-------------------------------------------- introduction : choices of update 584 563 // Display choice if "update" var is not specified … … 588 567 } 589 568 //-------------------------------------------------- local update : ./galleries 590 else 569 else if (!isset($_GET['metadata'])) 591 570 { 592 571 check_cat_id($_GET['update']); … … 603 582 $categories = insert_local_category('NULL'); 604 583 } 605 $end = get_moment(); 606 //echo get_elapsed_time($start, $end).' for update <br />'; 584 echo get_elapsed_time($start,get_moment()).' for scanning directories<br />'; 607 585 $template->assign_block_vars('update',array( 608 586 'CATEGORIES'=>$categories, … … 610 588 'DEL_CAT'=>$count_deleted 611 589 )); 590 if ($count_new > 0) 591 { 592 $url = PHPWG_ROOT_PATH.'admin.php?page=update&metadata=1'; 593 if (isset($page['cat'])) 594 { 595 $url.= '&update='.$page['cat']; 596 } 597 $template->assign_block_vars( 598 'update.sync_metadata', 599 array( 600 'U_URL' => add_session_id($url) 601 )); 602 } 612 603 } 613 604 //---------------------------------------- update informations about categories 614 if (isset($_GET['update']) 615 or isset($page['cat']) 616 or @is_file('./listing.xml') && DEBUG) 605 if (!isset($_GET['metadata']) 606 and (isset($_GET['update']) 607 or isset($page['cat']) 608 or @is_file('./listing.xml') && DEBUG)) 617 609 { 618 610 $start = get_moment(); 619 611 update_category('all'); 620 ordering('NULL'); 621 $end = get_moment(); 622 echo get_elapsed_time($start, $end).' for update_category(all)<br />'; 612 echo get_elapsed_time($start,get_moment()).' for update_category(all)<br />'; 613 $start = get_moment(); 614 ordering(); 615 echo get_elapsed_time($start, get_moment()).' for ordering categories<br />'; 616 } 617 //---------------------------------------------------- metadata synchronization 618 if (isset($_GET['metadata'])) 619 { 620 if (isset($_GET['update'])) 621 { 622 check_cat_id($_GET['update']); 623 } 624 625 $start = get_moment(); 626 // $files = get_filelist(1464); 627 if (isset($page['cat'])) 628 { 629 $files = get_filelist($page['cat'],true,true); 630 } 631 else 632 { 633 $files = get_filelist('',true,true); 634 } 635 echo get_elapsed_time($start, get_moment()).' for get_filelist<br />'; 636 637 $start = get_moment(); 638 update_metadata($files); 639 echo get_elapsed_time($start, get_moment()).' for metadata update<br />'; 623 640 } 624 641 //----------------------------------------------------------- sending html code
Note: See TracChangeset
for help on using the changeset viewer.