|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Upscheme\Task; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Adds cms test data and all items from other domains. |
|
14
|
|
|
*/ |
|
15
|
|
|
class CmsAddTestData extends BaseAddTestData |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Returns the list of task names which this task depends on. |
|
19
|
|
|
* |
|
20
|
|
|
* @return string[] List of task names |
|
21
|
|
|
*/ |
|
22
|
|
|
public function after() : array |
|
23
|
|
|
{ |
|
24
|
|
|
return ['MShopSetLocale']; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Adds cms test data. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function up() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->info( 'Adding cms test data', 'v' ); |
|
34
|
|
|
|
|
35
|
|
|
$this->context()->setEditor( 'ai-cms-grapesjs:lib/custom' ); |
|
|
|
|
|
|
36
|
|
|
$this->process( $this->getData() ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the test data array |
|
42
|
|
|
* |
|
43
|
|
|
* @return array Multi-dimensional array of test data |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function getData() |
|
46
|
|
|
{ |
|
47
|
|
|
$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'cms.php'; |
|
48
|
|
|
|
|
49
|
|
|
if( ( $testdata = include( $path ) ) == false ) { |
|
50
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for cms domain', $path ) ); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $testdata; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Adds the product data from the given array |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $testdata Multi-dimensional array of test data |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function process( array $testdata ) |
|
63
|
|
|
{ |
|
64
|
|
|
$manager = $this->getManager( 'cms' ); |
|
65
|
|
|
$listManager = $manager->getSubManager( 'lists' ); |
|
66
|
|
|
|
|
67
|
|
|
$manager->begin(); |
|
68
|
|
|
|
|
69
|
|
|
$this->storeTypes( $testdata, ['cms/lists/type'] ); |
|
70
|
|
|
|
|
71
|
|
|
foreach( $testdata['cms'] as $entry ) |
|
72
|
|
|
{ |
|
73
|
|
|
$item = $manager->create()->fromArray( $entry ); |
|
74
|
|
|
$item = $this->addListData( $listManager, $item, $entry ); |
|
75
|
|
|
|
|
76
|
|
|
$manager->save( $item ); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$manager->commit(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|