Passed
Push — master ( 69e622...703c98 )
by Aimeos
05:19
created

IndexRemoveTextMeta::getPostDependencies()   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
 * Adds typeid column to list tables and migrates data in type column.
14
 */
15
class IndexRemoveTextMeta extends \Aimeos\MW\Setup\Task\Base
16
{
17
	private $indexes = [
18
		'idx_msindte_value' => 'ALTER TABLE "mshop_index_text" DROP INDEX "idx_msindte_value"',
19
		'unq_msindte_p_s_tid_lt' => 'ALTER TABLE "mshop_index_text" DROP INDEX "unq_msindte_p_s_tid_lt"',
20
		'idx_msindte_p_s_lt_la_ty_do_va' => 'ALTER TABLE "mshop_index_text" DROP INDEX "idx_msindte_p_s_lt_la_ty_do_va"',
21
	];
22
	private $columns = [
23
		'textid' => 'ALTER TABLE "mshop_index_text" DROP "textid"',
24
		'listtype' => 'ALTER TABLE "mshop_index_text" DROP "listtype"',
25
		'domain' => 'ALTER TABLE "mshop_index_text" DROP "domain"',
26
		'type' => 'ALTER TABLE "mshop_index_text" DROP "type"',
27
	];
28
29
30
	/**
31
	 * Returns the list of task names which this task depends on.
32
	 *
33
	 * @return string[] List of task names
34
	 */
35
	public function getPreDependencies()
36
	{
37
		return ['TablesCreateMShop'];
38
	}
39
40
41
	/**
42
	 * Returns the list of task names which depends on this task.
43
	 *
44
	 * @return string[] List of task names
45
	 */
46
	public function getPostDependencies()
47
	{
48
		return ['MShopSetLocale'];
49
	}
50
51
52
	/**
53
	 * Executes the task
54
	 */
55
	public function migrate()
56
	{
57
		$this->msg( 'Remove meta columns from mshop_index_text table', 0 ); $this->status( '' );
58
		$schema = $this->getSchema( 'db-product' );
59
60
		foreach( $this->indexes as $index => $stmt )
61
		{
62
			$this->msg( sprintf( 'Checking index "%1$s": ', $index ), 1 );
63
64
			if( $schema->tableExists( 'mshop_index_text' ) === true
65
				&& $schema->indexExists( 'mshop_index_text', $index ) === true )
66
			{
67
				$this->execute( $stmt );
68
				$this->status( 'done' );
69
			}
70
			else
71
			{
72
				$this->status( 'OK' );
73
			}
74
		}
75
76
		foreach( $this->columns as $column => $stmt )
77
		{
78
			$this->msg( sprintf( 'Checking column "%1$s": ', $column ), 1 );
79
80
			if( $schema->tableExists( 'mshop_index_text' ) === true
81
				&& $schema->columnExists( 'mshop_index_text', $column ) === true )
82
			{
83
				$this->execute( $stmt );
84
				$this->status( 'done' );
85
			}
86
			else
87
			{
88
				$this->status( 'OK' );
89
			}
90
		}
91
	}
92
}