From 8dc2b92d667f1401ab9f1315a36add61658f899c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 6 May 2021 10:26:09 +0200 Subject: Moderize Database handling * Auto-convert to utf8mb4_unicode_520_ci * Use foreach instead of while to loop over results * Drop useless statement caching * Keep emulated prepares, as we sometimes loop over nested queries --- modules-available/rebootcontrol/hooks/cron.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'modules-available/rebootcontrol/hooks') diff --git a/modules-available/rebootcontrol/hooks/cron.inc.php b/modules-available/rebootcontrol/hooks/cron.inc.php index 8f5c73a0..73de020d 100644 --- a/modules-available/rebootcontrol/hooks/cron.inc.php +++ b/modules-available/rebootcontrol/hooks/cron.inc.php @@ -5,7 +5,7 @@ */ if (in_array((int)date('G'), [6, 7, 9, 12, 15]) && in_array(date('i'), ['00', '01', '02', '03'])) { $res = Database::simpleQuery('SELECT hostid, host, port, username, sshkey, script FROM reboot_jumphost'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { RebootControl::wakeViaJumpHost($row, '255.255.255.255', [['macaddr' => '00:11:22:33:44:55']]); } } @@ -171,7 +171,7 @@ if ($res->rowCount() === 0) return; Stuff::$subnets = []; -while ($row = $res->fetch(PDO::FETCH_ASSOC)) { +foreach ($res as $row) { if (!isset(Stuff::$subnets[$row['subnetid']])) { Stuff::$subnets[$row['subnetid']] = []; } @@ -194,7 +194,7 @@ $res = Database::simpleQuery("SELECT subnetid FROM reboot_subnet WHERE subnetid IN (:active) AND nextdirectcheck < UNIX_TIMESTAMP() AND fixed = 0 ORDER BY nextdirectcheck ASC LIMIT 10", ['active' => array_keys(Stuff::$subnets)]); cron_log('Direct checks: ' . $res->rowCount() . ' (' . implode(', ', array_keys(Stuff::$subnets)) . ')'); -while ($row = $res->fetch(PDO::FETCH_ASSOC)) { +foreach ($res as $row) { $dst = (int)$row['subnetid']; cron_log('Direct check for subnetid ' . $dst); $result = testServerToClient($dst); @@ -239,7 +239,7 @@ if (count($combos) > 0) { ORDER BY sxs.nextcheck ASC LIMIT 10", ['combos' => $combos]); cron_log('C2C checks: ' . $res->rowCount()); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $src = (int)$row['srcid']; $dst = (int)$row['dstid']; $result = testClientToClient($src, $dst); -- cgit v1.2.3-55-g7522