Passed
Push — master ( 7f3d9f...459a43 )
by Aimeos
02:49
created

CustomerRemoveConstraints::migrate()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 4
b 0
f 0
nc 3
nop 0
dl 0
loc 21
rs 9.5222
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Removes constraints from users_* tables before migrating to bigint (Laravel 8)
14
 */
15
class CustomerRemoveConstraints 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() : array
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() : array
34
	{
35
		return ['TablesCreateMShop'];
36
	}
37
38
39
	/**
40
	 * Executes the task
41
	 */
42
	public function migrate()
43
	{
44
		$this->msg( sprintf( 'Remove constraints in users related tables' ), 0, '' );
45
46
		$rname = 'db-customer';
47
		$schema = $this->getSchema( $rname );
48
49
		if( $schema->tableExists( 'users' ) && $schema->columnExists( 'users', 'id' )
50
			&& $schema->getColumnDetails( 'users', 'id' )->getDataType() !== 'bigint'
51
		) {
52
			$conn = $this->acquire( $rname );
53
			$dbal = $conn->getRawObject();
54
55
			if( !( $dbal instanceof \Doctrine\DBAL\Connection ) ) {
56
				throw new \Aimeos\MW\Setup\Exception( 'Not a DBAL connection' );
57
			}
58
59
			$dbalManager = $dbal->getSchemaManager();
60
			$dbalManager->tryMethod( 'dropForeignKey', 'fk_lvuad_pid', 'users_address' );
61
			$dbalManager->tryMethod( 'dropForeignKey', 'fk_lvupr_pid', 'users_property' );
62
			$dbalManager->tryMethod( 'dropForeignKey', 'fk_lvuli_pid', 'users_list' );
63
		}
64
	}
65
}
66