Completed
Push — master ( 3ebc3a...94026d )
by Iurii
01:26
created

Skeleton::hookModuleInstallBefore()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
/**
4
 * @package Skeleton module
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2015, Iurii Makukh
7
 * @license https://www.gnu.org/licenses/gpl.html GNU/GPLv3
8
 */
9
10
namespace gplcart\modules\skeleton;
11
12
use gplcart\core\Module;
13
14
/**
15
 * Main class for Skeleton module
16
 */
17
class Skeleton extends Module
18
{
19
20
    /**
21
     * Constructor
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
26
    }
27
28
    /**
29
     * Implements hook "module.install.before"
30
     */
31
    public function hookModuleInstallBefore(&$result)
32
    {
33
        if (!class_exists('ZipArchive')) {
34
            $result = 'Class ZipArchive does not exist';
35
        }
36
    }
37
38
    /**
39
     * Implements hook "route.list"
40
     * @param array $routes
41
     */
42
    public function hookRouteList(array &$routes)
43
    {
44
        $routes['admin/tool/skeleton'] = array(
45
            'menu' => array('admin' => 'Create module'),
46
            'handlers' => array(
47
                'controller' => array('gplcart\\modules\\skeleton\\controllers\\Skeleton', 'editSkeleton')
48
            )
49
        );
50
    }
51
52
    /**
53
     * Implements hook "job.handlers"
54
     * @param array $handlers
55
     */
56
    public function hookJobHandlers(array &$handlers)
57
    {
58
        $handlers['skeleton'] = array(
59
            'handlers' => array(
60
                'process' => array('gplcart\\modules\\skeleton\\handlers\\Extract', 'process')
61
            ),
62
        );
63
    }
64
65
    /**
66
     * Implements hook "validator.handlers"
67
     * @param array $handlers
68
     */
69
    public function hookValidatorHandlers(array &$handlers)
70
    {
71
        $handlers['skeleton'] = array(
72
            'handlers' => array(
73
                'validate' => array('gplcart\\modules\\skeleton\\handlers\\Validator', 'skeleton')
74
            ),
75
        );
76
    }
77
78
    /**
79
     * Implements hook "cron"
80
     */
81
    public function hookCron()
82
    {
83
        // Automatically delete created files older than 1 day
84
        $lifespan = 86400;
85
        $directory = GC_PRIVATE_DOWNLOAD_DIR . '/skeleton';
86
        if (is_dir($directory)) {
87
            gplcart_file_delete($directory, array('zip'), $lifespan);
88
        }
89
    }
90
91
}
92