Completed
Branch master (1b2f30)
by Michael
06:29 queued 03:22
created

include/onupdate.inc.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4
5
/**
6
 * @param $module
7
 * @return bool
8
 */
9
function xoops_module_update_smartfaq($module)
10
{
11
    // Load SmartDbUpdater from the SmartObject Framework if present
12
    $smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartobject/class/smartdbupdater.php';
13
    if (!file_exists($smartdbupdater)) {
14
        $smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartfaq/class/smartdbupdater.php';
15
    }
16
    include_once($smartdbupdater);
17
18
    $dbupdater = new SmartobjectDbupdater();
19
20
    ob_start();
21
22
    echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br />';
23
24
    // Adding partialview field
25
    $table = new SmartDbTable('smartfaq_faq');
26
    if (!$table->fieldExists('partialview')) {
27
        $table->addNewField('partialview', "tinyint(1) NOT NULL default '0'");
28
    }
29
30
    // Changing categoryid type to int(11)
31
    $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false);
32
33
    if (!$dbupdater->updateTable($table)) {
34
        /**
35
         * @todo trap the errors
36
         */
37
    }
38
    unset($table);
39
40
    // Editing smartfaq_categories table
41
    $table = new SmartDbTable('smartfaq_categories');
42
    // Changing categoryid type to int(11)
43
    $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false);
44
45
    // Changing parentid type to int(11)
46
    $table->addAlteredField('parentid', "int(11) NOT NULL default '0'", false);
47
48
    if (!$dbupdater->updateTable($table)) {
49
        /**
50
         * @todo trap the errors
51
         */
52
    }
53
    unset($table);
54
55
    // Editing smartfaq_answers table
56
    $table = new SmartDbTable('smartfaq_answers');
57
    // Changing categoryid type to int(11)
58
    $table->addAlteredField('answerid', "int(11) NOT NULL default '0'", false);
59
60
    // Changing parentid type to int(11)
61
    $table->addAlteredField('faqid', "int(11) NOT NULL default '0'", false);
62
63
    if (!$dbupdater->updateTable($table)) {
64
        /**
65
         * @todo trap the errors
66
         */
67
    }
68
    unset($table);
69
70
    /**
71
     * Check for items with categoryid=0
72
     */
73
    include_once(XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php');
74
    $smartfaq_faqHandler      = $answerHandler = sf_gethandler('faq');
0 ignored issues
show
$answerHandler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
75
    $smartfaq_categoryHandler = $answerHandler = sf_gethandler('category');
0 ignored issues
show
$answerHandler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
76
77
    //find a valid categoryid
78
    $categoriesObj = $smartfaq_categoryHandler->getCategories(1, 0, 0, 'weight', 'ASC', false);
79
    if (count($categoriesObj) > 0) {
80
        $categoryid = $categoriesObj[0]->getVar('categoryid');
81
        $criteria   = new CriteriaCompo();
82
        $criteria->add(new Criteria('categoryid', 0));
83
        $smartfaq_faqHandler->updateAll('categoryid', $categoryid, $criteria);
84
        echo '&nbsp;&nbsp;Cleaning up questions with categoryid=0<br />';
85
    }
86
87
    echo '</code>';
88
89
    $feedback = ob_get_clean();
90
    if (method_exists($module, 'setMessage')) {
91
        $module->setMessage($feedback);
92
    } else {
93
        echo $feedback;
94
    }
95
96
    return true;
97
}
98
99
/**
100
 * @param $module
101
 * @return bool
102
 */
103
function xoops_module_install_smartfaq($module)
104
{
105
    ob_start();
106
107
    include_once(XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/include/functions.php');
108
109
    $feedback = ob_get_clean();
110
    if (method_exists($module, 'setMessage')) {
111
        $module->setMessage($feedback);
112
    } else {
113
        echo $feedback;
114
    }
115
116
    return true;
117
}
118