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