ExtensionSchemaUpdater   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 68
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setConfiguration() 0 3 1
A execute() 0 3 3
A isSupportedDBType() 0 3 1
A hasDatabaseSchema() 0 3 1
A performUpdate() 0 17 2
A buildExtensionUpdateDefinition() 0 8 1
1
<?php
2
3
namespace SWL\MediaWiki\Hooks;
4
5
use DatabaseUpdater;
6
7
/**
8
 * Fired when MediaWiki is updated to allow extensions to update the database
9
 *
10
 * https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates
11
 *
12
 * @ingroup SWL
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author Jeroen De Dauw < [email protected] >
18
 * @author mwjames
19
 */
20
class ExtensionSchemaUpdater {
21
22
	protected $databaseUpdater;
23
	protected $configuration;
24
25
	/**
26
	 * @since 1.0
27
	 *
28
	 * @param DatabaseUpdater $databaseUpdater
29
	 */
30 4
	public function __construct( DatabaseUpdater $databaseUpdater ) {
31 4
		$this->databaseUpdater = $databaseUpdater;
32 4
	}
33
34
	/**
35
	 * @since 1.0
36
	 *
37
	 * @param array $configuration
38
	 */
39 2
	public function setConfiguration( array $configuration ) {
40 2
		$this->configuration = $configuration;
41 2
	}
42
43
	/**
44
	 * @since 1.0
45
	 *
46
	 * @return boolean
47
	 */
48 3
	public function execute() {
49 3
		return $this->isSupportedDBType() && $this->hasDatabaseSchema() ? $this->performUpdate() : true;
50
	}
51
52 3
	private function isSupportedDBType() {
53 3
		return in_array( $this->databaseUpdater->getDB()->getType(), array( 'mysql', 'sqlite' ) );
54
	}
55
56 2
	private function hasDatabaseSchema() {
57 2
		return isset( $this->configuration['egSwlSqlDatabaseSchemaPath'] );
58
	}
59
60 2
	protected function performUpdate() {
61
62
		$tables = array(
63 2
			'swl_groups',
64
			'swl_changes',
65
			'swl_sets',
66
			'swl_edits_per_group',
67
			'swl_sets_per_group',
68
			'swl_users_per_group'
69
		);
70
71 2
		foreach ( $tables as $tableName ) {
72 2
			$this->databaseUpdater->addExtensionUpdate( $this->buildExtensionUpdateDefinition( $tableName ) );
73
		}
74
75 2
		return true;
76
	}
77
78 2
	protected function buildExtensionUpdateDefinition( $tableName ) {
79
		return array(
80 2
			'addTable',
81 2
			$tableName,
82 2
			$this->configuration['egSwlSqlDatabaseSchemaPath'],
83
			true
84
		);
85
	}
86
87
}
88