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

MigrateCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 9 1
A execute() 0 7 1
1
<?php
2
/**
3
 * @author Thomas Müller <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2017, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OC\Core\Command\Db\Migrations;
23
24
25
use OC\DB\MigrationService;
26
use OC\Migration\ConsoleOutput;
27
use OCP\IDBConnection;
28
use Symfony\Component\Console\Command\Command;
29
use Symfony\Component\Console\Input\InputArgument;
30
use Symfony\Component\Console\Input\InputInterface;
31
use Symfony\Component\Console\Output\OutputInterface;
32
33
class MigrateCommand extends Command {
34
35
	/** @var IDBConnection */
36
	private $connection;
37
38
	/**
39
	 * @param IDBConnection $connection
40
	 */
41
	public function __construct(IDBConnection $connection) {
42
		$this->connection = $connection;
43
		parent::__construct();
44
	}
45
46
	protected function configure() {
47
		$this
48
			->setName('migrations:migrate')
49
			->setDescription('Execute a migration to a specified version or the latest available version.')
50
			->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
51
			->addArgument('version', InputArgument::OPTIONAL, 'The version number (YYYYMMDDHHMMSS) or alias (first, prev, next, latest) to migrate to.', 'latest');
52
53
		parent::configure();
54
	}
55
56
	public function execute(InputInterface $input, OutputInterface $output) {
57
		$appName = $input->getArgument('app');
58
		$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
59
		$version = $input->getArgument('version');
60
61
		$ms->migrate($version);
62
	}
63
64
}
65