Passed
Push — master ( 49f6b0...199364 )
by Aimeos
09:07
created

FEUsersMigrateCountryTypo3   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPostDependencies() 0 3 1
A migrate() 0 19 4
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2021
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Adds siteid column to fe_users table.
14
 */
15
class FEUsersMigrateCountryTypo3 extends \Aimeos\MW\Setup\Task\Base
16
{
17
	/**
18
	 * Returns the list of task names which depends on this task.
19
	 *
20
	 * @return string[] List of task names
21
	 */
22
	public function getPostDependencies() : array
23
	{
24
		return ['TablesCreateMShop'];
25
	}
26
27
28
	/**
29
	 * Add column siteid to fe_users table.
30
	 *
31
	 */
32
	public function migrate()
33
	{
34
		$this->msg( sprintf( 'Migrating "%1$s" column in "%2$s" table', 'static_info_country', 'fe_users' ), 0 );
35
36
		$schema = $this->getSchema( 'db-customer' );
37
38
		if( $schema->tableExists( 'fe_users' ) === true && $schema->tableExists( 'static_countries' ) === true
39
			&& $schema->columnExists( 'fe_users', 'static_info_country' ) === true )
40
		{
41
			$stmt = 'UPDATE fe_users SET static_info_country = (
42
				SELECT cn_iso_2 FROM static_countries WHERE cn_iso_3 = static_info_country
43
			) WHERE LENGTH(static_info_country) = 3';
44
45
			$this->execute( $stmt, 'db-customer' );
46
			$this->status( 'done' );
47
		}
48
		else
49
		{
50
			$this->status( 'OK' );
51
		}
52
	}
53
}
54