aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/ws_functions.inc.php55
-rw-r--r--ws.php7
2 files changed, 43 insertions, 19 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index d41a4129d..7b25a045f 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -1665,13 +1665,6 @@ function ws_images_setInfo($params, &$service)
return new PwgError(401, 'Access denied');
}
- // name
- // category_id
- // file_content
- // file_sum
- // thumbnail_content
- // thumbnail_sum
-
$params['image_id'] = (int)$params['image_id'];
if ($params['image_id'] <= 0)
{
@@ -1691,9 +1684,7 @@ SELECT *
}
// database registration
- $update = array(
- 'id' => $params['image_id'],
- );
+ $update = array();
$info_columns = array(
'name',
@@ -1703,18 +1694,38 @@ SELECT *
'date_creation',
);
- $perform_update = false;
foreach ($info_columns as $key)
{
if (isset($params[$key]))
{
- $perform_update = true;
- $update[$key] = $params[$key];
+ if ('fill_if_empty' == $params['single_value_mode'])
+ {
+ if (empty($image_row[$key]))
+ {
+ $update[$key] = $params[$key];
+ }
+ }
+ elseif ('replace' == $params['single_value_mode'])
+ {
+ $update[$key] = $params[$key];
+ }
+ else
+ {
+ new PwgError(
+ 500,
+ '[ws_images_setInfo]'
+ .' invalid parameter single_value_mode "'.$params['single_value_mode'].'"'
+ .', possible values are {fill_if_empty, replace}.'
+ );
+ exit();
+ }
}
}
- if ($perform_update)
+ if (count(array_keys($update)) > 0)
{
+ $update['id'] = $params['image_id'];
+
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
mass_updates(
IMAGES_TABLE,
@@ -1731,7 +1742,7 @@ SELECT *
ws_add_image_category_relations(
$params['image_id'],
$params['categories'],
- $params['replace_mode']
+ ('replace' == $params['multiple_value_mode'] ? true : false)
);
}
@@ -1742,20 +1753,30 @@ SELECT *
$tag_ids = explode(',', $params['tag_ids']);
- if ($params['replace_mode'])
+ if ('replace' == $params['multiple_value_mode'])
{
set_tags(
$tag_ids,
$params['image_id']
);
}
- else
+ elseif ('append' == $params['multiple_value_mode'])
{
add_tags(
$tag_ids,
array($params['image_id'])
);
}
+ else
+ {
+ new PwgError(
+ 500,
+ '[ws_images_setInfo]'
+ .' invalid parameter multiple_value_mode "'.$params['multiple_value_mode'].'"'
+ .', possible values are {replace, append}.'
+ );
+ exit();
+ }
}
invalidate_user_cache();
diff --git a/ws.php b/ws.php
index 003ead80e..f4d1ce029 100644
--- a/ws.php
+++ b/ws.php
@@ -289,10 +289,13 @@ function ws_addDefaultMethods( $arr )
'default' => 0,
'maxValue' => $conf['available_permission_levels']
),
- 'replace_mode' => array('default' => false),
+ 'single_value_mode' => array('default' => 'fill_if_empty'),
+ 'multiple_value_mode' => array('default' => 'append'),
),
'POST method only. Admin only
-<br/><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.'
+<br/><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.
+<br/><b>single_value_mode</b> can be "fill_if_empty" (only use the input value if the corresponding values is currently empty) or "replace" (overwrite any existing value) and applies to single values properties like name/author/date_creation/comment
+<br/><b>multiple_value_mode</b> can be "append" (no change on existing values, add the new values) or "replace" and applies to multiple values properties like tag_ids/categories'
);
$service->addMethod(