From 1229906bc79254bc22c9e08e04a025d8bb1d89bf Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 4 Jul 2018 13:02:31 +0200 Subject: [serversetup-bwlp] Delete menu entries missing from POST data --- modules-available/serversetup-bwlp/page.inc.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'modules-available/serversetup-bwlp/page.inc.php') diff --git a/modules-available/serversetup-bwlp/page.inc.php b/modules-available/serversetup-bwlp/page.inc.php index 00b658c4..dc53070b 100644 --- a/modules-available/serversetup-bwlp/page.inc.php +++ b/modules-available/serversetup-bwlp/page.inc.php @@ -343,20 +343,24 @@ class Page_ServerSetup extends Page $ret = Database::exec("INSERT INTO serversetup_menuentry (menuid, entryid, hotkey, title, hidden, sortval, plainpass, md5pass) VALUES (:menuid, :entryid, :hotkey, :title, :hidden, :sortval, :plainpass, '')", $params, true); - if ($ret && !empty($entry['plainpass'])) { + if ($ret) { $key = Database::lastInsertId(); - Database::exec('UPDATE serversetup_menuentry SET md5pass = :md5pass WHERE menuentryid = :id', [ - 'md5pass' => IPxe::makeMd5Pass($entry['plainpass'], $key), - 'key' => $id, - ]); + $keepIds[] = (int)$key; + if (!empty($entry['plainpass'])) { + Database::exec('UPDATE serversetup_menuentry SET md5pass = :md5pass WHERE menuentryid = :id', [ + 'md5pass' => IPxe::makeMd5Pass($entry['plainpass'], $key), + 'id' => $key, + ]); + } } } if ($ret === false) { Message::addWarning('error-saving-entry', $entry['title'], Database::lastError()); } - } + Database::exec('DELETE FROM serversetup_menuentry WHERE menuid = :menuid AND menuentryid NOT IN (:keep)', + ['menuid' => $menu['menuid'], 'keep' => $keepIds]); Message::addSuccess('menu-saved'); } -- cgit v1.2.3-55-g7522