Passed
Push — master ( bb78f2...5dc509 )
by Aimeos
19:06 queued 11:52
created

CustomerRemoveLostUserDataTypo3   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 14 4
A before() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2021
6
 */
7
8
9
namespace Aimeos\Upscheme\Task;
10
11
12
/**
13
 * Removes address and list records without user entry
14
 */
15
class CustomerRemoveLostUserDataTypo3 extends Base
16
{
17
	private $sql = [
18
		'fe_users_address' => [
19
			'fk_mcusad_pid' => 'DELETE FROM fe_users_address WHERE NOT EXISTS ( SELECT uid FROM fe_users AS u WHERE parentid=u.uid )'
20
		],
21
		'fe_users_list' => [
22
			'fk_mcusli_pid' => 'DELETE FROM fe_users_list WHERE NOT EXISTS ( SELECT uid FROM fe_users AS u WHERE parentid=u.uid )'
23
		],
24
		'fe_users_property' => [
25
			'fk_mcuspr_pid' => 'DELETE FROM fe_users_property WHERE NOT EXISTS ( SELECT uid FROM fe_users AS u WHERE parentid=u.uid )'
26
		]
27
	];
28
29
30
	/**
31
	 * Returns the list of task names which depends on this task.
32
	 *
33
	 * @return string[] List of task names
34
	 */
35
	public function before() : array
36
	{
37
		return ['TablesCreateMShop'];
38
	}
39
40
41
	/**
42
	 * Migrate database schema
43
	 */
44
	public function up()
45
	{
46
		$this->info( 'Remove left over TYPO3 fe_users references', 'v' );
47
48
		$db = $this->db( 'db-customer' );
49
50
		foreach( $this->sql as $table => $map )
51
		{
52
			foreach( $map as $constraint => $sql )
53
			{
54
				$this->info( sprintf( 'Remove records from %1$s', $table ), 'vv', 1 );
55
56
				if( !$db->hasForeign( $table, $constraint ) ) {
57
					$db->exec( $sql );
58
				}
59
			}
60
		}
61
	}
62
}
63