summaryrefslogtreecommitdiffstats
path: root/inc/property.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-28 18:18:34 +0200
committerSimon Rettberg2014-05-28 18:18:34 +0200
commite4e79982dd3c447a4ced762a6069db553e246f59 (patch)
treed17f74565ed5347350edeab412a07c77bd80a636 /inc/property.inc.php
parentWIP (diff)
downloadslx-admin-e4e79982dd3c447a4ced762a6069db553e246f59.tar.gz
slx-admin-e4e79982dd3c447a4ced762a6069db553e246f59.tar.xz
slx-admin-e4e79982dd3c447a4ced762a6069db553e246f59.zip
Fixed some bugs from Sateserver v05
Diffstat (limited to 'inc/property.inc.php')
-rw-r--r--inc/property.inc.php57
1 files changed, 32 insertions, 25 deletions
diff --git a/inc/property.inc.php b/inc/property.inc.php
index 5c316517..77d2b985 100644
--- a/inc/property.inc.php
+++ b/inc/property.inc.php
@@ -6,8 +6,9 @@
*/
class Property
{
+
private static $cache = false;
-
+
/**
* Retrieve value from property store.
*
@@ -18,90 +19,96 @@ class Property
private static function get($key, $default = false)
{
if (self::$cache === false) {
+ if (mt_rand(1, 20) === 10) {
+ Database::exec("DELETE FROM property WHERE dateline <> 0 AND dateline < UNIX_TIMESTAMP()");
+ }
$res = Database::simpleQuery("SELECT name, value FROM property");
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
self::$cache[$row['name']] = $row['value'];
}
}
- if (!isset(self::$cache[$key])) return $default;
+ if (!isset(self::$cache[$key]))
+ return $default;
return self::$cache[$key];
}
-
+
/**
* Set value in property store.
*
* @param string $key key of value to set
* @param type $value the value to store for $key
+ * @param int minage how long to keep this entry around at least, in minutes. 0 for infinite
*/
- private static function set($key, $value)
+ private static function set($key, $value, $minage = 0)
{
- Database::exec("INSERT INTO property (name, value) VALUES (:key, :value)"
- . " ON DUPLICATE KEY UPDATE value = VALUES(value)", array(
- 'key' => $key,
- 'value' => $value
- ));
+ Database::exec("INSERT INTO property (name, value, dateline) VALUES (:key, :value, :dateline)"
+ . " ON DUPLICATE KEY UPDATE value = VALUES(value), dateline = VALUES(dateline)", array(
+ 'key' => $key,
+ 'value' => $value,
+ 'dateline' => time() + ($minage * 60)
+ ));
if (self::$cache !== false) {
self::$cache[$key] = $value;
}
}
-
+
public static function getServerIp()
{
return self::get('server-ip', 'none');
}
-
+
public static function setServerIp($value)
{
self::set('server-ip', $value);
}
-
+
public static function getIPxeIp()
{
- return self::get('ipxe-ip', 'none');
+ return self::get('ipxe-ip', 'not-set');
}
-
+
public static function setIPxeIp($value)
{
self::set('ipxe-ip', $value);
}
-
+
public static function getIPxeTaskId()
{
return self::get('ipxe-task');
}
-
+
public static function setIPxeTaskId($value)
{
self::set('ipxe-task', $value);
}
-
+
public static function getBootMenu()
{
return json_decode(self::get('ipxe-menu'), true);
}
-
+
public static function setBootMenu($value)
{
self::set('ipxe-menu', json_encode($value));
}
-
+
public static function getVersionCheckTaskId()
{
return self::get('versioncheck-task');
}
-
+
public static function setVersionCheckTaskId($value)
{
self::set('versioncheck-task', $value);
}
-
+
public static function getVersionCheckInformation()
{
$data = json_decode(self::get('versioncheck-data'), true);
if (isset($data['time']) && $data['time'] + 120 > time())
return $data;
$task = Taskmanager::submit('DownloadText', array(
- 'url' => CONFIG_REMOTE_ML . '/list.php'
+ 'url' => CONFIG_REMOTE_ML . '/list.php'
));
if (!isset($task['id']))
return false;
@@ -116,17 +123,17 @@ class Property
self::setVersionCheckInformation($data);
return $data;
}
-
+
public static function setVersionCheckInformation($value)
{
self::set('versioncheck-data', json_encode($value));
}
-
+
public static function getVmStoreConfig()
{
return json_decode(self::get('vmstore-config'), true);
}
-
+
public static function setVmStoreConfig($value)
{
self::set('vmstore-config', json_encode($value));