namespace OC\BackgroundJob;
+use OCP\AppFramework\QueryException;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\IJobList;
use OCP\AutoloadNotAllowedException;
* @return IJob|null
*/
private function buildJob($row) {
- $class = $row['class'];
- /**
- * @var Job $job
- */
try {
- if (!class_exists($class)) {
- // job from disabled app or old version of an app, no need to do anything
- return null;
+ try {
+ // Try to load the job as a service
+ /** @var Job $job */
+ $job = \OC::$server->query($row['class']);
+ } catch (QueryException $e) {
+ if (class_exists($row['class'])) {
+ $class = $row['class'];
+ $job = new $class();
+ } else {
+ // job from disabled app or old version of an app, no need to do anything
+ return null;
+ }
}
- $job = new $class();
+
$job->setId($row['id']);
$job->setLastRun($row['last_run']);
$job->setArgument(json_decode($row['argument'], true));
return $job;
} catch (AutoloadNotAllowedException $e) {
// job is from a disabled app, ignore
+ return null;
}
- return null;
}
/**