From bbe117080de593376007b89e76384bf449f1a004 Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 23 Feb 2016 15:58:31 +0100 Subject: feature #321, set status with pwg.categories.setInfos --- include/ws_functions/pwg.categories.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'include') diff --git a/include/ws_functions/pwg.categories.php b/include/ws_functions/pwg.categories.php index 9c337f7c2..502c8f18d 100644 --- a/include/ws_functions/pwg.categories.php +++ b/include/ws_functions/pwg.categories.php @@ -591,6 +591,33 @@ function ws_categories_add($params, &$service) */ function ws_categories_setInfo($params, &$service) { + // does the category really exist? + $query = ' +SELECT * + FROM '.CATEGORIES_TABLE.' + WHERE id = '.$params['category_id'].' +;'; + $categories = query2array($query); + if (count($categories) == 0) + { + return new PwgError(404, 'category_id not found'); + } + + $category = $categories[0]; + + if (!empty($params['status'])) + { + if (!in_array($params['status'], array('private','public'))) + { + return new PwgError(WS_ERR_INVALID_PARAM, "Invalid status, only public/private"); + } + + if ($params['status'] != $category['status']) + { + set_cat_status(array($params['category_id']), $params['status']); + } + } + $update = array( 'id' => $params['category_id'], ); -- cgit v1.2.3