Changeset 2303


Ignore:
Timestamp:
Apr 19, 2008, 4:59:18 AM (16 years ago)
Author:
rvelices
Message:
  • removed some unused code
  • mass_updates function does not need SELECT VERSION()
  • rewrote update_uppercats to avoid db update if no change
File:
1 edited

Legend:

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

    r2094 r2303  
    6363function delete_categories($ids)
    6464{
    65   global $counts;
    66 
    6765  if (count($ids) == 0)
    6866  {
     
    125123  pwg_query($query);
    126124
    127   if (isset($counts['del_categories']))
    128   {
    129     $counts['del_categories']+= count($ids);
    130   }
    131125  trigger_action('delete_categories', $ids);
    132126}
     
    139133function delete_elements($ids)
    140134{
    141   global $counts;
    142 
    143135  if (count($ids) == 0)
    144136  {
     
    202194  pwg_query($query);
    203195
    204   if (isset($counts['del_elements']))
    205   {
    206     $counts['del_elements']+= count($ids);
    207   }
    208196  trigger_action('delete_elements', $ids);
    209197}
     
    579567    // depending on the MySQL version, we use the multi table update or N
    580568    // update queries
    581     $query = 'SELECT VERSION() AS version;';
    582     list($mysql_version) = mysql_fetch_array(pwg_query($query));
    583     if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0)
     569    if (count($datas) < 10 or version_compare(mysql_get_server_info(), '4.0.4') < 0)
    584570    {
    585571      // MySQL is prior to version 4.0.4, multi table update feature is not
     
    11881174function update_uppercats()
    11891175{
    1190   $uppercat_ids = array();
    1191 
    1192   $query = '
    1193 SELECT id, id_uppercat
     1176  $query = '
     1177SELECT id, id_uppercat, uppercats
    11941178  FROM '.CATEGORIES_TABLE.'
    11951179;';
    1196   $result = pwg_query($query);
    1197   while ($row = mysql_fetch_array($result))
    1198   {
    1199     $uppercat_ids[$row['id']] =
    1200       !empty($row['id_uppercat']) ? $row['id_uppercat'] : 'NULL';
    1201   }
    1202 
    1203   // uppercats array associates a category id to the list of uppercats id.
    1204   $uppercats = array();
    1205 
    1206   foreach (array_keys($uppercat_ids) as $id)
    1207   {
    1208     $uppercats[$id] = array();
     1180  $cat_map = hash_from_query($query, 'id');
     1181
     1182  $datas = array();
     1183  foreach ($cat_map as $id => $cat)
     1184  {
     1185    $upper_list = array();
    12091186
    12101187    $uppercat = $id;
    1211 
    1212     while ($uppercat != 'NULL')
    1213     {
    1214       array_push($uppercats[$id], $uppercat);
    1215       $uppercat = $uppercat_ids[$uppercat];
    1216     }
    1217   }
    1218 
    1219   $datas = array();
    1220 
    1221   foreach ($uppercats as $id => $list)
    1222   {
    1223     array_push(
    1224       $datas,
    1225       array(
    1226         'id' => $id,
    1227         'uppercats' => implode(',', array_reverse($list))
    1228         )
    1229       );
    1230   }
    1231 
     1188    while ($uppercat)
     1189    {
     1190      array_push($upper_list, $uppercat);
     1191      $uppercat = $cat_map[$uppercat]['id_uppercat'];
     1192    }
     1193
     1194    $new_uppercats = implode(',', array_reverse($upper_list));
     1195    if ($new_uppercats != $cat['uppercats'])
     1196    {
     1197      array_push(
     1198        $datas,
     1199        array(
     1200          'id' => $id,
     1201          'uppercats' => $new_uppercats
     1202          )
     1203        );
     1204    }
     1205  }
    12321206  $fields = array('primary' => array('id'), 'update' => array('uppercats'));
    12331207  mass_updates(CATEGORIES_TABLE, $fields, $datas);
Note: See TracChangeset for help on using the changeset viewer.