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
|
|
|
* Rebuilds the index. |
14
|
|
|
*/ |
15
|
|
|
class IndexRebuild extends \Aimeos\MW\Setup\Task\Base |
16
|
|
|
{ |
17
|
|
|
private static $execute = false; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Returns if the index should be rebuilt or not. |
22
|
|
|
* |
23
|
|
|
* @return bool |
24
|
|
|
*/ |
25
|
|
|
private static function getExecute(): bool |
26
|
|
|
{ |
27
|
|
|
return self::$execute; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Set if the index should be rebuilt or not. |
33
|
|
|
* |
34
|
|
|
* @param bool $value |
35
|
|
|
*/ |
36
|
|
|
private static function setExecute(bool $value): void |
37
|
|
|
{ |
38
|
|
|
self::$execute = $value; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Force index rebuild. |
44
|
|
|
*/ |
45
|
|
|
public static function forceExecute(): void |
46
|
|
|
{ |
47
|
|
|
self::setExecute(true); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns the list of task names which this task depends on. |
53
|
|
|
* |
54
|
|
|
* @return string[] List of task names |
55
|
|
|
*/ |
56
|
|
|
public function getPreDependencies() |
57
|
|
|
{ |
58
|
|
|
return ['TablesCreateMShop', 'MShopSetLocale']; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the list of task names which depends on this task. |
64
|
|
|
* |
65
|
|
|
* @return array List of task names |
66
|
|
|
*/ |
67
|
|
|
public function getPostDependencies() |
68
|
|
|
{ |
69
|
|
|
return []; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Rebuilds the index if requested before via Helper\IndexRebuild. |
75
|
|
|
*/ |
76
|
|
|
public function migrate() |
77
|
|
|
{ |
78
|
|
|
if (self::getExecute() === true) { |
79
|
|
|
\Aimeos\MW\Common\Base::checkClass(\Aimeos\MShop\Context\Item\Iface::class, $this->additional); |
80
|
|
|
$this->msg('Rebuilding index', 0); |
81
|
|
|
|
82
|
|
|
$timestamp = date('Y-m-d H:i:s'); |
83
|
|
|
\Aimeos\MShop::create($this->additional, 'index') |
84
|
|
|
->rebuild() |
85
|
|
|
->cleanup($timestamp); |
86
|
|
|
self::setExecute(false); |
87
|
|
|
|
88
|
|
|
$this->status('done'); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|