Completed
Pull Request — stable10 (#894)
by Lukas
10:09 queued 46s
created

RemoveOrphaned::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 8
loc 8
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OC\Settings;
25
26
use OC\BackgroundJob\JobList;
27
use OC\BackgroundJob\TimedJob;
28
use OC\NeedsUpdateException;
29
use OCP\BackgroundJob\IJobList;
30
use OCP\ILogger;
31
32
/**
33
 * Class RemoveOrphaned
34
 *
35
 * @package OC\Settings
36
 */
37
class RemoveOrphaned extends TimedJob {
38
39
	/** @var IJobList */
40
	private $jobList;
41
42
	/** @var ILogger */
43
	private $logger;
44
45
	/** @var Manager */
46
	private $manager;
47
48
	public function __construct(Manager $manager = null) {
49
		if($manager !== null) {
50
			$this->manager = $manager;
51
		} else {
52
			// fix DI for Jobs
53
			$this->manager = \OC::$server->getSettingsManager();
54
		}
55
	}
56
57
	/**
58
	 * run the job, then remove it from the job list
59
	 *
60
	 * @param JobList $jobList
61
	 * @param ILogger $logger
62
	 */
63 View Code Duplication
	public function execute($jobList, ILogger $logger = null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
		// add an interval of 15 mins
65
		$this->setInterval(15*60);
66
67
		$this->jobList = $jobList;
68
		$this->logger = $logger;
69
		parent::execute($jobList, $logger);
70
	}
71
72
	/**
73
	 * @param array $argument
74
	 * @throws \Exception
75
	 * @throws \OC\NeedsUpdateException
76
	 */
77
	protected function run($argument) {
78
		try {
79
			\OC_App::loadApps();
80
		} catch (NeedsUpdateException $ex) {
81
			// only run when apps are up to date
82
			return;
83
		}
84
85
		$this->manager->checkForOrphanedClassNames();
86
87
		// remove the job once executed successfully
88
		$this->jobList->remove($this);
89
	}
90
91
}
92