empty tag list in batch manager causes notices #968

Open
opened 2026-10-05 00:26:00 +02:00 by adam · 0 comments
Owner

If you go to Batch Manager and add a Tag filter but then don't enter any tags, it generates a number of notices, especially in PHP 7.2+
Fix:

diff --git a/admin/batch_manager.php b/admin/batch_manager.php
index e6c14b63c..86733db38 100644
--- a/admin/batch_manager.php
+++ b/admin/batch_manager.php
@@ -137,7 +137,8 @@ if (isset($_POST['submitFilter']))
 
   if (isset($_POST['filter_tags_use']))
   {
-    $_SESSION['bulk_manager_filter']['tags'] = get_tag_ids($_POST['filter_tags'], false);
+    if (empty($_POST['filter_tags'])) $_SESSION['bulk_manager_filter']['tags'] = [];
+    else $_SESSION['bulk_manager_filter']['tags'] = get_tag_ids($_POST['filter_tags'], false);
 
     if (isset($_POST['tag_mode']) and in_array($_POST['tag_mode'], array('AND', 'OR')))
     {
diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php
index 7c3078a82..abb0967ae 100644
--- a/admin/batch_manager_global.php
+++ b/admin/batch_manager_global.php
@@ -557,7 +557,7 @@ $template->assign('filter_category_selected', $selected_category);
 // categories can't be broken.
 $associated_categories = array();
 
-if (count($page['cat_elements_id']) > 0)
+if (!empty($page['cat_elements_id']))
 {
   $query = '
 SELECT
@@ -576,7 +576,7 @@ SELECT
 
 $template->assign('associated_categories', $associated_categories);
 
-if (count($page['cat_elements_id']) > 0)
+if (!empty($page['cat_elements_id']))
 {
   // remove tags
   $template->assign('associated_tags', get_common_tags($page['cat_elements_id'], -1));
@@ -648,7 +648,7 @@ else
 
 $nb_thumbs_page = 0;
 
-if (count($page['cat_elements_id']) > 0)
+if (!empty($page['cat_elements_id']))
 {
   $nav_bar = create_navigation_bar(
     $base_url.get_query_string_diff(array('start')),
@@ -739,7 +739,7 @@ SELECT id,path,representative_ext,file,filesize,level,name,width,height,rotation
 
 $template->assign(array(
   'nb_thumbs_page' => $nb_thumbs_page,
-  'nb_thumbs_set' => count($page['cat_elements_id']),
+  'nb_thumbs_set' => empty($page['cat_elements_id']) ? 0 : count($page['cat_elements_id']),
   'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories')),
   ));
If you go to Batch Manager and add a Tag filter but then don't enter any tags, it generates a number of notices, especially in PHP 7.2+ Fix: ```diff diff --git a/admin/batch_manager.php b/admin/batch_manager.php index e6c14b63c..86733db38 100644 --- a/admin/batch_manager.php +++ b/admin/batch_manager.php @@ -137,7 +137,8 @@ if (isset($_POST['submitFilter'])) if (isset($_POST['filter_tags_use'])) { - $_SESSION['bulk_manager_filter']['tags'] = get_tag_ids($_POST['filter_tags'], false); + if (empty($_POST['filter_tags'])) $_SESSION['bulk_manager_filter']['tags'] = []; + else $_SESSION['bulk_manager_filter']['tags'] = get_tag_ids($_POST['filter_tags'], false); if (isset($_POST['tag_mode']) and in_array($_POST['tag_mode'], array('AND', 'OR'))) { diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php index 7c3078a82..abb0967ae 100644 --- a/admin/batch_manager_global.php +++ b/admin/batch_manager_global.php @@ -557,7 +557,7 @@ $template->assign('filter_category_selected', $selected_category); // categories can't be broken. $associated_categories = array(); -if (count($page['cat_elements_id']) > 0) +if (!empty($page['cat_elements_id'])) { $query = ' SELECT @@ -576,7 +576,7 @@ SELECT $template->assign('associated_categories', $associated_categories); -if (count($page['cat_elements_id']) > 0) +if (!empty($page['cat_elements_id'])) { // remove tags $template->assign('associated_tags', get_common_tags($page['cat_elements_id'], -1)); @@ -648,7 +648,7 @@ else $nb_thumbs_page = 0; -if (count($page['cat_elements_id']) > 0) +if (!empty($page['cat_elements_id'])) { $nav_bar = create_navigation_bar( $base_url.get_query_string_diff(array('start')), @@ -739,7 +739,7 @@ SELECT id,path,representative_ext,file,filesize,level,name,width,height,rotation $template->assign(array( 'nb_thumbs_page' => $nb_thumbs_page, - 'nb_thumbs_set' => count($page['cat_elements_id']), + 'nb_thumbs_set' => empty($page['cat_elements_id']) ? 0 : count($page['cat_elements_id']), 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories')), )); ``` <!-- github-sync-id:516883455 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#968