Installer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A install() 0 5 2
A setupTable() 0 8 2
1
<?php
2
3
namespace Wikibase\QueryEngine\SQLStore\Setup;
4
5
use Doctrine\DBAL\DBALException;
6
use Doctrine\DBAL\Schema\AbstractSchemaManager;
7
use Doctrine\DBAL\Schema\Table;
8
use Psr\Log\LoggerInterface;
9
use Wikibase\QueryEngine\QueryEngineException;
10
use Wikibase\QueryEngine\QueryStoreInstaller;
11
use Wikibase\QueryEngine\SQLStore\StoreSchema;
12
13
/**
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class Installer implements QueryStoreInstaller {
18
19
	private $logger;
20
	private $schemaManager;
21
	private $storeSchema;
22
23
	public function __construct( LoggerInterface $logger, StoreSchema $storeSchema, AbstractSchemaManager $schemaManager ) {
24
		$this->logger = $logger;
25
		$this->storeSchema = $storeSchema;
26
		$this->schemaManager = $schemaManager;
27
	}
28
29
	/**
30
	 * @see QueryStoreInstaller::install
31
	 *
32
	 * @throws QueryEngineException
33
	 */
34
	public function install() {
35
		foreach ( $this->storeSchema->getTables() as $table ) {
36
			$this->setupTable( $table );
37
		}
38
	}
39
40
	/**
41
	 * Sets up the tables of the store.
42
	 *
43
	 * @param Table $table
44
	 */
45
	private function setupTable( Table $table ) {
46
		try {
47
			$this->schemaManager->createTable( $table );
48
		}
49
		catch ( DBALException $ex ) {
50
			$this->logger->alert( $ex->getMessage(), array( 'exception' => $ex ) );
51
		}
52
	}
53
54
}
55