Completed
Push — master ( 26162c...99f624 )
by Iurii
02:16
created

Export::hookCron()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
/**
4
 * @package Exporter
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\export;
11
12
use gplcart\core\Module;
13
14
/**
15
 * Main class for Exporter module
16
 */
17
class Export 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 array $routes
31
     */
32
    public function hookRouteList(array &$routes)
33
    {
34
        // Module settings page
35
        $routes['admin/module/settings/export'] = array(
36
            'access' => 'module_edit',
37
            'handlers' => array(
38
                'controller' => array('gplcart\\modules\\export\\controllers\\Settings', 'editSettings')
39
            )
40
        );
41
42
        // Export page
43
        $routes['admin/tool/export'] = array(
44
            'menu' => array('admin' => 'Export'),
45
            'access' => 'export_product',
46
            'handlers' => array(
47
                'controller' => array('gplcart\\modules\\export\\controllers\\Export', 'doExport')
48
            )
49
        );
50
    }
51
52
    /**
53
     * Implements hook "cron"
54
     */
55
    public function hookCron()
56
    {
57
        // Automatically delete created files older than 1 day
58
        $lifespan = 86400;
59
        $directory = GC_PRIVATE_DOWNLOAD_DIR . '/export';
60
        if (is_dir($directory)) {
61
            gplcart_file_delete($directory, array('csv'), $lifespan);
62
        }
63
    }
64
65
    /**
66
     * Implements hook "job.handlers"
67
     * @param array $handlers
68
     */
69
    public function hookJobHandlers(array &$handlers)
70
    {
71
        $handlers['export_product'] = array(
72
            'handlers' => array(
73
                'process' => array('gplcart\\modules\\export\\handlers\\Export', 'process')
74
            ),
75
        );
76
    }
77
78
    /**
79
     * Implements hook "user.role.permissions"
80
     * @param array $permissions
81
     */
82
    public function hookUserRolePermissions(array &$permissions)
83
    {
84
        $permissions['export_product'] = 'Exporter: export products';
85
    }
86
87
}
88