-
Notifications
You must be signed in to change notification settings - Fork 0
/
lkebp.php
197 lines (172 loc) · 6.26 KB
/
lkebp.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
<?php
/**
* Copyright (C) Lk Interactive - All Rights Reserved.
*
* This is proprietary software therefore it cannot be distributed or reselled.
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
*
* @author Lk Interactive <[email protected]>
* @copyright 2020.
* @license Commercial license
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require dirname(__FILE__) . '/vendor/autoload.php';
use LkEbp\LkEbpImport;
class LkEbp extends Module
{
private $_html;
private $importFolder;
/**
* Lk_Neonegoce constructor.
*/
public function __construct()
{
$this->name = 'lkebp';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'Lk Interactive';
$this->need_instance = 1;
$this->ps_versions_compliancy = array('min' => '1.7.6.0', 'max' => _PS_VERSION_);
$this->bootstrap = true;
$this->importFolder = _PS_ROOT_DIR_ . '/import-ebp';
parent::__construct();
$this->displayName = $this->trans('Lk Interactive - EBP connector.', array(), 'Modules.Lkebp.Admin');
$this->description = $this->trans('This module is made for import data from ebp crm.', array(), 'Modules.Lkebp.Admin');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall ?', 'ebp');
}
/**
* @return mixed
*/
public function install()
{
include dirname(__FILE__) . '/sql/install.php';
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
$this->createImportFolder();
return parent::install();
}
/**
* @return bool
*/
public function uninstall()
{
include dirname(__FILE__) . '/sql/uninstall.php';
$this->deleteImportFolder();
if (!parent::uninstall()) {
return false;
}
return true;
}
/**
* Create import folder
* @since 1.0.0
*/
public function createImportFolder()
{
/* Test if import folder exist*/
if (!is_dir($this->importFolder)) {
mkdir($this->importFolder, 0755, true);
chmod($this->importFolder, 0755);
}
}
/**
* Delete import folder
* @since 1.0.0
*/
public function deleteImportFolder()
{
/* Test if import folder exist*/
if (is_dir($this->importFolder)) {
rmdir($this->importFolder);
}
}
/**
* Return content in admin config module area
*
* @return string
* @since 1.00.0
*/
public function getContent()
{
$this->_html .= '';
$this->_html .= $this->_postProcess();
$this->_html .= $this->displayForm();
return $this->_html;
}
/**
* @return string|null
*/
public function _postProcess()
{
if (Tools::isSubmit('SubmitImportEntity')) {
if (Configuration::get('PS_SHOP_ENABLE')) {
Tools::redirectAdmin('index.php?tab=AdminModules&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=' . $this->name . '&importnotcontinue');
} else {
$entities = Tools::getValue('entity');
$import_entity = [];
if (is_array($entities) && !empty($entities)) {
foreach ($entities as $entity) {
$import_entity[$entity] = $entity;
}
$LkEpImport = new LkEbpImport($this->importFolder);
if ($LkEpImport->getImportFiles()) {
if ($LkEpImport->prepareImport($import_entity)) {
Tools::redirectAdmin('index.php?tab=AdminModules&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=' . $this->name . '&validation');
}
}
}
}
}
}
/**
* Prepare smarty variable cor config tpl
*
* @return mixed
*/
public function displayForm()
{
$store_url = $this->context->link->getBaseLink();
$this->context->smarty->assign(array(
'cron_url' => array(
'category' => $store_url . 'modules/'.$this->name.'/'.$this->name.'-cron.php?token=' . Tools::substr(Tools::encrypt($this->name.'/cron'), 0, 10) . '&entity=category&id_shop=' . $this->context->shop->id,
'product' => $store_url . 'modules/'.$this->name.'/'.$this->name.'-cron.php?token=' . Tools::substr(Tools::encrypt($this->name.'/cron'), 0, 10) . '&entity=product&id_shop=' . $this->context->shop->id,
'combination' => $store_url . 'modules/'.$this->name.'/'.$this->name.'-cron.php?token=' . Tools::substr(Tools::encrypt($this->name.'/cron'), 0, 10) . '&entity=combination&id_shop=' . $this->context->shop->id,
),
'logs' => $this->getLogs(),
'shop_enable' => Configuration::get('PS_SHOP_ENABLE'),
'import_form' => './index.php?tab=AdminModules&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=' . $this->name . '',
));
return $this->display(__FILE__, 'views/templates/admin/configuration.tpl');
}
/**
* Get formatted logs based on current month file
*
* @return mixed
* @since 1.0.0
*/
private function getLogs()
{
$file = dirname(__FILE__) . '/logs/logs-import-' . date('m-Y') . '.log';
$Logs = [];
if (file_exists($file)) {
$handle = Tools::file_get_contents($file);
$logsArray = explode('---', $handle);
foreach ($logsArray as $key => $logs) {
if (!empty($logs)) {
$contentLog = explode('[#]', $logs);
$Logs[$key]['Date'] = explode('[##]', $contentLog[1]);
foreach ($contentLog as $k => $log) {
if (!empty(trim($log)) && $k != 1) {
$Logs[$key]['infos'][] = $log;
}
}
}
}
return $Logs;
}
}
}