Passed
Push — master ( e6de74...f68097 )
by Aimeos
04:48
created

PriceMigrateTaxrate::before()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2019-2022
6
 */
7
8
9
namespace Aimeos\Upscheme\Task;
10
11
12
class PriceMigrateTaxrate extends Base
13
{
14
	public function after() : array
15
	{
16
		return ['Price'];
17
	}
18
19
20
	public function up()
21
	{
22
		$this->info( 'Migrating taxrate column in price table', 'vv' );
23
24
		$conn = $this->context()->db( 'db-price' );
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

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