Completed
Push — 2016.04 ( 690368...e61816 )
by Aimeos
04:37
created

CustomerChangeAddressRefidParentidTypo3   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 66
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPreDependencies() 0 4 1
A getPostDependencies() 0 4 1
A mysql() 0 4 1
A process() 0 19 4
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Renames the "refid" column to "parentid"
14
 */
15
class CustomerChangeAddressRefidParentidTypo3 extends \Aimeos\MW\Setup\Task\Base
16
{
17
	private $mysql = array(
18
		'refid' => array(
19
			'ALTER TABLE "fe_users_address" CHANGE "refid" "parentid" INTEGER NOT NULL',
20
			'ALTER TABLE "fe_users_address" DROP INDEX "idx_t3feuad_refid", ADD INDEX "idx_t3feuad_pid" ("parentid")',
21
		),
22
	);
23
24
25
	/**
26
	 * Returns the list of task names which this task depends on.
27
	 *
28
	 * @return array List of task names
29
	 */
30
	public function getPreDependencies()
31
	{
32
		return array();
33
	}
34
35
36
	/**
37
	 * Returns the list of task names which depends on this task.
38
	 *
39
	 * @return string[] List of task names
40
	 */
41
	public function getPostDependencies()
42
	{
43
		return array( 'TablesCreateTypo3' );
44
	}
45
46
47
	/**
48
	 * Executes the task for MySQL databases.
49
	 */
50
	protected function mysql()
51
	{
52
		$this->process( $this->mysql );
53
	}
54
55
56
	/**
57
	 * Changes the column in table
58
	 *
59
	 * array string $stmts List of SQL statements for changing the columns
60
	 */
61
	protected function process( array $stmts )
62
	{
63
		$table = 'fe_users_address';
64
		$this->msg( sprintf( 'Rename "refid" to "parentid" in table "%1$s"', $table ), 0 ); $this->status( '' );
65
66
		foreach( $stmts as $column => $stmts )
67
		{
68
			$this->msg( sprintf( 'Checking column "%1$s"', $column ), 1 );
69
70
			if( $this->schema->tableExists( $table )
71
				&& $this->schema->columnExists( $table, $column ) === true
72
			) {
73
				$this->executeList( $stmts );
74
				$this->status( 'done' );
75
			} else {
76
				$this->status( 'OK' );
77
			}
78
		}
79
	}
80
}
81