aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2009-06-24 21:42:39 +0000
committerplegall <plg@piwigo.org>2009-06-24 21:42:39 +0000
commit91c7200b59367be519aad81e3d1724fd3bdc1c0d (patch)
tree35a34f394b6c417d46d7647c702c5bcd83c3bfa0
parent90cc8dccf3140aee43c3bf1a9af77b90a6ff7cbc (diff)
feature 1033 added: new API method pwg.categories.setInfo makes possible to
change the name and comment of a given category. git-svn-id: http://piwigo.org/svn/branches/2.0@3453 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--include/ws_functions.inc.php53
-rw-r--r--tools/piwigo_remote.pl30
-rw-r--r--ws.php12
3 files changed, 89 insertions, 6 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 422cfd176..979e855ef 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -1733,6 +1733,59 @@ SELECT
}
}
+function ws_categories_setInfo($params, &$service)
+{
+ global $conf;
+ if (!is_admin() || is_adviser() )
+ {
+ return new PwgError(401, 'Access denied');
+ }
+
+ // category_id
+ // name
+ // comment
+
+ $params['category_id'] = (int)$params['category_id'];
+ if ($params['category_id'] <= 0)
+ {
+ return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
+ }
+
+ // database registration
+ $update = array(
+ 'id' => $params['category_id'],
+ );
+
+ $info_columns = array(
+ 'name',
+ 'comment',
+ );
+
+ $perform_update = false;
+ foreach ($info_columns as $key)
+ {
+ if (isset($params[$key]))
+ {
+ $perform_update = true;
+ $update[$key] = $params[$key];
+ }
+ }
+
+ if ($perform_update)
+ {
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+ mass_updates(
+ CATEGORIES_TABLE,
+ array(
+ 'primary' => array('id'),
+ 'update' => array_diff(array_keys($update), array('id'))
+ ),
+ array($update)
+ );
+ }
+
+}
+
function ws_logfile($string)
{
return true;
diff --git a/tools/piwigo_remote.pl b/tools/piwigo_remote.pl
index 32ecbf030..ceb2af4b9 100644
--- a/tools/piwigo_remote.pl
+++ b/tools/piwigo_remote.pl
@@ -24,19 +24,37 @@ use POSIX qw(ceil floor);
my %opt = ();
GetOptions(
\%opt,
- qw/action=s file=s thumbnail=s high=s original=s categories=s chunk_size=i define=s%/
+ qw/
+ action=s
+ file=s
+ thumbnail=s
+ high=s
+ original=s
+ categories=s
+ chunk_size=i
+ base_url=s
+ username=s
+ password=s
+ define=s%
+ /
);
our $ua = LWP::UserAgent->new;
$ua->cookie_jar({});
my %conf;
-$conf{base_url} = 'http://localhost/piwigo/2.0';
$conf{response_format} = 'json';
-$conf{username} = 'plg';
-$conf{password} = 'plg';
$conf{limit} = 10;
-$conf{chunk_size} = defined $opt{chunk_size} ? $opt{chunk_size} : 500_000;
+
+my %conf_default = (
+ base_url => 'http://localhost/piwigo/2.0',
+ username => 'plg',
+ password => 'plg',
+ chunk_size => 500_000,
+);
+foreach my $conf_key (keys %conf_default) {
+ $conf{$conf_key} = defined $opt{$conf_key} ? $opt{$conf_key} : $conf_default{$conf_key}
+}
my $result = undef;
my $query = undef;
@@ -216,7 +234,7 @@ if ($opt{action} eq 'pwg.images.exist') {
# print Dumper($response);
}
-if ($opt{action} eq 'pwg.images.setInfo') {
+if ($opt{action} eq 'pwg.images.setInfo' or $opt{action} eq 'pwg.categories.setInfo') {
$form = {
method => $opt{action},
};
diff --git a/ws.php b/ws.php
index 6c4c9a451..e2e128f1b 100644
--- a/ws.php
+++ b/ws.php
@@ -270,6 +270,18 @@ function ws_addDefaultMethods( $arr )
'POST method only. Admin only
<br/><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.'
);
+
+ $service->addMethod(
+ 'pwg.categories.setInfo',
+ 'ws_categories_setInfo',
+ array(
+ 'category_id' => array(),
+
+ 'name' => array('default' => null),
+ 'comment' => array('default' => null),
+ ),
+ 'POST method only.'
+ );
}
add_event_handler('ws_add_methods', 'ws_addDefaultMethods');