InstallCommandExecutor   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 73
ccs 0
cts 56
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 15 2
A startInstallation() 0 3 1
A createDumpStore() 0 8 1
A createTermStore() 0 8 1
A createQueryEngine() 0 10 2
A reportInstallationFailure() 0 5 1
A reportInstallationSuccess() 0 7 1
1
<?php
2
3
namespace Queryr\Replicator\Cli\Install;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
/**
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
class InstallCommandExecutor {
13
	use InstallerTrait;
14
15
	private $output;
16
17
	public function __construct( InputInterface $input, OutputInterface $output ) {
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
		$this->output = $output;
19
	}
20
21
	public function run() {
22
		$this->startInstallation();
23
24
		try {
25
			$this->establishDatabaseConnection();
26
			$this->createDumpStore();
27
			$this->createTermStore();
28
			$this->createQueryEngine();
29
30
			$this->reportInstallationSuccess();
31
		}
32
		catch ( InstallationException $ex ) {
33
			$this->reportInstallationFailure( $ex->getMessage() );
34
		}
35
	}
36
37
	private function startInstallation() {
38
		$this->output->writeln( '<info>Installing QueryR Replicator.</info>' );
39
	}
40
41
	private function createDumpStore() {
42
		$this->tryTask(
43
			'Creating dump store',
44
			function() {
45
				$this->factory->newEntityStoreInstaller()->install();
46
			}
47
		);
48
	}
49
50
	private function createTermStore() {
51
		$this->tryTask(
52
			'Creating term store',
53
			function() {
54
				$this->factory->newTermStoreInstaller()->install();
55
			}
56
		);
57
	}
58
59
	private function createQueryEngine() {
60
		if ( defined( 'WIKIBASE_QUERYENGINE_VERSION' ) ) {
61
			$this->tryTask(
62
				'Creating query engine',
63
				function () {
64
					$this->factory->newQueryEngineInstaller()->install();
65
				}
66
			);
67
		}
68
	}
69
70
	private function reportInstallationFailure( $failureMessage ) {
71
		$this->writeProgressEnd( 'failed!' );
72
		$this->writeError( 'Error! Installation of QueryR Replicator failed.' );
73
		$this->writeError( 'Reason: ' . $failureMessage );
74
	}
75
76
	private function reportInstallationSuccess() {
77
		$tag = 'bg=green;fg=black';
78
79
		$this->output->writeln(
80
			"<$tag>Installation of QueryR Replicator has completed successfully.</$tag>"
81
		);
82
	}
83
84
}
85