1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MW\Setup\Task; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Migrates the tax rate in price table |
14
|
|
|
*/ |
15
|
|
|
class PriceMigrateTaxrate extends \Aimeos\MW\Setup\Task\Base |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Returns the list of task names which this task depends on. |
19
|
|
|
* |
20
|
|
|
* @return string[] List of task names |
21
|
|
|
*/ |
22
|
|
|
public function getPreDependencies() |
23
|
|
|
{ |
24
|
|
|
return array( 'TablesCreateMShop' ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns the list of task names which depends on this task. |
30
|
|
|
* |
31
|
|
|
* @return string[] List of task names |
32
|
|
|
*/ |
33
|
|
|
public function getPostDependencies() |
34
|
|
|
{ |
35
|
|
|
return []; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Migrate database schema |
41
|
|
|
*/ |
42
|
|
|
public function migrate() |
43
|
|
|
{ |
44
|
|
|
$dbdomain = 'db-price'; |
45
|
|
|
$this->msg( 'Migrating taxrate column in price table', 0 ); |
46
|
|
|
|
47
|
|
|
if( $this->getSchema( $dbdomain )->tableExists( 'mshop_price' ) === false ) |
48
|
|
|
{ |
49
|
|
|
$this->status( 'OK' ); |
50
|
|
|
return; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$start = 0; |
54
|
|
|
$conn = $this->acquire( $dbdomain ); |
55
|
|
|
$select = 'SELECT "id", "taxrate" FROM "mshop_price" WHERE "taxrate" NOT LIKE \'{%\' LIMIT 1000 OFFSET :offset'; |
56
|
|
|
$update = 'UPDATE "mshop_price" SET "taxrate" = ? WHERE "id" = ?'; |
57
|
|
|
|
58
|
|
|
$stmt = $conn->create( $update, \Aimeos\MW\DB\Connection\Base::TYPE_PREP ); |
59
|
|
|
|
60
|
|
|
do |
61
|
|
|
{ |
62
|
|
|
$count = 0; |
63
|
|
|
$map = []; |
64
|
|
|
$sql = str_replace( ':offset', $start, $select ); |
65
|
|
|
$result = $conn->create( $sql )->execute(); |
66
|
|
|
|
67
|
|
|
while( ( $row = $result->fetch() ) !== false ) |
68
|
|
|
{ |
69
|
|
|
$map[$row['id']] = $row['taxrate']; |
70
|
|
|
$count++; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
foreach( $map as $id => $taxrate ) |
74
|
|
|
{ |
75
|
|
|
$stmt->bind( 1, json_encode( ['' => $taxrate], JSON_FORCE_OBJECT ) ); |
76
|
|
|
$stmt->bind( 2, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
77
|
|
|
|
78
|
|
|
$stmt->execute()->finish(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$start += $count; |
82
|
|
|
} |
83
|
|
|
while( $count === 1000 ); |
84
|
|
|
|
85
|
|
|
$this->release( $conn, $dbdomain ); |
86
|
|
|
|
87
|
|
|
$this->status( 'done' ); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|