aboutsummaryrefslogtreecommitdiffstats
path: root/admin/update.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2004-11-30 20:26:44 +0000
committerplegall <plg@piwigo.org>2004-11-30 20:26:44 +0000
commit759b1e883999c12f7f59865e4fd8c5aea7e90885 (patch)
treeb8e7e52a65c5277f2cb4cd7890d77ae468e9b633 /admin/update.php
parent514bac91c66f6eaff63380ec544fe5bccfdebed4 (diff)
- 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 git-svn-id: http://piwigo.org/svn/trunk@625 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/update.php43
1 files changed, 7 insertions, 36 deletions
diff --git a/admin/update.php b/admin/update.php
index ac364e465..45bef3bce 100644
--- a/admin/update.php
+++ b/admin/update.php
@@ -42,8 +42,7 @@ define('CURRENT_DATE', date('Y-m-d'));
* the purpose of this function is to give a rank for all categories
* (insides its sub-category), even the newer that have none at te
* beginning. For this, ordering function selects all categories ordered by
- * rank ASC then name ASC for each uppercat. It also updates the global rank
- * which is able to order any two categorie in the whole tree
+ * rank ASC then name ASC for each uppercat.
*
* @returns void
*/
@@ -58,6 +57,7 @@ SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat
ORDER BY id_uppercat,rank,name
;';
$result = pwg_query($query);
+ $datas = array();
while ($row = mysql_fetch_array($result))
{
if ($row['id_uppercat'] != $current_uppercat)
@@ -65,42 +65,12 @@ SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat
$current_rank = 0;
$current_uppercat = $row['id_uppercat'];
}
- $query = '
-UPDATE '.CATEGORIES_TABLE.'
- SET rank = '.++$current_rank.'
- WHERE id = '.$row['id'].'
-;';
- pwg_query($query);
+ $data = array('id' => $row['id'], 'rank' => ++$current_rank);
+ array_push($datas, $data);
}
- // global rank update
- $query = '
-UPDATE '.CATEGORIES_TABLE.'
- SET global_rank = rank
- WHERE id_uppercat IS NULL
-;';
- pwg_query($query);
- $query = '
-SELECT DISTINCT(id_uppercat)
- FROM '.CATEGORIES_TABLE.'
- WHERE id_uppercat IS NOT NULL
-;';
- $result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
- {
- $query = '
-SELECT global_rank
- FROM '.CATEGORIES_TABLE.'
- WHERE id = '.$row['id_uppercat'].'
-;';
- list($uppercat_global_rank) = mysql_fetch_array(pwg_query($query));
- $query = '
-UPDATE '.CATEGORIES_TABLE.'
- SET global_rank = CONCAT(\''.$uppercat_global_rank.'\', \'.\', rank)
- WHERE id_uppercat = '.$row['id_uppercat'].'
-;';
- pwg_query($query);
- }
+ $fields = array('primary' => array('id'), 'update' => array('rank'));
+ mass_updates(CATEGORIES_TABLE, $fields, $datas);
}
function insert_local_category($id_uppercat)
@@ -650,6 +620,7 @@ else if (isset($_POST['submit'])
echo get_elapsed_time($start,get_moment()).' for update_category(all)<br />';
$start = get_moment();
ordering();
+ update_global_rank();
echo get_elapsed_time($start, get_moment()).' for ordering categories<br />';
}
// +-----------------------------------------------------------------------+