|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Wfdownloads; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
You may not change or alter any portion of this comment or credits |
|
7
|
|
|
of supporting developers from this source code or any supporting source code |
|
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
/** |
|
15
|
|
|
* Wfdownloads module |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
18
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
19
|
|
|
* @package wfdownload |
|
20
|
|
|
* @since 3.23 |
|
21
|
|
|
* @author marcan <[email protected]>, Xoops Development Team |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Contains the classes for updating database tables |
|
26
|
|
|
* |
|
27
|
|
|
* @license GNU |
|
28
|
|
|
* @author marcan <[email protected]> |
|
29
|
|
|
* @link http://www.smartfactory.ca The SmartFactory |
|
30
|
|
|
* @package Wfdownloads |
|
31
|
|
|
* @subpackage dbUpdater |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
use XoopsModules\Wfdownloads; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Dbupdater class |
|
38
|
|
|
* |
|
39
|
|
|
* Class performing the database update for the module |
|
40
|
|
|
* |
|
41
|
|
|
* @package Wfdownloads |
|
42
|
|
|
* @author marcan <[email protected]> |
|
43
|
|
|
* @link http://www.smartfactory.ca The SmartFactory |
|
44
|
|
|
*/ |
|
45
|
|
|
class Dbupdater |
|
46
|
|
|
{ |
|
47
|
|
|
public function __construct() |
|
48
|
|
|
{ |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Use to execute a general query |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $query query that will be executed |
|
55
|
|
|
* @param string $goodmsg message displayed on success |
|
56
|
|
|
* @param string $badmsg message displayed on error |
|
57
|
|
|
* |
|
58
|
|
|
* @return bool true if success, false if an error occured |
|
59
|
|
|
*/ |
|
60
|
|
|
public function runQuery($query, $goodmsg, $badmsg) |
|
61
|
|
|
{ |
|
62
|
|
|
$ret = $GLOBALS['xoopsDB']->query($query); |
|
63
|
|
|
if (!$ret) { |
|
64
|
|
|
echo "<li class='err'>$badmsg</li>"; |
|
65
|
|
|
|
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
echo "<li class='ok'>$goodmsg</li>"; |
|
69
|
|
|
|
|
70
|
|
|
return true; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Use to rename a table |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $from name of the table to rename |
|
77
|
|
|
* @param string $to new name of the renamed table |
|
78
|
|
|
* |
|
79
|
|
|
* @return bool true if success, false if an error occured |
|
80
|
|
|
*/ |
|
81
|
|
|
public function renameTable($from, $to) |
|
82
|
|
|
{ |
|
83
|
|
|
$from = $GLOBALS['xoopsDB']->prefix($from); |
|
84
|
|
|
$to = $GLOBALS['xoopsDB']->prefix($to); |
|
85
|
|
|
|
|
86
|
|
|
$query = \sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
87
|
|
|
$ret = $GLOBALS['xoopsDB']->query($query); |
|
88
|
|
|
if (!$ret) { |
|
89
|
|
|
echo "<li class='err'>" . \sprintf(\_AM_WFDOWNLOADS_DB_MSG_RENAME_TABLE_ERR, $from) . '</li>'; |
|
90
|
|
|
|
|
91
|
|
|
return false; |
|
92
|
|
|
} |
|
93
|
|
|
echo "<li class='ok'>" . \sprintf(\_AM_WFDOWNLOADS_DB_MSG_RENAME_TABLE, $from, $to) . '</li>'; |
|
94
|
|
|
|
|
95
|
|
|
return true; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Use to update a table |
|
100
|
|
|
* |
|
101
|
|
|
* @param DbupdaterTable $table {@link DbupdaterTable} that will be updated |
|
102
|
|
|
* |
|
103
|
|
|
* @return bool true if success, false if an error occured |
|
104
|
|
|
*/ |
|
105
|
|
|
public function updateTable(DbupdaterTable $table) |
|
106
|
|
|
{ |
|
107
|
|
|
$ret = true; |
|
108
|
|
|
echo '<ul>'; |
|
109
|
|
|
|
|
110
|
|
|
// If table has a structure, create the table |
|
111
|
|
|
if ($table->getStructure()) { |
|
112
|
|
|
$ret = $table->createTable() && $ret; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
// If table is flag for drop, drop it |
|
116
|
|
|
if ($table->_flagForDrop) { |
|
|
|
|
|
|
117
|
|
|
$ret = $table->dropTable() && $ret; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
// If table has data, insert it |
|
121
|
|
|
if ($table->getData()) { |
|
122
|
|
|
$ret = $table->addData() && $ret; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
// If table has new fields to be added, add them |
|
126
|
|
|
if ($table->getNewFields()) { |
|
127
|
|
|
$ret = $table->addNewFields() && $ret; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
// If table has altered field, alter the table |
|
131
|
|
|
if ($table->getAlteredFields()) { |
|
132
|
|
|
$ret = $table->alterTable() && $ret; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
// If table has updated field values, update the table |
|
136
|
|
|
if ($table->getUpdatedFields()) { |
|
137
|
|
|
$ret = $table->updateFieldsValues($table) && $ret; |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
// If table has droped field, alter the table |
|
141
|
|
|
if ($table->getDropedFields()) { |
|
142
|
|
|
$ret = $table->dropFields($table) && $ret; |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
//felix |
|
145
|
|
|
// If table has updated field values, update the table |
|
146
|
|
|
if ($table->getUpdatedWhere()) { |
|
147
|
|
|
$ret = $table->updateWhereValues($table) && $ret; |
|
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
echo '</ul>'; |
|
151
|
|
|
|
|
152
|
|
|
return $ret; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.