From 4adf36f2e53c191160af2e2f43555424af036dd8 Mon Sep 17 00:00:00 2001 From: Linty Date: Mon, 19 Feb 2024 17:06:59 +0100 Subject: [PATCH] fixes #2120 add new return value to 'pwg.categories.move' method API Added a new return value for API method 'pwg.categories.move': updated_cats . This value returns an array of albums whose values have been modified after an album has been moved (for the moment, the data is the id and the number of photos in its sub-albums). --- include/ws_functions/pwg.categories.php | 37 +++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/include/ws_functions/pwg.categories.php b/include/ws_functions/pwg.categories.php index ab61d6d4d..4d9907690 100644 --- a/include/ws_functions/pwg.categories.php +++ b/include/ws_functions/pwg.categories.php @@ -1161,9 +1161,10 @@ function ws_categories_move($params, &$service) // we can't move physical categories $categories_in_db = array(); + $update_cat_ids = array(); $query = ' -SELECT id, name, dir +SELECT id, name, dir, uppercats FROM '. CATEGORIES_TABLE .' WHERE id IN ('. implode(',', $category_ids) .') ;'; @@ -1171,6 +1172,7 @@ SELECT id, name, dir while ($row = pwg_db_fetch_assoc($result)) { $categories_in_db[ $row['id'] ] = $row; + $update_cat_ids = array_merge($update_cat_ids, array_slice(explode(',', $row['uppercats']), 0, -1)); // we break on error at first physical category detected if (!empty($row['dir'])) @@ -1241,9 +1243,40 @@ SELECT id, name, dir $row['uppercats'], 'admin.php?page=album-' ); + $update_cat_ids = array_merge($update_cat_ids, array_slice(explode(',', $row['uppercats']), 0, -1)); } - return array('new_ariane_string' => $cat_display_name); + $query = ' +SELECT + category_id, + COUNT(*) AS nb_photos + FROM '.IMAGE_CATEGORY_TABLE.' + GROUP BY category_id +;'; + + $nb_photos_in = query2array($query, 'category_id', 'nb_photos'); + + $update_cats = []; + foreach (array_unique($update_cat_ids) as $update_cat) + { + $nb_sub_photos = 0; + $sub_cat_without_parent = array_diff(get_subcat_ids(array($update_cat)), array($update_cat)); + + foreach ($sub_cat_without_parent as $id_sub_cat) + { + $nb_sub_photos += isset($nb_photos_in[$id_sub_cat]) ? $nb_photos_in[$id_sub_cat] : 0; + } + + $update_cats[] = array( + 'cat_id' => $update_cat, + 'nb_sub_photos' => $nb_sub_photos, + ); + } + + return array( + 'new_ariane_string' => $cat_display_name, + 'updated_cats' => $update_cats, + ); } /**