From aa4d6fd462a3d86d1384a1d2dba85a6dc837b623 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 23 Jul 2024 11:46:40 +0200 Subject: [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. --- .../serversetup-bwlp-ipxe/inc/menuentry.inc.php | 2 +- .../serversetup-bwlp-ipxe/install.inc.php | 31 +++++++++++++++------- 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; } -- cgit v1.2.3-55-g7522