Passed
Push — master ( 34ac4e...42601f )
by Aimeos
06:35
created

IndexRemovePriceMeta::getPreDependencies()   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
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Removes meta data from index price table
14
 */
15
class IndexRemovePriceMeta extends \Aimeos\MW\Setup\Task\Base
16
{
17
	private $clear = 'DELETE FROM "mshop_index_price"';
18
	private $indexes = [
19
		'unq_msindpr_p_s_prid_lt' => 'ALTER TABLE "mshop_index_price" DROP INDEX "unq_msindpr_p_s_prid_lt"',
20
		'idx_msindpr_s_lt_cu_ty_va' => 'ALTER TABLE "mshop_index_price" DROP INDEX "idx_msindpr_s_lt_cu_ty_va"',
21
		'idx_msindpr_p_s_lt_cu_ty_va' => 'ALTER TABLE "mshop_index_price" DROP INDEX "idx_msindpr_p_s_lt_cu_ty_va"',
22
	];
23
	private $columns = [
24
		'priceid' => 'ALTER TABLE "mshop_index_price" DROP "priceid"',
25
		'listtype' => 'ALTER TABLE "mshop_index_price" DROP "listtype"',
26
		'type' => 'ALTER TABLE "mshop_index_price" DROP "type"',
27
		'costs' => 'ALTER TABLE "mshop_index_price" DROP "costs"',
28
		'rebate' => 'ALTER TABLE "mshop_index_price" DROP "rebate"',
29
		'taxrate' => 'ALTER TABLE "mshop_index_price" DROP "taxrate"',
30
		'quantity' => 'ALTER TABLE "mshop_index_price" DROP "quantity"',
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 [];
42
	}
43
44
45
	/**
46
	 * Returns the list of task names which depends on this task.
47
	 *
48
	 * @return string[] List of task names
49
	 */
50
	public function getPostDependencies()
51
	{
52
		return ['TablesCreateMShop'];
53
	}
54
55
56
	/**
57
	 * Executes the task
58
	 */
59
	public function migrate()
60
	{
61
		$this->msg( 'Remove meta columns from mshop_index_price table', 0 ); $this->status( '' );
62
		$schema = $this->getSchema( 'db-product' );
63
64
		foreach( $this->indexes as $index => $stmt )
65
		{
66
			$this->msg( sprintf( 'Checking index "%1$s": ', $index ), 1 );
67
68
			if( $schema->tableExists( 'mshop_index_price' ) === true
69
				&& $schema->indexExists( 'mshop_index_price', $index ) === true )
70
			{
71
				$this->execute( $this->clear );
72
				$this->execute( $stmt );
73
				$this->status( 'done' );
74
			}
75
			else
76
			{
77
				$this->status( 'OK' );
78
			}
79
		}
80
81
		foreach( $this->columns as $column => $stmt )
82
		{
83
			$this->msg( sprintf( 'Checking column "%1$s": ', $column ), 1 );
84
85
			if( $schema->tableExists( 'mshop_index_price' ) === true
86
				&& $schema->columnExists( 'mshop_index_price', $column ) === true )
87
			{
88
				$this->execute( $stmt );
89
				$this->status( 'done' );
90
			}
91
			else
92
			{
93
				$this->status( 'OK' );
94
			}
95
		}
96
	}
97
}