From 7c5748d3a6bc12ece61ccf782047f6200b79b325 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 20 Apr 2021 16:40:25 +0200 Subject: [serversetup-bwlp-ipxe] Add iPXE version selector --- inc/property.inc.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'inc/property.inc.php') diff --git a/inc/property.inc.php b/inc/property.inc.php index 3911b0d4..1b979982 100644 --- a/inc/property.inc.php +++ b/inc/property.inc.php @@ -33,24 +33,30 @@ class Property } /** - * Set value in property store. + * Set value in property store. Passing null or false as the value deletes the + * entry from the property table. * * @param string $key key of value to set - * @param string $value the value to store for $key + * @param string|null|false $value the value to store for $key * @param int $maxAgeMinutes how long to keep this entry around at least, in minutes. 0 for infinite */ public static function set($key, $value, $maxAgeMinutes = 0) { - if (self::$cache === false || self::get($key) != $value) { // Simple compare, so it works for numbers accidentally casted to string somewhere + if ($value === false || $value === null) { + Database::exec("DELETE FROM property WHERE name = :key", ['key' => $key]); + if (self::$cache !== false) { + unset(self::$cache[$key]); + } + } else { Database::exec("INSERT INTO property (name, value, dateline) VALUES (:key, :value, :dateline)" - . " ON DUPLICATE KEY UPDATE value = VALUES(value), dateline = VALUES(dateline)", array( + . " ON DUPLICATE KEY UPDATE value = VALUES(value), dateline = VALUES(dateline)", [ 'key' => $key, 'value' => $value, 'dateline' => ($maxAgeMinutes === 0 ? 0 : time() + ($maxAgeMinutes * 60)) - )); - } - if (self::$cache !== false) { - self::$cache[$key] = $value; + ]); + if (self::$cache !== false) { + self::$cache[$key] = $value; + } } } -- cgit v1.2.3-55-g7522