From 484a431a7e257ab6f8484a9e4100d70657da17ea Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 5 Dec 2004 22:02:36 +0000 Subject: if all links between a category and elements have disappeared, no line is returned by the update_category query but the update must be done with nb_images = 0 and date_last = NULL git-svn-id: http://piwigo.org/svn/trunk@637 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/admin/include/functions.php b/admin/include/functions.php index 0d2972740..987cddb9a 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -504,15 +504,24 @@ SELECT category_id, FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id WHERE category_id IN ('.implode(',', $cat_ids).') GROUP BY category_id -'; +;'; $result = pwg_query($query); $datas = array(); + $query_ids = array(); while ( $row = mysql_fetch_array( $result ) ) { + array_push($query_ids, $row['category_id']); array_push($datas, array('id' => $row['category_id'], 'date_last' => $row['date_last'], 'nb_images' => $row['nb_images'])); } + // if all links between a category and elements have disappeared, no line + // is returned but the update must be done ! + foreach (array_diff($cat_ids, $query_ids) as $id) + { + array_push($datas, array('id' => $id, 'nb_images' => 0)); + } + $fields = array('primary' => array('id'), 'update' => array('date_last', 'nb_images')); mass_updates(CATEGORIES_TABLE, $fields, $datas); -- cgit v1.2.3