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
|
|
|
* Updates key columns |
14
|
|
|
*/ |
15
|
|
|
class AttributeMigrateKey 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 []; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns the list of task names which depends on this task. |
30
|
|
|
* |
31
|
|
|
* @return array List of task names |
32
|
|
|
*/ |
33
|
|
|
public function getPostDependencies() |
34
|
|
|
{ |
35
|
|
|
return ['TablesCreateMShop']; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Executes the task |
41
|
|
|
*/ |
42
|
|
|
public function migrate() |
43
|
|
|
{ |
44
|
|
|
$this->msg( 'Update attribute "key" columns', 0 ); $this->status( '' ); |
45
|
|
|
|
46
|
|
|
$schema = $this->getSchema( 'db-attribute' ); |
47
|
|
|
|
48
|
|
|
$this->msg( sprintf( 'Checking table %1$s', $table ), 1 ); |
|
|
|
|
49
|
|
|
|
50
|
|
|
if( $schema->tableExists( 'mshop_attribute' ) && $schema->columnExists( $table, 'key' ) |
51
|
|
|
&& ( $item = $schema->getColumnDetails( 'mshop_attribute', 'key' ) ) && ( $item->getMaxLength() !== 32 ) |
52
|
|
|
) { |
53
|
|
|
$dbm = $this->additional->getDatabaseManager(); |
54
|
|
|
$conn = $dbm->acquire( $rname ); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$select = sprintf( 'SELECT "id", "domain", "type", "code" FROM "%1$s"', $table ); |
57
|
|
|
$update = sprintf( 'UPDATE "%1$s" SET "key" = ? WHERE "id" = ?', $table ); |
58
|
|
|
|
59
|
|
|
$stmt = $conn->create( $update, \Aimeos\MW\DB\Connection\Base::TYPE_PREP ); |
60
|
|
|
$result = $conn->create( $select )->execute(); |
61
|
|
|
|
62
|
|
|
while( ( $row = $result->fetch() ) !== false ) |
63
|
|
|
{ |
64
|
|
|
$stmt->bind( 1, md5( $row['domain'] . '|' . $row['type'] . '|' . $row['code'] ) ); |
65
|
|
|
$stmt->bind( 2, $row['id'] ); |
66
|
|
|
$stmt->execute()->finish(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$dbm->release( $conn, $rname ); |
70
|
|
|
|
71
|
|
|
$this->status( 'done' ); |
72
|
|
|
} |
73
|
|
|
else |
74
|
|
|
{ |
75
|
|
|
$this->status( 'OK' ); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|