|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Smartfaq; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* SmartobjectDbupdater class |
|
7
|
|
|
* |
|
8
|
|
|
* Class performing the database update for the module |
|
9
|
|
|
* |
|
10
|
|
|
* @author marcan <[email protected]> |
|
11
|
|
|
* @link https://www.smartfactory.ca The SmartFactory |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use XoopsModules\Smartfaq; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class SmartobjectDbupdater |
|
18
|
|
|
*/ |
|
19
|
|
|
class SmartobjectDbupdater |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* SmartobjectDbupdater constructor. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Use to execute a general query |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $query query that will be executed |
|
32
|
|
|
* @param string $goodmsg message displayed on success |
|
33
|
|
|
* @param string $badmsg message displayed on error |
|
34
|
|
|
* |
|
35
|
|
|
* @return bool true if success, false if an error occurred |
|
36
|
|
|
*/ |
|
37
|
|
|
public function runQuery($query, $goodmsg, $badmsg) |
|
38
|
|
|
{ |
|
39
|
|
|
global $xoopsDB; |
|
40
|
|
|
$ret = $xoopsDB->queryF($query); |
|
41
|
|
|
if (!$ret) { |
|
42
|
|
|
echo " $badmsg<br>"; |
|
43
|
|
|
|
|
44
|
|
|
return false; |
|
45
|
|
|
} |
|
46
|
|
|
echo " $goodmsg<br>"; |
|
47
|
|
|
|
|
48
|
|
|
return true; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Use to rename a table |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $from name of the table to rename |
|
55
|
|
|
* @param string $to new name of the renamed table |
|
56
|
|
|
* |
|
57
|
|
|
* @return bool true if success, false if an error occurred |
|
58
|
|
|
*/ |
|
59
|
|
|
public function renameTable($from, $to) |
|
60
|
|
|
{ |
|
61
|
|
|
global $xoopsDB; |
|
62
|
|
|
|
|
63
|
|
|
$from = $xoopsDB->prefix($from); |
|
64
|
|
|
$to = $xoopsDB->prefix($to); |
|
65
|
|
|
|
|
66
|
|
|
$query = \sprintf('ALTER TABLE `%s` RENAME %s', $from, $to); |
|
67
|
|
|
$ret = $xoopsDB->queryF($query); |
|
68
|
|
|
if (!$ret) { |
|
69
|
|
|
echo ' ' . \sprintf(\_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>'; |
|
70
|
|
|
|
|
71
|
|
|
return false; |
|
72
|
|
|
} |
|
73
|
|
|
echo ' ' . \sprintf(\_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>'; |
|
74
|
|
|
|
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Use to update a table |
|
80
|
|
|
* |
|
81
|
|
|
* @param Smartfaq\SmartDbTable $table {@link SmartDbTable} that will be updated |
|
82
|
|
|
* |
|
83
|
|
|
* @return bool true if success, false if an error occurred |
|
84
|
|
|
* @see DbTable |
|
85
|
|
|
*/ |
|
86
|
|
|
public function updateTable($table) |
|
87
|
|
|
{ |
|
88
|
|
|
global $xoopsDB; |
|
89
|
|
|
|
|
90
|
|
|
$ret = true; |
|
91
|
|
|
|
|
92
|
|
|
// If table has a structure, create the table |
|
93
|
|
|
if ($table->getStructure()) { |
|
94
|
|
|
$ret = $table->createTable() && $ret; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// If table is flag for drop, drop it |
|
98
|
|
|
if ($table->getFlagForDrop()) { |
|
99
|
|
|
$ret = $table->dropTable() && $ret; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
// If table has data, insert it |
|
103
|
|
|
if ($table->getData()) { |
|
104
|
|
|
$ret = $table->addData() && $ret; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
// If table has new fields to be added, add them |
|
108
|
|
|
if ($table->getNewFields()) { |
|
109
|
|
|
$ret = $table->addNewFields() && $ret; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// If table has altered field, alter the table |
|
113
|
|
|
if ($table->getAlteredFields()) { |
|
114
|
|
|
$ret = $table->alterTable() && $ret; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
// If table has updated field values, update the table |
|
118
|
|
|
if ($table->getUpdatedFields()) { |
|
119
|
|
|
$ret = $table->updateFieldsValues($table) && $ret; |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
// If table has dropped field, alter the table |
|
123
|
|
|
if ($table->getDroppedFields()) { |
|
124
|
|
|
$ret = $table->dropFields($table) && $ret; |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
//felix |
|
127
|
|
|
// If table has updated field values, update the table |
|
128
|
|
|
if ($table->getUpdatedWhere()) { |
|
129
|
|
|
$ret = $table->updateWhereValues($table) && $ret; |
|
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return $ret; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.