Announcement

  •  » Extensions
  •  » Problem with get_fulldirs (implode)

#1 2017-06-06 03:14:16

windracer
Member
St. Pete, FL
2014-12-28
448

Problem with get_fulldirs (implode)

I'm working on my first Piwigo plugin, so be gentle. ;)

As part of my plugin functionality, I need to build the full path to a physical album (category). I found the get_fulldirs function in admin/include/functions.php. It seems to take a list of category ids (uppercats) and is supposed to return an array of corresponding directories.

So I am calling it like this:

Code:

// get destination category information
$dest_cat_info = get_cat_info($target_cat);
$dest_uppercats = $dest_cat_info['uppercats'];
$dest_cat_dir = get_fulldirs($dest_uppercats);

$target_cat contains the id of the category (physical album). $dest_uppercats will contain the value of categories.uppercats for the given category. I pass this to get_fulldirs and this is the error I get:

Code:

Warning: implode(): Invalid arguments passed in /usr/local/piwigo-beta/admin/include/functions.php on line 1049


Warning:  [mysql error 1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 5

SELECT id, uppercats, site_id
  FROM categories
  WHERE dir IS NOT NULL
    AND id IN (
)
; in /usr/local/piwigo-beta/include/dblayer/functions_mysqli.inc.php on line 845


Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in /usr/local/piwigo-beta/include/dblayer/functions_mysqli.inc.php:911 Stack trace: #0 /usr/local/piwigo-beta/admin/include/functions.php(1051): query2array('\nSELECT id, upp...') #1 /usr/local/piwigo-beta/plugins/physical_photo_move/admin.php(83): get_fulldirs('7,8,9') #2 /usr/local/piwigo-beta/admin/plugin.php(68): include_once('/usr/local/piwi...') #3 /usr/local/piwigo-beta/admin.php(302): include('/usr/local/piwi...') #4 {main} thrown in /usr/local/piwigo-beta/include/dblayer/functions_mysqli.inc.php on line 911

You can see in the traceback that the string in $dest_uppercats passed to the function is '7,8,9' (which is correct in this test case). But notice the IN list of the SQL is empty. The code in functions.php is failing here, on the implode line:

Code:

// categories : id, site_id, uppercats
$query = '
SELECT id, uppercats, site_id
  FROM '.CATEGORIES_TABLE.'
  WHERE dir IS NOT NULL
    AND id IN (
'.wordwrap(implode(', ', $cat_ids), 80, "\n").')
;';
$categories = query2array($query);

If I remove the wordwrap/implode calls in functions.php like this:

Code:

// categories : id, site_id, uppercats
$query = '
SELECT id, uppercats, site_id
  FROM '.CATEGORIES_TABLE.'
  WHERE dir IS NOT NULL
    AND id IN ('.$cat_ids.')
;';
  $categories = query2array($query);

It works properly and I get the array of directories in $dest_cat_dir.

So is this a bug or am I doing something wrong?

Also, is there better developer documentation available somewhere that describes all the function calls and such available other than reading the code on GitHub?

Piwigo version: 2.9.0
PHP version: 7.0.18-0ubuntu0.17.04.1
MySQL version: 5.7.18-0ubuntu0.17.04.1

Offline

 

#2 2017-06-06 21:38:04

windracer
Member
St. Pete, FL
2014-12-28
448

Re: Problem with get_fulldirs (implode)

Figured it out ... programmer error. :o

get_fulldirs expects an array of category ids, and I was passing it a string of comma-separated category ids. This was causing the implode error in get_fulldirs. I fixed my code like this.

Before:

Code:

// get destination category information
$dest_cat_info = get_cat_info($target_cat);
$dest_uppercats = $dest_cat_info['uppercats'];
$dest_cat_dir = get_fulldirs($dest_uppercats);

After:

Code:

// get destination category information
$dest_cat_info = get_cat_info($target_cat);
$dest_uppercats = explode(',',  $dest_cat_info['uppercats']);
$dest_cat_path = get_fulldirs($dest_uppercats);

So basically I used explode to turn the CSV string into an array before passing it to get_fulldirs.

Offline

 

#3 2017-06-07 17:58:38

flop25
Piwigo Team
2006-07-06
7037

Re: Problem with get_fulldirs (implode)

Hello
nice you are going a step further and i'm quite curious about your goals
sorry we couldn't answer you yesterday but you have still questions ... ;)


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

 

#4 2017-06-07 21:38:20

windracer
Member
St. Pete, FL
2014-12-28
448

Re: Problem with get_fulldirs (implode)

I do have some more questions ... I'll start a new thread. ;)

Offline

 
  •  » Extensions
  •  » Problem with get_fulldirs (implode)

Board footer

Powered by FluxBB

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