Passed
Push — master ( 94d09c...7ff05c )
by Aimeos
05:44
created

PriceMigrateTaxrate::up()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
nc 3
nop 0
dl 0
loc 28
c 0
b 0
f 0
cc 3
rs 9.7666
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2019-2021
6
 */
7
8
9
namespace Aimeos\Upscheme\Task;
10
11
12
class PriceMigrateTaxrate extends Base
13
{
14
	public function before() : array
15
	{
16
		return ['Price'];
17
	}
18
19
20
	public function up()
21
	{
22
		$db = $this->db( 'db-price' );
23
24
		if( !$db->hasTable( 'mshop_price' ) ) {
25
			return;
26
		}
27
28
		$this->info( 'Migrating taxrate column in price table', 'v' );
29
30
		$dbm = $this->context()->db();
0 ignored issues
show
Bug introduced by
The method context() does not exist on Aimeos\Upscheme\Task\PriceMigrateTaxrate. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

30
		$dbm = $this->/** @scrutinizer ignore-call */ context()->db();
Loading history...
31
		$conn = $dbm->acquire( 'db-price' );
32
33
		$select = 'SELECT "id", "taxrate" FROM "mshop_price" WHERE "taxrate" NOT LIKE \'{%\'';
34
		$update = 'UPDATE "mshop_price" SET "taxrate" = ? WHERE "id" = ?';
35
36
		$stmt = $conn->create( $update );
37
		$result = $conn->create( $select )->execute();
38
39
		while( ( $row = $result->fetch() ) !== null )
40
		{
41
			$stmt->bind( 1, json_encode( ['' => $row['taxrate']], JSON_FORCE_OBJECT ) );
42
			$stmt->bind( 2, $row['id'], \Aimeos\MW\DB\Statement\Base::PARAM_INT );
43
44
			$stmt->execute()->finish();
45
		}
46
47
		$dbm->release( $conn, 'db-price' );
48
	}
49
}
50