Uninstaller   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
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 uninstall() 0 5 2
A dropTable() 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\QueryStoreUninstaller;
11
use Wikibase\QueryEngine\SQLStore\StoreConfig;
12
use Wikibase\QueryEngine\SQLStore\StoreSchema;
13
14
/**
15
 * @licence GNU GPL v2+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class Uninstaller implements QueryStoreUninstaller {
19
20
	private $logger;
21
	private $schemaManager;
22
	private $storeSchema;
23
24
	public function __construct( LoggerInterface $logger, StoreSchema $storeSchema, AbstractSchemaManager $schemaManager ) {
25
		$this->logger = $logger;
26
		$this->storeSchema = $storeSchema;
27
		$this->schemaManager = $schemaManager;
28
	}
29
30
	/**
31
	 * @see QueryStoreUninstaller::uninstall
32
	 *
33
	 * @throws QueryEngineException
34
	 */
35
	public function uninstall() {
36
		foreach ( $this->storeSchema->getTables() as $table ) {
37
			$this->dropTable( $table );
38
		}
39
	}
40
41
	/**
42
	 * Removes the tables belonging to the store.
43
	 *
44
	 * @param Table $table
45
	 */
46
	private function dropTable( Table $table ) {
47
		try {
48
			$this->schemaManager->dropTable( $table->getName() );
49
		}
50
		catch ( DBALException $ex ) {
51
			$this->logger->alert( $ex->getMessage(), array( 'exception' => $ex ) );
52
		}
53
	}
54
55
}
56