|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2024 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Upscheme\Task; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Adds locale records to tables. |
|
14
|
|
|
*/ |
|
15
|
|
|
class LocaleCreateSite extends Base |
|
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 ['MShopAddLocaleLangCurData']; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Returns the list of task names which depends on this task. |
|
30
|
|
|
* |
|
31
|
|
|
* @return string[] List of task names |
|
32
|
|
|
*/ |
|
33
|
|
|
public function before() : array |
|
34
|
|
|
{ |
|
35
|
|
|
return ['MShopAddLocaleData']; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Adds locale data. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function up() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->info( 'Create site and locale', 'vv' ); |
|
45
|
|
|
|
|
46
|
|
|
$context = $this->context()->setEditor( 'core' ); // Set editor for further tasks |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
$config = $context->config(); |
|
49
|
|
|
$site = $config->get( 'setup/site', 'default' ); |
|
50
|
|
|
$lang = $config->get( 'setup/language', 'en' ); |
|
51
|
|
|
$curr = $config->get( 'setup/currency', 'USD' ); |
|
52
|
|
|
$demo = $config->get( 'setup/default/demo', '' ); |
|
53
|
|
|
|
|
54
|
|
|
$siteId = $this->createSite( $site ); |
|
55
|
|
|
$this->createLocale( $siteId, ['locale.languageid' => $lang, 'locale.currencyid' => $curr] ); |
|
56
|
|
|
|
|
57
|
|
|
if( $demo === '1' ) |
|
58
|
|
|
{ |
|
59
|
|
|
foreach( $this->data()['locale'] ?? [] as $entry ) { |
|
60
|
|
|
$this->createLocale( $siteId, $entry ); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
protected function createSite( string $code ) : string |
|
67
|
|
|
{ |
|
68
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'locale', 'Standard' )->getSubManager( 'site', 'Standard' ); |
|
69
|
|
|
|
|
70
|
|
|
try |
|
71
|
|
|
{ |
|
72
|
|
|
$item = $manager->find( $code ); |
|
73
|
|
|
} |
|
74
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
|
75
|
|
|
{ |
|
76
|
|
|
$manager->begin(); |
|
77
|
|
|
$item = $manager->insert( $manager->create()->setCode( $code )->setLabel( ucfirst( $code ) ) ); |
|
78
|
|
|
$manager->commit(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $item->getSiteId(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
protected function createLocale( string $siteId, array $data ) |
|
86
|
|
|
{ |
|
87
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'locale', 'Standard' ); |
|
88
|
|
|
|
|
89
|
|
|
try { |
|
90
|
|
|
$manager->save( $manager->create()->fromArray( $data ) ); |
|
91
|
|
|
} catch( \Aimeos\MShop\Exception $e ) { |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
protected function data() : array |
|
97
|
|
|
{ |
|
98
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
99
|
|
|
$filename = __DIR__ . $ds . 'data' . $ds . 'locale.php'; |
|
100
|
|
|
|
|
101
|
|
|
if( ( $data = include( $filename ) ) == false ) { |
|
102
|
|
|
throw new \RuntimeException( sprintf( 'No data file "%1$s" found', $filename ) ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $data; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|