zoneminder icon indicating copy to clipboard operation
zoneminder copied to clipboard

Fatal PHP error in ?view=console

Open onlyjob opened this issue 1 year ago • 6 comments

ZoneMinder 1.36.35 with PHP8.2 on Debian 12 "bookworm" (Debian package).

I'm getting the following server-side error when opening console view in browser:

PHP message: PHP Fatal error:  Uncaught Error:
 Call to a member function UrlToIndex() on null in 
  /usr/share/zoneminder/www/includes/Monitor.php:494
Stack trace:
#0 /usr/share/zoneminder/www/skins/classic/views/js/console.js.php(24): ZM\Monitor->UrlToIndex()
#1 /usr/share/zoneminder/www/skins/classic/includes/functions.php(929): require_once('...')
#2 /usr/share/zoneminder/www/skins/classic/views/console.php(447): xhtmlFooter()
#3 /usr/share/zoneminder/www/index.php(309): require_once('...')
#4 {main}
  thrown in /usr/share/zoneminder/www/includes/Monitor.php on line 494"

onlyjob avatar Feb 21 '25 14:02 onlyjob

I think line 182 should be if(!$this->{'Server'}) { instead of if (!property_exists($this, 'Server')) { The line above ensures that the property exists, but is empty if ServerId is not empty but is not valid.

Is it possiblie that the monitor has a non-empty but not valid ServerId?

connortechnology avatar Feb 21 '25 14:02 connortechnology

I'm not sure about the cause... I have no multiserver configuration but I may have changed something after upgrade that caused it... The issue seems to have gone once I've cleared "groups" to "all" in console...

onlyjob avatar Feb 21 '25 14:02 onlyjob

Hmm... yeah I tested my theory and it didn't pan out. So you had a group selected... I wonder if there was a deleted monitor in that group or something like that? Time to do more testing.

connortechnology avatar Feb 21 '25 14:02 connortechnology

I also thought about "non-empty but not valid ServerId" but issue cleared only after manipulation with groups.

Before that I did re-save configuration of all cameras, trying to set server explicitly either to "None" or to "Auto" in attempt to resolve the issue (just in case there was something historical left in camera settings.) I created this bug report after failing to clear the error, but then, unexpectedly, it was gone after I tried selecting groups.

Sorry for lack of clear reproducer. Perhaps null value should be handled somehow, just in case?

onlyjob avatar Feb 21 '25 14:02 onlyjob

I think it is. Normally when we load a db record, it contains an entry for ServerId, so the property gets defined.

If the record didn't exist, then we might do return new ZM\Monitor(); Which would create an empty object, but all those fields aren't actually defined as properties. Hence the test for the property existing.

It appears there though that the property exists, but is null.... and we don't test for that... so I think I see how the code should be improved...

connortechnology avatar Feb 21 '25 14:02 connortechnology

If you are able to make it happen again, can you try replacing the function with the following? public function Server() { if (!property_exists($this, 'Server')) $this->{'Server'} = $this->ServerId() ? Server::find_one(array('Id'=>$this->{'ServerId'})) : new Server(); if (!$this->{'Server'}) # the find_one can return null $this->{'Server'} = new Server(); return $this->{'Server'}; }

connortechnology avatar Feb 21 '25 14:02 connortechnology