Completed
Push — master ( ca5656...60398b )
by Morris
32:43 queued 16:28
created

ExecuteCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 * @author Thomas Müller <[email protected]>
5
 *
6
 * @copyright Copyright (c) 2017 Joas Schilling <[email protected]>
7
 * @copyright Copyright (c) 2017, ownCloud GmbH
8
 *
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
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, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OC\Core\Command\Db\Migrations;
26
27
28
use OC\DB\MigrationService;
29
use OC\Migration\ConsoleOutput;
30
use OCP\IConfig;
31
use OCP\IDBConnection;
32
use Symfony\Component\Console\Command\Command;
33
use Symfony\Component\Console\Input\InputArgument;
34
use Symfony\Component\Console\Input\InputInterface;
35
use Symfony\Component\Console\Output\OutputInterface;
36
37
class ExecuteCommand extends Command {
38
39
	/** @var IDBConnection */
40
	private $connection;
41
	/** @var IConfig */
42
	private $config;
43
44
	/**
45
	 * ExecuteCommand constructor.
46
	 *
47
	 * @param IDBConnection $connection
48
	 * @param IConfig $config
49
	 */
50
	public function __construct(IDBConnection $connection, IConfig $config) {
51
		$this->connection = $connection;
52
		$this->config = $config;
53
54
		parent::__construct();
55
	}
56
57
	protected function configure() {
58
		$this
59
			->setName('migrations:execute')
60
			->setDescription('Execute a single migration version manually.')
61
			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
62
			->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null);
63
64
		parent::configure();
65
	}
66
67
	/**
68
	 * @param InputInterface $input
69
	 * @param OutputInterface $output
70
	 * @return int
71
	 */
72
	public function execute(InputInterface $input, OutputInterface $output) {
73
		$appName = $input->getArgument('app');
74
		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
75
		$version = $input->getArgument('version');
76
77
		if ($this->config->getSystemValue('debug', false) === false) {
78
			$olderVersions = $ms->getMigratedVersions();
79
			$olderVersions[] = '0';
80
			$olderVersions[] = 'prev';
81
			if (in_array($version,  $olderVersions, true)) {
82
				$output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
83
				return 1;
84
			}
85
		}
86
87
88
		$ms->executeStep($version);
89
		return 0;
90
	}
91
92
}
93