|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Upscheme\Task; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Adds locale records to tables. |
|
14
|
|
|
*/ |
|
15
|
|
|
class MShopAddLocaleData extends Base |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Adds locale site data. |
|
19
|
|
|
* |
|
20
|
|
|
* @param \Aimeos\MShop\Common\Manager\Iface $localeManager Locale manager |
|
21
|
|
|
* @param array $data Associative list of locale site data |
|
22
|
|
|
* @param string $manager Manager implementation name |
|
23
|
|
|
* @param string|null $parentId Parent id of the locale item |
|
24
|
|
|
* @return array Associative list of keys from the data and generated site ID |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function addLocaleSiteData( \Aimeos\MShop\Common\Manager\Iface $localeManager, array $data, $manager = 'Standard', $parentId = null ) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->info( 'Adding data for MShop locale sites', 'vv', 1 ); |
|
29
|
|
|
|
|
30
|
|
|
$siteIds = []; |
|
31
|
|
|
$manager = $localeManager->getSubManager( 'site', $manager ); |
|
32
|
|
|
|
|
33
|
|
|
foreach( $data as $key => $dataset ) |
|
34
|
|
|
{ |
|
35
|
|
|
$manager->begin(); |
|
36
|
|
|
|
|
37
|
|
|
try |
|
38
|
|
|
{ |
|
39
|
|
|
$item = $manager->insert( $manager->create()->fromArray( $dataset ), $parentId ); |
|
40
|
|
|
$manager->commit(); |
|
41
|
|
|
} |
|
42
|
|
|
catch( \Aimeos\Base\DB\Exception $e ) |
|
43
|
|
|
{ |
|
44
|
|
|
$manager->rollback(); |
|
45
|
|
|
$item = $manager->find( $key ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$siteIds[$key] = ['id' => $item->getId(), 'site' => $item->getSiteId()]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $siteIds; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Adds locale currency data. |
|
57
|
|
|
* |
|
58
|
|
|
* @param \Aimeos\MShop\Common\Manager\Iface $localeManager Locale manager |
|
59
|
|
|
* @param array $data Associative list of locale currency data |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function addLocaleCurrencyData( \Aimeos\MShop\Common\Manager\Iface $localeManager, array $data ) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->info( 'Adding data for MShop locale currencies', 'vv', 1 ); |
|
64
|
|
|
|
|
65
|
|
|
$manager = $localeManager->getSubManager( 'currency', 'Standard' ); |
|
66
|
|
|
$items = $manager->search( $manager->filter()->slice( 0, 0x7fffffff ) ); |
|
67
|
|
|
|
|
68
|
|
|
foreach( $data as $key => $dataset ) { |
|
69
|
|
|
$items->has( $key ) ?: $manager->save( $manager->create()->fromArray( $dataset, true ) ); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Adds locale language data. |
|
76
|
|
|
* |
|
77
|
|
|
* @param \Aimeos\MShop\Common\Manager\Iface $localeManager Locale manager |
|
78
|
|
|
* @param array $data Associative list of locale language data |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function addLocaleLanguageData( \Aimeos\MShop\Common\Manager\Iface $localeManager, array $data ) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->info( 'Adding data for MShop locale languages', 'vv', 1 ); |
|
83
|
|
|
|
|
84
|
|
|
$manager = $localeManager->getSubManager( 'language', 'Standard' ); |
|
85
|
|
|
$items = $manager->search( $manager->filter()->slice( 0, 0x7fffffff ) ); |
|
86
|
|
|
|
|
87
|
|
|
foreach( $data as $key => $dataset ) { |
|
88
|
|
|
$items->has( $key ) ?: $manager->save( $manager->create()->fromArray( $dataset, true ) ); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Adds locale data. |
|
95
|
|
|
* |
|
96
|
|
|
* @param \Aimeos\MShop\Common\Manager\Iface $localeManager Locale manager |
|
97
|
|
|
* @param array $data Associative list of locale data |
|
98
|
|
|
*/ |
|
99
|
|
|
protected function addLocaleData( \Aimeos\MShop\Common\Manager\Iface $localeManager, array $data, array $siteIds ) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->info( 'Adding data for MShop locales', 'vv', 1 ); |
|
102
|
|
|
|
|
103
|
|
|
foreach( $data as $dataset ) |
|
104
|
|
|
{ |
|
105
|
|
|
if( !isset( $siteIds[$dataset['site']] ) ) { |
|
106
|
|
|
throw new \RuntimeException( sprintf( 'No ID for site for key "%1$s" found', $dataset['site'] ) ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$this->context()->setLocale( $localeManager->create()->setSiteId( $siteIds[$dataset['site']]['site'] ) ); |
|
|
|
|
|
|
110
|
|
|
$item = $localeManager->create()->fromArray( $dataset, true ); |
|
111
|
|
|
|
|
112
|
|
|
try { |
|
113
|
|
|
$localeManager->save( $item ); |
|
114
|
|
|
} catch( \Aimeos\Base\DB\Exception $e ) { ; } // if locale combination was already available |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|