From 8ec19d91564255a9e701965e6cfcdffe17e685cf Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 3 Nov 2017 13:17:50 +0100 Subject: [inc/module] Fix sorting bug, show errors in debug mode, add optional param to isAvailable() --- inc/module.inc.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/module.inc.php b/inc/module.inc.php index 7211c68c..ec3d095b 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -29,12 +29,14 @@ class Module * @param string $moduleId module to check * @return bool true if module is available and activated */ - public static function isAvailable($moduleId) + public static function isAvailable($moduleId, $activate = true) { $module = self::get($moduleId); if ($module === false) return false; - $module->activate(); + if ($activate) { + $module->activate(); + } return !$module->hasMissingDependencies(); } @@ -56,7 +58,7 @@ class Module $mod->depsChecked = true; foreach ($mod->dependencies as $dep) { if (!self::resolveDepsByName($dep)) { - error_log("Disabling module {$mod->name}: Dependency $dep failed."); + trigger_error("Disabling module {$mod->name}: Dependency $dep failed.", E_USER_WARNING); $mod->depsMissing = true; return false; } @@ -75,9 +77,9 @@ class Module foreach (self::$modules as $module) { if (self::resolveDeps($module)) { $ret[] = $module; - } - if ($sortById) { - $sort[] = $module->name; + if ($sortById) { + $sort[] = $module->name; + } } } if ($sortById) { -- cgit v1.2.3-55-g7522 From 3230b55c7794e684ce37ede6450e5e904337d3ea Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 3 Nov 2017 15:57:24 +0100 Subject: [inc/event] Don't try to start DozmodLauncher task - doesn't exist --- inc/event.inc.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'inc') diff --git a/inc/event.inc.php b/inc/event.inc.php index a16be97b..66601607 100644 --- a/inc/event.inc.php +++ b/inc/event.inc.php @@ -31,10 +31,6 @@ class Event $ldadpId = Trigger::ldadp(); $ipxeId = Trigger::ipxe(); - Taskmanager::submit('DozmodLauncher', array( - 'operation' => 'start' - )); - // Check status of all tasks // Mount vm store if ($mountId === false) { -- cgit v1.2.3-55-g7522 From 4b2252beb4eaecdc47e3054ed1e3a666e3d44a17 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 13 Nov 2017 23:40:04 +0100 Subject: [inc/Download] Keep curl handle open for connection reuse --- inc/download.inc.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'inc') diff --git a/inc/download.inc.php b/inc/download.inc.php index b3496e85..e5764d37 100644 --- a/inc/download.inc.php +++ b/inc/download.inc.php @@ -3,29 +3,36 @@ class Download { + private static $curlHandle = false; + /** * Common initialization for download and downloadToFile * Return file handle to header file */ private static function initCurl($url, $timeout, &$head) { - $ch = curl_init(); - if ($ch === false) - Util::traceError('Could not initialize cURL'); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, ceil($timeout / 2)); - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_AUTOREFERER, true); - curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); - curl_setopt($ch, CURLOPT_MAXREDIRS, 6); + if (self::$curlHandle === false) { + self::$curlHandle = curl_init(); + if (self::$curlHandle === false) { + Util::traceError('Could not initialize cURL'); + } + curl_setopt(self::$curlHandle, CURLOPT_CONNECTTIMEOUT, ceil($timeout / 2)); + curl_setopt(self::$curlHandle, CURLOPT_TIMEOUT, $timeout); + curl_setopt(self::$curlHandle, CURLOPT_FOLLOWLOCATION, true); + curl_setopt(self::$curlHandle, CURLOPT_AUTOREFERER, true); + curl_setopt(self::$curlHandle, CURLOPT_BINARYTRANSFER, true); + curl_setopt(self::$curlHandle, CURLOPT_MAXREDIRS, 6); + } + + curl_setopt(self::$curlHandle, CURLOPT_URL, $url); + $tmpfile = tempnam('/tmp/', 'bwlp-'); $head = fopen($tmpfile, 'w+b'); unlink($tmpfile); if ($head === false) Util::traceError("Could not open temporary head file $tmpfile for writing."); - curl_setopt($ch, CURLOPT_WRITEHEADER, $head); - return $ch; + curl_setopt(self::$curlHandle, CURLOPT_WRITEHEADER, $head); + return self::$curlHandle; } /** @@ -55,7 +62,6 @@ class Download } else { $code = 999; } - curl_close($ch); return $data; } @@ -89,7 +95,6 @@ class Download } else { $code = 999; } - curl_close($ch); return $data; } @@ -111,7 +116,6 @@ class Download curl_setopt($ch, CURLOPT_FILE, $fh); $res = curl_exec($ch); $head = self::getContents($head); - curl_close($ch); fclose($fh); if ($res === false) { @unlink($target); -- cgit v1.2.3-55-g7522 From d563c786fd5d37f274a462bc81f97802a555032e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 13 Nov 2017 23:44:10 +0100 Subject: [inc/Taskmanager] Fix phpdoc --- inc/taskmanager.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php index 1920190f..dcf54448 100644 --- a/inc/taskmanager.inc.php +++ b/inc/taskmanager.inc.php @@ -96,7 +96,7 @@ class Taskmanager /** * Wait for the given task's completion. * - * @param type $task task to wait for + * @param array $task task to wait for * @param int $timeout maximum time in ms to wait for completion of task * @return array result/status of task, or false if it couldn't be queried */ -- cgit v1.2.3-55-g7522