Passed
Push — master ( 3c693d...ccd5ca )
by Roeland
28:56 queued 14:09
created

MoveAvatars   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 2 1
A run() 0 13 3
A __construct() 0 4 1
1
<?php
2
/**
3
 * @copyright 2016 Roeland Jago Douma <[email protected]>
4
 *
5
 * @author Morris Jobke <[email protected]>
6
 * @author Roeland Jago Douma <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
namespace OC\Repair\Owncloud;
25
26
use OCP\BackgroundJob\IJobList;
27
use OCP\IConfig;
28
use OCP\Migration\IOutput;
29
use OCP\Migration\IRepairStep;
30
31
class MoveAvatars implements IRepairStep {
32
33
	/** @var IJobList */
34
	private $jobList;
35
36
	/** @var IConfig */
37
	private $config;
38
39
	/**
40
	 * MoveAvatars constructor.
41
	 *
42
	 * @param IJobList $jobList
43
	 * @param IConfig $config
44
	 */
45
	public function __construct(IJobList $jobList,
46
								IConfig $config) {
47
		$this->jobList = $jobList;
48
		$this->config = $config;
49
	}
50
51
	/**
52
	 * @return string
53
	 */
54
	public function getName() {
55
		return 'Add move avatar background job';
56
	}
57
58
	public function run(IOutput $output) {
59
		// only run once
60
		if ($this->config->getAppValue('core', 'moveavatarsdone') === 'yes') {
61
			$output->info('Repair step already executed');
62
			return;
63
		}
64
		if ($this->config->getSystemValue('enable_avatars', true) === false) {
65
			$output->info('Avatars are disabled');
66
		} else {
67
			$output->info('Add background job');
68
			$this->jobList->add(MoveAvatarsBackgroundJob::class);
69
			// if all were done, no need to redo the repair during next upgrade
70
			$this->config->setAppValue('core', 'moveavatarsdone', 'yes');
71
		}
72
	}
73
}
74