Completed
Push — development ( 227e3a...98bb7e )
by Andrij
14:37
created

Cli   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 79
rs 10
wmc 7
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
B create_admin() 0 22 4
B truncate() 0 31 1
1
<?php
2
3
(defined('BASEPATH')) OR exit('No direct script access allowed');
4
5
/**
6
 * Helper controller for maintenance
7
 */
8
class Cli extends \MY_Controller
9
{
0 ignored issues
show
introduced by
Opening brace of a class must be on the same line as the definition
Loading history...
10
11
    public function __construct() {
12
13
        if (PHP_SAPI !== 'cli') {
14
            $this->core->error_404();
15
        }
16
        parent::__construct();
17
        $this->load->helper('cli');
18
    }
19
20
    /**
21
     *
22
     * @param string $name
23
     * @param string $email
24
     * @param string $password
25
     * < php index.php exchange cli create_admin >
0 ignored issues
show
introduced by
Parameter comment must start with a capital letter
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
26
     */
27
    public function create_admin($name = null, $email = null, $password = null) {
28
29
        // This is defaults. Order must be like in function arguments
30
        $argumentsDefaults = [
31
                              'admin',
32
                              '[email protected]',
33
                              'admin',
34
                             ];
35
        $argumentsValues = func_get_args();
36
        $data = [];
37
38
        foreach ($argumentsDefaults as $i => $value) {
39
            $data[$i] = $argumentsValues[$i] ?: $argumentsDefaults[$i];
40
        }
41
42
        $res = $this->dx_auth->register($data[0], $data[2], $data[1], '', '', '');
43
44
        $this->db->update('users', ['role_id' => 1], ['email' => $data[1]], 1);
45
46
        _outputLine($res ? 'Created' : 'Error');
47
48
    }
49
50
    /**
51
     * Truncates data for 1C import
52
     * < php index.php exchange cli truncate >
53
     */
54
    public function truncate() {
55
56
        //        if (true != _confirm('Really truncate data for import', true)) {
57
        //            _outputLine('Canceled');
58
        //            return;
59
        //        }
60
61
        $this->db->truncate('shop_category');
62
        $this->db->truncate('shop_category_i18n');
63
64
        $this->db->truncate('shop_brands');
65
        $this->db->truncate('shop_brands_i18n');
66
67
        $this->db->truncate('shop_products');
68
        $this->db->truncate('shop_products_i18n');
69
        $this->db->truncate('shop_product_variants');
70
        $this->db->truncate('shop_product_variants_i18n');
71
        $this->db->truncate('shop_product_categories');
72
73
        $this->db->truncate('shop_product_properties');
74
        $this->db->truncate('shop_product_properties_i18n');
75
        $this->db->truncate('shop_product_properties_categories');
76
        $this->db->truncate('shop_product_properties_data');
77
        $this->db->truncate('shop_product_properties_data_i18n');
78
        $this->db->truncate('shop_product_images');
79
80
        $this->db->truncate('shop_orders');
81
        $this->db->truncate('shop_orders_products');
82
83
        _outputLine('Data truncated!');
84
    }
85
86
}