Installer::setupTable()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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