summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-07-23 11:46:40 +0200
committerSimon Rettberg2024-07-23 11:46:40 +0200
commitaa4d6fd462a3d86d1384a1d2dba85a6dc837b623 (patch)
treed52774c493f2a477a15d1308a590a5ecd121e2c2
parent[statistics_reporting] Fix undefined variable access (diff)
downloadslx-admin-aa4d6fd462a3d86d1384a1d2dba85a6dc837b623.tar.gz
slx-admin-aa4d6fd462a3d86d1384a1d2dba85a6dc837b623.tar.xz
slx-admin-aa4d6fd462a3d86d1384a1d2dba85a6dc837b623.zip
[serversetup-bwlp-ipxe] serversetup_bootentry.module must not be NULL
I'm not entirely sure how the column ended up being NULL in one instance, but this should not happen and makes no sense, so change the table definition accordingly to avoid script errors.
-rw-r--r--modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php2
-rw-r--r--modules-available/serversetup-bwlp-ipxe/install.inc.php31
2 files changed, 23 insertions, 10 deletions
diff --git a/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
index da94a16b..fee60eb0 100644
--- a/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php
@@ -63,7 +63,7 @@ class MenuEntry
}
}
$this->hotkey = self::getKeyCode($row['hotkey'] ?? '');
- if (!empty($row['bootentry'])) {
+ if (!empty($row['bootentry']) && $row['module'] !== null) {
$this->bootEntry = BootEntry::fromJson($row['module'], $row['bootentry']);
} elseif (isset($row['refmenuid'])) {
$this->bootEntry = BootEntry::forMenu($row['refmenuid']);
diff --git a/modules-available/serversetup-bwlp-ipxe/install.inc.php b/modules-available/serversetup-bwlp-ipxe/install.inc.php
index 5af00493..9714d381 100644
--- a/modules-available/serversetup-bwlp-ipxe/install.inc.php
+++ b/modules-available/serversetup-bwlp-ipxe/install.inc.php
@@ -7,7 +7,7 @@ $result[] = tableCreate('serversetup_bootentry', "
`hotkey` varchar(8) CHARACTER SET ascii NOT NULL,
`title` varchar(100) NOT NULL,
`builtin` tinyint(1) NOT NULL,
- `module` varchar(30) DEFAULT NULL,
+ `module` varchar(30) NOT NULL,
`data` blob NOT NULL,
PRIMARY KEY (`entryid`)
");
@@ -113,18 +113,31 @@ if (Module::get('locations') !== false) {
// 2019-09-21 Add module column to bootentry
if (!tableHasColumn('serversetup_bootentry', 'module')) {
+ // First, nullable, so we can update old entries
if (Database::exec("ALTER TABLE serversetup_bootentry
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');
- 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']]);
- } else {
- Database::exec("UPDATE serversetup_bootentry SET module = '.exec' WHERE entryid = :id", ['id' => $row['entryid']]);
- }
+ } else {
+ $result[] = UPDATE_FAILED;
+ }
+}
+// 2024-07-22 NULLable module column makes no sense and breaks slx-admin - disallow
+if (tableGetDescribeColumn('serversetup_bootentry', 'module', 'Null') === 'YES') {
+ // Update any old fields that now have NULL as module
+ $res = Database::simpleQuery('SELECT entryid, data FROM serversetup_bootentry WHERE module IS NULL');
+ 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']]);
+ } else {
+ Database::exec("UPDATE serversetup_bootentry SET module = '.exec' WHERE entryid = :id", ['id' => $row['entryid']]);
}
+ }
+ // Just to be safe
+ Database::simpleQuery('DELETE FROM serversetup_bootentry WHERE module IS NULL');
+ if (Database::exec("ALTER TABLE serversetup_bootentry
+ MODIFY `module` varchar(30) CHARACTER SET ascii NOT NULL") !== false) {
+ $result[] = UPDATE_DONE;
} else {
$result[] = UPDATE_FAILED;
}