summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc
diff options
context:
space:
mode:
authorSimon Rettberg2017-03-10 12:40:00 +0100
committerSimon Rettberg2017-03-10 12:40:00 +0100
commit950ea6ead0dc3a1ba59db580f2a2b1977165375d (patch)
tree62ad336897433309851c622238b403e5862ac98a /modules-available/sysconfig/inc
parent[statistics_reporting] Fix caption of reporting label (german translation) (diff)
downloadslx-admin-950ea6ead0dc3a1ba59db580f2a2b1977165375d.tar.gz
slx-admin-950ea6ead0dc3a1ba59db580f2a2b1977165375d.tar.xz
slx-admin-950ea6ead0dc3a1ba59db580f2a2b1977165375d.zip
[sysconfig] configtgz.inc.php: Move static functions to bottom
Diffstat (limited to 'modules-available/sysconfig/inc')
-rw-r--r--modules-available/sysconfig/inc/configtgz.inc.php232
1 files changed, 118 insertions, 114 deletions
diff --git a/modules-available/sysconfig/inc/configtgz.inc.php b/modules-available/sysconfig/inc/configtgz.inc.php
index 7ec58785..ba48c7ed 100644
--- a/modules-available/sysconfig/inc/configtgz.inc.php
+++ b/modules-available/sysconfig/inc/configtgz.inc.php
@@ -82,7 +82,122 @@ class ConfigTgz
));
return true;
}
-
+
+ /**
+ *
+ * @param bool $deleteOnError
+ * @param int $timeoutMs
+ * @return string - OK (success)
+ * - OUTDATED (updating failed, but old version still exists)
+ * - MISSING (failed and no old version available)
+ */
+ public function generate($deleteOnError = false, $timeoutMs = 0)
+ {
+ if (!($this->configId > 0) || !is_array($this->modules) || $this->file === false)
+ Util::traceError ('configId <= 0 or modules not array in ConfigTgz::rebuild()');
+ $files = array();
+ // Get all config modules for system config
+ foreach ($this->modules as $module) {
+ if (!empty($module['filepath']) && file_exists($module['filepath']))
+ $files[] = $module['filepath'];
+ }
+ // Get stuff other modules want to inject
+ $handler = function($hook) {
+ include $hook->file;
+ return isset($file) ? $file : false;
+ };
+ foreach (Hook::load('config-tgz') as $hook) {
+ $file = $handler($hook);
+ if ($file !== false) {
+ $files[] = $file;
+ }
+ }
+ // Hand over to tm
+ $task = Taskmanager::submit('RecompressArchive', array(
+ 'inputFiles' => $files,
+ 'outputFile' => $this->file
+ ));
+ // Wait for completion
+ if ($timeoutMs > 0 && !Taskmanager::isFailed($task) && !Taskmanager::isFinished($task))
+ $task = Taskmanager::waitComplete($task, $timeoutMs);
+ if ($task === true || (isset($task['statusCode']) && $task['statusCode'] === TASK_FINISHED)) {
+ // Success!
+ $this->markUpdated();
+ return true;
+ }
+ if (!is_array($task) || !isset($task['id']) || Taskmanager::isFailed($task)) {
+ // Failed...
+ Taskmanager::addErrorMessage($task);
+ if (!$deleteOnError)
+ $this->markFailed();
+ else
+ $this->delete();
+ return false;
+ }
+ // Still running, add callback
+ TaskmanagerCallback::addCallback($task, 'cbConfTgzCreated', array(
+ 'configid' => $this->configId,
+ 'deleteOnError' => $deleteOnError
+ ));
+ return $task['id'];
+ }
+
+ public function delete()
+ {
+ if ($this->configId === 0)
+ Util::traceError('ConfigTgz::delete called with invalid config id!');
+ $ret = Database::exec("DELETE FROM configtgz WHERE configid = :configid LIMIT 1", array(
+ 'configid' => $this->configId
+ ), true) !== false;
+ if ($ret !== false) {
+ if ($this->file !== false)
+ Taskmanager::submit('DeleteFile', array('file' => $this->file), true);
+ $this->configId = 0;
+ $this->modules = false;
+ $this->file = false;
+ }
+ return $ret;
+ }
+
+ public function markOutdated()
+ {
+ if ($this->configId === 0)
+ Util::traceError('ConfigTgz::markOutdated called with invalid config id!');
+ return $this->mark('OUTDATED');
+ }
+
+ private function markUpdated()
+ {
+ if ($this->configId === 0)
+ Util::traceError('ConfigTgz::markUpdated called with invalid config id!');
+ Event::activeConfigChanged();
+ if ($this->areAllModulesUpToDate())
+ return $this->mark('OK');
+ return $this->mark('OUTDATED');
+ }
+
+ private function markFailed()
+ {
+ if ($this->configId === 0)
+ Util::traceError('ConfigTgz::markFailed called with invalid config id!');
+ if ($this->file === false || !file_exists($this->file))
+ return $this->mark('MISSING');
+ return $this->mark('OUTDATED');
+ }
+
+ private function mark($status)
+ {
+ Database::exec("UPDATE configtgz SET status = :status WHERE configid = :configid LIMIT 1", array(
+ 'configid' => $this->configId,
+ 'status' => $status
+ ));
+ return $status;
+ }
+
+ /*
+ * Static part
+ */
+
public static function insert($title, $moduleIds)
{
if (!is_array($moduleIds))
@@ -116,7 +231,7 @@ class ConfigTgz
}
return $instance;
}
-
+
public static function get($configId)
{
$ret = Database::queryFirst("SELECT configid, title, filepath FROM configtgz WHERE configid = :configid", array(
@@ -137,7 +252,7 @@ class ConfigTgz
}
return $instance;
}
-
+
public static function getAllForModule($moduleId)
{
$res = Database::simpleQuery("SELECT configid, title, filepath FROM configtgz_x_module "
@@ -215,115 +330,4 @@ class ConfigTgz
$config->markUpdated();
}
- /**
- *
- * @param bool $deleteOnError
- * @param int $timeoutMs
- * @return string - OK (success)
- * - OUTDATED (updating failed, but old version still exists)
- * - MISSING (failed and no old version available)
- */
- public function generate($deleteOnError = false, $timeoutMs = 0)
- {
- if (!($this->configId > 0) || !is_array($this->modules) || $this->file === false)
- Util::traceError ('configId <= 0 or modules not array in ConfigTgz::rebuild()');
- $files = array();
- // Get all config modules for system config
- foreach ($this->modules as $module) {
- if (!empty($module['filepath']) && file_exists($module['filepath']))
- $files[] = $module['filepath'];
- }
- // Get stuff other modules want to inject
- $handler = function($hook) {
- include $hook->file;
- return isset($file) ? $file : false;
- };
- foreach (Hook::load('config-tgz') as $hook) {
- $file = $handler($hook);
- if ($file !== false) {
- $files[] = $file;
- }
- }
- // Hand over to tm
- $task = Taskmanager::submit('RecompressArchive', array(
- 'inputFiles' => $files,
- 'outputFile' => $this->file
- ));
- // Wait for completion
- if ($timeoutMs > 0 && !Taskmanager::isFailed($task) && !Taskmanager::isFinished($task))
- $task = Taskmanager::waitComplete($task, $timeoutMs);
- if ($task === true || (isset($task['statusCode']) && $task['statusCode'] === TASK_FINISHED)) {
- // Success!
- $this->markUpdated();
- return true;
- }
- if (!is_array($task) || !isset($task['id']) || Taskmanager::isFailed($task)) {
- // Failed...
- Taskmanager::addErrorMessage($task);
- if (!$deleteOnError)
- $this->markFailed();
- else
- $this->delete();
- return false;
- }
- // Still running, add callback
- TaskmanagerCallback::addCallback($task, 'cbConfTgzCreated', array(
- 'configid' => $this->configId,
- 'deleteOnError' => $deleteOnError
- ));
- return $task['id'];
- }
-
- public function delete()
- {
- if ($this->configId === 0)
- Util::traceError('ConfigTgz::delete called with invalid config id!');
- $ret = Database::exec("DELETE FROM configtgz WHERE configid = :configid LIMIT 1", array(
- 'configid' => $this->configId
- ), true) !== false;
- if ($ret !== false) {
- if ($this->file !== false)
- Taskmanager::submit('DeleteFile', array('file' => $this->file), true);
- $this->configId = 0;
- $this->modules = false;
- $this->file = false;
- }
- return $ret;
- }
-
- public function markOutdated()
- {
- if ($this->configId === 0)
- Util::traceError('ConfigTgz::markOutdated called with invalid config id!');
- return $this->mark('OUTDATED');
- }
-
- private function markUpdated()
- {
- if ($this->configId === 0)
- Util::traceError('ConfigTgz::markUpdated called with invalid config id!');
- Event::activeConfigChanged();
- if ($this->areAllModulesUpToDate())
- return $this->mark('OK');
- return $this->mark('OUTDATED');
- }
-
- private function markFailed()
- {
- if ($this->configId === 0)
- Util::traceError('ConfigTgz::markFailed called with invalid config id!');
- if ($this->file === false || !file_exists($this->file))
- return $this->mark('MISSING');
- return $this->mark('OUTDATED');
- }
-
- private function mark($status)
- {
- Database::exec("UPDATE configtgz SET status = :status WHERE configid = :configid LIMIT 1", array(
- 'configid' => $this->configId,
- 'status' => $status
- ));
- return $status;
- }
-
}