xoops_module_update_oledrion()   F
last analyzed

Complexity

Conditions 46
Paths 0

Size

Total Lines 437
Code Lines 134

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 134
dl 0
loc 437
rs 3.3333
c 4
b 0
f 1
cc 46
nc 0
nop 2

How to fix   Long Method    Complexity   

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
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * oledrion
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 * @author      Hossein Azizabadi ([email protected])
19
 * @param $module
20
 * @param $version
21
 */
22
23
use XoopsModules\Oledrion;
24
25
/**
26
 * @param $module
27
 * @param $version
28
 */
29
function xoops_module_update_oledrion($module, $version)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
function xoops_module_update_oledrion(/** @scrutinizer ignore-unused */ $module, $version)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $version is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
function xoops_module_update_oledrion($module, /** @scrutinizer ignore-unused */ $version)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
{
31
    global $xoopsDB;
32
33
    // Présence des nouvelles tables et nouvelles zones dans la base de données
34
    // Nouvelle table oledrion_gateways_options
35
    $tableName = $xoopsDB->prefix('oledrion_gateways_options');
36
    if (!Oledrion\Utility::tableExists($tableName)) {
37
        $sql = 'CREATE TABLE ' . $tableName . " (
38
                `option_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
39
                `option_gateway` VARCHAR(50) NOT NULL COMMENT 'nom de la passerelle de paiement',
40
                `option_name` VARCHAR(50) NOT NULL,
41
                `option_value` TEXT NOT NULL,
42
                PRIMARY KEY  (`option_id`),
43
                KEY `option_gateway` (`option_gateway`),
44
                KEY `option_name` (`option_name`),
45
                KEY `option_gateway_name` (`option_gateway`,`option_name`)
46
                ) ENGINE=InnoDB";
47
        $xoopsDB->queryF($sql);
48
    }
49
50
    // Nouveau champ cmd_comment dans Commands
51
    $tableName = $xoopsDB->prefix('oledrion_commands');
52
    if (!Oledrion\Utility::fieldExists('cmd_comment', $tableName)) {
53
        Oledrion\Utility::addField('`cmd_comment` TEXT NOT NULL', $tableName);
54
    }
55
56
    if (!Oledrion\Utility::fieldExists('cmd_vat_number', $tableName)) {
57
        Oledrion\Utility::addField('`cmd_vat_number` VARCHAR( 255 ) NOT NULL', $tableName);
58
    }
59
60
    /**
61
     * Nouvelle table oledrion_lists
62
     * @since 2.2.2009.01.29
63
     */
64
    $tableName = $xoopsDB->prefix('oledrion_lists');
65
    if (!Oledrion\Utility::tableExists($tableName)) {
66
        $sql = 'CREATE TABLE ' . $tableName . ' (
67
                `list_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
68
                `list_uid` MEDIUMINT(8) UNSIGNED NOT NULL,
69
                `list_title` VARCHAR(255) NOT NULL,
70
                `list_date` INT(10) UNSIGNED NOT NULL,
71
                `list_productscount` MEDIUMINT(8) UNSIGNED NOT NULL,
72
                `list_views` MEDIUMINT(8) UNSIGNED NOT NULL,
73
                `list_password` VARCHAR(50) NOT NULL,
74
                `list_type` TINYINT(3) UNSIGNED NOT NULL,
75
                `list_description` TEXT NOT NULL,
76
                PRIMARY KEY  (`list_id`),
77
                KEY `list_uid` (`list_uid`)
78
                ) ENGINE=InnoDB';
79
        $xoopsDB->queryF($sql);
80
    }
81
82
    /**
83
     * Nouvelle table oledrion_lists
84
     * @since 2.2.2009.01.29
85
     */
86
    $tableName = $xoopsDB->prefix('oledrion_products_list');
87
    if (!Oledrion\Utility::tableExists($tableName)) {
88
        $sql = 'CREATE TABLE ' . $tableName . ' (
89
                `productlist_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
90
                `productlist_list_id` INT(10) UNSIGNED NOT NULL,
91
                `productlist_product_id` INT(10) UNSIGNED NOT NULL,
92
                PRIMARY KEY  (`productlist_id`),
93
                KEY `productlist_list_id` (`productlist_list_id`),
94
                KEY `productlist_product_id` (`productlist_product_id`)
95
                ) ENGINE=InnoDB';
96
        $xoopsDB->queryF($sql);
97
    }
98
99
    if (!Oledrion\Utility::fieldExists('productlist_date', $tableName)) {
100
        Oledrion\Utility::addField('productlist_date DATE NOT NULL', $tableName);
101
    }
102
103
    /**
104
     * Nouvelle table oledrion_attributes
105
     * @since 2.3.2009.03.09
106
     */
107
    $tableName = $xoopsDB->prefix('oledrion_attributes');
108
    if (!Oledrion\Utility::tableExists($tableName)) {
109
        $sql = "CREATE TABLE `$tableName` (
110
              `attribute_id` int(10) unsigned NOT NULL auto_increment,
111
              `attribute_weight` mediumint(7) unsigned default NULL,
112
              `attribute_title` varchar(255) default NULL,
113
              `attribute_name` varchar(255) NOT NULL,
114
              `attribute_type` tinyint(3) unsigned default NULL,
115
              `attribute_mandatory` tinyint(1) unsigned default NULL,
116
              `attribute_values` text,
117
              `attribute_names` text,
118
              `attribute_prices` text,
119
              `attribute_stocks` text,
120
              `attribute_product_id` int(11) unsigned default NULL,
121
              `attribute_default_value` varchar(255) default NULL,
122
              `attribute_option1` mediumint(7) unsigned default NULL,
123
              `attribute_option2` mediumint(7) unsigned default NULL,
124
              PRIMARY KEY  (`attribute_id`),
125
              KEY `attribute_product_id` (`attribute_product_id`),
126
              KEY `attribute_weight` (`attribute_weight`)
127
            ) ENGINE=InnoDB;";
128
        $xoopsDB->queryF($sql);
129
    }
130
131
    /**
132
     * Nouvelle table oledrion_caddy_attributes
133
     * @since 2.3.2009.03.10
134
     */
135
    $tableName = $xoopsDB->prefix('oledrion_caddy_attributes');
136
    if (!Oledrion\Utility::tableExists($tableName)) {
137
        $sql = "CREATE TABLE `$tableName` (
138
              `ca_id` int(10) unsigned NOT NULL auto_increment,
139
              `ca_cmd_id` int(10) unsigned NOT NULL,
140
              `ca_caddy_id` int(10) unsigned NOT NULL,
141
              `ca_attribute_id` int(10) unsigned NOT NULL,
142
              `ca_attribute_values` text NOT NULL,
143
              `ca_attribute_names` text NOT NULL,
144
              `ca_attribute_prices` text NOT NULL,
145
              PRIMARY KEY  (`ca_id`),
146
              KEY `ca_cmd_id` (`ca_cmd_id`),
147
              KEY `ca_caddy_id` (`ca_caddy_id`),
148
              KEY `ca_attribute_id` (`ca_attribute_id`)
149
        ) ENGINE=InnoDB;";
150
        $xoopsDB->queryF($sql);
151
    }
152
153
    /**
154
     * Augmentation des types numéraires pour accepter le million
155
     * @since 2.3.2009.04.20
156
     */
157
    $definition = Oledrion\Utility::getFieldDefinition('product_price', $xoopsDB->prefix('oledrion_products'));
158
    if ('' !== $definition) {
159
        if ('decimal(7,2)' === xoops_trim($definition['Type'])) {
160
            $tablesToUpdates = [
161
                'oledrion_products'  => [
162
                    'product_price',
163
                    'product_shipping_price',
164
                    'product_discount_price',
165
                    'product_ecotaxe',
166
                ],
167
                'oledrion_caddy'     => ['caddy_price'],
168
                'oledrion_commands'  => ['cmd_shipping'],
169
                'oledrion_discounts' => [
170
                    'disc_price_degress_l1total',
171
                    'disc_price_degress_l2total',
172
                    'disc_price_degress_l3total',
173
                    'disc_price_degress_l4total',
174
                    'disc_price_degress_l5total',
175
                ],
176
            ];
177
            foreach ($tablesToUpdates as $tableName => $fields) {
178
                foreach ($fields as $field) {
179
                    $sql = 'ALTER TABLE ' . $xoopsDB->prefix($tableName) . ' CHANGE `' . $field . '` `' . $field . '` DECIMAL( 16, 2 ) NOT NULL';
180
                    $xoopsDB->queryF($sql);
181
                }
182
            }
183
        }
184
    }
185
186
    /**
187
     * Add product_property
188
     * @since 2.3.2012.08.03
189
     */
190
    $tableName = $xoopsDB->prefix('oledrion_products');
191
    if (!Oledrion\Utility::fieldExists('product_property1', $tableName)) {
192
        Oledrion\Utility::addField('`product_property1` varchar(255) NOT NULL', $tableName);
193
    }
194
195
    if (!Oledrion\Utility::fieldExists('product_property2', $tableName)) {
196
        Oledrion\Utility::addField('`product_property2` varchar(255) NOT NULL', $tableName);
197
    }
198
199
    if (!Oledrion\Utility::fieldExists('product_property3', $tableName)) {
200
        Oledrion\Utility::addField('`product_property3` varchar(255) NOT NULL', $tableName);
201
    }
202
203
    if (!Oledrion\Utility::fieldExists('product_property4', $tableName)) {
204
        Oledrion\Utility::addField('`product_property4` varchar(255) NOT NULL', $tableName);
205
    }
206
207
    if (!Oledrion\Utility::fieldExists('product_property5', $tableName)) {
208
        Oledrion\Utility::addField('`product_property5` varchar(255) NOT NULL', $tableName);
209
    }
210
211
    if (!Oledrion\Utility::fieldExists('product_property6', $tableName)) {
212
        Oledrion\Utility::addField('`product_property6` varchar(255) NOT NULL', $tableName);
213
    }
214
215
    if (!Oledrion\Utility::fieldExists('product_property7', $tableName)) {
216
        Oledrion\Utility::addField('`product_property7` varchar(255) NOT NULL', $tableName);
217
    }
218
219
    if (!Oledrion\Utility::fieldExists('product_property8', $tableName)) {
220
        Oledrion\Utility::addField('`product_property8` varchar(255) NOT NULL', $tableName);
221
    }
222
223
    if (!Oledrion\Utility::fieldExists('product_property9', $tableName)) {
224
        Oledrion\Utility::addField('`product_property9` varchar(255) NOT NULL', $tableName);
225
    }
226
227
    if (!Oledrion\Utility::fieldExists('product_property10', $tableName)) {
228
        Oledrion\Utility::addField('`product_property10` varchar(255) NOT NULL', $tableName);
229
    }
230
231
    /**
232
     * Nouvelle table oledrion_packing
233
     * @since 2.3.4 2013.03.5
234
     */
235
    $tableName = $xoopsDB->prefix('oledrion_packing');
236
    if (!Oledrion\Utility::tableExists($tableName)) {
237
        $sql = "CREATE TABLE `$tableName` (
238
              `packing_id` int(5) unsigned NOT NULL auto_increment,
239
              `packing_title` varchar(255) NOT NULL default '',
240
              `packing_width` varchar(50) NOT NULL,
241
              `packing_length` varchar(50) NOT NULL,
242
              `packing_weight` varchar(50) NOT NULL,
243
              `packing_image` varchar(255) NOT NULL,
244
              `packing_description` text,
245
              `packing_price` decimal(16,2) NOT NULL,
246
              `packing_online` tinyint(1) NOT NULL default '1',
247
              PRIMARY KEY  (`packing_id`),
248
              KEY `packing_title` (`packing_title`),
249
              KEY `packing_online` (`packing_online`),
250
              KEY `packing_price` (`packing_price`)
251
            ) ENGINE=InnoDB;";
252
        $xoopsDB->queryF($sql);
253
    }
254
255
    /**
256
     * Nouvelle table oledrion_location
257
     * @since 2.3.4 2013.03.5
258
     */
259
    $tableName = $xoopsDB->prefix('oledrion_location');
260
    if (!Oledrion\Utility::tableExists($tableName)) {
261
        $sql = "CREATE TABLE `$tableName` (
262
              `location_id` int(5) unsigned NOT NULL auto_increment,
263
              `location_pid` int(5) unsigned NOT NULL default '0',
264
              `location_title` varchar(255) NOT NULL default '',
265
              `location_online` tinyint(1) NOT NULL default '1',
266
              `location_type` enum('location','parent') NOT NULL,
267
              PRIMARY KEY  (`location_id`),
268
              KEY `location_title` (`location_title`),
269
              KEY `location_pid` (`location_pid`),
270
              KEY `location_online` (`location_online`)
271
            ) ENGINE=InnoDB;";
272
        $xoopsDB->queryF($sql);
273
    }
274
275
    /**
276
     * Nouvelle table oledrion_delivery
277
     * @since 2.3.4 2013.03.5
278
     */
279
    $tableName = $xoopsDB->prefix('oledrion_delivery');
280
    if (!Oledrion\Utility::tableExists($tableName)) {
281
        $sql = "CREATE TABLE `$tableName` (
282
              `delivery_id` int(10) unsigned NOT NULL auto_increment,
283
              `delivery_title` varchar(255) NOT NULL default '',
284
              `delivery_description` text,
285
              `delivery_online` tinyint(1) NOT NULL default '1',
286
              `delivery_image` varchar(255) NOT NULL,
287
              PRIMARY KEY  (`delivery_id`),
288
              KEY `delivery_title` (`delivery_title`),
289
              KEY `delivery_online` (`delivery_online`)
290
            ) ENGINE=InnoDB;";
291
        $xoopsDB->queryF($sql);
292
    }
293
294
    /**
295
     * Nouvelle table oledrion_payment
296
     * @since 2.3.4 2013.03.5
297
     */
298
    $tableName = $xoopsDB->prefix('oledrion_payment');
299
    if (!Oledrion\Utility::tableExists($tableName)) {
300
        $sql = "CREATE TABLE `$tableName` (
301
              `payment_id` int(10) unsigned NOT NULL auto_increment,
302
              `payment_title` varchar(255) NOT NULL default '',
303
              `payment_description` text,
304
              `payment_online` tinyint(1) NOT NULL default '1',
305
              `payment_type` enum('online','offline') NOT NULL,
306
              `payment_gateway` varchar(64) NOT NULL default '',
307
              `payment_image` varchar(255) NOT NULL,
308
              PRIMARY KEY  (`payment_id`),
309
              KEY `payment_title` (`payment_title`),
310
              KEY `payment_online` (`payment_online`),
311
              KEY `payment_type` (`payment_type`),
312
              KEY `payment_gateway` (`payment_gateway`)
313
            ) ENGINE=InnoDB;";
314
        $xoopsDB->queryF($sql);
315
    }
316
317
    /**
318
     * Nouvelle table oledrion_location_delivery
319
     * @since 2.3.4 2013.03.5
320
     */
321
    $tableName = $xoopsDB->prefix('oledrion_location_delivery');
322
    if (!Oledrion\Utility::tableExists($tableName)) {
323
        $sql = "CREATE TABLE `$tableName` (
324
              `ld_id` int(5) unsigned NOT NULL auto_increment,
325
              `ld_location` int(5) unsigned NOT NULL,
326
              `ld_delivery` int(5) unsigned NOT NULL,
327
              `ld_price` decimal(16,2) NOT NULL,
328
              `ld_delivery_time` mediumint(8) unsigned NOT NULL,
329
              PRIMARY KEY  (`ld_id`),
330
              KEY `ld_location` (`ld_location`),
331
              KEY `ld_delivery` (`ld_delivery`)
332
            ) ENGINE=InnoDB;";
333
        $xoopsDB->queryF($sql);
334
    }
335
336
    /**
337
     * Nouvelle table oledrion_delivery_payment
338
     * @since 2.3.4 2013.03.5
339
     */
340
341
    $tableName = $xoopsDB->prefix('oledrion_delivery_payment');
342
    if (!Oledrion\Utility::tableExists($tableName)) {
343
        $sql = "CREATE TABLE `$tableName` (
344
              `dp_id` int(5) unsigned NOT NULL auto_increment,
345
              `dp_delivery` int(5) unsigned NOT NULL,
346
              `dp_payment` int(5) unsigned NOT NULL,
347
              PRIMARY KEY  (`dp_id`),
348
              KEY `dp_delivery` (`dp_delivery`),
349
              KEY `dp_payment` (`dp_payment`)
350
            ) ENGINE=InnoDB;";
351
        $xoopsDB->queryF($sql);
352
    }
353
354
    /**
355
     * Nouvelle table oledrion_delivery_payment
356
     * @since 2.3.4 2013.03.15
357
     */
358
359
    $tableName = $xoopsDB->prefix('oledrion_payment_log');
360
    if (!Oledrion\Utility::tableExists($tableName)) {
361
        $sql = "CREATE TABLE `$tableName` (
362
                  `log_id` int(10) unsigned NOT NULL auto_increment,
363
                  `log_create` int(10) unsigned NOT NULL,
364
                  `log_status` tinyint(1) unsigned NOT NULL,
365
                  `log_ip` varchar(32) NOT NULL,
366
                  `log_type` enum('online','offline') NOT NULL,
367
                  `log_payment` int(10) unsigned NOT NULL,
368
                  `log_gateway` varchar(64) NOT NULL default '',
369
                  `log_uid` int(10) unsigned NOT NULL,
370
                  `log_command` int(10) unsigned NOT NULL,
371
                  `log_amount` double(16,2) NOT NULL,
372
                  `log_authority` varchar(255) NOT NULL,
373
                  PRIMARY KEY  (`log_id`),
374
                  KEY `log_uid` (`log_uid`),
375
                  KEY `log_command` (`log_command`),
376
                  KEY `log_status` (`log_status`)
377
                ) ENGINE=InnoDB;";
378
        $xoopsDB->queryF($sql);
379
    }
380
381
    /**
382
     * Add New fields to Commands
383
     * @since 2.3.2013.03.15
384
     */
385
    $tableName = $xoopsDB->prefix('oledrion_commands');
386
    if (!Oledrion\Utility::fieldExists('cmd_create', $tableName)) {
387
        Oledrion\Utility::addField('`cmd_create` int(10) unsigned NOT NULL', $tableName);
388
    }
389
390
    if (!Oledrion\Utility::fieldExists('cmd_packing', $tableName)) {
391
        Oledrion\Utility::addField('`cmd_packing` varchar(255) NOT NULL', $tableName);
392
    }
393
394
    if (!Oledrion\Utility::fieldExists('cmd_packing_id', $tableName)) {
395
        Oledrion\Utility::addField('`cmd_packing_id` int(5) unsigned NOT NULL', $tableName);
396
    }
397
398
    if (!Oledrion\Utility::fieldExists('cmd_location', $tableName)) {
399
        Oledrion\Utility::addField('`cmd_location` varchar(255) NOT NULL', $tableName);
400
    }
401
402
    if (!Oledrion\Utility::fieldExists('cmd_location_id', $tableName)) {
403
        Oledrion\Utility::addField('`cmd_location_id` int(5) unsigned NOT NULL', $tableName);
404
    }
405
406
    if (!Oledrion\Utility::fieldExists('cmd_delivery', $tableName)) {
407
        Oledrion\Utility::addField('`cmd_delivery` varchar(255) NOT NULL', $tableName);
408
    }
409
410
    if (!Oledrion\Utility::fieldExists('cmd_delivery_id', $tableName)) {
411
        Oledrion\Utility::addField('`cmd_delivery_id` int(5) unsigned NOT NULL', $tableName);
412
    }
413
414
    if (!Oledrion\Utility::fieldExists('cmd_payment', $tableName)) {
415
        Oledrion\Utility::addField('`cmd_payment` varchar(255) NOT NULL', $tableName);
416
    }
417
418
    if (!Oledrion\Utility::fieldExists('cmd_payment_id', $tableName)) {
419
        Oledrion\Utility::addField('`cmd_payment_id` int(5) unsigned NOT NULL', $tableName);
420
    }
421
422
    if (!Oledrion\Utility::fieldExists('cmd_status', $tableName)) {
423
        Oledrion\Utility::addField('`cmd_status` tinyint(1) unsigned NOT NULL default "1"', $tableName);
424
    }
425
426
    if (!Oledrion\Utility::fieldExists('cmd_mobile', $tableName)) {
427
        Oledrion\Utility::addField('`cmd_mobile` varchar(30) NOT NULL', $tableName);
428
    }
429
430
    if (!Oledrion\Utility::fieldExists('cmd_packing_price', $tableName)) {
431
        Oledrion\Utility::addField('`cmd_packing_price` decimal(16,2) NOT NULL', $tableName);
432
    }
433
434
    /**
435
     * Add/update product urls
436
     * @since 2.3.2013.08.03
437
     */
438
    $tableName = $xoopsDB->prefix('oledrion_products');
439
440
    if (!Oledrion\Utility::fieldExists('product_url2', $tableName)) {
441
        Oledrion\Utility::addField('`product_url2` VARCHAR( 255 ) NOT NULL AFTER `product_url`', $tableName);
442
    }
443
444
    if (!Oledrion\Utility::fieldExists('product_url3', $tableName)) {
445
        Oledrion\Utility::addField('`product_url3` VARCHAR( 255 ) NOT NULL AFTER `product_url`', $tableName);
446
    }
447
448
    /**
449
     * Add cmd_track
450
     * @since 2014.01.03
451
     */
452
    $tableName = $xoopsDB->prefix('oledrion_commands');
453
454
    if (!Oledrion\Utility::fieldExists('cmd_track', $tableName)) {
455
        Oledrion\Utility::addField('`cmd_track` VARCHAR( 255 ) NOT NULL', $tableName);
456
    }
457
458
    /**
459
     * Add cmd_track
460
     * @since 2014.01.10
461
     */
462
    $tableName = $xoopsDB->prefix('oledrion_related');
463
464
    if (!Oledrion\Utility::fieldExists('related_product_percent', $tableName)) {
465
        Oledrion\Utility::addField('`related_product_percent` INT( 4 ) NOT NULL', $tableName);
466
    }
467
}
468