Completed
Push — master ( 01b1a5...81f493 )
by Michael
04:03
created

update.php ➔ xoops_module_update_smartobject()   F

Complexity

Conditions 30
Paths > 20000

Size

Total Lines 265
Code Lines 82

Duplication

Lines 45
Ratio 16.98 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 30
eloc 82
c 2
b 1
f 0
nc 5850000
nop 1
dl 45
loc 265
rs 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
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                  Copyright (c) 2000-2016 XOOPS.org                        //
6
//                       <http://xoops.org/>                             //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
28
29
include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php');
30
include_once(XOOPS_ROOT_PATH . '/modules/smartobject/class/smartdbupdater.php');
31
32
/**
33
 * @param $module
34
 * @return bool
35
 */
36
function xoops_module_update_smartobject($module)
37
{
38
    ob_start();
39
40
    $dbVersion = smart_GetMeta('version', 'smartobject');
0 ignored issues
show
Documentation introduced by
'smartobject' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
    if (!$dbVersion) {
42
        $dbVersion = 0;
43
    }
44
45
    $dbupdater = new SmartobjectDbupdater();
46
47
    echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
48
49
    // db migrate version = 1
50
    $newDbVersion = 1;
51
    if ($dbVersion < $newDbVersion) {
52
        echo 'Database migrate to version ' . $newDbVersion . '<br>';
53
54
        // Create table smartobject_link
55
        $table = new SmartDbTable('smartobject_link');
56
        if (!$table->exists()) {
57
            $table->setStructure("CREATE TABLE %s (
58
              `linkid` int(11) NOT NULL auto_increment,
59
              `from_uid` int(11) NOT NULL default '0',
60
              `from_email` varchar(255) NOT NULL default '',
61
              `from_name` varchar(255) NOT NULL default '',
62
              `to_uid` int(11) NOT NULL default '0',
63
              `to_email` varchar(255) NOT NULL default '',
64
              `to_name` varchar(255) NOT NULL default '',
65
              `link` varchar(255) NOT NULL default '',
66
              `subject` varchar(255) NOT NULL default '',
67
              `body` TEXT NOT NULL,
68
              `mid` int(11) NOT NULL default '0',
69
              `mid_name` varchar(255) NOT NULL default '',
70
71
              PRIMARY KEY  (`linkid`)
72
            ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
73
74
            if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
75
                /**
76
                 * @todo trap the errors
77
                 */
78
            }
79
        }
80
        unset($table);
81
        // Create table smartobject_link
82
        $table = new SmartDbTable('smartobject_link');
83
        if (!$table->fieldExists('date')) {
84
            $table->addNewField('date', "int(11) NOT NULL default '0'");
85
            if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
86
                /**
87
                 * @todo trap the errors
88
                 */
89
            }
90
        }
91
        unset($table);
92
93
        // Create table smartobject_tag
94
        $table = new SmartDbTable('smartobject_tag');
95
        if (!$table->exists()) {
96
            $table->setStructure("CREATE TABLE %s (
97
              `tagid` int(11) NOT NULL auto_increment,
98
              `name` varchar(255) NOT NULL default '',
99
              `description` TEXT NOT NULL,
100
              PRIMARY KEY  (`id`)
101
            ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
102
103
            if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
104
                /**
105
                 * @todo trap the errors
106
                 */
107
            }
108
        }
109
110
        // Create table smartobject_tag_text
111
        $table = new SmartDbTable('smartobject_tag_text');
112
        if (!$table->exists()) {
113
            $table->setStructure("CREATE TABLE %s (
114
              `tagid` int(11) NOT NULL default 0,
115
              `language` varchar(255) NOT NULL default '',
116
              `value` TEXT NOT NULL,
117
              PRIMARY KEY  (`id`, `language`)
118
            ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;");
119
120
            if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
121
                /**
122
                 * @todo trap the errors
123
                 */
124
            }
125
        }
126
127
        // Create table smartobject_adsense
128
        $table = new SmartDbTable('smartobject_adsense');
129
        if (!$table->exists()) {
130
            $table->setStructure("
131
  `adsenseid` int(11) NOT NULL auto_increment,
132
  `format` VARCHAR(100) NOT NULL,
133
  `description` TEXT NOT NULL,
134
  `style` TEXT NOT NULL,
135
  `border_color` varchar(6) NOT NULL default '',
136
  `background_color` varchar(6) NOT NULL default '',
137
  `link_color` varchar(6) NOT NULL default '',
138
  `url_color` varchar(6) NOT NULL default '',
139
  `text_color` varchar(6) NOT NULL default '',
140
  `client_id` varchar(100) NOT NULL default '',
141
  `tag` varchar(50) NOT NULL default '',
142
  PRIMARY KEY  (`adsenseid`)
143
            ");
144
        }
145
146
        if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
147
            /**
148
             * @todo trap the errors
149
             */
150
        }
151
    }
152
    // db migrate version = 2
153
    $newDbVersion = 2;
154
    if ($dbVersion < $newDbVersion) {
155
        echo 'Database migrate to version ' . $newDbVersion . '<br>';
156
157
        // Create table smartobject_rating
158
        $table = new SmartDbTable('smartobject_rating');
159
        if (!$table->exists()) {
160
            $table->setStructure('
161
  `ratingid` int(11) NOT NULL auto_increment,
162
  `dirname` VARCHAR(255) NOT NULL,
163
  `item` VARCHAR(255) NOT NULL,
164
  `itemid` int(11) NOT NULL,
165
  `uid` int(11) NOT NULL,
166
  `rate` int(1) NOT NULL,
167
  `date` int(11) NOT NULL,
168
  PRIMARY KEY  (`ratingid`),
169
  UNIQUE (`dirname`, `item`, `itemid`, `uid`)
170
            ');
171
        }
172
173
        if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
174
            /**
175
             * @todo trap the errors
176
             */
177
        }
178
179
        // Create table smartobject_currency
180
        $table = new SmartDbTable('smartobject_currency');
181
        $table->setData("2, 'EUR', 'Euro', '�', 0.65, 0");
182
        $table->setData("3, 'USD', 'American dollar', '$', 0.9, 0");
183
        $table->setData("1, 'CAD', 'Canadian dollar', '$', 1, 1");
184
185
        if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
186
            /**
187
             * @todo trap the errors
188
             */
189
        }
190
    }
191
192
    // db migrate version = 3
193
    $newDbVersion = 3;
194 View Code Duplication
    if ($dbVersion < $newDbVersion) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
195
        echo 'Database migrate to version ' . $newDbVersion . '<br>';
196
197
        // Create table smartobject_customtag
198
        $table = new SmartDbTable('smartobject_customtag');
199
        if (!$table->exists()) {
200
            $table->setStructure('
201
              `customtagid` int(11) NOT NULL auto_increment,
202
              `name` VARCHAR(255) NOT NULL,
203
              `description` TEXT NOT NULL,
204
              `content` TEXT NOT NULL,
205
              `language` TEXT NOT NULL,
206
              PRIMARY KEY  (`customtagid`)
207
            ');
208
        }
209
210
        if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
211
            /**
212
             * @todo trap the errors
213
             */
214
        }
215
    }
216
217
    // db migrate version = 4
218
    $newDbVersion = 4;
219 View Code Duplication
    if ($dbVersion < $newDbVersion) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
220
        echo 'Database migrate to version ' . $newDbVersion . '<br>';
221
222
        // Create table smartobject_currency
223
        $table = new SmartDbTable('smartobject_currency');
224
        if (!$table->exists()) {
225
            $table->setStructure('
226
              `currencyid` int(11) NOT NULL auto_increment,
227
              `iso4217` VARCHAR(5) NOT NULL,
228
              `name` VARCHAR(255) NOT NULL,
229
              `symbol`  VARCHAR(1) NOT NULL,
230
              `rate` float NOT NULL,
231
              `default_currency` int(1) NOT NULL,
232
              PRIMARY KEY  (`currencyid`)
233
            ');
234
        }
235
236
        if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
237
            /**
238
             * @todo trap the errors
239
             */
240
        }
241
    }
242
243
    // db migrate version = 6
244
    $newDbVersion = 6;
245
    if ($dbVersion < $newDbVersion) {
246
        echo 'Database migrate to version ' . $newDbVersion . '<br>';
247
    }
248
249
    $newDbVersion = 7;
250
    if ($dbVersion < $newDbVersion) {
251
        echo 'Database migrate to version ' . $newDbVersion . '<br>';
252
253
        // Create table smartobject_file
254
        $table = new SmartDbTable('smartobject_file');
255
        if (!$table->exists()) {
256
            $table->setStructure('
257
              `fileid` int(11) NOT NULL auto_increment,
258
              `caption` varchar(255) collate latin1_general_ci NOT NULL,
259
              `url` varchar(255) collate latin1_general_ci NOT NULL,
260
              `description` text collate latin1_general_ci NOT NULL,
261
               PRIMARY KEY  (`fileid`)
262
            ');
263
            if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
264
                /**
265
                 * @todo trap the errors
266
                 */
267
            }
268
        }
269
        unset($table);
270
        // Create table smartobject_urllink
271
        $table = new SmartDbTable('smartobject_urllink');
272
        if (!$table->exists()) {
273
            $table->setStructure('
274
              `urllinkid` int(11) NOT NULL auto_increment,
275
              `caption` varchar(255) collate latin1_general_ci NOT NULL,
276
              `url` varchar(255) collate latin1_general_ci NOT NULL,
277
              `description` text collate latin1_general_ci NOT NULL,
278
              `target` varchar(10) collate latin1_general_ci NOT NULL,
279
                PRIMARY KEY  (`urllinkid`)
280
            ');
281
            if (!$dbupdater->updateTable($table)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
282
                /**
283
                 * @todo trap the errors
284
                 */
285
            }
286
        }
287
        unset($table);
288
    }
289
    echo '</code>';
290
291
    $feedback = ob_get_clean();
292
    if (method_exists($module, 'setMessage')) {
293
        $module->setMessage($feedback);
294
    } else {
295
        echo $feedback;
296
    }
297
    smart_SetMeta('version', $newDbVersion, 'smartobject'); //Set meta version to current
0 ignored issues
show
Documentation introduced by
'smartobject' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
298
299
    return true;
300
}
301
302
/**
303
 * @param $module
304
 * @return string
305
 */
306
function xoops_module_install_smartobject($module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

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

Loading history...
307
{
308
    ob_start();
309
310
    echo 'Using the ImpressCMS onInstall event';
311
    $feedback = ob_get_clean();
312
313
    return $feedback;
314
}
315