Completed
Push — master ( 8c23c8...3a0c6f )
by Aimeos
02:00
created

TypesMigrateColumnsLaravel::getPreDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Adds the new type columns
14
 */
15
class TypesMigrateColumnsLaravel extends \Aimeos\MW\Setup\Task\TypesMigrateColumns
16
{
17
	private $tables = [
18
		'db-customer' => ['users_list', 'users_property'],
19
	];
20
21
	private $constraints = [
22
		'db-customer' => ['users_list' => 'unq_lvuli_sid_dm_rid_tid_pid', 'users_property' => 'unq_lvupr_sid_tid_lid_value'],
23
	];
24
25
	private $migrations = [
26
		'db-customer' => [
27
			'users_list' => 'UPDATE "users_list" SET "type" = ( SELECT "code" FROM "users_list_type" AS t WHERE t."id" = "typeid" AND t."domain" = "domain" LIMIT 1 ) WHERE "type" IS NULL',
28
			'users_property' => 'UPDATE "users_property" SET "type" = ( SELECT "code" FROM "users_property_type" AS t WHERE t."id" = "typeid" AND t."domain" = "domain" LIMIT 1 ) WHERE "type" IS NULL',
29
		],
30
	];
31
32
33
	/**
34
	 * Returns the list of task names which this task depends on.
35
	 *
36
	 * @return string[] List of task names
37
	 */
38
	public function getPreDependencies()
39
	{
40
		return [];
41
	}
42
43
44
	/**
45
	 * Returns the list of task names which depends on this task.
46
	 *
47
	 * @return array List of task names
48
	 */
49
	public function getPostDependencies()
50
	{
51
		return ['TablesCreateMShop'];
52
	}
53
54
55
	/**
56
	 * Executes the task
57
	 */
58
	public function migrate()
59
	{
60
		$this->msg( sprintf( 'Add new type columns for Laravel' ), 0 );
61
		$this->status( '' );
62
63
		foreach( $this->tables as $rname => $list ) {
64
			$this->addColumn( $rname, $list );
65
		}
66
67
		$this->msg( sprintf( 'Drop old unique indexes for Laravel' ), 0 );
68
		$this->status( '' );
69
70
		foreach( $this->constraints as $rname => $list ) {
71
			$this->dropIndex( $rname, $list );
72
		}
73
74
		$this->msg( sprintf( 'Migrate typeid to type for Laravel' ), 0 );
75
		$this->status( '' );
76
77
		foreach( $this->migrations as $rname => $list ) {
78
			$this->migrateData( $rname, $list );
79
		}
80
	}
81
}