•  » Engine
  •  » Version 2.50 Problem with Pwg.images.addSimple

#1 2013-03-19 15:25:57

kenl
Member
2013-01-12
91

Version 2.50 Problem with Pwg.images.addSimple

Hello,

I believe there is an issue with Pwg.images.addSimple in release 2.50.  It seems the issue was introduced from my request in this post:  [Forum, topic 21433] pwg.images.addSimple - escape character for commas in tags

When I upload a photo with multiple tags, using the addSimple API, only 1 tag is created that is a combination of the multiple tags.

For example, using the addSimple perl example:

Code:

$ua->post(
    $conf{base_url}.'/ws.php',
    {
        method => 'pwg.images.addSimple',
        image => ['C:\\Temp\\IMAG0320-001.jpg'],
        category => 10,
        tags => 'test_name, test_name2',
        name => 'A nice title',
        comment => 'A longer description',
        author => 'Paul Nikanon',
        level => 2,
    }

The results in 1 tag "test_name, test_name2" instead of 2 tags.

Looking at the ws_images_addSimple function in the file ws_functions.inc.php I found the following lines, which give php warnings:

Code:

    if (is_array($params[tags]))
    {
      foreach ($params[tags] as $tag_name)

I believe that apostrophes are required like this:

Code:

    if (is_array($params['tags']))
    {
      foreach ($params['tags'] as $tag_name)

That, at least, eliminates the php warnings.  However, it does not solve the problem.

Can you take a look at it?

Thanks,
KenL

Offline

 

#2 2013-03-31 05:30:44

kenl
Member
2013-01-12
91

Re: Version 2.50 Problem with Pwg.images.addSimple

Hi, Can someone from the Piwigo team take a look at this, please?

Thanks,
KenL

Offline

 

#3 2013-03-31 09:34:59

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13936

Re: Version 2.50 Problem with Pwg.images.addSimple

Offline

 

#4 2013-04-01 21:22:16

nicolas
Former Piwigo Team
2004-12-30
1234

Re: Version 2.50 Problem with Pwg.images.addSimple

kenl wrote:

Code:

    if (is_array($params['tags']))
    {
      foreach ($params['tags'] as $tag_name)

That, at least, eliminates the php warnings.  However, it does not solve the problem.

Can you take a look at it?

Thanks,
KenL

Yes the problem of quote is fixed as plg said in [Bugtracker] ticket 2881

And I confirm your main problem is not solved. [Subversion] r20814 commit try to fix the problem alloying tags parameter to be an array. But if you give pwg.images.addSimple method a string with two tags separated by a comma, the webservice core transform the tags parameter as an array and the method received an array with one tag and not two.

The problem is in include/ws_core.inc.php file. I think the parameter should not be converted to array :

Code:

--- a/include/ws_core.inc.php
+++ b/include/ws_core.inc.php
@@ -509,7 +509,7 @@ Request format: ".@$this->_requestFormat." Response format: ".@$this->_responseF
         {
           return new PwgError(WS_ERR_INVALID_PARAM, $name.' must be scalar' );
         }
-        if ( ($flags&WS_PARAM_FORCE_ARRAY) )
+        if ( ($flags&WS_PARAM_FORCE_ARRAY) && !$flags&WS_PARAM_ACCEPT_ARRAY)
         {
           $this->makeArrayParam( $the_param );
         }

Of course I can submit the bug.

Offline

 

#5 2013-04-02 06:07:38

rvelices
Former Piwigo Team
2005-12-29
1960

Re: Version 2.50 Problem with Pwg.images.addSimple

Offline

 

#6 2013-04-02 11:27:25

nicolas
Former Piwigo Team
2004-12-30
1234

Re: Version 2.50 Problem with Pwg.images.addSimple

Thanks Radu, it's perfect and better than what I wrote.

Offline

 

#7 2013-04-03 17:01:04

kenl
Member
2013-01-12
91

Re: Version 2.50 Problem with Pwg.images.addSimple

Thank you for making the changes.  Typical tags are now processed correctly.

However, tags with escaped commas are not processed correctly.

For example:
tags => 'test\, name, test_name2',

Results in 3 tags:  "test" "name" and "test_name2".

I was hoping for "test, name" and "test_name2"

Can you take a look at it?

KenL

Offline

 

#8 2013-04-03 17:07:54

flop25
Piwigo Team
2006-07-06
7037

Re: Version 2.50 Problem with Pwg.images.addSimple

see [Bugtracker] ticket 2845

edit: you're using the 2.5?


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#9 2013-04-03 22:11:28

nicolas
Former Piwigo Team
2004-12-30
1234

Re: Version 2.50 Problem with Pwg.images.addSimple

flop25 wrote:

see [Bugtracker] ticket 2845

edit: you're using the 2.5?

Your modification ([Subversion] r20741) is correct and you have imagine it can do the trick but I think you didn't test or perhaps not in a not complete way.

My use case to reproduce the problem of @kenl :

You add a tag "my tag with a comma" to an image 1.
You add a tag "my tag\, with a comma" to an image 2.

The image 1 has tag "my tag with a comma"
And the image 2 has also the tag "my tag with a comma".

The function tag_id_from_tag_name() (in admin/include/functions.php) retrieve the same id for the second tag "my tag\, with a comma" because of the algorithm used :
1) search for the same existing tag -> failed
2) search for the same existing tag, case insensitive -> failed
3) search for the same tag url name -> succeed so return the tag for existing id


I don'y know how to fix that in a good way. The str2url function (in include/functions.inc.php) removes comma from tag for url. But the ones we want to add has an escape comma so the comma should not be removed. It's not so simple because backslash is removed before.

Last edited by nicolas (2013-04-03 22:11:47)

Offline

 

#10 2013-04-03 22:15:51

flop25
Piwigo Team
2006-07-06
7037

Re: Version 2.50 Problem with Pwg.images.addSimple

thx!
what a fail ^^!


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#11 2013-04-03 22:22:30

nicolas
Former Piwigo Team
2004-12-30
1234

Re: Version 2.50 Problem with Pwg.images.addSimple

flop25 wrote:

thx!
what a fail ^^!

I read several times kenl message before understanding the problem.

A possible solution (but very ugly solution) to pass step 3 is to split tag which contains comma and converts parts with str2url and concatenates the results and finally search it in database.
Another solution is to allow comma in url tag name. I don't think it is a problem. The str2url function is used for tags but also for categories names.

Offline

 

#12 2013-04-09 22:13:35

nicolas
Former Piwigo Team
2004-12-30
1234

Re: Version 2.50 Problem with Pwg.images.addSimple

I submitted [Bugtracker] ticket 2886 if anyone want to fix it.

Offline

 

#13 2013-04-18 16:18:35

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13936

Re: Version 2.50 Problem with Pwg.images.addSimple

With Piwigo 2.5r22282 I have performed a few tests, they all work fine:

$ perl tools/piwigo_remote.pl --base=http://localhost/piwigo/dev/branches/2.5 --user=plg --pass=plg --action=pwg.images.addSimple --define image=test.jpg --define category=5 --define tags="tag1, tag2, tag3"
$VAR1 = {
          'result' => {
                        'image_id' => 78,
                        'url' => 'http://localhost/piwigo/dev/branches/2.5/picture.php?/78/category/5'
                      },
          'stat' => 'ok'
        };

=> 3 tags "tag1", "tag2" and "tag3"

$ perl tools/piwigo_remote.pl --base=http://localhost/piwigo/dev/branches/2.5 --user=plg --pass=plg --action=pwg.images.addSimple --define image=test.jpg --define category=5 --define tags="de la fontaine\, jean"
$VAR1 = {
          'result' => {
                        'image_id' => 80,
                        'url' => 'http://localhost/piwigo/dev/branches/2.5/picture.php?/80/category/5'
                      },
          'stat' => 'ok'
        };

=> 1 tag "de la fontaine, jean"

$ perl tools/piwigo_remote.pl --base=http://localhost/piwigo/dev/branches/2.5 --user=plg --pass=plg --action=pwg.images.addSimple --define image=test.jpg --define category=5 --define tags="de la fontaine\, jean, tag3"
$VAR1 = {
          'result' => {
                        'image_id' => 81,
                        'url' => 'http://localhost/piwigo/dev/branches/2.5/picture.php?/81/category/5'
                      },
          'stat' => 'ok'
        };

=> 2 tags "de la fontaine, jean", "tag3"

$ perl tools/piwigo_remote.pl --base=http://localhost/piwigo/dev/branches/2.5 --user=plg --pass=plg --action=pwg.images.addSimple --define image=test.jpg --define category=5 --define tags="de la fontaine\, jean, kramer\, john"
$VAR1 = {
          'result' => {
                        'image_id' => 82,
                        'url' => 'http://localhost/piwigo/dev/branches/2.5/picture.php?/82/category/5'
                      },
          'stat' => 'ok'
        };

=> 2 tags "de la fontaine, jean" , "kramer, john"


For me it's OK for Piwigo 2.5.1

Offline

 

#14 2013-04-18 16:41:08

nicolas
Former Piwigo Team
2004-12-30
1234

Re: Version 2.50 Problem with Pwg.images.addSimple

You read too quickly !!!

When you try to add a tag which url_name already exists it doesn't work.

Example : I have a tag Jean de la Fontaine

I want to add an image with "Jean\, de la Fontaine" and I expect the new tag to be created but it doesn't. My suggestion is to allow comma in url tag name.

Offline

 
  •  » Engine
  •  » Version 2.50 Problem with Pwg.images.addSimple

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2025 · Contact