Skip to content

Commit

Permalink
feature 889 added: pwg.images.exist check the existence of a photo in…
Browse files Browse the repository at this point in the history
… the

database based on its md5sum. (avoid failing on pwg.images.add).


git-svn-id: http://piwigo.org/svn/trunk@2683 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Oct 7, 2008
1 parent 42c665e commit 3eecf04
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
39 changes: 39 additions & 0 deletions include/ws_functions.inc.php
Expand Up @@ -1457,4 +1457,43 @@ function ws_tags_add($params, &$service)

return $creation_output;
}

function ws_images_exist($params, &$service)
{
if (!is_admin() or is_adviser())
{
return new PwgError(401, 'Access denied');
}

// search among photos the list of photos already added, based on md5sum
// list
$md5sums = preg_split(
'/[\s,;\|]/',
$params['md5sum_list'],
-1,
PREG_SPLIT_NO_EMPTY
);

$query = '
SELECT
id,
md5sum
FROM '.IMAGES_TABLE.'
WHERE md5sum IN (\''.implode("','", $md5sums).'\')
;';
$id_of_md5 = simple_hash_from_query($query, 'md5sum', 'id');

$result = array();

foreach ($md5sums as $md5sum)
{
$result[$md5sum] = null;
if (isset($id_of_md5[$md5sum]))
{
$result[$md5sum] = $id_of_md5[$md5sum];
}
}

return $result;
}
?>
19 changes: 19 additions & 0 deletions tools/piwigo_remote.pl
Expand Up @@ -173,6 +173,25 @@
print Dumper(from_json($response->content));
}

if ($opt{action} eq 'pwg.images.exist') {
$form = {
method => $opt{action},
};

foreach my $key (keys %{ $opt{define} }) {
$form->{$key} = $opt{define}{$key};
}

my $response = $ua->post(
$conf{base_url}.'/ws.php?format=json',
$form
);

use Data::Dumper;
print Dumper(from_json($response->content)->{result});
# print Dumper($response);
}

$query = pwg_ws_get_query(
method => 'pwg.session.logout'
);
Expand Down
9 changes: 9 additions & 0 deletions ws.php
Expand Up @@ -229,6 +229,15 @@ function ws_addDefaultMethods( $arr )
),
'administration method only'
);

$service->addMethod(
'pwg.images.exist',
'ws_images_exist',
array(
'md5sum_list'=> array(),
),
'check existence of a photo list'
);
}

add_event_handler('ws_add_methods', 'ws_addDefaultMethods');
Expand Down

0 comments on commit 3eecf04

Please sign in to comment.