-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.php
184 lines (151 loc) · 4.99 KB
/
Bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* Class Shopware_Plugins_Frontend_SwagBgTrans_Bootstrap
*
* @package Shopware\Plugins\Local\SwagBgTrans
* @author Stefan Bofirov
*/
class Shopware_Plugins_Frontend_SwagBgTrans_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
/**
* Returns current plugin version
*
* @return string
*/
public function getVersion()
{
return '0.0.2';
}
/**
* Returns a nice name for plugin manager list
*
* @return string
*/
public function getLabel()
{
return 'Bulgarian Translation';
}
/**
* Returns plugin information for the plugin manager
*
* @return array
*/
public function getInfo()
{
return array(
'version' => $this->getVersion(),
'label' => $this->getLabel(),
'description' => $this->getDescription(),
);
}
/**
* Returns plugin description
*
* @return string
*/
public function getDescription()
{
return 'Lorem ipsum';
}
/**
* Install plugin method
*
* @return array|bool
*/
public function install()
{
$this->importFrontendTranslations();
$this->importBackendTranslations();
$this->addBackendLanguage();
$this->importBaseTranslations();
$this->importDocumentsTranslations();
$this->importNewsletterTranslations();
$this->importWidgetsTranslations();
$this->importConfigFormTranslations();
return array('success' => true, 'invalidateCache' => array('backend', 'config', 'frontend'));
}
public function update()
{
if (version_compare($this->getVersion(), '0.0.2', '<=')) {
$sql = file_get_contents($this->Path() . 'Snippets/frontend-0.0.2.sql');
Shopware()->Db()->exec($sql);
}
return true;
}
public function uninstall()
{
// do not delete bulgarian snippets when remove plugin
// $sql = "DELETE FROM `s_core_snippets` WHERE `localeID` = 30;";
// Shopware()->Db()->exec($sql);
return true;
}
public function importFrontendTranslations()
{
$sql = file_get_contents($this->Path() . 'Snippets/frontend.sql');
Shopware()->Db()->exec($sql);
}
public function importBackendTranslations()
{
$sqlPart1 = file_get_contents($this->Path() . 'Snippets/backend.part1.sql');
Shopware()->Db()->exec($sqlPart1);
$sqlPart2 = file_get_contents($this->Path() . 'Snippets/backend.part2.sql');
Shopware()->Db()->exec($sqlPart2);
$sqlPart3 = file_get_contents($this->Path() . 'Snippets/backend.part3.sql');
Shopware()->Db()->exec($sqlPart3);
$sqlPart4 = file_get_contents($this->Path() . 'Snippets/backend.part4.sql');
Shopware()->Db()->exec($sqlPart4);
$sqlPart5 = file_get_contents($this->Path() . 'Snippets/backend.part5.sql');
Shopware()->Db()->exec($sqlPart5);
$sqlPart6 = file_get_contents($this->Path() . 'Snippets/backend.part6.sql');
Shopware()->Db()->exec($sqlPart6);
}
public function importBaseTranslations()
{
$sql = file_get_contents($this->Path() . 'Snippets/base.sql');
Shopware()->Db()->exec($sql);
}
public function importDocumentsTranslations()
{
$sql = file_get_contents($this->Path() . 'Snippets/documents.sql');
Shopware()->Db()->exec($sql);
}
public function importNewsletterTranslations()
{
$sql = file_get_contents($this->Path() . 'Snippets/newsletter.sql');
Shopware()->Db()->exec($sql);
}
public function importWidgetsTranslations()
{
$sql = file_get_contents($this->Path() . 'Snippets/widgets.sql');
Shopware()->Db()->exec($sql);
}
public function importConfigFormTranslations()
{
$sql = file_get_contents($this->Path() . 'Snippets/config_forms.sql');
Shopware()->Db()->exec($sql);
$sql = file_get_contents($this->Path() . 'Snippets/config_elements.sql');
Shopware()->Db()->exec($sql);
}
public function addBackendLanguage()
{
$repository = Shopware()->Models()->getRepository('Shopware\Models\Config\Element');
$element = $repository->findOneBy(array('name' => 'backendLocales'));
if (count($element->getValues()) > 0) {
$values = $element->getValues();
$value = $values[0]->getValue();
if (!in_array(30, $value)) {
$value[] = 30;
$values[0]->setValue($value);
Shopware()->Models()->persist($values[0]);
}
} else {
$value = new \Shopware\Models\Config\Value();
$value->setElement($element);
$shop = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop')->find(1);
$value->setShop($shop);
$value->setValue(array(1, 2, 30));
Shopware()->Models()->persist($value);
}
Shopware()->Models()->flush();
}
}