From 858b43e87a9911269505c1fbc9036b374e89a565 Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 22 Nov 2009 23:58:44 +0000 Subject: merge r4344 from branch 2.0 to trunk feature 1051: new API method pwg.images.checkFiles. This method will be useful before asking for an update on photo files. Enhancement in code factorization. git-svn-id: http://piwigo.org/svn/trunk@4347 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/ws_functions.inc.php | 104 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 19 deletions(-) (limited to 'include/ws_functions.inc.php') diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index d6ea4f668..9e2040b96 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -989,25 +989,7 @@ function merge_chunks($output_filepath, $original_sum, $type) */ function add_file($file_path, $type, $original_sum, $file_sum) { - // resolve the $file_path depending on the $type - if ('thumb' == $type) { - $file_path = get_thumbnail_location( - array( - 'path' => $file_path, - 'tn_ext' => 'jpg', - ) - ); - } - - if ('high' == $type) { - @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); - $file_path = get_high_location( - array( - 'path' => $file_path, - 'has_high' => 'true' - ) - ); - } + $file_path = file_path_for_type($file_path, $type); $upload_dir = dirname($file_path); @@ -1501,6 +1483,90 @@ SELECT return $result; } +function ws_images_checkFiles($params, &$service) +{ + if (!is_admin() or is_adviser()) + { + return new PwgError(401, 'Access denied'); + } + + // input parameters + // + // image_id + // thumbnail_sum + // file_sum + // high_sum + + $params['image_id'] = (int)$params['image_id']; + if ($params['image_id'] <= 0) + { + return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id"); + } + + $query = ' +SELECT + path + FROM '.IMAGES_TABLE.' + WHERE id = '.$params['image_id'].' +;'; + $result = pwg_query($query); + if (mysql_num_rows($result) == 0) { + return new PwgError(404, "image_id not found"); + } + list($path) = mysql_fetch_row($result); + + $ret = array(); + + foreach (array('thumb', 'file', 'high') as $type) { + $param_name = $type; + if ('thumb' == $type) { + $param_name = 'thumbnail'; + } + + if (isset($params[$param_name.'_sum'])) { + $type_path = file_path_for_type($path, $type); + if (!is_file($type_path)) { + $ret[$param_name] = 'missing'; + } + else { + if (md5_file($type_path) != $params[$param_name.'_sum']) { + $ret[$param_name] = 'differs'; + } + else { + $ret[$param_name] = 'equals'; + } + } + } + } + + return $ret; +} + +function file_path_for_type($file_path, $type='thumb') +{ + // resolve the $file_path depending on the $type + if ('thumb' == $type) { + $file_path = get_thumbnail_location( + array( + 'path' => $file_path, + 'tn_ext' => 'jpg', + ) + ); + } + + if ('high' == $type) { + @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); + $file_path = get_high_location( + array( + 'path' => $file_path, + 'has_high' => 'true' + ) + ); + } + + return $file_path; +} + function ws_images_setInfo($params, &$service) { global $conf; -- cgit v1.2.3