summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_external/lib/failedstorage.php8
-rw-r--r--apps/files_sharing/lib/sharedstorage.php18
-rw-r--r--lib/private/backgroundjob/joblist.php17
-rw-r--r--tests/lib/backgroundjob/joblist.php26
4 files changed, 67 insertions, 2 deletions
diff --git a/apps/files_external/lib/failedstorage.php b/apps/files_external/lib/failedstorage.php
index 6afa98052c2..22ee5326491 100644
--- a/apps/files_external/lib/failedstorage.php
+++ b/apps/files_external/lib/failedstorage.php
@@ -197,4 +197,12 @@ class FailedStorage extends Common {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
+ public function getAvailability() {
+ throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
+ }
+
+ public function setAvailability($isAvailable) {
+ throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
+ }
+
}
diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 66803db1425..c7529df0617 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -662,4 +662,22 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
list($targetStorage, $targetInternalPath) = $this->resolvePath($path);
$targetStorage->changeLock($targetInternalPath, $type, $provider);
}
+
+ /**
+ * @return array [ available, last_checked ]
+ */
+ public function getAvailability() {
+ // shares do not participate in availability logic
+ return [
+ 'available' => true,
+ 'last_checked' => 0
+ ];
+ }
+
+ /**
+ * @param bool $available
+ */
+ public function setAvailability($available) {
+ // shares do not participate in availability logic
+ }
}
diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php
index e8915b47f24..f297bccbc7d 100644
--- a/lib/private/backgroundjob/joblist.php
+++ b/lib/private/backgroundjob/joblist.php
@@ -87,6 +87,11 @@ class JobList implements IJobList {
}
}
+ protected function removeById($id) {
+ $query = $this->conn->prepare('DELETE FROM `*PREFIX*jobs` WHERE `id` = ?');
+ $query->execute([$id]);
+ }
+
/**
* check if a job is in the list
*
@@ -134,17 +139,25 @@ class JobList implements IJobList {
$query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` > ? ORDER BY `id` ASC', 1);
$query->execute(array($lastId));
if ($row = $query->fetch()) {
- return $this->buildJob($row);
+ $jobId = $row['id'];
+ $job = $this->buildJob($row);
} else {
//begin at the start of the queue
$query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` ORDER BY `id` ASC', 1);
$query->execute();
if ($row = $query->fetch()) {
- return $this->buildJob($row);
+ $jobId = $row['id'];
+ $job = $this->buildJob($row);
} else {
return null; //empty job list
}
}
+ if (is_null($job)) {
+ $this->removeById($jobId);
+ return $this->getNext();
+ } else {
+ return $job;
+ }
}
/**
diff --git a/tests/lib/backgroundjob/joblist.php b/tests/lib/backgroundjob/joblist.php
index 13bee12479e..d5136676a47 100644
--- a/tests/lib/backgroundjob/joblist.php
+++ b/tests/lib/backgroundjob/joblist.php
@@ -202,4 +202,30 @@ class JobList extends \Test\TestCase {
$this->instance->remove($job);
}
+
+ public function testGetNextNonExisting() {
+ $job = new TestJob();
+ $this->instance->add($job, 1);
+ $this->instance->add('\OC\Non\Existing\Class');
+ $this->instance->add($job, 2);
+
+ $jobs = $this->instance->getAll();
+
+ $savedJob1 = $jobs[count($jobs) - 2];
+ $savedJob2 = $jobs[count($jobs) - 1];
+
+ $this->config->expects($this->any())
+ ->method('getAppValue')
+ ->with('backgroundjob', 'lastjob', 0)
+ ->will($this->returnValue($savedJob1->getId()));
+
+ $this->instance->getNext();
+
+ $nextJob = $this->instance->getNext();
+
+ $this->assertEquals($savedJob2, $nextJob);
+
+ $this->instance->remove($job, 1);
+ $this->instance->remove($job, 2);
+ }
}