forked from plentymarkets/plentymarkets-shopware-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlentyConnector.php
217 lines (190 loc) · 6.73 KB
/
PlentyConnector.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
namespace PlentyConnector;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Exception;
use PlentyConnector\Connector\ConfigService\Model\Config;
use PlentyConnector\Connector\IdentityService\Model\Identity;
use PlentyConnector\DependencyInjection\CompilerPass\CleanupDefinitionCompilerPass;
use PlentyConnector\DependencyInjection\CompilerPass\CommandGeneratorCompilerPass;
use PlentyConnector\DependencyInjection\CompilerPass\CommandHandlerCompilerPass;
use PlentyConnector\DependencyInjection\CompilerPass\ConnectorDefinitionCompilerPass;
use PlentyConnector\DependencyInjection\CompilerPass\EventHandlerCompilerPass;
use PlentyConnector\DependencyInjection\CompilerPass\MappingDefinitionCompilerPass;
use PlentyConnector\DependencyInjection\CompilerPass\QueryGeneratorCompilerPass;
use PlentyConnector\DependencyInjection\CompilerPass\QueryHandlerCompilerPass;
use PlentyConnector\DependencyInjection\CompilerPass\ValidatorServiceCompilerPass;
use PlentyConnector\Installer\CronjobInstaller;
use PlentyConnector\Installer\DatabaseInstaller;
use PlentyConnector\Installer\PermissionInstaller;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UninstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
require __DIR__ . '/autoload.php';
/**
* Class PlentyConnector.
*/
class PlentyConnector extends Plugin
{
const PERMISSION_READ = 'read';
const PERMISSION_WRITE = 'write';
/**
* List of all permissions
*/
const PERMISSIONS = [
self::PERMISSION_READ,
self::PERMISSION_WRITE,
];
/**
* List of all models
*/
const MODELS = [
Config::class,
Identity::class,
];
const CRONJOB_SYNCHRONIZE = 'Synchronize';
const CRONJOB_CLEANUP = 'Cleanup';
/**
* List of all cronjobs
*/
const CRONJOBS = [
self::CRONJOB_SYNCHRONIZE => 300,
self::CRONJOB_CLEANUP => 86400,
];
/**
* @param ContainerBuilder $container
*
* @throws Exception
*/
public function build(ContainerBuilder $container)
{
$container->setParameter('plenty_connector.plugin_dir', $this->getPath());
$this->loadFile($container, __DIR__ . '/Adapter/ShopwareAdapter/DependencyInjection/services.xml');
$this->loadFile($container, __DIR__ . '/Adapter/PlentymarketsAdapter/DependencyInjection/services.xml');
$this->loadFile($container, __DIR__ . '/DependencyInjection/services.xml');
$container->addCompilerPass(new CleanupDefinitionCompilerPass());
$container->addCompilerPass(new CommandGeneratorCompilerPass());
$container->addCompilerPass(new CommandHandlerCompilerPass());
$container->addCompilerPass(new ConnectorDefinitionCompilerPass());
$container->addCompilerPass(new EventHandlerCompilerPass());
$container->addCompilerPass(new MappingDefinitionCompilerPass());
$container->addCompilerPass(new QueryGeneratorCompilerPass());
$container->addCompilerPass(new QueryHandlerCompilerPass());
$container->addCompilerPass(new ValidatorServiceCompilerPass());
parent::build($container);
}
/**
* @param InstallContext $context
*
* @throws ServiceCircularReferenceException
* @throws ServiceNotFoundException
* @throws InvalidArgumentException
* @throws Exception
*/
public function install(InstallContext $context)
{
// Models
$databaseInstaller = new DatabaseInstaller(
$this->container->get('models'),
self::MODELS
);
$databaseInstaller->install($context);
// Cronjobs
$cronjobInstaller = new CronjobInstaller(
$this->container->get('dbal_connection'),
self::CRONJOBS
);
$cronjobInstaller->install($context);
// Permissions
$permissionInstaller = new PermissionInstaller(
$this->container->get('models'),
$this->container->get('acl'),
self::PERMISSIONS
);
$permissionInstaller->install($context);
parent::install($context);
}
/**
* @param UpdateContext $context
*
* @throws ServiceCircularReferenceException
* @throws ServiceNotFoundException
* @throws InvalidArgumentException
* @throws Exception
*/
public function update(UpdateContext $context)
{
// Models
$databaseInstaller = new DatabaseInstaller(
$this->container->get('models'),
self::MODELS
);
$databaseInstaller->update($context);
// Cronjobs
$cronjobInstaller = new CronjobInstaller(
$this->container->get('dbal_connection'),
self::CRONJOBS
);
$cronjobInstaller->update($context);
// Permissions
$permissionInstaller = new PermissionInstaller(
$this->container->get('models'),
$this->container->get('acl'),
self::PERMISSIONS
);
$permissionInstaller->update($context);
parent::update($context);
}
/**
* @param UninstallContext $context
*
* @throws ServiceCircularReferenceException
* @throws ServiceNotFoundException
* @throws InvalidArgumentException
* @throws Exception
*/
public function uninstall(UninstallContext $context)
{
// Models
$databaseInstaller = new DatabaseInstaller(
$this->container->get('models'),
self::MODELS
);
$databaseInstaller->uninstall($context);
// Cronjobs
$cronjobInstaller = new CronjobInstaller(
$this->container->get('dbal_connection'),
self::CRONJOBS
);
$cronjobInstaller->uninstall($context);
$permissionInstaller = new PermissionInstaller(
$this->container->get('models'),
$this->container->get('acl'),
self::PERMISSIONS
);
$permissionInstaller->uninstall($context);
parent::uninstall($context);
}
/**
* @param ContainerBuilder $container
* @param $filename
*
* @throws Exception
*/
private function loadFile(ContainerBuilder $container, $filename)
{
if (!is_file($filename)) {
return;
}
$loader = new XmlFileLoader(
$container,
new FileLocator()
);
$loader->load($filename);
}
}