|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Upscheme\Task; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Adds default records plugin to table. |
|
15
|
|
|
*/ |
|
16
|
|
|
class MShopAddPluginData extends Base |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Returns the list of task names which this task depends on. |
|
20
|
|
|
* |
|
21
|
|
|
* @return string[] List of task names |
|
22
|
|
|
*/ |
|
23
|
|
|
public function after() : array |
|
24
|
|
|
{ |
|
25
|
|
|
return ['Plugin']; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
public function up() |
|
30
|
|
|
{ |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Adds locale data. |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function process() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->info( 'Adding default plugin data', 'v' ); |
|
40
|
|
|
|
|
41
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
42
|
|
|
$pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::create( $this->context(), 'Standard' ); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$filename = __DIR__ . $ds . 'default' . $ds . 'data' . $ds . 'plugin.php'; |
|
45
|
|
|
|
|
46
|
|
|
if( ( $data = include( $filename ) ) == false ) { |
|
47
|
|
|
throw new \Aimeos\MW\Setup\Exception( sprintf( 'No data file "%1$s" found', $filename ) ); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if( isset( $data['plugin'] ) ) { |
|
51
|
|
|
$this->addPluginData( $pluginManager, $data['plugin'] ); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Adds plugin data. |
|
58
|
|
|
* |
|
59
|
|
|
* @param \Aimeos\MShop\Common\Manager\Iface $pluginManager Plugin manager |
|
60
|
|
|
* @param array $data Associative list of plugin data |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function addPluginData( \Aimeos\MShop\Common\Manager\Iface $pluginManager, array $data ) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->info( 'Adding data for MShop plugins', 'v' ); |
|
65
|
|
|
|
|
66
|
|
|
$types = []; |
|
67
|
|
|
$manager = $pluginManager->getSubManager( 'type' ); |
|
68
|
|
|
|
|
69
|
|
|
foreach( $manager->search( $manager->filter() ) as $item ) { |
|
70
|
|
|
$types['plugin/' . $item->getCode()] = $item; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$item = $pluginManager->create(); |
|
74
|
|
|
|
|
75
|
|
|
foreach( $data as $key => $dataset ) |
|
76
|
|
|
{ |
|
77
|
|
|
$item->setId( null ); |
|
78
|
|
|
$item->setType( $dataset['type'] ); |
|
79
|
|
|
$item->setProvider( $dataset['provider'] ); |
|
80
|
|
|
$item->setLabel( $dataset['label'] ); |
|
81
|
|
|
$item->setConfig( $dataset['config'] ); |
|
82
|
|
|
$item->setStatus( $dataset['status'] ); |
|
83
|
|
|
|
|
84
|
|
|
if( isset( $dataset['position'] ) ) { |
|
85
|
|
|
$item->setPosition( $dataset['position'] ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
try { |
|
89
|
|
|
$pluginManager->save( $item ); |
|
90
|
|
|
} catch( \Exception $e ) {; } // if plugin configuration was already available |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|