From 71fa0a75bf152b763fb3ee86dc5102b0c29d27b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 2 May 2016 15:26:12 +0200 Subject: [PATCH] Allow declaration of background jobs in info.xml --- lib/private/App/InfoParser.php | 11 +++++++---- lib/private/Installer.php | 3 +++ lib/private/legacy/app.php | 8 ++++++++ tests/data/app/expected-info.json | 3 ++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index 21422d4060..e945655020 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -89,6 +89,9 @@ class InfoParser { if (!array_key_exists('uninstall', $array['repair-steps'])) { $array['repair-steps']['uninstall'] = []; } + if (!array_key_exists('background-jobs', $array)) { + $array['background-jobs'] = []; + } if (array_key_exists('documentation', $array) && is_array($array['documentation'])) { foreach ($array['documentation'] as $key => $url) { @@ -128,6 +131,9 @@ class InfoParser { if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; } + if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { + $array['background-jobs'] = $array['background-jobs']['job']; + } return $array; } @@ -147,10 +153,7 @@ class InfoParser { if (!isset($array[$element])) { $array[$element] = ""; } - /** - * @var \SimpleXMLElement $node - */ - + /** @var \SimpleXMLElement $node */ // Has attributes if ($attributes = $node->attributes()) { $data = [ diff --git a/lib/private/Installer.php b/lib/private/Installer.php index 8ecc92e134..edc6306b8f 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -133,6 +133,8 @@ class Installer { } } + \OC_App::setupBackgroundJobs($info['background-jobs']); + //run appinfo/install.php if((!isset($data['noinstall']) or $data['noinstall']==false)) { self::includeAppScript($basedir . '/appinfo/install.php'); @@ -569,6 +571,7 @@ class Installer { if (is_null($info)) { return false; } + \OC_App::setupBackgroundJobs($info['background-jobs']); OC_App::executeRepairSteps($app, $info['repair-steps']['install']); diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index fe590e4159..dab4c1a70c 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -1190,6 +1190,7 @@ class OC_App { self::loadApp($appId, false); include $appPath . '/appinfo/update.php'; } + self::setupBackgroundJobs($appData['background-jobs']); //set remote/public handlers if (array_key_exists('ocsid', $appData)) { @@ -1240,6 +1241,13 @@ class OC_App { $r->run(); } + public static function setupBackgroundJobs(array $jobs) { + $queue = \OC::$server->getJobList(); + foreach ($jobs as $job) { + $queue->add($job); + } + } + /** * @param string $appId * @param string[] $steps diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index cef7a7fdab..81de5341ef 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -74,5 +74,6 @@ "post-migration": [], "live-migration": [], "uninstall": [] - } + }, + "background-jobs": [] }