Skip to content

Commit f8c04a4

Browse files
committed
Merge pull request #24392 from owncloud/declare-cron-jobs-in-info.xml
Declare cron jobs in info.xml
2 parents 15a479f + cc1d948 commit f8c04a4

File tree

8 files changed

+23
-12
lines changed

8 files changed

+23
-12
lines changed

apps/dav/appinfo/application.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ public function getSyncService() {
153153
return $this->getContainer()->query('SyncService');
154154
}
155155

156-
public function setupCron() {
157-
$jl = $this->getContainer()->getServer()->getJobList();
158-
$jl->add(new SyncJob());
159-
}
160-
161156
public function generateBirthdays() {
162157
try {
163158
/** @var BirthdayService $migration */

apps/dav/appinfo/info.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
<dependencies>
1717
<owncloud min-version="9.1" max-version="9.1" />
1818
</dependencies>
19+
<background-jobs>
20+
<job>OCA\DAV\CardDAV\Sync\SyncJob</job>
21+
</background-jobs>
1922
</info>

apps/dav/appinfo/install.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
use OCA\Dav\AppInfo\Application;
2323

2424
$app = new Application();
25-
$app->setupCron();
2625
$app->generateBirthdays();

apps/dav/appinfo/update.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
use OCA\Dav\AppInfo\Application;
2323

2424
$app = new Application();
25-
$app->setupCron();
2625
$app->generateBirthdays();

lib/private/App/InfoParser.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public function parse($file) {
8989
if (!array_key_exists('uninstall', $array['repair-steps'])) {
9090
$array['repair-steps']['uninstall'] = [];
9191
}
92+
if (!array_key_exists('background-jobs', $array)) {
93+
$array['background-jobs'] = [];
94+
}
9295

9396
if (array_key_exists('documentation', $array) && is_array($array['documentation'])) {
9497
foreach ($array['documentation'] as $key => $url) {
@@ -128,6 +131,9 @@ public function parse($file) {
128131
if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) {
129132
$array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step'];
130133
}
134+
if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) {
135+
$array['background-jobs'] = $array['background-jobs']['job'];
136+
}
131137
return $array;
132138
}
133139

@@ -147,10 +153,7 @@ function xmlToArray($xml) {
147153
if (!isset($array[$element])) {
148154
$array[$element] = "";
149155
}
150-
/**
151-
* @var \SimpleXMLElement $node
152-
*/
153-
156+
/** @var \SimpleXMLElement $node */
154157
// Has attributes
155158
if ($attributes = $node->attributes()) {
156159
$data = [

lib/private/Installer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public static function installApp( $data = array()) {
133133
}
134134
}
135135

136+
\OC_App::setupBackgroundJobs($info['background-jobs']);
137+
136138
//run appinfo/install.php
137139
if((!isset($data['noinstall']) or $data['noinstall']==false)) {
138140
self::includeAppScript($basedir . '/appinfo/install.php');
@@ -569,6 +571,7 @@ public static function installShippedApp($app) {
569571
if (is_null($info)) {
570572
return false;
571573
}
574+
\OC_App::setupBackgroundJobs($info['background-jobs']);
572575

573576
OC_App::executeRepairSteps($app, $info['repair-steps']['install']);
574577

lib/private/legacy/app.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ public static function updateApp($appId) {
11901190
self::loadApp($appId, false);
11911191
include $appPath . '/appinfo/update.php';
11921192
}
1193+
self::setupBackgroundJobs($appData['background-jobs']);
11931194

11941195
//set remote/public handlers
11951196
if (array_key_exists('ocsid', $appData)) {
@@ -1240,6 +1241,13 @@ public static function executeRepairSteps($appId, array $steps) {
12401241
$r->run();
12411242
}
12421243

1244+
public static function setupBackgroundJobs(array $jobs) {
1245+
$queue = \OC::$server->getJobList();
1246+
foreach ($jobs as $job) {
1247+
$queue->add($job);
1248+
}
1249+
}
1250+
12431251
/**
12441252
* @param string $appId
12451253
* @param string[] $steps

tests/data/app/expected-info.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@
7474
"post-migration": [],
7575
"live-migration": [],
7676
"uninstall": []
77-
}
77+
},
78+
"background-jobs": []
7879
}

0 commit comments

Comments
 (0)