diff options
-rw-r--r-- | modules-available/serversetup-bwlp-ipxe/inc/menuentry.inc.php | 2 | ||||
-rw-r--r-- | modules-available/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; } |