1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MW\Setup\Task; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Changes warehouse ID to NOT NULL in stock table. |
15
|
|
|
*/ |
16
|
|
|
class ProductChangeStockWarehouseIdNotNull extends \Aimeos\MW\Setup\Task\Base |
17
|
|
|
{ |
18
|
|
|
private $mysql = array( |
19
|
|
|
'UPDATE "mshop_product_stock" st |
20
|
|
|
SET "warehouseid" = ( SELECT "id" FROM "mshop_product_stock_warehouse" wh WHERE wh."siteid" = st."siteid" AND wh."code" = \'default\' ) |
21
|
|
|
WHERE "warehouseid" IS NULL', |
22
|
|
|
'ALTER TABLE "mshop_product_stock" |
23
|
|
|
DROP FOREIGN KEY "fk_msprost_stock_warehouseid", |
24
|
|
|
MODIFY "warehouseid" INTEGER NOT NULL', |
25
|
|
|
'ALTER TABLE "mshop_product_stock" |
26
|
|
|
ADD CONSTRAINT "fk_msprost_stock_warehouseid" |
27
|
|
|
FOREIGN KEY ("warehouseid") |
28
|
|
|
REFERENCES "mshop_product_stock_warehouse" ("id") |
29
|
|
|
ON UPDATE CASCADE |
30
|
|
|
ON DELETE CASCADE', |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns the list of task names which this task depends on. |
36
|
|
|
* |
37
|
|
|
* @return string[] List of task names |
38
|
|
|
*/ |
39
|
|
|
public function getPreDependencies() |
40
|
|
|
{ |
41
|
|
|
return array( 'ProductWarehouseRenameTable', 'MShopAddWarehouseData' ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns the list of task names which depends on this task. |
47
|
|
|
* |
48
|
|
|
* @return array List of task names |
49
|
|
|
*/ |
50
|
|
|
public function getPostDependencies() |
51
|
|
|
{ |
52
|
|
|
return []; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Executes the task for MySQL databases. |
58
|
|
|
*/ |
59
|
|
|
public function migrate() |
60
|
|
|
{ |
61
|
|
|
$table = 'mshop_product_stock'; |
62
|
|
|
$this->msg( sprintf( 'Changing warehouseid column in %1$s', $table ), 0 ); |
63
|
|
|
|
64
|
|
|
$schema = $this->getSchema( 'db-product' ); |
65
|
|
|
|
66
|
|
|
if( $schema->tableExists( $table ) === true |
67
|
|
|
&& $schema->columnExists( $table, 'warehouseid' ) |
68
|
|
|
&& $schema->getColumnDetails( $table, 'warehouseid' )->isNullable() === true |
69
|
|
|
) { |
70
|
|
|
$this->executeList( $this->mysql, 'db-product' ); |
71
|
|
|
$this->status( 'done' ); |
72
|
|
|
} else { |
73
|
|
|
$this->status( 'OK' ); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |