Changeset 2683


Ignore:
Timestamp:
Oct 8, 2008, 12:01:14 AM (16 years ago)
Author:
plg
Message:

feature 889 added: pwg.images.exist check the existence of a photo in the
database based on its md5sum. (avoid failing on pwg.images.add).

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r2672 r2683  
    14581458  return $creation_output;
    14591459}
     1460
     1461function ws_images_exist($params, &$service)
     1462{
     1463  if (!is_admin() or is_adviser())
     1464  {
     1465    return new PwgError(401, 'Access denied');
     1466  }
     1467
     1468  // search among photos the list of photos already added, based on md5sum
     1469  // list
     1470  $md5sums = preg_split(
     1471    '/[\s,;\|]/',
     1472    $params['md5sum_list'],
     1473    -1,
     1474    PREG_SPLIT_NO_EMPTY
     1475    );
     1476 
     1477  $query = '
     1478SELECT
     1479    id,
     1480    md5sum
     1481  FROM '.IMAGES_TABLE.'
     1482  WHERE md5sum IN (\''.implode("','", $md5sums).'\') 
     1483;';
     1484  $id_of_md5 = simple_hash_from_query($query, 'md5sum', 'id');
     1485
     1486  $result = array();
     1487 
     1488  foreach ($md5sums as $md5sum)
     1489  {
     1490    $result[$md5sum] = null;
     1491    if (isset($id_of_md5[$md5sum]))
     1492    {
     1493      $result[$md5sum] = $id_of_md5[$md5sum];
     1494    }
     1495  }
     1496
     1497  return $result;
     1498}
    14601499?>
  • trunk/tools/piwigo_remote.pl

    r2670 r2683  
    174174}
    175175
     176if ($opt{action} eq 'pwg.images.exist') {
     177    $form = {
     178        method => $opt{action},
     179    };
     180
     181    foreach my $key (keys %{ $opt{define} }) {
     182        $form->{$key} = $opt{define}{$key};
     183    }
     184
     185    my $response = $ua->post(
     186        $conf{base_url}.'/ws.php?format=json',
     187        $form
     188    );
     189
     190    use Data::Dumper;
     191    print Dumper(from_json($response->content)->{result});
     192    # print Dumper($response);
     193}
     194
    176195$query = pwg_ws_get_query(
    177196    method => 'pwg.session.logout'
  • trunk/ws.php

    r2670 r2683  
    230230    'administration method only'
    231231    );
     232
     233  $service->addMethod(
     234    'pwg.images.exist',
     235    'ws_images_exist',
     236    array(
     237      'md5sum_list'=> array(),
     238      ),
     239    'check existence of a photo list'
     240    );
    232241}
    233242
Note: See TracChangeset for help on using the changeset viewer.