2013-04-20 21:27:46 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\BackgroundJob;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DummyJobList
|
|
|
|
*
|
|
|
|
* in memory job list for testing purposes
|
|
|
|
*/
|
|
|
|
class DummyJobList extends \OC\BackgroundJob\JobList {
|
|
|
|
/**
|
|
|
|
* @var \OC\BackgroundJob\Job[]
|
|
|
|
*/
|
|
|
|
private $jobs = array();
|
|
|
|
|
|
|
|
private $last = 0;
|
|
|
|
|
2014-02-11 13:00:24 +00:00
|
|
|
public function __construct(){}
|
|
|
|
|
2013-04-20 21:27:46 +00:00
|
|
|
/**
|
|
|
|
* @param \OC\BackgroundJob\Job|string $job
|
2013-04-20 21:51:58 +00:00
|
|
|
* @param mixed $argument
|
2013-04-20 21:27:46 +00:00
|
|
|
*/
|
2013-04-20 21:51:58 +00:00
|
|
|
public function add($job, $argument = null) {
|
|
|
|
$job->setArgument($argument);
|
|
|
|
if (!$this->has($job, null)) {
|
2013-04-20 21:27:46 +00:00
|
|
|
$this->jobs[] = $job;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \OC\BackgroundJob\Job|string $job
|
2013-04-20 21:51:58 +00:00
|
|
|
* @param mixed $argument
|
2013-04-20 21:27:46 +00:00
|
|
|
*/
|
2013-04-20 21:51:58 +00:00
|
|
|
public function remove($job, $argument = null) {
|
2013-04-20 21:27:46 +00:00
|
|
|
$index = array_search($job, $this->jobs);
|
|
|
|
if ($index !== false) {
|
|
|
|
unset($this->jobs[$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if a job is in the list
|
|
|
|
*
|
|
|
|
* @param $job
|
2013-04-20 21:51:58 +00:00
|
|
|
* @param mixed $argument
|
2013-04-20 21:27:46 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2013-04-20 21:51:58 +00:00
|
|
|
public function has($job, $argument) {
|
2013-04-20 21:27:46 +00:00
|
|
|
return array_search($job, $this->jobs) !== false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get all jobs in the list
|
|
|
|
*
|
|
|
|
* @return \OC\BackgroundJob\Job[]
|
|
|
|
*/
|
|
|
|
public function getAll() {
|
|
|
|
return $this->jobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the next job in the list
|
|
|
|
*
|
|
|
|
* @return \OC\BackgroundJob\Job
|
|
|
|
*/
|
|
|
|
public function getNext() {
|
|
|
|
if (count($this->jobs) > 0) {
|
|
|
|
if ($this->last < (count($this->jobs) - 1)) {
|
|
|
|
$i = $this->last + 1;
|
|
|
|
} else {
|
|
|
|
$i = 0;
|
|
|
|
}
|
|
|
|
return $this->jobs[$i];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the job that was last ran
|
|
|
|
*
|
|
|
|
* @param \OC\BackgroundJob\Job $job
|
|
|
|
*/
|
|
|
|
public function setLastJob($job) {
|
|
|
|
$i = array_search($job, $this->jobs);
|
|
|
|
if ($i !== false) {
|
|
|
|
$this->last = $i;
|
|
|
|
} else {
|
|
|
|
$this->last = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 12:38:41 +00:00
|
|
|
/**
|
|
|
|
* @param int $id
|
|
|
|
* @return Job
|
|
|
|
*/
|
|
|
|
public function getById($id) {
|
|
|
|
foreach ($this->jobs as $job) {
|
|
|
|
if ($job->getId() === $id) {
|
|
|
|
return $job;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-04-20 21:27:46 +00:00
|
|
|
/**
|
|
|
|
* get the id of the last ran job
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getLastJob() {
|
|
|
|
return $this->last;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the lastRun of $job to now
|
|
|
|
*
|
|
|
|
* @param \OC\BackgroundJob\Job $job
|
|
|
|
*/
|
|
|
|
public function setLastRun($job) {
|
|
|
|
$job->setLastRun(time());
|
|
|
|
}
|
|
|
|
}
|