mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-07-06 01:42:29 +02:00
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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user