Passed
Push — master ( 69c572...92beea )
by Aimeos
05:23
created

TablesMigratePropertyKey::tables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2022
6
 */
7
8
9
namespace Aimeos\Upscheme\Task;
10
11
12
class TablesMigratePropertyKey extends Base
13
{
14
	protected function tables()
15
	{
16
		return [
17
			'db-attribute' => 'mshop_attribute_property',
18
			'db-customer' => 'mshop_customer_property',
19
			'db-media' => 'mshop_media_property',
20
			'db-price' => 'mshop_price_property',
21
			'db-product' => 'mshop_product_property',
22
		];
23
	}
24
25
26
	public function after() : array
27
	{
28
		return ['TypesMigrateColumns', 'TablesClearPropertyKey', 'Attribute', 'Customer', 'Media', 'Price', 'Product'];
29
	}
30
31
32
	public function up()
33
	{
34
		$this->info( 'Update property "key" columns', 'v' );
35
36
		foreach( $this->tables() as $rname => $table )
37
		{
38
			$this->info( sprintf( 'Checking table %1$s', $table ), 'vv', 1 );
39
40
			$db = $this->db( $rname );
41
			$db2 = $this->db( $rname, true );
42
43
			$update = $db->stmt()->update( $table )->set( $db->qi( 'key' ), '?' )->where( 'id', '?' );
44
45
			$q = $db->stmt();
46
			$result = $q->select( 'id', 'type', 'langid', 'value' )->from( $table )
47
				->where( $db->qi( 'key' ) . ' = \'\'' )->execute();
48
49
			while( $row = $result->fetch() )
50
			{
51
				$value = substr( $row['type'] . '|' . ( $row['langid'] ?: 'null' ) . '|' . $row['value'], 0, 255 );
52
				$update->setParameters( $value, $row['id'] )->execute();
0 ignored issues
show
Bug introduced by
$value of type string is incompatible with the type array expected by parameter $params of Doctrine\DBAL\Query\QueryBuilder::setParameters(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
				$update->setParameters( /** @scrutinizer ignore-type */ $value, $row['id'] )->execute();
Loading history...
53
			}
54
55
			$db2->close();
56
		}
57
	}
58
}
59