Changeset 625 for trunk/admin/update.php


Ignore:
Timestamp:
Nov 30, 2004, 9:26:44 PM (20 years ago)
Author:
plg
Message:
  • update_global_rank new function : far more intelligent update. Take into account the possiblity to have category tree not in category id ascending order
  • update global_rank when moving categories among the same parent
  • new function mass_updates : depending on MySQL version, create a temporary table, make one big insert and one big update by joining 2 tables (4.0.4 or above) or make 1 update per primary key
  • function update_category improved for representative_picture_id check : only one useful query (equivalent to NOT EXISTS) instead of N (N = number of categories) queries
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/update.php

    r614 r625  
    4343 * (insides its sub-category), even the newer that have none at te
    4444 * beginning. For this, ordering function selects all categories ordered by
    45  * rank ASC then name ASC for each uppercat. It also updates the global rank
    46  * which is able to order any two categorie in the whole tree
     45 * rank ASC then name ASC for each uppercat.
    4746 *
    4847 * @returns void
     
    5958;';
    6059  $result = pwg_query($query);
     60  $datas = array();
    6161  while ($row = mysql_fetch_array($result))
    6262  {
     
    6666      $current_uppercat = $row['id_uppercat'];
    6767    }
    68     $query = '
    69 UPDATE '.CATEGORIES_TABLE.'
    70   SET rank = '.++$current_rank.'
    71   WHERE id = '.$row['id'].'
    72 ;';
    73     pwg_query($query);
    74   }
    75   // global rank update
    76   $query = '
    77 UPDATE '.CATEGORIES_TABLE.'
    78   SET global_rank = rank
    79   WHERE id_uppercat IS NULL
    80 ;';
    81   pwg_query($query);
    82 
    83   $query = '
    84 SELECT DISTINCT(id_uppercat)
    85   FROM '.CATEGORIES_TABLE.'
    86   WHERE id_uppercat IS NOT NULL
    87 ;';
    88   $result = pwg_query($query);
    89   while ($row = mysql_fetch_array($result))
    90   {
    91     $query = '
    92 SELECT global_rank
    93   FROM '.CATEGORIES_TABLE.'
    94   WHERE id = '.$row['id_uppercat'].'
    95 ;';
    96     list($uppercat_global_rank) = mysql_fetch_array(pwg_query($query));
    97     $query = '
    98 UPDATE '.CATEGORIES_TABLE.'
    99   SET global_rank = CONCAT(\''.$uppercat_global_rank.'\', \'.\', rank)
    100   WHERE id_uppercat = '.$row['id_uppercat'].'
    101 ;';
    102     pwg_query($query);
    103   }
     68    $data = array('id' => $row['id'], 'rank' => ++$current_rank);
     69    array_push($datas, $data);
     70  }
     71
     72  $fields = array('primary' => array('id'), 'update' => array('rank'));
     73  mass_updates(CATEGORIES_TABLE, $fields, $datas);
    10474}
    10575
     
    651621  $start = get_moment();
    652622  ordering();
     623  update_global_rank();
    653624  echo get_elapsed_time($start, get_moment()).' for ordering categories<br />';
    654625}
Note: See TracChangeset for help on using the changeset viewer.