Changeset 3453 for branches/2.0


Ignore:
Timestamp:
Jun 24, 2009, 11:42:39 PM (15 years ago)
Author:
plg
Message:

feature 1033 added: new API method pwg.categories.setInfo makes possible to
change the name and comment of a given category.

Location:
branches/2.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/include/ws_functions.inc.php

    r3239 r3453  
    17341734}
    17351735
     1736function ws_categories_setInfo($params, &$service)
     1737{
     1738  global $conf;
     1739  if (!is_admin() || is_adviser() )
     1740  {
     1741    return new PwgError(401, 'Access denied');
     1742  }
     1743
     1744  // category_id
     1745  // name
     1746  // comment
     1747
     1748  $params['category_id'] = (int)$params['category_id'];
     1749  if ($params['category_id'] <= 0)
     1750  {
     1751    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
     1752  }
     1753
     1754  // database registration
     1755  $update = array(
     1756    'id' => $params['category_id'],
     1757    );
     1758
     1759  $info_columns = array(
     1760    'name',
     1761    'comment',
     1762    );
     1763
     1764  $perform_update = false;
     1765  foreach ($info_columns as $key)
     1766  {
     1767    if (isset($params[$key]))
     1768    {
     1769      $perform_update = true;
     1770      $update[$key] = $params[$key];
     1771    }
     1772  }
     1773
     1774  if ($perform_update)
     1775  {
     1776    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     1777    mass_updates(
     1778      CATEGORIES_TABLE,
     1779      array(
     1780        'primary' => array('id'),
     1781        'update'  => array_diff(array_keys($update), array('id'))
     1782        ),
     1783      array($update)
     1784      );
     1785  }
     1786 
     1787}
     1788
    17361789function ws_logfile($string)
    17371790{
  • branches/2.0/tools/piwigo_remote.pl

    r3239 r3453  
    2525GetOptions(
    2626    \%opt,
    27     qw/action=s file=s thumbnail=s high=s original=s categories=s chunk_size=i define=s%/
     27    qw/
     28          action=s
     29          file=s
     30          thumbnail=s
     31          high=s
     32          original=s
     33          categories=s
     34          chunk_size=i
     35          base_url=s
     36          username=s
     37          password=s
     38          define=s%
     39      /
    2840);
    2941
     
    3244
    3345my %conf;
    34 $conf{base_url} = 'http://localhost/piwigo/2.0';
    3546$conf{response_format} = 'json';
    36 $conf{username} = 'plg';
    37 $conf{password} = 'plg';
    3847$conf{limit} = 10;
    39 $conf{chunk_size} = defined $opt{chunk_size} ? $opt{chunk_size} : 500_000;
     48
     49my %conf_default = (
     50    base_url => 'http://localhost/piwigo/2.0',
     51    username => 'plg',
     52    password => 'plg',
     53    chunk_size => 500_000,
     54);
     55foreach my $conf_key (keys %conf_default) {
     56    $conf{$conf_key} = defined $opt{$conf_key} ? $opt{$conf_key} : $conf_default{$conf_key}
     57}
    4058
    4159my $result = undef;
     
    217235}
    218236
    219 if ($opt{action} eq 'pwg.images.setInfo') {
     237if ($opt{action} eq 'pwg.images.setInfo' or $opt{action} eq 'pwg.categories.setInfo') {
    220238    $form = {
    221239        method => $opt{action},
  • branches/2.0/ws.php

    r3192 r3453  
    271271<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.'
    272272    );
     273 
     274  $service->addMethod(
     275    'pwg.categories.setInfo',
     276    'ws_categories_setInfo',
     277    array(
     278      'category_id' => array(),
     279     
     280      'name' => array('default' => null),
     281      'comment' => array('default' => null),
     282      ),
     283    'POST method only.'
     284    );
    273285}
    274286
Note: See TracChangeset for help on using the changeset viewer.