Changeset 2307


Ignore:
Timestamp:
Apr 21, 2008, 12:25:40 AM (16 years ago)
Author:
rvelices
Message:

merge r 2306 from trunk to branch-1_7

  • merged function ordering() with update_global_rank() and also optimized the queries
Location:
branches/branch-1_7
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_7/admin/cat_list.php

    r2202 r2307  
    6161  mass_updates(CATEGORIES_TABLE, $fields, $datas);
    6262
    63   update_global_rank(@$_GET['parent_id']);
     63  update_global_rank();
    6464}
    6565
     
    8383  delete_categories(array($_GET['delete']));
    8484  array_push($page['infos'], l10n('cat_virtual_deleted'));
    85   ordering();
    8685  update_global_rank();
    8786}
     
    295294}
    296295// Add a link to Page bottom only if needed (10 or more categories)
    297 if ( isset($category['rank']) and $category['rank'] > 9 ) 
     296if ( isset($category['rank']) and $category['rank'] > 9 )
    298297{
    299298  $template->assign_block_vars('eop_link', array('ICON'=>'Displayed'));
  • branches/branch-1_7/admin/include/functions.php

    r2303 r2307  
    684684
    685685/**
    686  * updates the global_rank of categories under the given id_uppercat
    687  *
    688  * @param int id_uppercat
     686 * order categories (update categories.rank and global_rank database fields)
     687 * so that rank field are consecutive integers starting at 1 for each child
    689688 * @return void
    690689 */
    691 function update_global_rank($id_uppercat = 'all')
    692 {
    693   $query = '
    694 SELECT id,rank
     690function update_global_rank()
     691{
     692  $query = '
     693SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat, uppercats, rank, global_rank
    695694  FROM '.CATEGORIES_TABLE.'
    696 ;';
    697   $result = pwg_query($query);
    698   $ranks_array = array();
    699   while ($row = mysql_fetch_array($result))
    700   {
    701     $ranks_array[$row['id']] = $row['rank'];
    702   }
    703 
    704   // which categories to update ?
    705   $uppercats_array = array();
    706 
    707   $query = '
    708 SELECT id,uppercats
    709   FROM '.CATEGORIES_TABLE;
    710   if (is_numeric($id_uppercat))
    711   {
    712     $query.= '
    713   WHERE uppercats REGEXP \'(^|,)'.$id_uppercat.'(,|$)\'
    714     AND id != '.$id_uppercat.'
    715 ';
    716   }
    717   $query.= '
    718 ;';
     695  ORDER BY id_uppercat,rank,name
     696;';
     697
     698  $cat_map = array();
     699
     700  $current_rank = 0;
     701  $current_uppercat = '';
     702
    719703  $result = pwg_query($query);
    720704  while ($row = mysql_fetch_array($result))
    721705  {
    722     $uppercats_array[$row['id']] =  $row['uppercats'];
     706    if ($row['id_uppercat'] != $current_uppercat)
     707    {
     708      $current_rank = 0;
     709      $current_uppercat = $row['id_uppercat'];
     710    }
     711    ++$current_rank;
     712    $cat =
     713      array(
     714        'rank' =>        $current_rank,
     715        'rank_changed' =>$current_rank!=$row['rank'],
     716        'global_rank' => $row['global_rank'],
     717        'uppercats' =>   $row['uppercats'],
     718        );
     719    $cat_map[ $row['id'] ] = $cat;
    723720  }
    724721
    725722  $datas = array();
    726   foreach ($uppercats_array as $id => $uppercats)
    727   {
    728     array_push(
    729       $datas,
    730       array(
    731         'id'          => $id,
    732         'global_rank' => preg_replace(
     723
     724  foreach( $cat_map as $id=>$cat )
     725  {
     726    $new_global_rank = preg_replace(
    733727          '/(\d+)/e',
    734           "\$ranks_array['$1']",
    735           str_replace(',', '.', $uppercats)
    736           ),
    737         )
    738       );
     728          "\$cat_map['$1']['rank']",
     729          str_replace(',', '.', $cat['uppercats'] )
     730          );
     731    if ( $cat['rank_changed']
     732      or $new_global_rank!=$cat['global_rank']
     733      )
     734    {
     735      $datas[] = array(
     736          'id' => $id,
     737          'rank' => $cat['rank'],
     738          'global_rank' => $new_global_rank,
     739        );
     740    }
    739741  }
    740742
     
    743745    array(
    744746      'primary' => array('id'),
    745       'update'  => array('global_rank')
     747      'update'  => array('rank', 'global_rank')
    746748      ),
    747749    $datas
    748750    );
     751  return count($datas);
    749752}
    750753
     
    892895    $datas
    893896    );
    894 }
    895 
    896 /**
    897  * order categories (update categories.rank and global_rank database fields)
    898  *
    899  * the purpose of this function is to give a rank for all categories
    900  * (insides its sub-category), even the newer that have none at te
    901  * beginning. For this, ordering function selects all categories ordered by
    902  * rank ASC then name ASC for each uppercat.
    903  *
    904  * @returns void
    905  */
    906 function ordering()
    907 {
    908   $current_rank = 0;
    909   $current_uppercat = '';
    910 
    911   $query = '
    912 SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat
    913   FROM '.CATEGORIES_TABLE.'
    914   ORDER BY id_uppercat,rank,name
    915 ;';
    916   $result = pwg_query($query);
    917   $datas = array();
    918   while ($row = mysql_fetch_array($result))
    919   {
    920     if ($row['id_uppercat'] != $current_uppercat)
    921     {
    922       $current_rank = 0;
    923       $current_uppercat = $row['id_uppercat'];
    924     }
    925     $data = array('id' => $row['id'], 'rank' => ++$current_rank);
    926     array_push($datas, $data);
    927   }
    928 
    929   $fields = array('primary' => array('id'), 'update' => array('rank'));
    930   mass_updates(CATEGORIES_TABLE, $fields, $datas);
    931897}
    932898
     
    13711337
    13721338  update_uppercats();
    1373   ordering();
    13741339  update_global_rank();
    13751340
  • branches/branch-1_7/admin/maintenance.php

    r2061 r2307  
    4949    update_uppercats();
    5050    update_category('all');
    51     ordering();
    5251    update_global_rank();
    5352    invalidate_user_cache();
  • branches/branch-1_7/admin/site_update.php

    r2193 r2307  
    243243  // If $_POST['subcats-included'] != 1 ("Search in subcategories" is unchecked)
    244244  // $db_fulldirs doesn't include any subdirectories and $fs_fulldirs does
    245   // So $fs_fulldirs will be limited to the selected basedir 
     245  // So $fs_fulldirs will be limited to the selected basedir
    246246  // (if that one is in $fs_fulldirs)
    247247  if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1)
     
    254254  // die('That\'s why dirs or files synchronizations were duplicating cats.');
    255255
    256   $inserts = array(); 
     256  $inserts = array();
    257257  // new categories are the directories not present yet in the database
    258258  foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir)
     
    671671    echo ' -->'."\n";
    672672    $start = get_moment();
    673     ordering();
    674673    update_global_rank();
    675674    echo '<!-- ordering categories : ';
     
    829828    }
    830829  }
    831  
     830
    832831  foreach ( $files as $id=>$file )
    833832  {
     
    836835      in_array($id, $has_high_images)
    837836      );
    838    
     837
    839838    if ( is_array($data) )
    840839    {
     
    873872    {
    874873      // echo '<pre>', print_r($datas); echo '</pre>';
    875      
     874
    876875      mass_updates(
    877876        IMAGES_TABLE,
  • branches/branch-1_7/install/upgrade_1.3.1.php

    r1932 r2307  
    7272  ADD COLUMN commentable enum('true','false') NOT NULL default 'true'
    7373;",
    74  
     74
    7575  "
    7676ALTER TABLE phpwebgallery_categories
     
    9292  SET date_temp = date
    9393;",
    94  
     94
    9595  "
    9696ALTER TABLE phpwebgallery_comments
     
    127127  SET date_temp = date
    128128;",
    129  
     129
    130130  "
    131131ALTER TABLE phpwebgallery_history
     
    208208  ADD INDEX images_i5 (date_creation)
    209209;",
    210  
     210
    211211  "
    212212ALTER TABLE phpwebgallery_sessions
     
    223223  SET expiration_temp = expiration
    224224;",
    225  
     225
    226226  "
    227227ALTER TABLE phpwebgallery_sessions
     
    238238  DROP COLUMN expiration_temp
    239239;",
    240  
     240
    241241  "
    242242ALTER TABLE phpwebgallery_sites
     
    252252DROP TABLE phpwebgallery_user_category
    253253;",
    254  
     254
    255255  "
    256256ALTER TABLE phpwebgallery_users
     
    277277  ADD UNIQUE users_ui1 (username)
    278278;",
    279  
     279
    280280  "
    281281CREATE TABLE phpwebgallery_rate (
     
    343343{
    344344  $existing_indexes = array();
    345  
     345
    346346  $query = '
    347347SHOW INDEX
     
    530530
    531531// refresh calculated datas
    532 ordering();
    533532update_global_rank();
    534533update_category();
     
    588587  array(
    589588    'all sub-categories of private categories become private',
    590    
     589
    591590    'user permissions and group permissions have been erased',
    592591
Note: See TracChangeset for help on using the changeset viewer.