summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-05-06 10:26:09 +0200
committerSimon Rettberg2021-05-11 14:51:13 +0200
commit8dc2b92d667f1401ab9f1315a36add61658f899c (patch)
tree452c5fe040055884cf9d9ee834415db84999a9a1
parent[session] Add simple session overview table (diff)
downloadslx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.tar.gz
slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.tar.xz
slx-admin-8dc2b92d667f1401ab9f1315a36add61658f899c.zip
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
-rw-r--r--config.php.example4
-rw-r--r--inc/database.inc.php32
-rw-r--r--inc/property.inc.php4
-rw-r--r--inc/taskmanagercallback.inc.php2
-rw-r--r--install.php48
-rw-r--r--modules-available/adduser/page.inc.php2
-rw-r--r--modules-available/baseconfig/inc/baseconfig.inc.php2
-rw-r--r--modules-available/baseconfig/page.inc.php2
-rw-r--r--modules-available/dnbd3/baseconfig/getconfig.inc.php2
-rw-r--r--modules-available/dnbd3/hooks/main-warning.inc.php2
-rw-r--r--modules-available/dnbd3/inc/dnbd3util.inc.php8
-rw-r--r--modules-available/dnbd3/page.inc.php4
-rw-r--r--modules-available/dozmod/pages/actionlog.inc.php2
-rw-r--r--modules-available/dozmod/pages/expiredimages.inc.php2
-rw-r--r--modules-available/dozmod/pages/networkrules.inc.php2
-rw-r--r--modules-available/dozmod/pages/networkshares.inc.php2
-rw-r--r--modules-available/dozmod/pages/runscripts.inc.php4
-rw-r--r--modules-available/dozmod/pages/special.inc.php4
-rw-r--r--modules-available/dozmod/pages/users.inc.php4
-rw-r--r--modules-available/eventlog/page.inc.php2
-rw-r--r--modules-available/exams/page.inc.php8
-rw-r--r--modules-available/locationinfo/api.inc.php2
-rw-r--r--modules-available/locationinfo/inc/coursebackend.inc.php4
-rw-r--r--modules-available/locationinfo/inc/infopanel.inc.php4
-rw-r--r--modules-available/locationinfo/page.inc.php12
-rw-r--r--modules-available/locations/baseconfig/getconfig.inc.php2
-rw-r--r--modules-available/locations/inc/autolocation.inc.php2
-rw-r--r--modules-available/locations/inc/location.inc.php4
-rw-r--r--modules-available/locations/inc/locationutil.inc.php2
-rw-r--r--modules-available/locations/pages/details.inc.php4
-rw-r--r--modules-available/locations/pages/locations.inc.php8
-rw-r--r--modules-available/locations/pages/subnets.inc.php2
-rw-r--r--modules-available/minilinux/inc/minilinux.inc.php6
-rw-r--r--modules-available/minilinux/page.inc.php2
-rw-r--r--modules-available/news/page.inc.php2
-rw-r--r--modules-available/permissionmanager/inc/getpermissiondata.inc.php8
-rw-r--r--modules-available/permissionmanager/inc/permissionutil.inc.php4
-rw-r--r--modules-available/rebootcontrol/hooks/cron.inc.php8
-rw-r--r--modules-available/rebootcontrol/inc/rebootcontrol.inc.php6
-rw-r--r--modules-available/rebootcontrol/inc/rebootutils.inc.php4
-rw-r--r--modules-available/rebootcontrol/inc/scheduler.inc.php4
-rw-r--r--modules-available/rebootcontrol/pages/jumphost.inc.php4
-rw-r--r--modules-available/rebootcontrol/pages/subnet.inc.php6
-rw-r--r--modules-available/remoteaccess/inc/remoteaccess.inc.php4
-rw-r--r--modules-available/roomplanner/inc/room.inc.php2
-rw-r--r--modules-available/roomplanner/inc/simpleroom.inc.php2
-rw-r--r--modules-available/roomplanner/install.inc.php2
-rw-r--r--modules-available/roomplanner/page.inc.php6
-rw-r--r--modules-available/runmode/inc/runmode.inc.php6
-rw-r--r--modules-available/runmode/page.inc.php8
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php2
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php4
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php4
-rw-r--r--modules-available/serversetup-bwlp-ipxe/install.inc.php2
-rw-r--r--modules-available/serversetup-bwlp-ipxe/page.inc.php8
-rw-r--r--modules-available/session/page.inc.php2
-rw-r--r--modules-available/statistics/baseconfig/getconfig.inc.php2
-rw-r--r--modules-available/statistics/hooks/config-tgz.inc.php2
-rw-r--r--modules-available/statistics/hooks/cron.inc.php2
-rw-r--r--modules-available/statistics/inc/statistics.inc.php2
-rw-r--r--modules-available/statistics/install.inc.php2
-rw-r--r--modules-available/statistics/page.inc.php4
-rw-r--r--modules-available/statistics/pages/list.inc.php2
-rw-r--r--modules-available/statistics/pages/machine.inc.php8
-rw-r--r--modules-available/statistics/pages/projectors.inc.php2
-rw-r--r--modules-available/statistics/pages/replace.inc.php2
-rw-r--r--modules-available/statistics/pages/summary.inc.php12
-rw-r--r--modules-available/statistics_reporting/inc/getdata.inc.php4
-rw-r--r--modules-available/statistics_reporting/inc/queries.inc.php6
-rw-r--r--modules-available/sysconfig/addconfig.inc.php2
-rw-r--r--modules-available/sysconfig/api.inc.php2
-rw-r--r--modules-available/sysconfig/inc/configmodule.inc.php2
-rw-r--r--modules-available/sysconfig/inc/configtgz.inc.php14
-rw-r--r--modules-available/sysconfig/inc/sysconfig.inc.php2
-rw-r--r--modules-available/sysconfig/install.inc.php4
-rw-r--r--modules-available/sysconfig/page.inc.php6
-rw-r--r--modules-available/syslog/api.inc.php2
-rw-r--r--modules-available/syslog/page.inc.php4
78 files changed, 207 insertions, 175 deletions
diff --git a/config.php.example b/config.php.example
index df361ff9..c0921d28 100644
--- a/config.php.example
+++ b/config.php.example
@@ -7,11 +7,9 @@ define('CONFIG_SESSION_DIR', '/tmp/openslx');
define('CONFIG_SESSION_TIMEOUT', 86400 * 3);
// Put your mysql credentials here
-define('CONFIG_SQL_DSN', 'mysql:dbname=openslx;host=localhost');
+define('CONFIG_SQL_DSN', 'mysql:dbname=openslx;host=localhost;charset=utf8mb4');
define('CONFIG_SQL_USER', 'openslx');
define('CONFIG_SQL_PASS', '%MYSQL_OPENSLX_PASS%');
-// Set this to true if you mysql server doesn't default to UTF-8 on new connections
-define('CONFIG_SQL_FORCE_UTF8', true);
define('CONFIG_TM_PASSWORD', '%TM_OPENSLX_PASS%');
diff --git a/inc/database.inc.php b/inc/database.inc.php
index a4f7c1b9..a55555b4 100644
--- a/inc/database.inc.php
+++ b/inc/database.inc.php
@@ -11,10 +11,7 @@ class Database
* @var \PDO Database handle
*/
private static $dbh = false;
- /*
- * @var \PDOStatement[]
- */
- private static $statements = array();
+
private static $returnErrors;
private static $lastError = false;
private static $explainList = array();
@@ -30,11 +27,10 @@ class Database
return true;
self::$returnErrors = $returnErrors;
try {
- if (CONFIG_SQL_FORCE_UTF8) {
- self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
- } else {
- self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS);
- }
+ self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS, [
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+ PDO::ATTR_EMULATE_PREPARES => true,
+ ]);
} catch (PDOException $e) {
if (self::$returnErrors)
return false;
@@ -59,7 +55,7 @@ class Database
$res = self::simpleQuery($query, $args, $ignoreError);
if ($res === false)
return false;
- return $res->fetch(PDO::FETCH_ASSOC);
+ return $res->fetch();
}
/**
@@ -74,7 +70,7 @@ class Database
$res = self::simpleQuery($query, $args, $ignoreError);
if ($res === false)
return false;
- return $res->fetchAll(PDO::FETCH_ASSOC);
+ return $res->fetchAll();
}
/**
@@ -165,14 +161,10 @@ class Database
}
}
try {
- if (!isset(self::$statements[$query])) {
- self::$statements[$query] = self::$dbh->prepare($query);
- } else {
- //self::$statements[$query]->closeCursor();
- }
+ $stmt = self::$dbh->prepare($query);
$start = microtime(true);
- if (self::$statements[$query]->execute($args) === false) {
- self::$lastError = implode("\n", self::$statements[$query]->errorInfo());
+ if ($stmt->execute($args) === false) {
+ self::$lastError = implode("\n", $stmt->errorInfo());
if ($ignoreError === true || ($ignoreError === null && self::$returnErrors))
return false;
Util::traceError("Database Error: \n" . self::$lastError);
@@ -188,7 +180,7 @@ class Database
}
self::$queryCount += 1;
}
- return self::$statements[$query];
+ return $stmt;
} catch (Exception $e) {
self::$lastError = '(' . $e->getCode() . ') ' . $e->getMessage();
if ($ignoreError === true || ($ignoreError === null && self::$returnErrors))
@@ -225,7 +217,7 @@ class Database
$res = self::simpleQuery('EXPLAIN ' . $query, $args, true);
if ($res === false)
return;
- $rows = $res->fetchAll(PDO::FETCH_ASSOC);
+ $rows = $res->fetchAll();
if (empty($rows))
return;
$log = $veryslow;
diff --git a/inc/property.inc.php b/inc/property.inc.php
index 1b979982..e7f4cd25 100644
--- a/inc/property.inc.php
+++ b/inc/property.inc.php
@@ -21,7 +21,7 @@ class Property
if (self::$cache === false) {
$NOW = time();
$res = Database::simpleQuery("SELECT name, dateline, value FROM property");
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['dateline'] != 0 && $row['dateline'] < $NOW)
continue;
self::$cache[$row['name']] = $row['value'];
@@ -71,7 +71,7 @@ class Property
$res = Database::simpleQuery("SELECT dateline, value FROM property_list WHERE name = :key", compact('key'));
$NOW = time();
$return = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['dateline'] != 0 && $row['dateline'] < $NOW)
continue;
$return[] = $row['value'];
diff --git a/inc/taskmanagercallback.inc.php b/inc/taskmanagercallback.inc.php
index 29bae262..84754de0 100644
--- a/inc/taskmanagercallback.inc.php
+++ b/inc/taskmanagercallback.inc.php
@@ -56,7 +56,7 @@ class TaskmanagerCallback
if ($res === false)
return array();
$retval = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$retval[$row['taskid']][] = $row;
}
return $retval;
diff --git a/install.php b/install.php
index f0bb1c72..60cf9495 100644
--- a/install.php
+++ b/install.php
@@ -84,7 +84,7 @@ function tableGetDescribeColumn($table, $column, $what)
$table = preg_replace('/\W/', '', $table);
$res = Database::simpleQuery("DESCRIBE `$table`", array(), true);
if ($res !== false) {
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ((is_array($column) && in_array($row['Field'], $column)) || (is_string($column) && $row['Field'] === $column))
return $row[$what];
}
@@ -101,7 +101,7 @@ function tableGetIndex($table, $index)
$res = Database::simpleQuery("SHOW INDEX FROM `$table`", array(), true);
if ($res !== false) {
$matches = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$i = $row['Seq_in_index'] - 1;
if (isset($index[$i]) && $index[$i] === $row['Column_name']) {
if (!isset($matches[$row['Key_name']])) {
@@ -124,7 +124,7 @@ function tableDropColumn($table, $column)
$column = preg_replace('/\W/', '', $column);
$res = Database::simpleQuery("DESCRIBE `$table`", array(), true);
if ($res !== false) {
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ((is_array($column) && in_array($row['Field'], $column)) || (is_string($column) && $row['Field'] === $column))
Database::exec("ALTER TABLE `$table` DROP `{$row['Field']}`");
}
@@ -345,6 +345,45 @@ function runUpdateScript($module)
require_once $module->getDir() . '/install.inc.php';
}
+// Update collation/encoding etc
+$charsetUpdate = '';
+$COLLATION = 'utf8mb4_unicode_520_ci';
+$res = Database::queryFirst("SELECT @@character_set_database, @@collation_database");
+if ($res['@@character_set_database'] !== 'utf8mb4' || $res['@@collation_database'] !== $COLLATION) {
+ if (!preg_match('/dbname=(\w+)/', CONFIG_SQL_DSN, $out)) {
+ $charsetUpdate = 'Cannot update charset: DB Name unknown';
+ } else {
+ $db = $out[1];
+ $columns = Database::simpleQuery("SELECT
+ TABLE_NAME, COLUMN_NAME, COLUMN_DEFAULT, IS_NULLABLE, COLUMN_TYPE, EXTRA, COLUMN_COMMENT
+ FROM information_schema.COLUMNS
+ WHERE TABLE_SCHEMA = :db AND COLLATION_NAME LIKE 'utf8%' AND COLLATION_NAME <> :collation",
+ ['db' => $db, 'collation' => $COLLATION]);
+ foreach ($columns as $c) {
+ $args = [];
+ $str = $c['COLUMN_TYPE'] . ' CHARACTER SET utf8mb4 ' . $c['EXTRA'];
+ if ($c['IS_NULLABLE'] === 'NO') {
+ $str .= ' NOT NULL';
+ }
+ if (!($c['IS_NULLABLE'] === 'NO' && $c['COLUMN_DEFAULT'] === null)) {
+ $str .= ' DEFAULT ' . ($c['COLUMN_DEFAULT'] ?? 'NULL');
+ }
+ if (!empty($c['COLUMN_COMMENT'])) {
+ $str .= ' COMMENT :comment';
+ $args['comment'] = $c['COLUMN_COMMENT'];
+ }
+ $str .= ' COLLATE ' . $COLLATION;
+ if (Database::exec("ALTER TABLE {$c['TABLE_NAME']} MODIFY {$c['COLUMN_NAME']} $str", $args) === false) {
+ $charsetUpdate .= "\n+++ {$c['TABLE_NAME']}.{$c['COLUMN_NAME']} failed: " . Database::lastError();
+ $charsetUpdate .= "\nALTER TABLE {$c['TABLE_NAME']} MODIFY {$c['COLUMN_NAME']} $str";
+ }
+ }
+ if (empty($charsetUpdate) && Database::exec("ALTER DATABASE $db CHARACTER SET utf8mb4 COLLATE $COLLATION") === false) {
+ $charsetUpdate .= "\nCannot update database charset or collation: " . Database::lastError();
+ }
+ }
+} // End utf8 stuff
+
// Build dependency tree
Module::init();
$modules = Module::getEnabled();
@@ -411,7 +450,7 @@ if (DIRECT_MODE) {
<title>Install/Update SLXadmin</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
- <style type="text/css">
+ <style>
body, html {
color: #000;
background: #fff;
@@ -428,6 +467,7 @@ if (DIRECT_MODE) {
</style>
</head>
<body>
+ <pre>$charsetUpdate</pre>
<h1>Modules</h1>
<button onclick="slxRunInstall()" class="install-btn">Install/Upgrade</button>
<br>
diff --git a/modules-available/adduser/page.inc.php b/modules-available/adduser/page.inc.php
index 4ab69919..e81e9fb2 100644
--- a/modules-available/adduser/page.inc.php
+++ b/modules-available/adduser/page.inc.php
@@ -203,7 +203,7 @@ class Page_AddUser extends Page
} elseif ($show === 'list') {
User::assertPermission('user.view-list');
$page = new Paginate('SELECT userid, login, fullname, phone, email FROM user ORDER BY login', 50);
- $data = ['list' => $page->exec()->fetchAll(PDO::FETCH_ASSOC)];
+ $data = ['list' => $page->exec()->fetchAll()];
foreach ($data['list'] as &$u) {
// Don't allow deleting user 1 and self
$u['hide_delete'] = $u['userid'] == 1 || $u['userid'] == User::getId();
diff --git a/modules-available/baseconfig/inc/baseconfig.inc.php b/modules-available/baseconfig/inc/baseconfig.inc.php
index 064e0f89..2e8efeda 100644
--- a/modules-available/baseconfig/inc/baseconfig.inc.php
+++ b/modules-available/baseconfig/inc/baseconfig.inc.php
@@ -83,7 +83,7 @@ class BaseConfig
];
});
$res = Database::simpleQuery('SELECT setting, value, displayvalue FROM setting_global');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (!isset($defaults[$row['setting']]))
continue; // Setting is not defined in any <module>/baseconfig/settings.json
ConfigHolder::add($row['setting'], $row, -1);
diff --git a/modules-available/baseconfig/page.inc.php b/modules-available/baseconfig/page.inc.php
index 1566464b..7f9bef1f 100644
--- a/modules-available/baseconfig/page.inc.php
+++ b/modules-available/baseconfig/page.inc.php
@@ -199,7 +199,7 @@ class Page_BaseConfig extends Page
{
$res = Database::simpleQuery("SELECT setting, value, displayvalue $fields FROM $table "
. " {$where} ORDER BY setting ASC", $params);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (!isset($missing[$row['setting']]))
continue;
if (!isset($vars[$row['setting']]) || !is_array($vars[$row['setting']])) {
diff --git a/modules-available/dnbd3/baseconfig/getconfig.inc.php b/modules-available/dnbd3/baseconfig/getconfig.inc.php
index e4f84d81..6a3aec25 100644
--- a/modules-available/dnbd3/baseconfig/getconfig.inc.php
+++ b/modules-available/dnbd3/baseconfig/getconfig.inc.php
@@ -29,7 +29,7 @@ $res = Database::simpleQuery('SELECT s.fixedip, m.clientip, sxl.locationid FROM
$locationsAssoc = array_flip($locationIds);
$servers = array();
$fallback = array();
-while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+foreach ($res as $row) {
if ($row['fixedip'] === '<self>') {
$row['fixedip'] = Property::getServerIp();
$defPrio = 2000;
diff --git a/modules-available/dnbd3/hooks/main-warning.inc.php b/modules-available/dnbd3/hooks/main-warning.inc.php
index 5f8a844f..bee0a258 100644
--- a/modules-available/dnbd3/hooks/main-warning.inc.php
+++ b/modules-available/dnbd3/hooks/main-warning.inc.php
@@ -6,7 +6,7 @@ if (Dnbd3::isEnabled() && User::hasPermission('.dnbd3.access-page')) {
LEFT JOIN machine m USING (machineuuid)
WHERE errormsg IS NOT NULL');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$error = $row['errormsg'] ? $row['errormsg'] : '<unknown error>';
$lastSeen = Util::prettyTime($row['dnbd3lastseen']);
if ($row['fixedip'] === '<self>') {
diff --git a/modules-available/dnbd3/inc/dnbd3util.inc.php b/modules-available/dnbd3/inc/dnbd3util.inc.php
index 8e355370..d9bfaeee 100644
--- a/modules-available/dnbd3/inc/dnbd3util.inc.php
+++ b/modules-available/dnbd3/inc/dnbd3util.inc.php
@@ -12,7 +12,7 @@ class Dnbd3Util {
$res = Database::simpleQuery('SELECT s.serverid, s.machineuuid, s.fixedip, s.lastup, s.lastdown, m.clientip
FROM dnbd3_server s
LEFT JOIN machine m USING (machineuuid)');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (!empty($row['machineuuid'])) {
$allUuids[$row['machineuuid']] = true;
}
@@ -121,7 +121,7 @@ class Dnbd3Util {
WHERE machineuuid = :uuid',
array('uuid' => $machineUuid));
$assignedLocs = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$assignedLocs[] = $row['locationid'];
}
$modeData = (array)json_decode($modeData, true) + self::defaultRunmodeConfig();
@@ -142,7 +142,7 @@ class Dnbd3Util {
$floatIp = (float)sprintf('%u', $floatIp); // Float for 32bit php :/
}
$ranges = [['startaddr' => $floatIp, 'endaddr' => $floatIp]];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
settype($row['startaddr'], PHP_INT_SIZE === 4 ? 'float' : 'int');
settype($row['endaddr'], PHP_INT_SIZE === 4 ? 'float' : 'int');
self::mergeRanges($ranges, $row);
@@ -164,7 +164,7 @@ class Dnbd3Util {
$public = array();
$private = array();
$public[$self] = $self;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$ip = $row['fixedip'] ? $row['fixedip'] : $row['clientip'];
if ($ip === '<self>') {
continue;
diff --git a/modules-available/dnbd3/page.inc.php b/modules-available/dnbd3/page.inc.php
index d0842c23..a58f6fcc 100644
--- a/modules-available/dnbd3/page.inc.php
+++ b/modules-available/dnbd3/page.inc.php
@@ -174,7 +174,7 @@ class Page_Dnbd3 extends Page
$NOW = time();
$externalAllowed = User::hasPermission('configure.external');
$locsRunmode = User::getAllowedLocations('configure.proxy');
- while ($server = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $server) {
if (!is_null($server['machineuuid'])) {
// Auto proxy
if (!isset($dynClients[$server['machineuuid']])) {
@@ -355,7 +355,7 @@ class Page_Dnbd3 extends Page
$loc['recCount'] = 0;
}
$showLocs = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
settype($row['locationid'], 'int');
$loc =& $locCount[$row['locationid']];
$loc['clientCount'] = $row['cnt'];
diff --git a/modules-available/dozmod/pages/actionlog.inc.php b/modules-available/dozmod/pages/actionlog.inc.php
index eaa5218c..51fccb4f 100644
--- a/modules-available/dozmod/pages/actionlog.inc.php
+++ b/modules-available/dozmod/pages/actionlog.inc.php
@@ -144,7 +144,7 @@ class SubPage
// query action log
$res = Database::simpleQuery($query, $params);
$events = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['dateline_s'] = date('d.m.Y H:i', $row['dateline']);
if (isset($row['imgname'])) {
$row['targeturl'] = '?do=dozmod&section=actionlog&action=showtarget&uuid=' . $row['targetid'];
diff --git a/modules-available/dozmod/pages/expiredimages.inc.php b/modules-available/dozmod/pages/expiredimages.inc.php
index 0ecdaa77..b61b863b 100644
--- a/modules-available/dozmod/pages/expiredimages.inc.php
+++ b/modules-available/dozmod/pages/expiredimages.inc.php
@@ -22,7 +22,7 @@ class SubPage
ORDER BY b.displayname ASC, v.createtime ASC");
$NOW = time();
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['latexptime'] > $NOW && $row['latdelstate'] === 'KEEP') {
$row['hasNewerClass'] = 'glyphicon-ok green';
$row['checked'] = 'checked';
diff --git a/modules-available/dozmod/pages/networkrules.inc.php b/modules-available/dozmod/pages/networkrules.inc.php
index 710e90a9..218b7b06 100644
--- a/modules-available/dozmod/pages/networkrules.inc.php
+++ b/modules-available/dozmod/pages/networkrules.inc.php
@@ -74,7 +74,7 @@ class SubPage
$res = Database::simpleQuery('SELECT ruleid, rulename, ruledata
FROM sat.presetnetworkrule ORDER BY rulename ASC');
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$rows[] = $row;
}
Render::addTemplate('networkrules', [
diff --git a/modules-available/dozmod/pages/networkshares.inc.php b/modules-available/dozmod/pages/networkshares.inc.php
index 659321b4..852a8c67 100644
--- a/modules-available/dozmod/pages/networkshares.inc.php
+++ b/modules-available/dozmod/pages/networkshares.inc.php
@@ -66,7 +66,7 @@ class SubPage
$res = Database::simpleQuery('SELECT shareid, sharename, sharedata, active
FROM sat.presetnetworkshare ORDER BY sharename ASC');
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$dec = json_decode($row['sharedata'], true);
if (!is_array($dec)) {
$dec = [];
diff --git a/modules-available/dozmod/pages/runscripts.inc.php b/modules-available/dozmod/pages/runscripts.inc.php
index 9e6062d4..5665ba83 100644
--- a/modules-available/dozmod/pages/runscripts.inc.php
+++ b/modules-available/dozmod/pages/runscripts.inc.php
@@ -98,7 +98,7 @@ class SubPage
FROM sat.presetrunscript
ORDER BY scriptname ASC');
$rows = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['visibility'] == 0) {
$row['visibility'] = 'eye-close';
} elseif ($row['visibility'] == 1) {
@@ -139,7 +139,7 @@ class SubPage
$res = Database::simpleQuery('SELECT o.osid, o.displayname, pxo.osid AS isvalid FROM sat.operatingsystem o
LEFT JOIN sat.presetrunscript_x_operatingsystem pxo ON (o.osid = pxo.osid AND pxo.runscriptid = :runscriptid)
ORDER BY o.displayname ASC', ['runscriptid' => $id]);
- while ($osrow = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $osrow) {
$row['oslist'][] = [
'osid' => $osrow['osid'],
'displayname' => $osrow['displayname'],
diff --git a/modules-available/dozmod/pages/special.inc.php b/modules-available/dozmod/pages/special.inc.php
index 5a532b51..d6ac53d6 100644
--- a/modules-available/dozmod/pages/special.inc.php
+++ b/modules-available/dozmod/pages/special.inc.php
@@ -15,7 +15,7 @@ class SubPage
. " GROUP BY blocksha1, blocksize HAVING blockcount > 1 ORDER BY blockcount DESC, blocksha1 ASC");
$data = array('hashes' => array());
$spaceWasted = 0;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['hash_hex'] = bin2hex($row['blocksha1']);
$row['blocksize_s'] = Util::readableFileSize($row['blocksize']);
$data['hashes'][] = $row;
@@ -57,7 +57,7 @@ class SubPage
die('Database error: ' . Database::lastError());
}
$data = array('rows' => array());
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['createtime_s'] = date('d.m.Y H:i', $row['createtime']);
$row['filesize_s'] = Util::readableFileSize($row['filesize']);
$data['rows'][] = $row;
diff --git a/modules-available/dozmod/pages/users.inc.php b/modules-available/dozmod/pages/users.inc.php
index 50f0f763..cdf22b9d 100644
--- a/modules-available/dozmod/pages/users.inc.php
+++ b/modules-available/dozmod/pages/users.inc.php
@@ -42,7 +42,7 @@ class SubPage
. ' LEFT JOIN sat.organization USING (organizationid)'
. ' ORDER BY lastname ASC, firstname ASC');
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
settype($row['lastlogin'], 'int');
$row['canlogin'] = self::checked($row['canlogin']);
$row['issuperuser'] = self::checked($row['issuperuser']);
@@ -63,7 +63,7 @@ class SubPage
$res = Database::simpleQuery('SELECT organizationid, displayname, canlogin FROM sat.organization'
. ' ORDER BY displayname ASC');
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['canlogin'] = self::checked($row['canlogin']);
$rows[] = $row;
}
diff --git a/modules-available/eventlog/page.inc.php b/modules-available/eventlog/page.inc.php
index 1c81983c..250e1b24 100644
--- a/modules-available/eventlog/page.inc.php
+++ b/modules-available/eventlog/page.inc.php
@@ -16,7 +16,7 @@ class Page_EventLog extends Page
$lines = array();
$paginate = new Paginate("SELECT logid, dateline, logtypeid, description, extra FROM eventlog ORDER BY logid DESC", 50);
$res = $paginate->exec();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['date'] = Util::prettyTime($row['dateline']);
$row['icon'] = $this->typeToIcon($row['logtypeid']);
$row['color'] = $this->typeToColor($row['logtypeid']);
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php
index 868f5927..317e56c0 100644
--- a/modules-available/exams/page.inc.php
+++ b/modules-available/exams/page.inc.php
@@ -23,7 +23,7 @@ class Page_Exams extends Page
} else {
$tmp = Database::simpleQuery("SELECT locationid FROM exams_x_location WHERE examid= :examid", array('examid' => $examidOrLocations));
$active = array();
- while ($row = $tmp->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($tmp as $row) {
$active[] = (int)$row['locationid'];
}
}
@@ -40,7 +40,7 @@ class Page_Exams extends Page
. "GROUP BY examid "
. "ORDER BY examid ASC");
- while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($tmp as $exam) {
$view = $edit = false;
// User has permission for all locations
if (in_array(0, $this->userViewLocations)) {
@@ -87,7 +87,7 @@ class Page_Exams extends Page
"GROUP BY lectureid " .
"ORDER BY starttime ASC, displayname ASC",
['rangeMax' => $this->rangeMax, 'rangeMin' => $this->rangeMin]);
- while ($lecture = $tmp->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($tmp as $lecture) {
$this->lectures[] = $lecture;
}
}
@@ -111,7 +111,7 @@ class Page_Exams extends Page
return User::hasPermission('exams.edit');
// Check locations of existing exam
$res = Database::simpleQuery("SELECT locationid FROM exams_x_location WHERE examid= :examid", array('examid' => $examid));
- while ($locId = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $locId) {
if (!in_array($locId['locationid'], $this->userEditLocations))
return false;
}
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index d3ff9ebd..e1c35525 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -175,7 +175,7 @@ function getCalendar($idList)
$dbquery = Database::simpleQuery($query, array('idlist' => array_values($idList)));
$serverList = array();
- while ($dbresult = $dbquery->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($dbquery as $dbresult) {
if (!isset($serverList[$dbresult['serverid']])) {
$serverList[$dbresult['serverid']] = array(
'credentials' => json_decode($dbresult['credentials'], true),
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php
index 6e4d77ac..045952ed 100644
--- a/modules-available/locationinfo/inc/coursebackend.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend.inc.php
@@ -195,7 +195,7 @@ abstract class CourseBackend
array('locations' => $requestedLocationIds));
$returnValue = [];
$remoteIds = [];
- while ($row = $dbquery1->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($dbquery1 as $row) {
// Check if in cache - if lastUpdate is null then it is interpreted as 1970
if ($row['lastcalendarupdate'] + $this->getCacheTime() < $NOW) {
$remoteIds[$row['locationid']] = $row['serverlocationid'];
@@ -222,7 +222,7 @@ abstract class CourseBackend
'lastuse' => $NOW - $this->getRefreshTime(),
'minage' => $NOW - $this->getCacheTime(),
));
- while ($row = $dbquery4->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($dbquery4 as $row) {
$remoteIds[$row['locationid']] = $row['serverlocationid'];
}
}
diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php
index 6deb9db5..84a74e80 100644
--- a/modules-available/locationinfo/inc/infopanel.inc.php
+++ b/modules-available/locationinfo/inc/infopanel.inc.php
@@ -115,7 +115,7 @@ class InfoPanel
$dbquery = Database::simpleQuery($query, array('idlist' => $idList));
// Iterate over matching machines
- while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($dbquery as $row) {
if (isset($ignoreList[$row['machineuuid']]))
continue;
settype($row['locationid'], 'int');
@@ -175,7 +175,7 @@ class InfoPanel
$res = Database::simpleQuery("SELECT locationid, openingtime FROM location
WHERE locationid IN (:lids)", array('lids' => $allIds));
$openingTimes = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$openingTimes[(int)$row['locationid']] = $row;
}
// Now we got all the calendars for locations and parents
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index 9e7a704e..d4fa50ac 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -459,7 +459,7 @@ class Page_LocationInfo extends Page
// Build list of defined backends
$serverlist = array();
$dbquery2 = Database::simpleQuery("SELECT * FROM `locationinfo_coursebackend` ORDER BY servername ASC");
- while ($row = $dbquery2->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($dbquery2 as $row) {
if (isset($servertypes[$row['servertype']])) {
$row['typename'] = $servertypes[$row['servertype']];
} else {
@@ -512,7 +512,7 @@ class Page_LocationInfo extends Page
$server['list'] = [];
$res = Database::simpleQuery('SELECT dateline, message FROM locationinfo_backendlog
WHERE serverid = :id ORDER BY logid DESC LIMIT 100', ['id' => $id]);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['dateline_s'] = Util::prettyTime($row['dateline']);
$row['class'] = substr($row['message'], 0, 3) === '[F]' ? 'text-danger' : 'text-warning';
$row['message'] = Substr($row['message'], 3);
@@ -536,7 +536,7 @@ class Page_LocationInfo extends Page
LEFT JOIN `locationinfo_coursebackend` AS cb USING (serverid)
LEFT JOIN `location` AS loc USING (locationid)");
- while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($dbquery as $row) {
$locid = (int)$row['locationid'];
if (!isset($locations[$locid]) || !in_array($locid, $allowedLocations))
continue;
@@ -593,7 +593,7 @@ class Page_LocationInfo extends Page
}
$panels = array();
$locations = Location::getLocationsAssoc();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['paneltype'] === 'URL') {
$url = json_decode($row['panelconfig'], true)['url'];
$row['locations'] = $row['locationurl'] = $url;
@@ -721,7 +721,7 @@ class Page_LocationInfo extends Page
WHERE locationid IN (:locations) AND serverid IS NOT NULL", array('locations' => $chain));
$chain = array_flip($chain);
$best = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($best === false || $chain[$row['locationid']] < $chain[$best['locationid']]) {
$best = $row;
}
@@ -735,7 +735,7 @@ class Page_LocationInfo extends Page
// get Server / ID list
$res = Database::simpleQuery("SELECT serverid, servername FROM locationinfo_coursebackend ORDER BY servername ASC");
$serverList = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['serverid'] == $locConfig['serverid']) {
$row['selected'] = 'selected';
}
diff --git a/modules-available/locations/baseconfig/getconfig.inc.php b/modules-available/locations/baseconfig/getconfig.inc.php
index 26e43ed8..f2aa2b46 100644
--- a/modules-available/locations/baseconfig/getconfig.inc.php
+++ b/modules-available/locations/baseconfig/getconfig.inc.php
@@ -31,7 +31,7 @@ if (!empty($matchingLocations)) {
FROM setting_location WHERE locationid IN (:list)",
['list' => $matchingLocations]);
$tmp = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$tmp[(int)$row['locationid']][$row['setting']] = $row; // Put whole row so we have value and displayvalue
}
// Callback for pretty printing
diff --git a/modules-available/locations/inc/autolocation.inc.php b/modules-available/locations/inc/autolocation.inc.php
index 82c61251..f77cf714 100644
--- a/modules-available/locations/inc/autolocation.inc.php
+++ b/modules-available/locations/inc/autolocation.inc.php
@@ -22,7 +22,7 @@ class AutoLocation
}
$updates = array();
$nulls = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$loc = Location::mapIpToLocation($row['clientip']);
if ($loc === false) {
$nulls[] = $row['machineuuid'];
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 700edaf8..e4bce313 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -21,7 +21,7 @@ class Location
{
$res = Database::simpleQuery("SELECT locationid, parentlocationid, locationname FROM location");
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$rows[] = $row;
}
return $rows;
@@ -390,7 +390,7 @@ class Location
{
$res = Database::simpleQuery("SELECT startaddr, endaddr, locationid FROM subnet");
$subnets = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
settype($row['locationid'], 'int');
$subnets[] = $row;
}
diff --git a/modules-available/locations/inc/locationutil.inc.php b/modules-available/locations/inc/locationutil.inc.php
index 708cc8a2..960eefa8 100644
--- a/modules-available/locations/inc/locationutil.inc.php
+++ b/modules-available/locations/inc/locationutil.inc.php
@@ -124,7 +124,7 @@ class LocationUtil
$res = Database::simpleQuery($query, $params);
$return = [];
$locs = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (Location::isFixedLocationValid($row['fixedlocationid'], $row['subnetlocationid']))
continue;
$lid = (int)$row['fixedlocationid'];
diff --git a/modules-available/locations/pages/details.inc.php b/modules-available/locations/pages/details.inc.php
index 356620d3..86bfebd6 100644
--- a/modules-available/locations/pages/details.inc.php
+++ b/modules-available/locations/pages/details.inc.php
@@ -322,7 +322,7 @@ class SubPage
$res = Database::simpleQuery("SELECT subnetid, startaddr, endaddr FROM subnet WHERE locationid = :lid",
array('lid' => $locationId));
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['startaddr'] = long2ip($row['startaddr']);
$row['endaddr'] = long2ip($row['endaddr']);
$rows[] = $row;
@@ -360,7 +360,7 @@ class SubPage
if (Module::get('statistics') !== false) {
$mres = Database::simpleQuery("SELECT state FROM machine"
. " WHERE machine.locationid = :lid", array('lid' => $locationId));
- while ($row = $mres->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($mres as $row) {
$count++;
if ($row['state'] === 'IDLE') {
$online++;
diff --git a/modules-available/locations/pages/locations.inc.php b/modules-available/locations/pages/locations.inc.php
index 8afb454a..ce08e597 100644
--- a/modules-available/locations/pages/locations.inc.php
+++ b/modules-available/locations/pages/locations.inc.php
@@ -121,7 +121,7 @@ class SubPage
$res = Database::simpleQuery("SELECT m.locationid, Count(*) AS cnt,
Sum(If(m.state = 'OCCUPIED', 1, 0)) AS used, Sum(If(m.state = 'IDLE', 1, 0)) AS idle
FROM machine m WHERE (locationid IN (:allowedLocationIds) $extra) GROUP BY locationid", compact('allowedLocationIds'));
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$locId = (int)$row['locationid'];
if (isset($locationList[$locId])) {
$locationList[$locId]['clientCount'] = $row['cnt'];
@@ -135,7 +135,7 @@ class SubPage
}
$res = Database::simpleQuery("SELECT m.locationid, Count(DISTINCT sm.machineuuid) AS cnt FROM setting_machine sm
INNER JOIN machine m USING (machineuuid) GROUP BY m.locationid");
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$locId = (int)$row['locationid'];
if (isset($locationList[$locId])) {
$locationList[$locId]['machineVarsOverrideCount'] = $row['cnt'];
@@ -188,7 +188,7 @@ class SubPage
if (Module::get('baseconfig') !== false) {
$res = Database::simpleQuery("SELECT locationid, Count(*) AS cnt FROM `setting_location`
WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds'));
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$lid = (int)$row['locationid'];
if (isset($locationList[$lid])) {
$locationList[$lid]['overriddenVars'] = $row['cnt'];
@@ -202,7 +202,7 @@ class SubPage
$res = Database::simpleQuery("SELECT ml.locationid, m.title, ml.defaultentryid FROM serversetup_menu m
INNER JOIN serversetup_menu_location ml USING (menuid)
WHERE locationid IN (:allowedLocationIds) GROUP BY locationid", compact('allowedLocationIds'));
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$lid = (int)$row['locationid'];
if (isset($locationList[$lid])) {
if ($row['defaultentryid'] !== null) {
diff --git a/modules-available/locations/pages/subnets.inc.php b/modules-available/locations/pages/subnets.inc.php
index fb1e1e80..e568c655 100644
--- a/modules-available/locations/pages/subnets.inc.php
+++ b/modules-available/locations/pages/subnets.inc.php
@@ -67,7 +67,7 @@ class SubPage
FROM subnet
ORDER BY startaddr ASC, endaddr DESC");
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['startaddr'] = long2ip($row['startaddr']);
$row['endaddr'] = long2ip($row['endaddr']);
$row['locations'] = Location::getLocations($row['locationid']);
diff --git a/modules-available/minilinux/inc/minilinux.inc.php b/modules-available/minilinux/inc/minilinux.inc.php
index d64ef080..89a5035a 100644
--- a/modules-available/minilinux/inc/minilinux.inc.php
+++ b/modules-available/minilinux/inc/minilinux.inc.php
@@ -359,7 +359,7 @@ class MiniLinux
$list = [];
$res = Database::simpleQuery('SELECT branchid, versionid, title, dateline, orphan, taskid, installed
FROM minilinux_version ORDER BY branchid, dateline, versionid');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$list[$row['branchid']][$row['versionid']] = $row;
}
return $list;
@@ -473,7 +473,7 @@ class MiniLinux
GROUP BY be.data");
$return = [];
$usedMenuIds = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$data = json_decode($row['data'], true);
if (!isset($data['id']))
continue;
@@ -496,7 +496,7 @@ class MiniLinux
$res = Database::simpleQuery("SELECT menuid, title FROM serversetup_menu m
WHERE menuid IN (:menuid)", ['menuid' => array_unique($usedMenuIds)]);
$menus = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$menus[$row['menuid']] = $row['title'];
}
// Build output array
diff --git a/modules-available/minilinux/page.inc.php b/modules-available/minilinux/page.inc.php
index 03ec121e..33a7ab28 100644
--- a/modules-available/minilinux/page.inc.php
+++ b/modules-available/minilinux/page.inc.php
@@ -57,7 +57,7 @@ class Page_MiniLinux extends Page
$data = ['list' => [], 'show_refresh' => true];
$tooOld = strtotime('-7 days');
$showRefresh = strtotime('-5 minutes');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['lastupdate_s'] = Util::prettyTime($row['lastupdate']);
if ($row['lastupdate'] != 0 && $row['lastupdate'] < $tooOld) {
$row['update_class'] = 'text-danger';
diff --git a/modules-available/news/page.inc.php b/modules-available/news/page.inc.php
index 7a09d437..21b99952 100644
--- a/modules-available/news/page.inc.php
+++ b/modules-available/news/page.inc.php
@@ -122,7 +122,7 @@ class Page_News extends Page
$res = Database::simpleQuery("SELECT newsid, dateline, expires, title, content FROM vmchooser_pages
WHERE type = :type ORDER BY dateline DESC LIMIT 20", ['type' => $this->pageType]);
$foundActive = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['dateline_s'] = Util::prettyTime($row['dateline']);
$row['expires_s'] = $this->formatExpires($row['expires']);
if ($row['newsid'] == $this->newsId) {
diff --git a/modules-available/permissionmanager/inc/getpermissiondata.inc.php b/modules-available/permissionmanager/inc/getpermissiondata.inc.php
index 4dfb09ec..ead1e020 100644
--- a/modules-available/permissionmanager/inc/getpermissiondata.inc.php
+++ b/modules-available/permissionmanager/inc/getpermissiondata.inc.php
@@ -19,7 +19,7 @@ class GetPermissionData
LEFT JOIN role ON role_x_user.roleid = role.roleid
");
$userdata = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$userdata[$row['userid'] . ' ' . $row['login']][] = array(
'roleid' => $row['roleid'],
'rolename' => $row['rolename']
@@ -47,7 +47,7 @@ class GetPermissionData
$res = Database::simpleQuery("SELECT role.roleid AS roleid, rolename, GROUP_CONCAT(COALESCE(locationid, 0)) AS locationids FROM role
INNER JOIN role_x_location ON role.roleid = role_x_location.roleid GROUP BY roleid ORDER BY rolename ASC");
$locations = Location::getLocations(0, 0, false, true);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$locationids = explode(",", $row['locationids']);
if (in_array("0", $locationids)) {
$locationids = array_map("intval", Location::extractIds(Location::getTree()));
@@ -103,13 +103,13 @@ class GetPermissionData
if ($res === false)
return false;
$data["locations"] = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$data["locations"][] = $row['locationid'];
}
$res = Database::simpleQuery("SELECT roleid, permissionid FROM role_x_permission WHERE roleid = :roleid",
array("roleid" => $roleid));
$data["permissions"] = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$data["permissions"][] = $row['permissionid'];
}
return $data;
diff --git a/modules-available/permissionmanager/inc/permissionutil.inc.php b/modules-available/permissionmanager/inc/permissionutil.inc.php
index 6aa97600..48ebb77e 100644
--- a/modules-available/permissionmanager/inc/permissionutil.inc.php
+++ b/modules-available/permissionmanager/inc/permissionutil.inc.php
@@ -124,7 +124,7 @@ class PermissionUtil
}
self::makeComparisonVariants($parts, $compare, $wildcard, $wclen);
$retval = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (in_array($row['permissionid'], $compare, true)
|| ($wildcard !== false && strncmp($row['permissionid'], $wildcard, $wclen) === 0)) {
if (!$cacheAll || ($row['locationid'] == $locationid) || $row['locationid'] === null) {
@@ -178,7 +178,7 @@ class PermissionUtil
// Gather locationid from relevant rows
self::makeComparisonVariants($parts, $compare, $wildcard, $wclen);
$allowedLocations = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (in_array($row['permissionid'], $compare, true)
|| ($wildcard !== false && strncmp($row['permissionid'], $wildcard, $wclen) === 0)) {
$allowedLocations[(int)$row['locationid']] = true;
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);
diff --git a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
index da1dd69a..71801f1a 100644
--- a/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
+++ b/modules-available/rebootcontrol/inc/rebootcontrol.inc.php
@@ -167,7 +167,7 @@ class RebootControl
if (!empty($invalid)) {
$res = Database::simpleQuery('SELECT machineuuid, clientip, locationid FROM machine WHERE machineuuid IN (:uuids)',
['uuids' => array_keys($invalid)]);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (isset($invalid[$row['machineuuid']])) {
$valid[] = $row + $invalid[$row['machineuuid']];
} else {
@@ -300,7 +300,7 @@ class RebootControl
// Need all subnets...
$subnets = [];
$res = Database::simpleQuery('SELECT subnetid, start, end, isdirect FROM reboot_subnet');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row += [
'jumphosts' => [],
'direct' => [],
@@ -317,7 +317,7 @@ class RebootControl
LEFT JOIN reboot_subnet s ON (INET_ATON(jh.host) BETWEEN s.start AND s.end)
LEFT JOIN reboot_subnet_x_subnet sxs ON (sxs.srcid = s.subnetid AND sxs.reachable <> 0)
GROUP BY jh.hostid');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['subnets1'] === null && $row['subnets2'] === null)
continue;
$nets = explode(',', $row['subnets1'] . ',' . $row['subnets2']);
diff --git a/modules-available/rebootcontrol/inc/rebootutils.inc.php b/modules-available/rebootcontrol/inc/rebootutils.inc.php
index 99235e8a..f6843150 100644
--- a/modules-available/rebootcontrol/inc/rebootutils.inc.php
+++ b/modules-available/rebootcontrol/inc/rebootutils.inc.php
@@ -18,9 +18,9 @@ class RebootUtils
$res = Database::simpleQuery("SELECT $columns FROM machine
WHERE machineuuid IN (:list)", compact('list'));
if (!$assoc)
- return $res->fetchAll(PDO::FETCH_ASSOC);
+ return $res->fetchAll();
$ret = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$ret[$row['machineuuid']] = $row;
}
return $ret;
diff --git a/modules-available/rebootcontrol/inc/scheduler.inc.php b/modules-available/rebootcontrol/inc/scheduler.inc.php
index 292529fa..7da4b46b 100644
--- a/modules-available/rebootcontrol/inc/scheduler.inc.php
+++ b/modules-available/rebootcontrol/inc/scheduler.inc.php
@@ -117,7 +117,7 @@ class Scheduler
$res = Database::simpleQuery("SELECT s.locationid, s.action, s.nextexecution, s.options
FROM reboot_scheduler s
WHERE s.nextexecution < :now AND s.nextexecution > 0", ['now' => $now]);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
// Calculate next_execution for the event and update DB.
$options = json_decode($row['options'], true);
// Determine proper opening times by waling up tree
@@ -269,7 +269,7 @@ class Scheduler
LEFT JOIN reboot_scheduler rs USING (locationid)
WHERE l.locationid IN (:list)", ['list' => $childIdList]);
$locationData = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$locationData[$row['locationid']] = $row;
}
// Handle all child locations
diff --git a/modules-available/rebootcontrol/pages/jumphost.inc.php b/modules-available/rebootcontrol/pages/jumphost.inc.php
index bf0a67e2..90508e91 100644
--- a/modules-available/rebootcontrol/pages/jumphost.inc.php
+++ b/modules-available/rebootcontrol/pages/jumphost.inc.php
@@ -135,7 +135,7 @@ class SubPage
LEFT JOIN reboot_jumphost_x_subnet jxs USING (hostid)
GROUP BY hostid
ORDER BY hostid');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$hosts[] = $row;
}
$data = [
@@ -188,7 +188,7 @@ class SubPage
ORDER BY start ASC',
['id' => $id]);
$list = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['cidr'] = IpUtil::rangeToCidr($row['start'], $row['end']);
if ($row['hostid'] !== null) {
$row['checked'] = 'checked';
diff --git a/modules-available/rebootcontrol/pages/subnet.inc.php b/modules-available/rebootcontrol/pages/subnet.inc.php
index d165a59d..c1631cbd 100644
--- a/modules-available/rebootcontrol/pages/subnet.inc.php
+++ b/modules-available/rebootcontrol/pages/subnet.inc.php
@@ -115,7 +115,7 @@ class SubPage
GROUP BY subnetid, start, end
ORDER BY start ASC, end DESC');
$deadline = strtotime('-60 days');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['cidr'] = IpUtil::rangeToCidr($row['start'], $row['end']);
$row['lastseen_s'] = Util::prettyTime($row['lastseen']);
if ($row['lastseen'] && $row['lastseen'] < $deadline) {
@@ -149,7 +149,7 @@ class SubPage
ORDER BY h.host ASC', ['id' => $id]);
// Mark those assigned to the current subnet
$jh = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['checked'] = $row['subnetid'] === null ? '' : 'checked';
$jh[] = $row;
}
@@ -159,7 +159,7 @@ class SubPage
INNER JOIN reboot_subnet_x_subnet sxs ON (s.subnetid = sxs.srcid AND sxs.dstid = :id AND sxs.reachable = 1)
ORDER BY s.start ASC', ['id' => $id]);
$sn = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$sn[] = ['cidr' => IpUtil::rangeToCidr($row['start'], $row['end'])];
}
$subnet['sourceNets'] = $sn;
diff --git a/modules-available/remoteaccess/inc/remoteaccess.inc.php b/modules-available/remoteaccess/inc/remoteaccess.inc.php
index 9b6dea6a..a45915e8 100644
--- a/modules-available/remoteaccess/inc/remoteaccess.inc.php
+++ b/modules-available/remoteaccess/inc/remoteaccess.inc.php
@@ -35,7 +35,7 @@ class RemoteAccess
// Consider machines we tried to wake in the past 90 seconds as online
$wolDeadline = time() - 90;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['wolcount'] <= 0)
continue;
// This can't really be anything but a CSV list, but better be safe
@@ -62,7 +62,7 @@ class RemoteAccess
$NOW = time();
while ($num > 0) {
$list = [];
- for ($i = 0; $i < $num && $row = $res->fetch(PDO::FETCH_ASSOC); ++$i) {
+ for ($i = 0; $i < $num && $row = $res->fetch(); ++$i) {
$list[] = $row;
Database::exec("INSERT INTO remoteaccess_machine (machineuuid, password, woltime)
VALUES (:uuid, NULL, :now)
diff --git a/modules-available/roomplanner/inc/room.inc.php b/modules-available/roomplanner/inc/room.inc.php
index 855bdbcf..1a7a80ae 100644
--- a/modules-available/roomplanner/inc/room.inc.php
+++ b/modules-available/roomplanner/inc/room.inc.php
@@ -28,7 +28,7 @@ abstract class Room
'SELECT lr.locationid, lr.managerip, lr.tutoruuid, lr.roomplan, m.clientip as tutorip
FROM location_roomplan lr
LEFT JOIN machine m ON (lr.tutoruuid = m.machineuuid)');
- while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($ret as $row) {
$row = self::loadSingleRoom($row);
if ($row === false)
continue;
diff --git a/modules-available/roomplanner/inc/simpleroom.inc.php b/modules-available/roomplanner/inc/simpleroom.inc.php
index 78db6c4a..43ae43ca 100644
--- a/modules-available/roomplanner/inc/simpleroom.inc.php
+++ b/modules-available/roomplanner/inc/simpleroom.inc.php
@@ -21,7 +21,7 @@ class SimpleRoom extends Room
'SELECT machineuuid, clientip, position FROM machine WHERE fixedlocationid = :locationid',
['locationid' => $locationId]);
- while ($clientRow = $ret->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($ret as $clientRow) {
$position = json_decode($clientRow['position'], true);
if ($position === false || !isset($position['gridRow']) || !isset($position['gridCol']))
diff --git a/modules-available/roomplanner/install.inc.php b/modules-available/roomplanner/install.inc.php
index 13365fe1..05fd7589 100644
--- a/modules-available/roomplanner/install.inc.php
+++ b/modules-available/roomplanner/install.inc.php
@@ -47,7 +47,7 @@ if (tableHasColumn('location_roomplan', 'dedicatedmgr')) {
if ($ret === false) {
$res[] = UPDATE_FAILED;
} else {
- while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($ret as $row) {
$dedi = $row['dedicatedmgr'] != 0;
$data = json_encode(array('dedicatedmgr' => $dedi));
Database::exec("INSERT IGNORE INTO runmode (machineuuid, module, modeid, modedata, isclient)
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index 8c3beace..a591014b 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -195,7 +195,7 @@ class Page_Roomplanner extends Page
$returnObject = ['machines' => []];
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($result as $row) {
if (!Location::isFixedLocationValid($roomLocationId, $row['subnetlocationid']))
continue;
if (empty($row['hostname'])) {
@@ -393,7 +393,7 @@ class Page_Roomplanner extends Page
WHERE fixedlocationid = :locationid',
['locationid' => $this->locationid]);
$machines = [];
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($result as $row) {
$machine = [];
$pos = json_decode($row['position'], true);
if ($pos === false || !isset($pos['gridRow']) || !isset($pos['gridCol'])) {
@@ -429,7 +429,7 @@ class Page_Roomplanner extends Page
$machines = [];
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($result as $row) {
if (empty($row['hostname'])) {
$row['hostname'] = $row['clientip'];
}
diff --git a/modules-available/runmode/inc/runmode.inc.php b/modules-available/runmode/inc/runmode.inc.php
index 4d077f02..ccc432d2 100644
--- a/modules-available/runmode/inc/runmode.inc.php
+++ b/modules-available/runmode/inc/runmode.inc.php
@@ -139,7 +139,7 @@ class RunMode
$res = Database::simpleQuery('SELECT machineuuid, modeid, modedata FROM runmode WHERE module = :module',
compact('module'));
$ret = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($groupByModeId) {
if (!isset($ret[$row['modeid']])) {
$ret[$row['modeid']] = array();
@@ -177,7 +177,7 @@ class RunMode
WHERE module = :module AND modeid = :modeId",
compact('module', 'modeId'));
$ret = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($detailed && empty($row['hostname'])) {
$row['hostname'] = $row['clientip'];
}
@@ -204,7 +204,7 @@ class RunMode
}
$res = Database::simpleQuery("SELECT machineuuid, module, modeid, isclient $xtra FROM runmode");
$ret = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (!is_null($isClient) && ($row['isclient'] != 0) !== $isClient)
continue;
$ret[$row['machineuuid']] = $row;
diff --git a/modules-available/runmode/page.inc.php b/modules-available/runmode/page.inc.php
index 0b6dfa02..a551ddc5 100644
--- a/modules-available/runmode/page.inc.php
+++ b/modules-available/runmode/page.inc.php
@@ -198,15 +198,17 @@ class Page_RunMode extends Page
{
if ($onlyModule === false) {
$where = '';
+ $args = [];
} else {
$where = ' AND r.module = :moduleId ';
+ $args = ['moduleId' => $onlyModule];
}
$res = Database::simpleQuery("SELECT m.machineuuid, m.hostname, m.clientip, r.module, r.modeid, r.isclient"
. " FROM runmode r"
. " INNER JOIN machine m ON (m.machineuuid = r.machineuuid $where )"
- . " ORDER BY m.hostname ASC, m.clientip ASC", array('moduleId' => $onlyModule));
+ . " ORDER BY m.hostname ASC, m.clientip ASC", $args);
$modules = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (!isset($modules[$row['module']])) {
if (!Module::isAvailable($row['module']))
continue;
@@ -332,7 +334,7 @@ class Page_RunMode extends Page
LIMIT 100", $params);
$returnObject = [
- 'machines' => $result->fetchAll(PDO::FETCH_ASSOC)
+ 'machines' => $result->fetchAll()
];
}
}
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
index 8aef52e7..08b65ed6 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php
@@ -121,7 +121,7 @@ abstract class BootEntry
{
$res = Database::simpleQuery("SELECT entryid, data FROM serversetup_bootentry");
$ret = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$tmp = self::fromJson($row['module'], $row['data']);
if ($tmp === null)
continue;
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php
index e2e90c2a..8731bb7a 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php
@@ -18,7 +18,7 @@ class IPxe
{
$res = Database::simpleQuery('SELECT menuid, entryid FROM serversetup_menuentry ORDER BY sortval ASC');
$menus = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (!isset($menus[$row['menuid']])) {
$menus[(int)$row['menuid']] = [];
}
@@ -40,7 +40,7 @@ class IPxe
WHERE startaddr >= :start AND endaddr <= :end", compact('start', 'end'));
$locations = [];
// Iterate over result, eliminate those that are dominated by others
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
foreach ($locations as &$loc) {
if ($row['startaddr'] <= $loc['startaddr'] && $row['endaddr'] >= $loc['endaddr']) {
$loc = false;
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
index b1e13e87..587d9200 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxemenu.inc.php
@@ -43,7 +43,7 @@ class IPxeMenu
LEFT JOIN serversetup_bootentry b USING (entryid)
WHERE e.menuid = :menuid
ORDER BY e.sortval ASC, e.title ASC", ['menuid' => $menu['menuid']]);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$this->items[] = new MenuEntry($row);
}
// Make sure we have a default entry if the menu isn't empty
@@ -109,7 +109,7 @@ class IPxeMenu
if ($res->rowCount() > 0) {
// Make the location id key, preserving order (closest location is first)
$chain = array_flip($chain);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
// Overwrite the value (numeric ascending values, useless) with menu array of according location
$chain[(int)$row['locationid']] = $row;
}
diff --git a/modules-available/serversetup-bwlp-ipxe/install.inc.php b/modules-available/serversetup-bwlp-ipxe/install.inc.php
index 983988bb..a8f1cccc 100644
--- a/modules-available/serversetup-bwlp-ipxe/install.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/install.inc.php
@@ -117,7 +117,7 @@ if (!tableHasColumn('serversetup_bootentry', 'module')) {
ADD COLUMN `module` varchar(30) CHARACTER SET ascii DEFAULT NULL AFTER `builtin`") !== false) {
$result[] = UPDATE_DONE;
$res = Database::simpleQuery('SELECT entryid, data FROM serversetup_bootentry WHERE module IS NULL');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$json = json_decode($row['data'], true);
if (isset($json['script'])) {
Database::exec("UPDATE serversetup_bootentry SET module = '.script' WHERE entryid = :id", ['id' => $row['entryid']]);
diff --git a/modules-available/serversetup-bwlp-ipxe/page.inc.php b/modules-available/serversetup-bwlp-ipxe/page.inc.php
index 8fd6fd49..4e104e78 100644
--- a/modules-available/serversetup-bwlp-ipxe/page.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/page.inc.php
@@ -294,7 +294,7 @@ class Page_ServerSetup extends Page
) m
LEFT JOIN serversetup_localboot sl USING (systemmodel)
ORDER BY systemmodel');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['modelesc'] = urlencode($row['systemmodel']);
$row['options'] = $this->makeSelectArray(Localboot::BOOT_METHODS, $row);
$models[] = $row;
@@ -361,7 +361,7 @@ class Page_ServerSetup extends Page
GROUP BY menuid, title
ORDER BY title");
$menuTable = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (empty($row['locations'])) {
$locations = [];
$row['allowEdit'] = in_array(0, $allowedEdit);
@@ -433,7 +433,7 @@ class Page_ServerSetup extends Page
LEFT JOIN serversetup_bootentry be USING (entryid)
WHERE menuid = :id
ORDER BY sortval ASC", compact('id'));
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['entryid'] === null && $row['refmenuid'] !== null) {
$row['entryid'] = 'menu:' . $row['refmenuid'];
}
@@ -975,7 +975,7 @@ class Page_ServerSetup extends Page
ORDER BY m.title ASC', ['locationid' => $locationId]);
$menus = [];
$hasDefault = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$eids = explode(',', $row['entries']);
$row['default_entry_title'] = $menuEntries[$row['menu_default']] ?? '';
$row['entries'] = [];
diff --git a/modules-available/session/page.inc.php b/modules-available/session/page.inc.php
index 303415fe..ab90965b 100644
--- a/modules-available/session/page.inc.php
+++ b/modules-available/session/page.inc.php
@@ -65,7 +65,7 @@ class Page_Session extends Page
$res = Database::simpleQuery("SELECT userid, dateline, lastip, fixedip FROM session ORDER BY dateline DESC");
$sessions = [];
$perm = User::hasPermission('.adduser.user.*');
- while ($row = $res->fetch()) {
+ foreach ($res as $row) {
if ($perm || $row['userid'] == User::getId()) {
$row['dateline_s'] = Util::prettyTime($row['dateline']);
$sessions[] = $row;
diff --git a/modules-available/statistics/baseconfig/getconfig.inc.php b/modules-available/statistics/baseconfig/getconfig.inc.php
index e8afeffb..7bf25d5d 100644
--- a/modules-available/statistics/baseconfig/getconfig.inc.php
+++ b/modules-available/statistics/baseconfig/getconfig.inc.php
@@ -13,7 +13,7 @@ if (!$uuid) // Required at this point, bail out if not given
// Query machine specific settings
$res = Database::simpleQuery("SELECT setting, value FROM setting_machine WHERE machineuuid = :uuid", ['uuid' => $uuid]);
-while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+foreach ($res as $row) {
ConfigHolder::add($row['setting'], $row['value'], 500);
}
diff --git a/modules-available/statistics/hooks/config-tgz.inc.php b/modules-available/statistics/hooks/config-tgz.inc.php
index 8dffbff6..0a43e115 100644
--- a/modules-available/statistics/hooks/config-tgz.inc.php
+++ b/modules-available/statistics/hooks/config-tgz.inc.php
@@ -9,7 +9,7 @@ $res = Database::simpleQuery('SELECT h.hwname FROM statistic_hw h'
if ($res !== false) { // CHeck this in case we're running on old DB during update
$content = '';
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$content .= $row['hwname'] . "=beamer\n";
}
diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php
index 0de233a8..aecc4e3b 100644
--- a/modules-available/statistics/hooks/cron.inc.php
+++ b/modules-available/statistics/hooks/cron.inc.php
@@ -26,7 +26,7 @@ function state_cleanup()
// Query for logging
$res = Database::simpleQuery("SELECT machineuuid, clientip, state, logintime, lastseen, live_memfree, live_swapfree, live_tmpfree
FROM machine WHERE lastseen < If(state = 'STANDBY', $standby, $on) AND state <> 'OFFLINE'");
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
Database::exec('INSERT INTO clientlog (dateline, logtypeid, clientip, machineuuid, description, extra)
VALUES (UNIX_TIMESTAMP(), :type, :client, :uuid, :description, :longdesc)', array(
'type' => 'machine-mismatch-cron',
diff --git a/modules-available/statistics/inc/statistics.inc.php b/modules-available/statistics/inc/statistics.inc.php
index 1f8a081a..e3eaccc0 100644
--- a/modules-available/statistics/inc/statistics.inc.php
+++ b/modules-available/statistics/inc/statistics.inc.php
@@ -60,7 +60,7 @@ class Statistics
}
$res = Database::simpleQuery("SELECT $fields FROM machine WHERE clientip = :ip $sort", compact('ip'));
$list = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$m = new Machine();
foreach ($row as $key => $val) {
$m->{$key} = $val;
diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php
index 3becce8f..15d0d633 100644
--- a/modules-available/statistics/install.inc.php
+++ b/modules-available/statistics/install.inc.php
@@ -248,7 +248,7 @@ if (!tableHasColumn('machine', 'live_tmpsize')) {
// 2019-02-20: Convert bogus UUIDs
$res2 = Database::simpleQuery("SELECT machineuuid, macaddr FROM machine WHERE machineuuid LIKE '00000000000000_-%'");
-while ($row = $res2->fetch(PDO::FETCH_ASSOC)) {
+foreach ($res2 as $row) {
$new = strtoupper('baad1d00-9491-4716-b98b-' . preg_replace('/[^0-9a-f]/i', '', $row['macaddr']));
error_log('Replacing ' . $row['machineuuid'] . ' with ' . $new);
if (strlen($new) === 36) {
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index 20ff929a..6224d69c 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -171,7 +171,7 @@ class Page_Statistics extends Page
$ids = array_flip($ids);
$allowedMachines = [];
$seenLocations = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
unset($ids[$row['machineuuid']]);
settype($row['locationid'], 'int');
if (in_array($row['locationid'], $allowedLocations)) {
@@ -202,7 +202,7 @@ class Page_Statistics extends Page
$res = Database::simpleQuery('SELECT machineuuid, locationid FROM machine WHERE machineuuid IN (:ids)', compact('ids'));
$ids = array_flip($ids);
$delete = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
unset($ids[$row['machineuuid']]);
if (in_array($row['locationid'], $allowedLocations)) {
$delete[] = $row['machineuuid'];
diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php
index e9af994a..d3c8069e 100644
--- a/modules-available/statistics/pages/list.inc.php
+++ b/modules-available/statistics/pages/list.inc.php
@@ -59,7 +59,7 @@ class SubPage
// Only make client clickable if user is allowed to view details page
$detailsAllowedLocations = User::getAllowedLocations("machine.view-details");
$location = self::buildLocationLookup();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($singleMachine === 'none') {
$singleMachine = $row['machineuuid'];
} else {
diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php
index 87e8ad14..677ff580 100644
--- a/modules-available/statistics/pages/machine.inc.php
+++ b/modules-available/statistics/pages/machine.inc.php
@@ -36,7 +36,7 @@ class SubPage
'end' => $row['logintime'] + 300,
));
$session = false;
- while ($r = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $r) {
if ($session === false || abs($session['dateline'] - $row['logintime']) > abs($r['dateline'] - $row['logintime'])) {
$session = $r;
}
@@ -201,7 +201,7 @@ class SubPage
array('screen' => DeviceType::SCREEN, 'uuid' => $uuid));
$client['screens'] = array();
$ports = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($row['disconnecttime'] != 0)
continue;
$ports[] = $row['connector'];
@@ -227,7 +227,7 @@ class SubPage
$spans['graph'] = '';
$last = false;
$first = true;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (!$client['isclient'] && $row['typeid'] === Statistics::SESSION_LENGTH)
continue; // Don't differentiate between session and idle for non-clients
if ($first && $row['dateline'] > $cutoff && $client['lastboot'] > $cutoff) {
@@ -325,7 +325,7 @@ class SubPage
. ' WHERE machineuuid = :uuid ORDER BY logid DESC LIMIT 25', array('uuid' => $client['machineuuid']));
$count = 0;
$log = array();
- while ($row = $lres->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($lres as $row) {
if (substr($row['description'], -5) === 'on :0' && strpos($row['description'], 'root logged') === false) {
continue;
}
diff --git a/modules-available/statistics/pages/projectors.inc.php b/modules-available/statistics/pages/projectors.inc.php
index cc808cf0..97a21ebd 100644
--- a/modules-available/statistics/pages/projectors.inc.php
+++ b/modules-available/statistics/pages/projectors.inc.php
@@ -52,7 +52,7 @@ class SubPage
'screen' => DeviceType::SCREEN,
));
$data = array(
- 'projectors' => $res->fetchAll(PDO::FETCH_ASSOC)
+ 'projectors' => $res->fetchAll()
);
Render::addTemplate('projector-list', $data);
}
diff --git a/modules-available/statistics/pages/replace.inc.php b/modules-available/statistics/pages/replace.inc.php
index 9c16aed7..77f311ea 100644
--- a/modules-available/statistics/pages/replace.inc.php
+++ b/modules-available/statistics/pages/replace.inc.php
@@ -106,7 +106,7 @@ class SubPage
FROM machine old INNER JOIN machine new ON (old.clientip = new.clientip AND old.lastseen < new.firstseen AND old.lastseen > $oldCutoff AND new.firstseen > $newCutoff)
ORDER BY oldhost ASC, oldip ASC");
$list = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['oldlastseen_s'] = Util::prettyTime($row['oldlastseen']);
$row['newfirstseen_s'] = Util::prettyTime($row['newfirstseen']);
$list[] = $row;
diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php
index ce67070e..4599b8b6 100644
--- a/modules-available/statistics/pages/summary.inc.php
+++ b/modules-available/statistics/pages/summary.inc.php
@@ -67,7 +67,7 @@ class SubPage
$points1 = array('data' => array(), 'label' => 'Online', 'fillColor' => '#efe', 'strokeColor' => '#aea', 'pointColor' => '#7e7', 'pointStrokeColor' => '#fff', 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#7e7');
$points2 = array('data' => array(), 'label' => 'In use', 'fillColor' => '#fee', 'strokeColor' => '#eaa', 'pointColor' => '#e77', 'pointStrokeColor' => '#fff', 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#e77');
$sum = 0;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$x = explode('#', $row['data']);
if ($sum === 0) {
$labels[] = date('H:i', $row['dateline']);
@@ -103,7 +103,7 @@ class SubPage
$lines = array();
$json = array();
$id = 0;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (empty($row['systemmodel'])) {
continue;
}
@@ -131,7 +131,7 @@ class SubPage
$res = Database::simpleQuery("SELECT mbram, Count(*) AS `count` FROM machine m $join
WHERE $where GROUP BY mbram", $args);
$lines = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$gb = (int)ceil($row['mbram'] / 1024);
for ($i = 1; $i < count(StatisticsFilter::SIZE_RAM); ++$i) {
if (StatisticsFilter::SIZE_RAM[$i] < $gb) {
@@ -178,7 +178,7 @@ class SubPage
WHERE $where GROUP BY kvmstate ORDER BY `count` DESC", $args);
$lines = array();
$json = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$lines[] = $row;
$json[] = array(
'color' => isset($colors[$row['kvmstate']]) ? $colors[$row['kvmstate']] : '#000',
@@ -198,7 +198,7 @@ class SubPage
$res = Database::simpleQuery("SELECT id44mb, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY id44mb", $args);
$lines = array();
$total = 0;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$total += $row['count'];
$gb = (int)ceil($row['id44mb'] / 1024);
for ($i = 1; $i < count(StatisticsFilter::SIZE_ID44); ++$i) {
@@ -251,7 +251,7 @@ class SubPage
. " WHERE firstseen > :cutoff AND $where ORDER BY firstseen DESC LIMIT 32", $args);
$rows = array();
$count = 0;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (empty($row['hostname'])) {
$row['hostname'] = $row['clientip'];
}
diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php
index 13d39502..90af0c58 100644
--- a/modules-available/statistics_reporting/inc/getdata.inc.php
+++ b/modules-available/statistics_reporting/inc/getdata.inc.php
@@ -105,7 +105,7 @@ class GetData
$anonymize = 0 !== ($flags & GETDATA_ANONYMOUS);
$res = Queries::getUserStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if ($anonymize && $row['name'] !== 'anonymous') {
$row['name'] = md5($row['name'] . self::$salt);
}
@@ -120,7 +120,7 @@ class GetData
$anonymize = 0 !== ($flags & GETDATA_ANONYMOUS);
$res = Queries::getVMStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound);
$data = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
self::nullToZero($row);
if ($anonymize) {
$row['name'] = md5($row['name'] . self::$salt);
diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php
index 128d8e7d..8c6ff9a8 100644
--- a/modules-available/statistics_reporting/inc/queries.inc.php
+++ b/modules-available/statistics_reporting/inc/queries.inc.php
@@ -106,7 +106,7 @@ class Queries
$bounds = [$lowerTimeBound, $upperTimeBound];
}
$machines = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['firstseen'] = max($row['firstseen'], $from);
$row += array(
'totalTime' => self::timeDiff($row['firstseen'], $to, $bounds),
@@ -132,7 +132,7 @@ class Queries
ORDER BY dateline ASC LIMIT 1000", compact('last', 'to'));
$last = false;
$count = 0;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$count += 1; // Update count first, as we use it as a condition in outer loop. No continue before this
settype($row['logid'], 'int');
// Update for next query
@@ -375,7 +375,7 @@ class Queries
LEFT JOIN exams_x_location exl USING (examid)
WHERE starttime < $to AND endtime > $from
GROUP BY examid");
- while ($row = $eres->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($eres as $row) {
// Get all boot events
$data = ['from' => $row['starttime'], 'to' => $row['endtime']];
if (empty($row['locs'])) {
diff --git a/modules-available/sysconfig/addconfig.inc.php b/modules-available/sysconfig/addconfig.inc.php
index a22cdc46..af8aab37 100644
--- a/modules-available/sysconfig/addconfig.inc.php
+++ b/modules-available/sysconfig/addconfig.inc.php
@@ -122,7 +122,7 @@ class AddConfig_Start extends AddConfig_Base
$modGroups[$mod['group']] =& $mod;
}
unset($mod);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (!isset($mods[$row['moduletype']])) {
$mods[$row['moduletype']] = array(
'unique' => false,
diff --git a/modules-available/sysconfig/api.inc.php b/modules-available/sysconfig/api.inc.php
index 983c6dcb..c81d37b5 100644
--- a/modules-available/sysconfig/api.inc.php
+++ b/modules-available/sysconfig/api.inc.php
@@ -46,7 +46,7 @@ $res = Database::simpleQuery("SELECT c.title, c.filepath, c.status, cl.locationi
$best = 1000;
$row = false;
-while ($r = $res->fetch(PDO::FETCH_ASSOC)) {
+foreach ($res as $r) {
settype($r['locationid'], 'int');
$index = array_search($r['locationid'], $locationChain);
if ($index === false || $index > $best)
diff --git a/modules-available/sysconfig/inc/configmodule.inc.php b/modules-available/sysconfig/inc/configmodule.inc.php
index 580c15a0..fadc649a 100644
--- a/modules-available/sysconfig/inc/configmodule.inc.php
+++ b/modules-available/sysconfig/inc/configmodule.inc.php
@@ -153,7 +153,7 @@ abstract class ConfigModule
if ($ret === false)
return false;
$list = array();
- while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($ret as $row) {
$instance = self::instanceFromDbRow($row);
if ($instance === false)
continue;
diff --git a/modules-available/sysconfig/inc/configtgz.inc.php b/modules-available/sysconfig/inc/configtgz.inc.php
index 98f29753..015b5ccf 100644
--- a/modules-available/sysconfig/inc/configtgz.inc.php
+++ b/modules-available/sysconfig/inc/configtgz.inc.php
@@ -69,7 +69,7 @@ class ConfigTgz
// Delete old connections
Database::exec("DELETE FROM configtgz_x_module WHERE configid = :configid", array('configid' => $this->configId));
// Make connection
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
Database::exec("INSERT INTO configtgz_x_module (configid, moduleid) VALUES (:configid, :moduleid)", array(
'configid' => $this->configId,
'moduleid' => $row['moduleid']
@@ -170,7 +170,7 @@ class ConfigTgz
// Get mapping of moduleid to module name for prettier log display
$res = Database::simpleQuery('SELECT moduleid, title FROM configtgz_module');
$mods = [];
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$mods[$row['moduleid']] = $row['title'];
}
// Now extract module id from filename and if applicable, replace filename by module name
@@ -252,7 +252,7 @@ class ConfigTgz
'status' => 'OUTDATED'
));
$res = Database::simpleQuery("SELECT configid FROM configtgz");
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$configTgz = self::get($row['configid']);
if ($configTgz !== false) {
$configTgz->generate();
@@ -290,7 +290,7 @@ class ConfigTgz
}
$res = Database::simpleQuery("SELECT moduleid, moduletype, filepath, status FROM configtgz_module WHERE moduleid IN ($idstr)");
// Make connection
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
Database::exec("INSERT INTO configtgz_x_module (configid, moduleid) VALUES (:configid, :moduleid)", array(
'configid' => $instance->configId,
'moduleid' => $row['moduleid']
@@ -315,7 +315,7 @@ class ConfigTgz
. " INNER JOIN configtgz_module USING (moduleid) "
. " WHERE configid = :configid", array('configid' => $instance->configId));
$instance->modules = array();
- while ($row = $ret->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($ret as $row) {
$instance->modules[] = $row;
}
return $instance;
@@ -335,7 +335,7 @@ class ConfigTgz
if ($res === false)
return false;
$list = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$instance = new ConfigTgz;
$instance->configId = $row['configid'];
$instance->configTitle = $row['title'];
@@ -344,7 +344,7 @@ class ConfigTgz
. " INNER JOIN configtgz_module USING (moduleid) "
. " WHERE configid = :configid", array('configid' => $instance->configId));
$instance->modules = array();
- while ($innerRow = $innerRes->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($innerRes as $innerRow) {
$instance->modules[] = $innerRow;
}
$list[] = $instance;
diff --git a/modules-available/sysconfig/inc/sysconfig.inc.php b/modules-available/sysconfig/inc/sysconfig.inc.php
index 9ad3a36f..02131366 100644
--- a/modules-available/sysconfig/inc/sysconfig.inc.php
+++ b/modules-available/sysconfig/inc/sysconfig.inc.php
@@ -8,7 +8,7 @@ class SysConfig
$res = Database::simpleQuery("SELECT c.configid, c.title, c.filepath, c.status, Group_Concat(cl.locationid) AS locs FROM configtgz c"
. " LEFT JOIN configtgz_location cl USING (configid) GROUP BY c.configid");
$ret = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$ret[] = $row;
}
return $ret;
diff --git a/modules-available/sysconfig/install.inc.php b/modules-available/sysconfig/install.inc.php
index e9eaaf50..6c9edba2 100644
--- a/modules-available/sysconfig/install.inc.php
+++ b/modules-available/sysconfig/install.inc.php
@@ -87,7 +87,7 @@ if (!tableHasColumn('configtgz_module', 'dateline')) {
$update[] = UPDATE_DONE;
// Infer from module's filemtime
$res = Database::simpleQuery('SELECT moduleid, filepath FROM configtgz_module');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
Database::exec('UPDATE configtgz_module SET dateline = :mtime WHERE moduleid = :moduleid',
['moduleid' => $row['moduleid'], 'mtime' => filemtime($row['filepath'])]);
}
@@ -102,7 +102,7 @@ if (!tableHasColumn('configtgz', 'dateline')) {
INNER JOIN configtgz_x_module cxm USING (configid)
INNER JOIN configtgz_module m USING (moduleid)
GROUP BY configid');
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
Database::exec('UPDATE configtgz SET dateline = :mtime WHERE configid = :configid',
['configid' => $row['configid'], 'mtime' => $row['dateline']]);
}
diff --git a/modules-available/sysconfig/page.inc.php b/modules-available/sysconfig/page.inc.php
index ff3983c1..e868ec67 100644
--- a/modules-available/sysconfig/page.inc.php
+++ b/modules-available/sysconfig/page.inc.php
@@ -188,7 +188,7 @@ class Page_SysConfig extends Page
$locationName = false;
}
$hasDefault = false;
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
if (is_null($row['loclist'])) {
$locList = array();
} else {
@@ -291,7 +291,7 @@ class Page_SysConfig extends Page
. " ORDER BY module.title ASC", array('configid' => $configid));
$modules = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$modules[] = array(
'module' => $row['moduletitle'],
'moduleid' => $row['moduleid']
@@ -375,7 +375,7 @@ class Page_SysConfig extends Page
Message::addSuccess('module-deleted', $module['title']);
}
// Rebuild depending config.tgz
- while ($crow = $existing->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($existing as $crow) {
$config = ConfigTgz::get($crow['configid']);
if ($config !== false) {
$config->generate();
diff --git a/modules-available/syslog/api.inc.php b/modules-available/syslog/api.inc.php
index da3e1519..3378afe6 100644
--- a/modules-available/syslog/api.inc.php
+++ b/modules-available/syslog/api.inc.php
@@ -25,7 +25,7 @@ if (($user = Request::post('export-user', false, 'string')) !== false) {
unset($best);
foreach ($srcs as &$src) {
if (!isset($src['row'])) {
- $src['row'] = $src['res']->fetch(PDO::FETCH_ASSOC);
+ $src['row'] = $src['res']->fetch();
}
if ($src['row'] !== false && (!isset($best) || $src['row']['dateline'] < $best['dateline'])) {
$best =& $src['row'];
diff --git a/modules-available/syslog/page.inc.php b/modules-available/syslog/page.inc.php
index 410a1ed7..71a07e14 100644
--- a/modules-available/syslog/page.inc.php
+++ b/modules-available/syslog/page.inc.php
@@ -61,7 +61,7 @@ class Page_SysLog extends Page
WHERE dateline > $cutoff
GROUP BY logtypeid ORDER BY counter ASC");
$types = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$types[$row['logtypeid']] = $row;
}
if (Request::get('filter') !== false || Request::get('search') !== false) {
@@ -112,7 +112,7 @@ class Page_SysLog extends Page
WHERE $whereClause
ORDER BY logid DESC", 50);
$res = $paginate->exec($qArgs);
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['date'] = Util::prettyTime($row['dateline']);
$row['icon'] = $this->eventToIconName($row['logtypeid']);
$lines[] = $row;