aboutsummaryrefslogtreecommitdiffstats
path: root/include/ws_functions.inc.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2009-11-22 22:09:41 +0000
committerplegall <plg@piwigo.org>2009-11-22 22:09:41 +0000
commit6768482bcf5ba73a1fd429a1584134c2b213044d (patch)
treeec2e97b7c785c50312c63d18a792c75fb0cf8c49 /include/ws_functions.inc.php
parent2bba9bc48a96378668bb460b11c5bcdd48a33669 (diff)
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/branches/2.0@4344 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/ws_functions.inc.php')
-rw-r--r--include/ws_functions.inc.php104
1 files changed, 85 insertions, 19 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index bd5fb8418..a01322547 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;