From e6e7465b9d285b42e7ea3c61fe0c0c7b93f57d19 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 26 Dec 2016 23:24:29 +0100 Subject: [PATCH 1/5] fixes #593, delete by blocks of 100 photos, with a progress bar --- admin/batch_manager_global.php | 7 +- admin/themes/default/js/batchManagerGlobal.js | 99 +++++++++++++++++++ .../default/template/batch_manager_global.tpl | 4 +- include/ws_functions/pwg.images.php | 16 ++- ws.php | 3 +- 5 files changed, 122 insertions(+), 7 deletions(-) diff --git a/admin/batch_manager_global.php b/admin/batch_manager_global.php index 5453d447f..374041b9a 100644 --- a/admin/batch_manager_global.php +++ b/admin/batch_manager_global.php @@ -361,12 +361,13 @@ DELETE { if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) { - $deleted_count = delete_elements($collection, true); - if ($deleted_count > 0) + // now done with ajax calls, with blocks + // $deleted_count = delete_elements($collection, true); + if (count($collection) > 0) { $_SESSION['page_infos'][] = l10n_dec( '%d photo was deleted', '%d photos were deleted', - $deleted_count + count($collection) ); $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; diff --git a/admin/themes/default/js/batchManagerGlobal.js b/admin/themes/default/js/batchManagerGlobal.js index fc8d094ab..ce483204f 100644 --- a/admin/themes/default/js/batchManagerGlobal.js +++ b/admin/themes/default/js/batchManagerGlobal.js @@ -215,3 +215,102 @@ function selectDelDerivAll() { function selectDelDerivNone() { $("#action_delete_derivatives input[type=checkbox]").prop("checked", false); } + +/* delete photos by blocks, with progress bar */ +jQuery('#applyAction').click(function(e) { + if (typeof(elements) != "undefined") { + return true; + } + + if (jQuery('[name="selectAction"]').val() == 'delete') { + if (!jQuery("#action_delete input[name=confirm_deletion]").is(':checked')) { + jQuery("#action_delete span.errors").show(); + return false; + } + e.stopPropagation(); + } + else { + return true; + } + + jQuery('.bulkAction').hide(); + jQuery('#regenerationText').html(lang.deleteProgressMessage); + var maxRequests=1; + + var queuedManager = jQuery.manageAjax.create('queued', { + queue: true, + cacheResponse: false, + maxRequests: maxRequests + }); + + elements = Array(); + + if (jQuery('input[name=setSelected]').is(':checked')) { + elements = all_elements; + } + else { + jQuery('input[name="selection[]"]').filter(':checked').each(function() { + elements.push(jQuery(this).val()); + }); + } + + progressBar_max = elements.length; + var todo = 0; + var deleteBlockSize = 100; + var image_ids = Array(); + + jQuery('#applyActionBlock').hide(); + jQuery('select[name="selectAction"]').hide(); + jQuery('#regenerationMsg').show(); + jQuery('#progressBar').progressBar(0, { + max: progressBar_max, + textFormat: 'fraction', + boxImage: 'themes/default/images/progressbar.gif', + barImage: 'themes/default/images/progressbg_orange.gif' + }); + + for (i=0;i
-

+

{* also used for "move" action *} diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index 1d9d0cbd4..58dae7857 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -1739,6 +1739,20 @@ function ws_images_delete($params, $service) include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); delete_elements($image_ids, true); invalidate_user_cache(); + + if ($params['return_details']) + { + return array( + 'success' => true, + 'details' => array( + 'nb_processed' => count($image_ids), + ), + ); + } + else + { + return true; + } } /** @@ -1760,4 +1774,4 @@ function ws_images_checkUpload($params, $service) return $ret; } -?> \ No newline at end of file +?> diff --git a/ws.php b/ws.php index 1aff64897..16329635b 100644 --- a/ws.php +++ b/ws.php @@ -504,6 +504,7 @@ function ws_addDefaultMethods( $arr ) array( 'image_id' => array('flags'=>WS_PARAM_ACCEPT_ARRAY), 'pwg_token' => array(), + 'return_details' => array('default'=>false, 'type'=>WS_TYPE_BOOL), ), 'Deletes image(s).', $ws_functions_root . 'pwg.images.php', @@ -1024,4 +1025,4 @@ enabled_high, registration_date, registration_date_string, registration_date_sin ); } -?> \ No newline at end of file +?> From ba3ddf01ff58f4e223c48949ca522b91e7fcec0a Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 9 Jan 2017 14:07:03 +0100 Subject: [PATCH 2/5] feature #593, use the standard pwg_token available in the form --- admin/themes/default/js/batchManagerGlobal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/themes/default/js/batchManagerGlobal.js b/admin/themes/default/js/batchManagerGlobal.js index ce483204f..27c80103d 100644 --- a/admin/themes/default/js/batchManagerGlobal.js +++ b/admin/themes/default/js/batchManagerGlobal.js @@ -280,7 +280,7 @@ jQuery('#applyAction').click(function(e) { url: 'ws.php?format=json', data: { method: "pwg.images.delete", - pwg_token: wm_pwg_token, + pwg_token: jQuery("input[name=pwg_token").val(), return_details: true, image_id: image_ids }, From 3fb56511437d067e7b6023bd6eb6d0ec4c61aaf7 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 9 Jan 2017 14:07:47 +0100 Subject: [PATCH 3/5] feature #593, send image_ids as a coma separated string ... instead of a list, because default behavior of web servers is to limit the number of input fields and we don't want such a limit. --- admin/themes/default/js/batchManagerGlobal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/themes/default/js/batchManagerGlobal.js b/admin/themes/default/js/batchManagerGlobal.js index 27c80103d..10ece3508 100644 --- a/admin/themes/default/js/batchManagerGlobal.js +++ b/admin/themes/default/js/batchManagerGlobal.js @@ -282,7 +282,7 @@ jQuery('#applyAction').click(function(e) { method: "pwg.images.delete", pwg_token: jQuery("input[name=pwg_token").val(), return_details: true, - image_id: image_ids + image_id: image_ids.join(',') }, dataType: 'json', success: ( function(data) { todo += data.result.details.nb_processed; progressDelete(todo, progressBar_max, data.result.success) }), From edff7540eb58ee5d1bf7a70c1a9a7e26d8884938 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 9 Jan 2017 14:10:39 +0100 Subject: [PATCH 4/5] feature #593, dynamic bloc size instead of fixed at 100. 1000 by default or half of the element list. The action should alway require at least 2 ajax calls, even for 2 photos to delete (exception for 1 photo, of course) --- admin/themes/default/js/batchManagerGlobal.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/admin/themes/default/js/batchManagerGlobal.js b/admin/themes/default/js/batchManagerGlobal.js index 10ece3508..26e174b50 100644 --- a/admin/themes/default/js/batchManagerGlobal.js +++ b/admin/themes/default/js/batchManagerGlobal.js @@ -256,7 +256,10 @@ jQuery('#applyAction').click(function(e) { progressBar_max = elements.length; var todo = 0; - var deleteBlockSize = 100; + var deleteBlockSize = Math.min( + Number((elements.length/2).toFixed()), + 1000 + ); var image_ids = Array(); jQuery('#applyActionBlock').hide(); From 743bbb61f4a09e23bf55e2d363284401210b255e Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 9 Jan 2017 14:33:26 +0100 Subject: [PATCH 5/5] feature #593, simplify detailed output for pwg.images.delete --- admin/themes/default/js/batchManagerGlobal.js | 13 ++++++++----- include/ws_functions/pwg.images.php | 11 ++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/admin/themes/default/js/batchManagerGlobal.js b/admin/themes/default/js/batchManagerGlobal.js index 26e174b50..803402dbe 100644 --- a/admin/themes/default/js/batchManagerGlobal.js +++ b/admin/themes/default/js/batchManagerGlobal.js @@ -288,8 +288,14 @@ jQuery('#applyAction').click(function(e) { image_id: image_ids.join(',') }, dataType: 'json', - success: ( function(data) { todo += data.result.details.nb_processed; progressDelete(todo, progressBar_max, data.result.success) }), - error: ( function(data) { todo += data.result.details.nb_processed; progressDelete(todo, progressBar_max, false) }) + success: ( function(data) { + todo += data.result.nb_processed; + progressDelete(todo, progressBar_max, true) + }), + error: ( function(data) { + todo += deleteBlockSize; // TODO: might be not exact, if last query + progressDelete(todo, progressBar_max, false) + }) }); image_ids = Array(); @@ -304,9 +310,6 @@ function progressDelete(val, max, success) { boxImage: 'themes/default/images/progressbar.gif', barImage: 'themes/default/images/progressbg_orange.gif' }); - type = success ? 'regenerateSuccess': 'regenerateError' - s = jQuery('[name="'+type+'"]').val(); - jQuery('[name="'+type+'"]').val(++s); if (val == max) { jQuery('#applyAction').click(); diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index 58dae7857..b6647c8b5 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -1743,15 +1743,8 @@ function ws_images_delete($params, $service) if ($params['return_details']) { return array( - 'success' => true, - 'details' => array( - 'nb_processed' => count($image_ids), - ), - ); - } - else - { - return true; + 'nb_processed' => count($image_ids), + ); } }