-
Notifications
You must be signed in to change notification settings - Fork 7
/
ps_eventbus.php
217 lines (185 loc) · 6.29 KB
/
ps_eventbus.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
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
// DONT'T USE "use" STATEMENT HERE, IT'S NOT COMPAT WITH 1.6
// PREFER "use" IN CLASS DIRECTLY
require_once __DIR__ . '/vendor/autoload.php';
if (!defined('_PS_VERSION_')) {
exit;
}
class Ps_eventbus extends Module
{
// All hooks is here
use PrestaShop\Module\PsEventbus\Traits\UseHooks;
/**
* @var array<mixed>
*/
public $adminControllers;
/**
* @var string
*/
const VERSION = '0.0.0';
const DEFAULT_ENV = '';
/**
* @var string
*/
public $version;
/**
* @var PrestaShop\Module\PsEventbus\ServiceContainer\ServiceContainer
*/
private $container;
/**
* @var int the unique shop identifier (uuid v4)
*/
private $shopId;
/**
* @var int Defines the multistore compatibility level of the module
*/
public $multistoreCompatibility;
/**
* @var string contact email of the maintainers (please consider using github issues)
*/
public $emailSupport;
/**
* @var string available terms of services
*/
public $termsOfServiceUrl;
/**
* __construct.
*/
public function __construct()
{
if (defined('_PS_VERSION_') && version_compare(_PS_VERSION_, '1.7.8.0', '>=')) {
$this->multistoreCompatibility = parent::MULTISTORE_COMPATIBILITY_YES;
}
// @see https://devdocs.prestashop-project.org/8/modules/concepts/module-class/
$this->name = 'ps_eventbus';
$this->tab = 'administration';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->bootstrap = true;
$this->version = '0.0.0';
$this->module_key = '7d76e08a13331c6c393755886ec8d5ce';
parent::__construct();
$this->emailSupport = '[email protected]';
$this->termsOfServiceUrl =
'https://www.prestashop.com/en/prestashop-account-privacy';
$this->displayName = $this->l('PrestaShop EventBus');
$this->description = $this->l('Link your PrestaShop account to synchronize your shop data to a tech partner of your choice. Do not uninstall this module if you are already using a service, as it will prevent it from working.');
$this->confirmUninstall = $this->l('This action will immediately prevent your PrestaShop services and Community services from working as they are using PrestaShop CloudSync for syncing.');
$this->ps_versions_compliancy = ['min' => '1.6.1.11', 'max' => _PS_VERSION_];
$this->adminControllers = [];
// If PHP is not compliant, we will not load composer and the autoloader
if (!$this->isPhpVersionCompliant()) {
return;
}
if ($this->context->shop === null) {
throw new PrestaShopException('No shop context');
}
$this->shopId = (int) $this->context->shop->id;
}
/**
* @return Context
*/
public function getContext()
{
return $this->context;
}
/**
* @return array<mixed>
*/
public function getAdminControllers()
{
return $this->adminControllers;
}
/**
* @return bool
*/
public function install()
{
if (!$this->isPhpVersionCompliant()) {
$this->_errors[] = $this->l('This requires PHP 5.6 to work properly. Please upgrade your server configuration.');
// We return true during the installation of PrestaShop to not stop the whole process,
// Otherwise we warn properly the installation failed.
return defined('PS_INSTALLATION_IN_PROGRESS');
}
$installer = new PrestaShop\Module\PsEventbus\Module\Install($this, Db::getInstance());
return $installer->installDatabaseTables()
&& parent::install()
&& $this->registerHook($this->getHooks());
}
/**
* @return bool
*/
public function uninstall()
{
$uninstaller = new PrestaShop\Module\PsEventbus\Module\Uninstall($this, Db::getInstance());
return $uninstaller->uninstallMenu()
&& $uninstaller->uninstallDatabaseTables()
&& parent::uninstall();
}
/**
* @return PrestaShop\Module\PsEventbus\ServiceContainer\ServiceContainer
*
* @throws Exception
*/
public function getServiceContainer()
{
if (null === $this->container) {
$this->container = PrestaShop\Module\PsEventbus\ServiceContainer\ServiceContainer::createInstance(
__DIR__ . '/config.php'
);
}
return $this->container;
}
/**
* This function allows you to patch bugs that can be found related to "ServiceNotFoundException".
* It ensures that you have access to the SymfonyContainer, and also that you have access to FO services.
*
* @param string $serviceName
*
* @return mixed
*/
public function getService($serviceName)
{
return $this->getServiceContainer()->getService($serviceName);
}
/**
* @return Monolog\Logger
*/
public function getLogger()
{
return $this->getService('ps_eventbus.logger');
}
/**
* Set PHP compatibility to 5.6
*
* @return bool
*/
private function isPhpVersionCompliant()
{
return PHP_VERSION_ID >= 50600;
}
}