[Pkg-owncloud-commits] [owncloud] 10/457: add repair steps to get rid of old background jobs

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:05:16 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit d6becb8d828aef0b06df3de51fe9bb0d9710801d
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Tue May 12 18:19:44 2015 +0200

    add repair steps to get rid of old background jobs
---
 lib/private/repair.php           |  2 ++
 lib/repair/dropoldjobs.php       | 78 ++++++++++++++++++++++++++++++++++++++++
 tests/lib/repair/dropoldjobs.php | 40 +++++++++++++++++++++
 3 files changed, 120 insertions(+)

diff --git a/lib/private/repair.php b/lib/private/repair.php
index 0674207..c690fe4 100644
--- a/lib/private/repair.php
+++ b/lib/private/repair.php
@@ -32,6 +32,7 @@ use OC\Hooks\Emitter;
 use OC\Repair\AssetCache;
 use OC\Repair\CleanTags;
 use OC\Repair\Collation;
+use OC\Repair\DropOldJobs;
 use OC\Repair\SqliteAutoincrement;
 use OC\Repair\DropOldTables;
 use OC\Repair\FillETags;
@@ -106,6 +107,7 @@ class Repair extends BasicEmitter {
 			new FillETags(\OC_DB::getConnection()),
 			new CleanTags(\OC_DB::getConnection()),
 			new DropOldTables(\OC_DB::getConnection()),
+			new DropOldJobs(\OC::$server->getJobList()),
 		);
 	}
 
diff --git a/lib/repair/dropoldjobs.php b/lib/repair/dropoldjobs.php
new file mode 100644
index 0000000..89d7f96
--- /dev/null
+++ b/lib/repair/dropoldjobs.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * @author Arthur Schiwon <blizzz at owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Repair;
+
+use OC\Hooks\BasicEmitter;
+use OC\RepairStep;
+use OCP\BackgroundJob\IJobList;
+
+class DropOldJobs extends BasicEmitter implements RepairStep {
+
+	/** @var IJobList */
+	protected $jobList;
+
+	/**
+	 * @param IJobList $jobList
+	 */
+	public function __construct(IJobList $jobList) {
+		$this->jobList = $jobList;
+	}
+
+	/**
+	 * Returns the step's name
+	 *
+	 * @return string
+	 */
+	public function getName() {
+		return 'Drop old background jobs';
+	}
+
+	/**
+	 * Run repair step.
+	 * Must throw exception on error.
+	 *
+	 * @throws \Exception in case of failure
+	 */
+	public function run() {
+		$oldJobs = $this->oldJobs();
+		foreach($oldJobs as $job) {
+			if($this->jobList->has($job['class'], $job['arguments'])) {
+				$this->jobList->remove($job['class'], $job['arguments']);
+			}
+		}
+	}
+
+	/**
+	 * returns a list of old jobs as an associative array with keys 'class' and
+	 * 'arguments'.
+	 *
+	 * @return array
+	 */
+	public function oldJobs() {
+		return [
+			['class' => 'OC_Cache_FileGlobalGC', 'arguments' => null],
+			['class' => 'OC\Cache\FileGlobalGC', 'arguments' => null],
+		];
+	}
+
+
+}
diff --git a/tests/lib/repair/dropoldjobs.php b/tests/lib/repair/dropoldjobs.php
new file mode 100644
index 0000000..27d7860
--- /dev/null
+++ b/tests/lib/repair/dropoldjobs.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2015 Arthur Schiwon <blizzz at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Repair;
+
+use OCP\BackgroundJob\IJobList;
+
+/**
+ * Tests for the dropping old tables
+ *
+ * @see \OC\Repair\DropOldTables
+ */
+class DropOldJobs extends \Test\TestCase {
+	/** @var IJobList */
+	protected $jobList;
+
+	protected function setUp() {
+		parent::setUp();
+
+		$this->jobList = \OC::$server->getJobList();
+		$this->jobList->add('OC\Cache\FileGlobalGC');
+		$this->jobList->add('OC_Cache_FileGlobalGC');
+	}
+
+	public function testRun() {
+		$this->assertTrue($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC exists before repairing');
+		$this->assertTrue($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC exists before repairing');
+
+		$repair = new \OC\Repair\DropOldJobs($this->jobList);
+		$repair->run();
+
+		$this->assertFalse($this->jobList->has('OC\Cache\FileGlobalGC', null), 'Asserting that the job OC\Cache\FileGlobalGC does not exist after repairing');
+		$this->assertFalse($this->jobList->has('OC_Cache_FileGlobalGC', null), 'Asserting that the job OC_Cache_FileGlobalGC does not exist after repairing');
+	}
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list