1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Importer |
5
|
|
|
* @author Iurii Makukh |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\import; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Main class for Importer module |
16
|
|
|
*/ |
17
|
|
|
class Import extends Module |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constructor |
22
|
|
|
*/ |
23
|
|
|
public function __construct() |
24
|
|
|
{ |
25
|
|
|
parent::__construct(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Implements hook "route.list" |
30
|
|
|
* @param mixed $routes |
31
|
|
|
*/ |
32
|
|
|
public function hookRouteList(&$routes) |
33
|
|
|
{ |
34
|
|
|
// Settings |
35
|
|
|
$routes['admin/module/settings/import'] = array( |
36
|
|
|
'access' => 'module_edit', |
37
|
|
|
'handlers' => array( |
38
|
|
|
'controller' => array('gplcart\\modules\\import\\controllers\\Settings', 'editSettings') |
39
|
|
|
) |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
// Import page |
43
|
|
|
$routes['admin/tool/import'] = array( |
44
|
|
|
'menu' => array('admin' => 'Import'), |
45
|
|
|
'access' => 'import_product', |
46
|
|
|
'handlers' => array( |
47
|
|
|
'controller' => array('gplcart\\modules\\import\\controllers\\Import', 'doImport') |
48
|
|
|
) |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Implements hook "hook.cron" |
54
|
|
|
*/ |
55
|
|
|
public function hookCron() |
56
|
|
|
{ |
57
|
|
|
// Automatically delete uploaded files older than 1 day |
58
|
|
|
$lifespan = 86400; |
59
|
|
|
$directory = GC_PRIVATE_DIR . '/import'; |
60
|
|
|
if (is_dir($directory)) { |
61
|
|
|
gplcart_file_delete($directory, array('csv'), $lifespan); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Implements hook "user.role.permissions" |
67
|
|
|
* @param array $permissions |
68
|
|
|
*/ |
69
|
|
|
public function hookUserRolePermissions(array &$permissions) |
70
|
|
|
{ |
71
|
|
|
$permissions['import_product'] = 'Importer: import products'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Implements hook "job.handlers" |
76
|
|
|
* @param mixed $handlers |
77
|
|
|
*/ |
78
|
|
|
public function hookJobHandlers(array &$handlers) |
79
|
|
|
{ |
80
|
|
|
$handlers['import_product'] = array( |
81
|
|
|
'handlers' => array( |
82
|
|
|
'process' => array('gplcart\\modules\\import\\handlers\\Import', 'process') |
83
|
|
|
), |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|