|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Upscheme\Task; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Adds demo records to service tables. |
|
15
|
|
|
*/ |
|
16
|
|
|
class DemoAddServiceData extends MShopAddDataAbstract |
|
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 ['Service', 'Media', 'Price', 'Text', 'MShopAddTypeDataDefault']; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Insert service data. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function up() |
|
33
|
|
|
{ |
|
34
|
|
|
$context = $this->context(); |
|
|
|
|
|
|
35
|
|
|
$value = $context->config()->get( 'setup/default/demo', '' ); |
|
36
|
|
|
|
|
37
|
|
|
if( $value === '' ) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$this->info( 'Processing service demo data', 'vv' ); |
|
43
|
|
|
|
|
44
|
|
|
$items = $this->removeItems(); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
if( $value === '1' ) { |
|
48
|
|
|
$this->addDemoData(); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Adds the demo data to the database. |
|
55
|
|
|
* |
|
56
|
|
|
* @throws \RuntimeException If the file isn't found |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function addDemoData() |
|
59
|
|
|
{ |
|
60
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
61
|
|
|
$path = __DIR__ . $ds . 'data' . $ds . 'demo-service.php'; |
|
62
|
|
|
|
|
63
|
|
|
if( ( $data = include( $path ) ) == false ) { |
|
64
|
|
|
throw new \RuntimeException( sprintf( 'No file "%1$s" found for service domain', $path ) ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'service' ); |
|
68
|
|
|
|
|
69
|
|
|
foreach( $data as $entry ) |
|
70
|
|
|
{ |
|
71
|
|
|
$item = $manager->create()->fromArray( $entry ); |
|
72
|
|
|
|
|
73
|
|
|
$this->addRefItems( $item, $entry ); |
|
74
|
|
|
|
|
75
|
|
|
$manager->save( $item ); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Deletes the demo service items |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function removeItems() : \Aimeos\Map |
|
84
|
|
|
{ |
|
85
|
|
|
$context = $this->context(); |
|
86
|
|
|
$domains = ['media', 'price', 'text']; |
|
87
|
|
|
$manager = \Aimeos\MShop::create( $context, 'service' ); |
|
88
|
|
|
|
|
89
|
|
|
$filter = $manager->filter()->add( 'service.code', '=~', 'demo-' )->slice( 0, 0x7fffffff ); |
|
90
|
|
|
$items = $manager->search( $filter, $domains ); |
|
91
|
|
|
|
|
92
|
|
|
$this->removeRefItems( $items, $domains ); |
|
93
|
|
|
$manager->delete( $items ); |
|
94
|
|
|
|
|
95
|
|
|
return $items; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|