Completed
Push — master ( 858dca...453367 )
by Henry
06:29
created

Migrate::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
namespace Redaxscript\Console\Command;
3
4
use Redaxscript\Console\Parser;
5
use Redaxscript\Installer;
6
7
/**
8
 * children class to execute the migrate command
9
 *
10
 * @since 4.4.0
11
 *
12
 * @package Redaxscript
13
 * @category Console
14
 * @author Henry Ruhs
15
 */
16
17
class Migrate extends CommandAbstract
18
{
19
	/**
20
	 * array of the command
21
	 *
22
	 * @var array
23
	 */
24
25
	protected $_commandArray =
26
	[
27
		'migrate' =>
28
		[
29
			'description' => 'Migrate command',
30
			'argumentArray' =>
31
			[
32
				'database' =>
33
				[
34
					'description' => 'Migrate the database',
35
				]
36
			]
37
		]
38
	];
39
40
	/**
41
	 * run the command
42
	 *
43
	 * @since 4.4.0
44
	 *
45
	 * @param string $mode name of the mode
46
	 *
47
	 * @return string|null
48
	 */
49
50
	public function run(string $mode = null) : ?string
51
	{
52
		$parser = new Parser($this->_request);
53
		$parser->init($mode);
54
55
		/* run command */
56
57
		$argumentKey = $parser->getArgument(1);
58
		$haltOnError = (bool)$parser->getOption('halt-on-error');
59
		if ($argumentKey === 'database')
60
		{
61
			return $this->_database() ? $this->success() : $this->error($haltOnError);
62
		}
63
		return $this->getHelp();
64
	}
65
66
	/**
67
	 * migrate the database
68
	 *
69
	 * @since 4.4.0
70
	 *
71
	 * @return bool
72
	 */
73
74
	protected function _database() : bool
75
	{
76
		$installer = new Installer($this->_registry, $this->_request, $this->_language, $this->_config);
77
		$installer->init();
78
		return $installer->rawMigrate();
79
	}
80
}
81