FOGProject / fogproject

An open source computer cloning & management system
https://fogproject.org
GNU General Public License v3.0
1.08k stars 216 forks source link

Uncaught ValueError: max() : Argument #1 ($value) must contain at least one element in hostmanagementpage.class.php #559

Closed abulhol closed 1 year ago

abulhol commented 1 year ago

I have a couple of hosts in a FOG instance (running dev-branch). When I click on one of them on the "Hosts" page, e.g. navigating to http://localhost:8080/fog/management/index.php?node=host&sub=edit&id=1, the page loads for a while, and then it has no styling. In the Apache error log, I see this:

Got error 'PHP message: PHP Fatal error:  Uncaught ValueError: max(): Argument 
#1 ($value) must contain at least one element in /var/www/fog/lib/pages/hostmanagementpage.class.php:2932\nStack trace:\n
#0 /var/www/fog/lib/pages/hostmanagementpage.class.php(2932): max()\n
#1 /var/www/fog/lib/pages/hostmanagementpage.class.php(3250): HostManagementPage->hostImageHistory()\n
#2 /var/www/fog/lib/fog/fogpagemanager.class.php(220): HostManagementPage->edit()\n
#3 /var/www/fog/management/index.php(58): FOGPageManager->render()\n
#4 {main}\n  thrown in /var/www/fog/lib/pages/hostmanagementpage.class.php on line 2932', referer: http://localhost:8080/fog/management/index.php?node=host

I have now patched code in hostmanagementpage.class.php like so:

if (count($TaskIDs) == 0) {
    continue; 
}
$taskID = @max($TaskIDs);
if (!$taskID) {
    continue;
}

But I think that in the end it is related to: https://github.com/FOGProject/fogproject/issues/515

We set up a cronjob a while ago that deletes older logs every day like so:

0 0 * * 1 mysql -u fogmaster --password='' fog -se 'DELETE FROM tasks WHERE DATE(taskCreateTime) < CURDATE() - INTERVAL 1 MONTH;'
0 0 * * 1 mysql -u fogmaster --password='' fog -se 'DELETE FROM imagingLog WHERE DATE(ilFinishTime) < CURDATE() - INTERVAL 1 MONTH;'

Probably this makes the data partly inconsistent.

Maybe it's still good to put this extra code before calling the max function?

Sebastian-Roth commented 1 year ago

@abulhol This issue has been fixed months ago: 0bb39fd

May I ask you to update to FOG 1.5.10 which has been released. Altough #515 is still not addressed but I promise it will be.

abulhol commented 1 year ago

@Sebastian-Roth nice, thanks! We'll update to 1.5.10 then.