From: Tim Düsterhus Date: Sun, 21 Jun 2015 19:23:07 +0000 (+0200) Subject: Allow passing an array to BackgroundQueueHandler::enqueue(At|In) X-Git-Tag: 3.0.0_Beta_1~2249^2~3^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=70f9375bb46abad2e69b1fcddfdf5728e4c9919b;p=GitHub%2FWoltLab%2FWCF.git Allow passing an array to BackgroundQueueHandler::enqueue(At|In) --- diff --git a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php index 00519189dc..d8e4b05efe 100644 --- a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php @@ -18,38 +18,48 @@ use wcf\system\WCF; */ class BackgroundQueueHandler extends SingletonFactory { /** - * Enqueues the given job for execution in the specified number of + * Enqueues the given job(s) for execution in the specified number of * seconds. Defaults to "as soon as possible" (0 seconds). * - * @param \wcf\system\background\job\AbstractBackgroundJob $job The job to enqueue. - * @param int $time Minimum number of seconds to wait before performing the job. + * @param mixed $jobs Either an instance of \wcf\system\background\job\AbstractBackgroundJob or an array of these + * @param int $time Minimum number of seconds to wait before performing the job. * @see \wcf\system\background\BackgroundQueueHandler::enqueueAt() */ - public function enqueueIn(AbstractBackgroundJob $job, $time = 0) { - return self::enqueueAt($job, TIME_NOW + $time); + public function enqueueIn($jobs, $time = 0) { + return self::enqueueAt($jobs, TIME_NOW + $time); } /** - * Enqueues the given job for execution at the given time. + * Enqueues the given job(s) for execution at the given time. * Note: The time is a minimum time. Depending on the size of * the queue the job can be performed later as well! * - * @param \wcf\system\background\job\AbstractBackgroundJob $job The job to enqueue. - * @param int $time Earliest time to consider the job for execution. + * @param mixed $jobs Either an instance of \wcf\system\background\job\AbstractBackgroundJob or an array of these + * @param int $time Earliest time to consider the job for execution. */ - public function enqueueAt(AbstractBackgroundJob $job, $time) { + public function enqueueAt($jobs, $time) { if ($time < TIME_NOW) { throw new SystemException("You may not schedule a job in the past (".$time." is smaller than the current timestamp ".TIME_NOW.")."); } + if (!is_array($jobs)) $jobs = [ $jobs ]; + foreach ($jobs as $job) { + if (!($job instanceof AbstractBackgroundJob)) { + throw new SystemException('$jobs contains an item that does not extend \wcf\system\background\job\AbstractBackgroundJob.'); + } + } + WCF::getDB()->beginTransaction(); $sql = "INSERT INTO wcf".WCF_N."_background_job (job, time) VALUES (?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute([ - serialize($job), - $time - ]); + foreach ($jobs as $job) { + $statement->execute([ + serialize($job), + $time + ]); + } + WCF::getDB()->commitTransaction(); } /**