aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/ws_functions.inc.php39
-rw-r--r--tools/piwigo_remote.pl19
-rw-r--r--ws.php9
3 files changed, 67 insertions, 0 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 57a12ac3b..f14aff70a 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -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;
+}
?>
diff --git a/tools/piwigo_remote.pl b/tools/piwigo_remote.pl
index f11e0d457..3e3031c82 100644
--- a/tools/piwigo_remote.pl
+++ b/tools/piwigo_remote.pl
@@ -173,6 +173,25 @@ if ($opt{action} eq 'pwg.tags.add') {
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'
);
diff --git a/ws.php b/ws.php
index 6c0ce26ad..f36053312 100644
--- a/ws.php
+++ b/ws.php
@@ -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');