Passed
Push — master ( c52784...833dd8 )
by Aimeos
28:15 queued 16:05
created

TypesMigrateColumnsFosuser::up()   A

Complexity

Conditions 6
Paths 17

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 17
nop 0
dl 0
loc 32
rs 9.1111
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2023
6
 */
7
8
9
 namespace Aimeos\Upscheme\Task;
10
11
12
/**
13
 * Adds the new type columns
14
 */
15
class TypesMigrateColumnsFosuser extends TypesMigrateColumns
16
{
17
	private $tables = [
18
		'db-customer' => ['fos_user_list', 'fos_user_property'],
19
	];
20
21
	private $constraints = [
22
		'db-customer' => ['fos_user_list' => 'unq_mcusli_sid_dm_rid_tid_pid', 'fos_user_property' => 'unq_mcuspr_sid_tid_lid_value'],
23
	];
24
25
	private $migrations = [
26
		'db-customer' => [
27
			'fos_user_list' => 'UPDATE fos_user_list SET type = ( SELECT code FROM fos_user_list_type AS t WHERE t.id = typeid AND t.domain = domain ) WHERE type = \'\'',
28
			'fos_user_property' => 'UPDATE fos_user_property SET type = ( SELECT code FROM fos_user_property_type AS t WHERE t.id = typeid AND t.domain = domain ) WHERE type = \'\'',
29
		],
30
	];
31
32
	private $drops = [
33
		'db-customer' => ['fos_user_list' => 'fk_fosusli_typeid', 'fos_user_property' => 'fk_fosuspr_typeid'],
34
	];
35
36
37
	/**
38
	 * Executes the task
39
	 */
40
	public function up()
41
	{
42
		$db = $this->db( 'db-customer' );
43
44
		if( !$db->hasTable( 'fos_user' ) ) {
45
			return;
46
		}
47
48
		$this->info( 'Migrate typeid to type for FosUser', 'vv' );
49
50
		$this->info( 'Add new type columns for FosUser', 'vv', 1 );
51
52
		foreach( $this->tables as $rname => $list ) {
53
			$this->addColumn( $rname, $list );
54
		}
55
56
		$this->info( 'Drop old unique indexes for FosUser', 'vv', 1 );
57
58
		foreach( $this->constraints as $rname => $list ) {
59
			$this->dropIndex( $rname, $list );
60
		}
61
62
		$this->info( 'Migrate typeid to type for FosUser', 'vv', 1 );
63
64
		foreach( $this->migrations as $rname => $list ) {
65
			$this->migrateData( $rname, $list );
66
		}
67
68
		$this->info( 'Drop typeid columns for FosUser', 'vv', 1 );
69
70
		foreach( $this->drops as $rname => $list ) {
71
			$this->dropColumn( $rname, $list );
72
		}
73
	}
74
}
75