From fb84527e3b11334150498d11c416cedb6a21dbb5 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 15 Sep 2021 13:47:41 +0200 Subject: [PATCH] issue #164 add new API method pwg.images.uploadCompleted + trigger ws_images_uploadCompleted when this API method is called + trigger empty_lounge (can be called at another moment with different effect) --- admin/include/functions.php | 6 ++- .../default/template/photos_add_direct.tpl | 6 ++- include/ws_functions/pwg.images.php | 53 ++++++++++++++++++- tools/triggers_list.php | 14 +++++ ws.php | 13 +++++ 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/admin/include/functions.php b/admin/include/functions.php index d2b5b8ca7..0486a28e1 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -1961,7 +1961,6 @@ INSERT IGNORE return; } $logger->debug(__FUNCTION__.', exec='.$exec_id.' wins the race and gets the token!'); - sleep(5); $max_image_id = 0; @@ -2008,7 +2007,10 @@ DELETE conf_delete_param('empty_lounge_running'); $logger->debug(__FUNCTION__.', exec='.$exec_id.', ends'); - return count($rows); + + trigger_notify('empty_lounge', $rows); + + return $rows; } /** diff --git a/admin/themes/default/template/photos_add_direct.tpl b/admin/themes/default/template/photos_add_direct.tpl index 5ea533c31..d0c20132e 100644 --- a/admin/themes/default/template/photos_add_direct.tpl +++ b/admin/themes/default/template/photos_add_direct.tpl @@ -223,10 +223,12 @@ jQuery(document).ready(function(){ Piecon.reset(); jQuery.ajax({ - url: "ws.php?format=json&method=pwg.images.emptyLounge", + url: "ws.php?format=json&method=pwg.images.uploadCompleted", type:"POST", data: { - pwg_token: pwg_token + pwg_token: pwg_token, + image_id: uploadedPhotos.join(","), + category_id: uploadCategory.id, } }); diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index ecb3ccd57..302db82d6 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -2106,11 +2106,62 @@ function ws_images_emptyLounge($params, $service) { include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); - $ret = array('count' => empty_lounge()); + $ret = array('rows' => empty_lounge()); return $ret; } +/** + * API method + * Empties the lounge, where photos may wait before taking off. + * @since 12 + * @param mixed[] $params + */ +function ws_images_uploadCompleted($params, $service) +{ + include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); + + if (get_pwg_token() != $params['pwg_token']) + { + return new PwgError(403, 'Invalid security token'); + } + + if (!is_array($params['image_id'])) + { + $params['image_id'] = preg_split( + '/[\s,;\|]/', + $params['image_id'], + -1, + PREG_SPLIT_NO_EMPTY + ); + } + $params['image_id'] = array_map('intval', $params['image_id']); + + $image_ids = array(); + foreach ($params['image_id'] as $image_id) + { + if ($image_id > 0) + { + $image_ids[] = $image_id; + } + } + + // the list of images moved from the lounge might not be the same than + // $image_ids (canbe a subset or more image_ids from another upload too) + $moved_from_lounge = empty_lounge(); + + trigger_notify( + 'ws_images_uploadCompleted', + array( + 'image_ids' => $image_ids, + 'category_id' => $params['category_id'], + 'moved_from_lounge' => $moved_from_lounge, + ) + ); + + return array('moved_from_lounge' => $moved_from_lounge); +} + /** * API method * add md5sum at photos, by block. Returns how md5sum were added and how many are remaining. diff --git a/tools/triggers_list.php b/tools/triggers_list.php index 2b3b05035..e0abd6a1d 100644 --- a/tools/triggers_list.php +++ b/tools/triggers_list.php @@ -468,6 +468,20 @@ array( 'files' => array('admin\include\functions_upload.inc.php (add_uploaded_file)'), 'infos' => 'New in 2.11', ), +array( + 'name' => 'empty_lounge', + 'type' => 'trigger_notify', + 'vars' => array('array', 'rows'), + 'files' => array('admin\include\functions.php (empty_lounge)'), + 'infos' => 'New in 12', +), +array( + 'name' => 'ws_images_uploadCompleted', + 'type' => 'trigger_notify', + 'vars' => array('array', 'upload_data'), + 'files' => array('include\ws_functions\pwg.images.php (ws_images_uploadCompleted)'), + 'infos' => 'New in 12', +), array( 'name' => 'loc_end_password', 'type' => 'trigger_notify', diff --git a/ws.php b/ws.php index 3e2e0daae..848174048 100644 --- a/ws.php +++ b/ws.php @@ -817,6 +817,19 @@ function ws_addDefaultMethods( $arr ) array('admin_only'=>true) ); + $service->addMethod( + 'pwg.images.uploadCompleted', + 'ws_images_uploadCompleted', + array( + 'image_id' => array('default'=>null, 'flags'=>WS_PARAM_ACCEPT_ARRAY), + 'pwg_token' => array(), + 'category_id' => array('default'=>null, 'type'=>WS_TYPE_ID), + ), + 'Notifiy Piwigo you have finished to upload a set of photos. It will empty the lounge, if any.', + $ws_functions_root . 'pwg.images.php', + array('admin_only'=>true) + ); + $service->addMethod( 'pwg.images.setInfo', 'ws_images_setInfo',