Passed
Push — master ( 11a9d1...1a8053 )
by Aimeos
02:37
created

CustomerRemoveSignedConstraints   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPostDependencies() 0 3 1
A getPreDependencies() 0 3 1
B migrate() 0 53 6
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2019
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Removes signed constraints from users_* tables before migrating to unsigned
14
 */
15
class CustomerRemoveSignedConstraints extends \Aimeos\MW\Setup\Task\Base
16
{
17
	/**
18
	 * Returns the list of task names which this task depends on.
19
	 *
20
	 * @return string[] List of task names
21
	 */
22
	public function getPreDependencies()
23
	{
24
		return ['CustomerChangeAddressRefidParentidLaravel'];
25
	}
26
27
28
	/**
29
	 * Returns the list of task names which depends on this task.
30
	 *
31
	 * @return array List of task names
32
	 */
33
	public function getPostDependencies()
34
	{
35
		return ['TablesCreateMShop'];
36
	}
37
38
39
	/**
40
	 * Executes the task
41
	 */
42
	public function migrate()
43
	{
44
		$schema = $this->getSchema( 'db-customer' );
45
		$sql = 'SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = \'users\' AND COLUMN_NAME = \'id\'';
46
47
		try {
48
			$type = $this->getValue( $sql, 'COLUMN_TYPE', 'db-customer' );
49
		} catch( \Aimeos\MW\Setup\Exception $e ) {
50
			$type = null;
51
		}
52
53
		if( in_array( $type, ['int(10)', 'int(11)'] ) )
54
		{
55
			$this->msg( sprintf( 'Remove signed constraints in users related tables' ), 0 );
56
			$this->status( '' );
57
58
59
			$this->msg( 'Checking constraint in "users_address"', 1 );
60
61
			if( $schema->constraintExists( 'users_address', 'fk_lvuad_pid' ) )
62
			{
63
				$this->execute( 'ALTER TABLE "users_address" DROP FOREIGN KEY "fk_lvuad_pid"', 'db-customer' );
64
				$this->status( 'done' );
65
			}
66
			else
67
			{
68
				$this->status( 'OK' );
69
			}
70
71
72
			$this->msg( 'Checking constraint in "users_list"', 1 );
73
74
			if( $schema->constraintExists( 'users_list', 'fk_lvuli_pid' ) )
75
			{
76
				$this->execute( 'ALTER TABLE "users_list" DROP FOREIGN KEY "fk_lvuli_pid"', 'db-customer' );
77
				$this->status( 'done' );
78
			}
79
			else
80
			{
81
				$this->status( 'OK' );
82
			}
83
84
85
			$this->msg( 'Checking constraint in "users_property"', 1 );
86
87
			if( $schema->constraintExists( 'users_property', 'fk_lvupr_pid' ) )
88
			{
89
				$this->execute( 'ALTER TABLE "users_property" DROP FOREIGN KEY "fk_lvupr_pid"', 'db-customer' );
90
				$this->status( 'done' );
91
			}
92
			else
93
			{
94
				$this->status( 'OK' );
95
			}
96
		}
97
	}
98
}