]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow dependency injection for background jobs
authorJoas Schilling <nickvergessen@owncloud.com>
Fri, 18 Dec 2015 10:44:32 +0000 (11:44 +0100)
committerJoas Schilling <nickvergessen@owncloud.com>
Fri, 18 Dec 2015 13:20:30 +0000 (14:20 +0100)
lib/private/backgroundjob/joblist.php

index 75c205833fe922dbfd39785929f01fb5d7e10bf7..3618b0f9e5e389a77a820fdc32d7415577f3000d 100644 (file)
@@ -24,6 +24,7 @@
 
 namespace OC\BackgroundJob;
 
+use OCP\AppFramework\QueryException;
 use OCP\BackgroundJob\IJob;
 use OCP\BackgroundJob\IJobList;
 use OCP\AutoloadNotAllowedException;
@@ -232,24 +233,29 @@ class JobList implements IJobList {
         * @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;
        }
 
        /**