Announcement

  •  » Extensions
  •  » Possible fix for MugShot error Parameter must be object with countable

#1 2020-10-08 07:07:24

dd-b
Member
Minneapolis, MN USA
2018-04-16
69

Possible fix for MugShot error Parameter must be object with countable

This is very preliminary, but...I may have found a fix for this MugShot error

Code:

Warning: count(): Parameter must be an array or an object that implements Countable in /home/johnbray/piwigo.fancy-test.com/plugins/MugShot/main.inc.php on line 163

Warning: Cannot modify header information - headers already sent by (output started at /home/johnbray/piwigo.fancy-test.com/plugins/MugShot/main.inc.php:163) in /home/johnbray/piwigo.fancy-test.com/include/page_header.php on line 101

Line 163 of MugShot's main.inc.php is:

Code:

return (count($res) == 0) ? 0 : $res;

By changing it to

Code:

 return (gettype($res) == 'integer' ? $res : count($res));

the error (both errors shown above) go away.

I did some debugging and when the error happened, $res was getting set to an integer value rather than an array.  The old code might work if count($res) returned 0 when $res was not an array; did that happen in the past?  Anyway, I changed it around, checked the type returned and if it was an integer just returned that, and if not then took the count and returned that.

That one bit seems to be fixed when I make this change (including the second error about headers; no idea why that also changed). 

This could be completely bogus; I won't be at all happy until I get MugShot actually working, rather than just eliminating one error that was being issued.

So -- I offer this for whatever it's worth, particularly for anybody more knowledgeable than me who can tell me that this is in fact nonsense and I'm wasting my time (and convince me).  But it looks slightly hopeful to me. (These are of course just changes to my local copy of MugShot on my dev site! I have no contact with the original author of MugShot and no way to make any actual changes.)

Piwigo 2.10.2 Check for upgrade
Operating system: Linux
PHP: 7.4.3 (Show info) [2020-10-07 21:54:56]
MySQL: 5.7.29-log [2020-10-07 21:54:56]
Graphics Library: ImageMagick 6.9.7-4

Offline

 

#2 2020-10-08 16:44:23

drewlander
Member
2020-10-07
20

Re: Possible fix for MugShot error Parameter must be object with countable

I have never looked at the code but this is how I would adjust that line because you are actually changing the outcome by returning the count instead of the variable as is the case in the original code.

return empty($res) ? 0 : $res;

This covers all plausible cases and to be honest I dont know if that variable is supposed to be an integer or a collection of strings (array). If it is null then it returns 0. If it is 0 then it returns 0. If it is not 0 and not null then it return whatever the value is.

Last edited by drewlander (2020-10-08 16:51:54)

Offline

 

#3 2020-10-08 19:38:06

dd-b
Member
Minneapolis, MN USA
2018-04-16
69

Re: Possible fix for MugShot error Parameter must be object with countable

Hmmm; you're right, the original code returns either the variable $res or 0, whereas mine returns the count($res) or the value of $res if it's an integer.  I let myself get distracted by my own ideas of good design I think :-( .

Your version behaves the same as mine at the same level of testing. I'll go forward with your version until I either get it working or find problems I can't fix.

It makes sense that they'd behave the same in my test conditions so far, anyway. When I get it actually trying to add the mug-shot button to the toolbar I may learn something.

Offline

 

#4 2020-10-08 20:27:08

drewlander
Member
2020-10-07
20

Re: Possible fix for MugShot error Parameter must be object with countable

if empty() does not work out for you then it is because the variable is not initialized at all which is most likely the result of some really poor coding elsewhere in the stack that ate an exception and moved on. In that case you can try something like

return !isset($res) ? 0 : $res;

But I think the assumption is that the variable will always be initialized and we are really only checking if its null/empty or has an enumerable value.

Or if you want to get really fancy you could do something like this

echo isset($res) ? empty($res) ? 0 : count($res) : 0;

The case above
checks if the variable is initialized. If not then return 0
checks if the variable is = ''. If not then return 0.
else return $res

Hard to say what the right or wrong way is without knowing the intentions of the author.

Software developer by trade. If you have any questions on errors with this lmk.  I just started with piwigo to throw up an album for my sisters birthday. Checked out the plugin and saw errors. deleted. But if someone else is willing to work through it I dont mind helping. 

thx
-d

Offline

 

#5 2020-10-08 22:38:32

dd-b
Member
Minneapolis, MN USA
2018-04-16
69

Re: Possible fix for MugShot error Parameter must be object with countable

Yeah, software developer since 1968, web developer since 1993 or some such. (That "1968" means the new stuff is sometimes lost in among so much old stuff, though.)

I do seem to have started working this through. I badly need face-tagging functionality (manual is sufficient) for the web site for a photo archive I'm starting for a science fiction fan group.

I'm still kicking around fixing Mug Shot vs. fixing the original facetag; did you give up on tagging people entirely, or are you using facetag? I had it working briefly once but haven't been able to recreate it.

Meanwhile, I just found another piece of what seems to be very bad code in Mug Shot, see new thread.

Offline

 

#6 2020-10-08 23:04:10

drewlander
Member
2020-10-07
20

Re: Possible fix for MugShot error Parameter must be object with countable

Im just not tagging faces at all for my purposes at this point because it wasn't very important really. The only thing I struggled with was to have the slideshow and auto play videos within but I have that resolved as well.  Some of my scans are as much as 150mb images so I did notice some loading issues on very large images but they were resolved since installing the gdThumbs plugin.  All things considered piwigo is not too bad.  Ill check the other thread.

Offline

 

#7 2020-10-08 23:22:32

drewlander
Member
2020-10-07
20

Re: Possible fix for MugShot error Parameter must be object with countable

I got it working.

You dont need the empty() code fix, but it sure doesnt hurt with the poor code surrounding it.  You need to install Private Shares plugin. Create a group. Edit your user. Add them to the group. Now mugshot works. Codefix is optional but recommended given how fragile this code is.

Offline

 

#8 2020-10-08 23:27:36

dd-b
Member
Minneapolis, MN USA
2018-04-16
69

Re: Possible fix for MugShot error Parameter must be object with countable

Fascinating!

I've got it working here, just now, as well -- without "private shares" plugin (which I don't immediately recognize, will go look but I'm rushing to get to something else I need to do). I did have to take three tries to get the group configuration right (but that group facility is part of why I like mugshot; that and multiple saves).

I also put in a fix for the deprecated use of create_function(), and that seems to work (and gets rid of a warning). That's not instantly urgent, except that the warning messes up the page.

There's also a warning about pcre.jit=0 being needed (probably specific to my hosting environment -- Dreamhost cheap shared hosting).  And Dreamhost seems to have locked that on, at least I can't get it to change.  I'll bug them about that aspect if that turns out to be what's really happening.

Offline

 

#9 2020-10-08 23:33:49

drewlander
Member
2020-10-07
20

Re: Possible fix for MugShot error Parameter must be object with countable

I just nav to
/var/www/html/piwigo
then
grep -ri "PSHARE_ADMIN_BASE_URL"
found the reference in mugshots but not in any other code. Searched plugins for the text and found it was a constant in private shares plugin.  Installed. Viola.

Offline

 

#10 2020-10-08 23:49:42

drewlander
Member
2020-10-07
20

Re: Possible fix for MugShot error Parameter must be object with countable

dd-b wrote:

Fascinating!
I also put in a fix for the deprecated use of create_function(), and that seems to work (and gets rid of a warning). That's not instantly urgent, except that the warning messes up the page.

how did you fix that? Something like this I assume:
$tab_codes = array_map(function ($a) { return $a['code']; }, $tabs);

Offline

 

#11 2020-10-09 00:32:46

dd-b
Member
Minneapolis, MN USA
2018-04-16
69

Re: Possible fix for MugShot error Parameter must be object with countable

Yep, so much like that it's basically identical in fact :-)

Ah, that's the connection to private plugin, okay!

Offline

 

#12 2020-10-09 07:01:31

dd-b
Member
Minneapolis, MN USA
2018-04-16
69

Re: Possible fix for MugShot error Parameter must be object with countable

private_share has the same use of the deprecated create_function(), same fix works there.

Doesn't look like the author of MugShot (cccraig) has been active on GitHub essentially since the last MugShot release, and there are pull requests sitting there that I'd think he'd adopt if he were active.  Which means no chance of getting my fixes (or some better version of them, if necessary) adopted and formally distributed.  I'm working towards getting them assembled as a clean patch, with documentation, to share with people. I suppose I could clone MugShot and make changes to it and distribute that, but since I don't understand most of MugShot that has down sides both for me and for anybody who picks up my version and uses it.

Anybody have thoughts about the "best" way to resurrect MugShot in some form?

Offline

 

#13 2020-10-09 07:10:16

drewlander
Member
2020-10-07
20

Re: Possible fix for MugShot error Parameter must be object with countable

Fork it and resubmit with a different name?  piwigo-mugshot is a fork from piwigo-facetag anyway. Triple fork it.  I dare ya.  ;-p

Mugshots alone has been forked already like 6 times or something. facetag was forked like 4 or 5.

If you resubmit a fork can you call it "faceshot" for my amusement?

Last edited by drewlander (2020-10-09 07:26:29)

Offline

 

#14 2020-10-09 20:02:25

dd-b
Member
Minneapolis, MN USA
2018-04-16
69

Re: Possible fix for MugShot error Parameter must be object with countable

Well, I accidentally forked it when poking around to see the existing forks (every one I checked is at or behind the MugShot repository; no new work checked in to the master branch at least). Might as well keep that and work from there,eh? 

I am not above using your name suggestion; we'll see!

Offline

 

#15 2020-10-09 20:49:32

dd-b
Member
Minneapolis, MN USA
2018-04-16
69

Re: Possible fix for MugShot error Parameter must be object with countable

Wow, the standard installation of MugShot installs a repo linked back to github! So my changes are perfectly identified via git diff. Now, they're set up as experimental with comments and old code, so not the way to  make the final changes, but it means there's zero doubt exactly what I changed.

Offline

 
  •  » Extensions
  •  » Possible fix for MugShot error Parameter must be object with countable

Board footer

Powered by FluxBB

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