1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MW\Setup\Task; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Adds default attribute |
14
|
|
|
*/ |
15
|
|
|
class MShopAddAttributeData extends MShopAddDataAbstract |
16
|
|
|
{ |
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 getPreDependencies() |
24
|
|
|
{ |
25
|
|
|
return array( 'MShopAddTypeData' ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Returns the list of task names which depends on this task. |
31
|
|
|
* |
32
|
|
|
* @return array List of task names |
33
|
|
|
*/ |
34
|
|
|
public function getPostDependencies() |
35
|
|
|
{ |
36
|
|
|
return []; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Adds the default codes |
42
|
|
|
*/ |
43
|
|
|
protected function process() |
44
|
|
|
{ |
45
|
|
|
$iface = '\\Aimeos\\MShop\\Context\\Item\\Iface'; |
46
|
|
|
if( !( $this->additional instanceof $iface ) ) { |
47
|
|
|
throw new \Aimeos\MW\Setup\Exception( sprintf( 'Additionally provided object is not of type "%1$s"', $iface ) ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$site = $this->additional->getLocale()->getSite()->getCode(); |
51
|
|
|
$this->msg( sprintf( 'Adding default attribute data for site "%1$s"', $site ), 0 ); |
52
|
|
|
|
53
|
|
|
$ds = DIRECTORY_SEPARATOR; |
54
|
|
|
$path = __DIR__ . $ds . 'default' . $ds . 'data' . $ds . 'attribute.php'; |
55
|
|
|
|
56
|
|
|
if( ( $data = include( $path ) ) == false ) { |
57
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for default codes', $path ) ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->additional, 'attribute' ); |
61
|
|
|
$item = $manager->createItem(); |
62
|
|
|
$num = $total = 0; |
63
|
|
|
|
64
|
|
|
foreach( $data as $dataset ) |
65
|
|
|
{ |
66
|
|
|
try |
67
|
|
|
{ |
68
|
|
|
$total++; |
69
|
|
|
$item->setId( null )->fromArray( $dataset ); |
70
|
|
|
$item->setTypeId( $this->getTypeId( 'attribute/type', $dataset['attribute.domain'], $dataset['attribute.type'] ) ); |
71
|
|
|
|
72
|
|
|
$manager->saveItem( $item ); |
73
|
|
|
$num++; |
74
|
|
|
} |
75
|
|
|
catch( \Exception $e ) { ; } // if attribute was already available |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->status( $num > 0 ? $num . '/' . $total : 'OK' ); |
79
|
|
|
} |
80
|
|
|
} |