fixes #2007 no longer possible to update a filteredSearch

* Piwigo will create a new search for any modification in the filters
* we keep the "origin" of the new search with piwigo_search.forked_from field
This commit is contained in:
plegall
2023-09-27 16:30:05 +02:00
parent 61492d092e
commit fdd2177e78
5 changed files with 38 additions and 50 deletions

View File

@@ -67,14 +67,6 @@ function get_search_array($search_id)
{
bad_request('this search identifier does not exist');
}
else
{
if (!empty($search['created_by']) and $search['created_by'] != $user['user_id'])
{
// we need to fork this search
save_search_and_redirect(unserialize($search['rules']), $search['id']);
}
}
return unserialize($search['rules']);
}
@@ -1726,7 +1718,7 @@ SELECT
}
}
function save_search_and_redirect($rules, $forked_from=null)
function save_search($rules, $forked_from=null)
{
global $user;
@@ -1745,14 +1737,14 @@ function save_search_and_redirect($rules, $forked_from=null)
)
);
redirect(
make_index_url(
array(
'section' => 'search',
'search' => $search_uuid,
)
$url = make_index_url(
array(
'section' => 'search',
'search' => $search_uuid,
)
);
return array($search_uuid, $url);
}
?>

View File

@@ -690,34 +690,29 @@ SELECT *
/**
* API method
* Returns a list of elements corresponding to a query search
* Registers a new search
* @param mixed[] $params
* @option string query
* @option int per_page
* @option int page
* @option string order (optional)
*/
function ws_images_filteredSearch_update($params, $service)
function ws_images_filteredSearch_create($params, $service)
{
global $user;
include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php');
// * check the search exists
if (empty(get_search_id_pattern($params['search_id'])))
if (isset($params['search_id']))
{
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid search_id input parameter.');
}
if (empty(get_search_id_pattern($params['search_id'])))
{
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid search_id input parameter.');
}
$search_info = get_search_info($params['search_id']);
if (empty($search_info))
{
return new PwgError(WS_ERR_INVALID_PARAM, 'This search does not exist.');
}
if (!empty($search_info['created_by']) and $search_info['created_by'] != $user['user_id'])
{
return new PwgError(WS_ERR_INVALID_PARAM, 'This search was created by another user.');
$search_info = get_search_info($params['search_id']);
if (empty($search_info))
{
return new PwgError(WS_ERR_INVALID_PARAM, 'This search does not exist.');
}
}
$search = array('mode' => 'AND');
@@ -846,15 +841,12 @@ function ws_images_filteredSearch_update($params, $service)
$search['fields']['date_posted'] = $params['date_posted'];
}
// register search rules in database, then they will be available on
// thumbnails page and picture page.
$query ='
UPDATE '.SEARCH_TABLE.'
SET rules = \''.pwg_db_real_escape_string(serialize($search)).'\'
, last_seen = NOW()
WHERE id = '.$search_info['id'].'
;';
pwg_query($query);
list($search_uuid, $search_url) = save_search($search, $search_info['id'] ?? null);
return array(
'search_id' => $search_uuid,
'search_url' => $search_url,
);
}
/**

View File

@@ -92,5 +92,6 @@ if (count($first_author) > 0)
);
}
save_search_and_redirect($search);
list($search_uuid, $search_url) = save_search($search);
redirect($search_url);
?>

View File

@@ -700,13 +700,13 @@ $(document).ready(function () {
function performSearch(params, reload = false) {
$.ajax({
url: "ws.php?format=json&method=pwg.images.filteredSearch.update",
url: "ws.php?format=json&method=pwg.images.filteredSearch.create",
type:"POST",
dataType: "json",
data: params,
success:function(data) {
if (reload) {
reloadPage();
if (reload && typeof data.result.search_url !== 'undefined') {
reloadPage(data.result.search_url);
}
},
error:function(e) {
@@ -842,6 +842,6 @@ function updateFilters(filterName, mode) {
}
}
function reloadPage(){
location.reload(true);
function reloadPage(url){
window.location.href = url;
}

9
ws.php
View File

@@ -1369,10 +1369,13 @@ enabled_high, registration_date, registration_date_string, registration_date_sin
);
$service->addMethod(
'pwg.images.filteredSearch.update',
'ws_images_filteredSearch_update',
'pwg.images.filteredSearch.create',
'ws_images_filteredSearch_create',
array(
'search_id' => array(),
'search_id' => array(
'flags' => WS_PARAM_OPTIONAL,
'info' => 'prior search_id (or search_key), if any',
),
'allwords' => array(
'flags' => WS_PARAM_OPTIONAL,
'info' => 'query to search by words',