Completed
Push — development ( ef9e73...b2c3e4 )
by Andrij
20:27
created

Gallery_install::make_install()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 169
Code Lines 124

Duplication

Lines 169
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 124
c 1
b 0
f 0
nc 1
nop 0
dl 169
loc 169
rs 8.2857

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
if (!defined('BASEPATH')) {
4
    exit('No direct script access allowed');
5
}
6
7
/**
8
 * Image CMS
9
 *
10
 * Gallery main model
11
 * @property CI_Loader load
12
 * @property CI_DB_forge dbforge
13
 */
14 View Code Duplication
class Gallery_install extends CI_Model
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
0 ignored issues
show
introduced by
Opening brace of a class must be on the same line as the definition
Loading history...
16
17
    public function __construct() {
18
19
        parent::__construct();
20
    }
21
22
    public function make_install() {
23
24
        // Enable url access and install default settings
25
26
        $params = [
27
                   'max_image_size'          => 5,
28
                   'max_width'               => 0,
29
                   'max_height'              => 0,
30
                   'quality'                 => 95,
31
                   'maintain_ratio'          => TRUE,
32
                   'maintain_ratio_prev'     => TRUE,
33
                   'maintain_ratio_icon'     => TRUE,
34
                   'prev_img_width'          => 500,
35
                   'prev_img_height'         => 500,
36
                   'thumb_width'             => 100,
37
                   'thumb_height'            => 100,
38
                   'watermark_text'          => '',
39
                   'wm_vrt_alignment'        => 'bottom',
40
                   'wm_hor_alignment'        => 'right',
41
                   'watermark_font_size'     => '14',
42
                   'watermark_color'         => 'ffffff',
43
                   'watermark_padding'       => '-5',
44
                   'watermark_font_path'     => './uploads/defaultFont.ttf',
45
                   'order_by'                => 'date',
46
                   'sort_order'              => 'desc',
47
                   'watermark_type'          => 'text',
48
                   'watermark_image_opacity' => 50,
49
                  ];
50
51
        $this->db->where('name', 'gallery');
52
        $this->db->update('components', ['enabled' => 1, 'settings' => serialize($params)]);
53
54
        $this->load->dbforge();
55
56
        /* Albums table */
57
        $fields = [
58
                   'id'          => [
59
                                     'type'           => 'INT',
60
                                     'constraint'     => 11,
61
                                     'auto_increment' => TRUE,
62
                                    ],
63
                   'category_id' => [
64
                                     'type'       => 'INT',
65
                                     'constraint' => 11,
66
                                    ],
67
                   'name'        => [
68
                                     'type'       => 'VARCHAR',
69
                                     'constraint' => 250,
70
                                    ],
71
                   'description' => [
72
                                     'type'       => 'VARCHAR',
73
                                     'constraint' => 500,
74
                                    ],
75
                   'cover_id'    => [
76
                                     'type'       => 'INT',
77
                                     'constraint' => 11,
78
                                     'default'    => 0,
79
                                    ],
80
                   'position'    => [
81
                                     'type'       => 'INT',
82
                                     'constraint' => 9,
83
                                     'default'    => 0,
84
                                    ],
85
                   'created'     => [
86
                                     'type'       => 'INT',
87
                                     'constraint' => 11,
88
                                    ],
89
                   'updated'     => [
90
                                     'type'       => 'INT',
91
                                     'constraint' => 11,
92
                                    ],
93
                   'tpl_file'    => [
94
                                     'type'       => 'VARCHAR',
95
                                     'constraint' => 200,
96
                                    ],
97
                  ];
98
99
        $this->dbforge->add_key('id', TRUE);
100
        $this->dbforge->add_field($fields);
101
        $this->dbforge->create_table('gallery_albums', TRUE);
102
103
        /* Images table */
104
        $fields2 = [
105
                    'id'          => [
106
                                      'type'           => 'INT',
107
                                      'constraint'     => 11,
108
                                      'auto_increment' => TRUE,
109
                                     ],
110
                    'album_id'    => [
111
                                      'type'       => 'INT',
112
                                      'constraint' => 11,
113
                                     ],
114
                    'file_name'   => [
115
                                      'type'       => 'VARCHAR',
116
                                      'constraint' => 150,
117
                                     ],
118
                    'file_ext'    => [
119
                                      'type'       => 'VARCHAR',
120
                                      'constraint' => 8,
121
                                     ],
122
                    'file_size'   => [
123
                                      'type'       => 'VARCHAR',
124
                                      'constraint' => 20,
125
                                     ],
126
                    'position'    => [
127
                                      'type'       => 'INT',
128
                                      'constraint' => 9,
129
                                     ],
130
                    'width'       => [
131
                                      'type'       => 'INT',
132
                                      'constraint' => 6,
133
                                     ],
134
                    'height'      => [
135
                                      'type'       => 'INT',
136
                                      'constraint' => 6,
137
                                     ],
138
                    'description' => [
139
                                      'type'       => 'VARCHAR',
140
                                      'constraint' => 500,
141
                                     ],
142
                    'uploaded'    => [
143
                                      'type'       => 'INT',
144
                                      'constraint' => 11,
145
                                     ],
146
                    'views'       => [
147
                                      'type'       => 'INT',
148
                                      'constraint' => 11,
149
                                     ],
150
                   ];
151
152
        $this->dbforge->add_key('id', TRUE);
153
        $this->dbforge->add_field($fields2);
154
        $this->dbforge->create_table('gallery_images', TRUE);
155
156
        /* Categories table */
157
        $category = [
158
                     'id'          => [
159
                                       'type'           => 'INT',
160
                                       'constraint'     => 11,
161
                                       'auto_increment' => TRUE,
162
                                      ],
163
                     'name'        => [
164
                                       'type'       => 'VARCHAR',
165
                                       'constraint' => 250,
166
                                      ],
167
                     'description' => [
168
                                       'type'       => 'VARCHAR',
169
                                       'constraint' => 500,
170
                                      ],
171
                     'cover_id'    => [
172
                                       'type'       => 'INT',
173
                                       'constraint' => 11,
174
                                       'default'    => 0,
175
                                      ],
176
                     'position'    => [
177
                                       'type'       => 'INT',
178
                                       'constraint' => 9,
179
                                       'default'    => 0,
180
                                      ],
181
                     'created'     => [
182
                                       'type'       => 'INT',
183
                                       'constraint' => 11,
184
                                      ],
185
                    ];
186
187
        $this->dbforge->add_key('id', TRUE);
188
        $this->dbforge->add_field($category);
189
        $this->dbforge->create_table('gallery_category', TRUE);
190
    }
191
192
    public function deinstall() {
193
        $this->load->dbforge();
194
        $this->dbforge->drop_table('gallery_albums');
195
        $this->dbforge->drop_table('gallery_images');
196
        $this->dbforge->drop_table('gallery_category');
197
    }
198
199
}
200
201
/* End of file install.php */