mambax7 /
smartobject
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * |
||
| 5 | * Module: SmartSection |
||
| 6 | * Author: The SmartFactory <www.smartfactory.ca> |
||
| 7 | * Licence: GNU |
||
| 8 | */ |
||
| 9 | |||
| 10 | use XoopsModules\Wfdownloads; |
||
| 11 | use XoopsModules\Smartobject; |
||
| 12 | |||
| 13 | require_once __DIR__ . '/admin_header.php'; |
||
| 14 | require_once SMARTCONTENT_ROOT_PATH . 'class/dbupdater.php'; |
||
| 15 | |||
| 16 | smartcontent_xoops_cp_header(); |
||
| 17 | |||
| 18 | // ========================================================================================= |
||
| 19 | // This function updates any existing table of a 2.x version to the format used |
||
| 20 | // in the release of WF-Downloads 3.00 |
||
| 21 | // ========================================================================================= |
||
| 22 | function update_tables_to_300() |
||
| 23 | { |
||
| 24 | $dbupdater = new Wfdownloads\Dbupdater(); |
||
| 25 | |||
| 26 | if (!wfdownloads_TableExists('wfdownloads_meta')) { |
||
| 27 | // Create table wfdownloads_meta |
||
| 28 | $table = new Wfdownloads\DbupdaterTable('wfdownloads_meta'); |
||
| 29 | $table->setStructure("CREATE TABLE `%s` ( |
||
| 30 | metakey varchar(50) NOT NULL default '', |
||
| 31 | metavalue varchar(255) NOT NULL default '', |
||
| 32 | PRIMARY KEY (metakey)) |
||
| 33 | ENGINE=MyISAM;"); |
||
| 34 | |||
| 35 | $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2))); |
||
| 36 | if ($dbupdater->updateTable($table)) { |
||
| 37 | echo 'wfdownloads_meta table created<br>'; |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | $download_fields = [ |
||
| 42 | 'lid' => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false], |
||
| 43 | 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 44 | 'title' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
||
| 45 | 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 46 | 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
||
| 47 | 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
||
| 48 | 'homepage' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
||
| 49 | 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
||
| 50 | 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
||
| 51 | 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
||
| 52 | 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 53 | 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 54 | 'publisher' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 55 | 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
||
| 56 | 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
||
| 57 | 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 58 | 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
||
| 59 | 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 60 | 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 61 | 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 62 | 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 63 | 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
||
| 64 | 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 65 | 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 66 | 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 67 | 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 68 | 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 69 | 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
||
| 70 | 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 71 | 'published' => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true], |
||
| 72 | 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
||
| 73 | 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 74 | 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
||
| 75 | 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 76 | 'ipaddress' => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true], |
||
| 77 | 'notifypub' => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true], |
||
| 78 | 'summary' => ['Type' => 'text NOT NULL', 'Default' => false] |
||
| 79 | ]; |
||
| 80 | |||
| 81 | $renamed_fields = [ |
||
| 82 | 'logourl' => 'screenshot' |
||
| 83 | ]; |
||
| 84 | |||
| 85 | echo '<br><b>Checking Download table</b><br>'; |
||
| 86 | $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
||
| 87 | $downloadHandler = $helperWfdownloads->getHandler('Download'); |
||
| 88 | $download_table = new Wfdownloads\DbupdaterTable('wfdownloads_downloads'); |
||
| 89 | $fields = get_table_info($downloadHandler->table, $download_fields); |
||
| 90 | // Check for renamed fields |
||
| 91 | rename_fields($download_table, $renamed_fields, $fields, $download_fields); |
||
| 92 | update_table($download_fields, $fields, $download_table); |
||
| 93 | if ($dbupdater->updateTable($download_table)) { |
||
| 94 | echo 'Downloads table updated<br>'; |
||
| 95 | } |
||
| 96 | unset($fields); |
||
| 97 | |||
| 98 | $mod_fields = [ |
||
| 99 | 'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false], |
||
| 100 | 'lid' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 101 | 'cid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 102 | 'title' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 103 | 'url' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 104 | 'filename' => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true], |
||
| 105 | 'filetype' => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true], |
||
| 106 | 'homepage' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 107 | 'version' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
||
| 108 | 'size' => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true], |
||
| 109 | 'platform' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
||
| 110 | 'screenshot' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 111 | 'submitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 112 | 'publisher' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 113 | 'status' => ['Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true], |
||
| 114 | 'date' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
||
| 115 | 'hits' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 116 | 'rating' => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true], |
||
| 117 | 'votes' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 118 | 'comments' => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 119 | 'license' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 120 | 'mirror' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 121 | 'price' => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true], |
||
| 122 | 'paypalemail' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 123 | 'features' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 124 | 'requirements' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 125 | 'homepagetitle' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 126 | 'forumid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 127 | 'limitations' => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true], |
||
| 128 | 'dhistory' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 129 | 'published' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
||
| 130 | 'expired' => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true], |
||
| 131 | 'updated' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 132 | 'offline' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true], |
||
| 133 | 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 134 | 'description' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 135 | 'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 136 | 'requestdate' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
||
| 137 | ]; |
||
| 138 | |||
| 139 | $renamed_fields = [ |
||
| 140 | 'logourl' => 'screenshot' |
||
| 141 | ]; |
||
| 142 | |||
| 143 | echo '<br><b>Checking Modified Downloads table</b><br>'; |
||
| 144 | // $moduleHandler = xoops_getModuleHandler('modification', 'wfdownloads'); |
||
| 145 | $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
||
| 146 | $moduleHandler = $helperWfdownloads->getHandler('Modification'); |
||
| 147 | $mod_table = new Wfdownloads\DbupdaterTable('wfdownloads_mod'); |
||
| 148 | $fields = get_table_info($moduleHandler->table, $mod_fields); |
||
| 149 | rename_fields($mod_table, $renamed_fields, $fields, $mod_fields); |
||
| 150 | update_table($mod_fields, $fields, $mod_table); |
||
| 151 | if ($dbupdater->updateTable($mod_table)) { |
||
| 152 | echo 'Modified Downloads table updated <br>'; |
||
| 153 | } |
||
| 154 | unset($fields); |
||
| 155 | |||
| 156 | $cat_fields = [ |
||
| 157 | 'cid' => ['Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false], |
||
| 158 | 'pid' => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true], |
||
| 159 | 'title' => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true], |
||
| 160 | 'imgurl' => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true], |
||
| 161 | 'description' => ['Type' => 'text NULL', 'Default' => true], |
||
| 162 | 'total' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 163 | 'summary' => ['Type' => 'text NOT NULL', 'Default' => false], |
||
| 164 | 'spotlighttop' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 165 | 'spotlighthis' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 166 | 'dohtml' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
||
| 167 | 'dosmiley' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
||
| 168 | 'doxcode' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
||
| 169 | 'doimage' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
||
| 170 | 'dobr' => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true], |
||
| 171 | 'weight' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true] |
||
| 172 | ]; |
||
| 173 | echo '<br><b>Checking Category table</b><br>'; |
||
| 174 | // $catHandler = xoops_getModuleHandler('category', 'wfdownloads'); |
||
| 175 | $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
||
| 176 | $catHandler = $helperWfdownloads->getHandler('Report'); |
||
| 177 | |||
| 178 | $cat_table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
||
| 179 | $fields = get_table_info($catHandler->table, $cat_fields); |
||
| 180 | update_table($cat_fields, $fields, $cat_table); |
||
| 181 | if ($dbupdater->updateTable($cat_table)) { |
||
| 182 | echo 'Category table updated<br>'; |
||
| 183 | } |
||
| 184 | unset($fields); |
||
| 185 | |||
| 186 | $broken_fields = [ |
||
| 187 | 'reportid' => ['Type' => 'int(5) NOT NULL auto_increment', 'Default' => false], |
||
| 188 | 'lid' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 189 | 'sender' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true], |
||
| 190 | 'ip' => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true], |
||
| 191 | 'date' => ['Type' => "varchar(11) NOT NULL default '0'", 'Default' => true], |
||
| 192 | 'confirmed' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true], |
||
| 193 | 'acknowledged' => ['Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true] |
||
| 194 | ]; |
||
| 195 | echo '<br><b>Checking Broken Report table</b><br>'; |
||
| 196 | $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
||
| 197 | $brokenHandler = $helperWfdownloads->getHandler('Report'); |
||
| 198 | // $brokenHandler = xoops_getModuleHandler('report', 'wfdownloads'); |
||
| 199 | $broken_table = new Wfdownloads\DbupdaterTable('wfdownloads_broken'); |
||
| 200 | $fields = get_table_info($brokenHandler->table, $broken_fields); |
||
| 201 | update_table($broken_fields, $fields, $broken_table); |
||
| 202 | if ($dbupdater->updateTable($broken_table)) { |
||
| 203 | echo 'Broken Reports table updated<br>'; |
||
| 204 | } |
||
| 205 | unset($fields); |
||
| 206 | } |
||
| 207 | |||
| 208 | // ========================================================================================= |
||
| 209 | // we are going to change the names for the fields like nohtml, nosmilies, noxcode, noimage, nobreak in |
||
| 210 | // the wfdownloads_cat table into dohtml, dosmilies and so on. Therefore the logic will change |
||
| 211 | // 0=yes 1=no and the currently stored value need to be changed accordingly |
||
| 212 | // ========================================================================================= |
||
| 213 | /** |
||
| 214 | * @return array|bool |
||
| 215 | */ |
||
| 216 | function invert_nohtm_dohtml_values() |
||
| 217 | { |
||
| 218 | $ret = []; |
||
| 219 | global $xoopsDB; |
||
| 220 | $helperWfdownloads = \Xmf\Module\Helper::getHelper('wfdownloads'); |
||
| 221 | $catHandler = $helperWfdownloads->getHandler('Category'); |
||
| 222 | $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table); |
||
| 223 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
||
| 224 | $fields[$existing_field['field']] = $existing_field['type']; |
||
| 225 | } |
||
| 226 | if (in_array('nohtml', array_keys($fields))) { |
||
|
0 ignored issues
–
show
|
|||
| 227 | $dbupdater = new Wfdownloads\Dbupdater(); |
||
| 228 | //Invert column values |
||
| 229 | // alter options in wfdownloads_cat |
||
| 230 | $table = new Wfdownloads\DbupdaterTable('wfdownloads_cat'); |
||
| 231 | $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'"); |
||
| 232 | $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'"); |
||
| 233 | $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'"); |
||
| 234 | $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'"); |
||
| 235 | $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'"); |
||
| 236 | |||
| 237 | //inverting values no=1 <=> do=0 |
||
| 238 | // have to store teporarly as value = 2 to |
||
| 239 | // avoid putting everithing to same value |
||
| 240 | // if you change 1 to 0, then 0 to one, |
||
| 241 | // every value will be 1, follow me? |
||
| 242 | $table->addUpdatedWhere('dohtml', 2, '=1'); |
||
| 243 | $table->addUpdatedWhere('dohtml', 1, '=0'); |
||
| 244 | $table->addUpdatedWhere('dohtml', 0, '=2'); |
||
| 245 | |||
| 246 | $table->addUpdatedWhere('dosmiley', 2, '=1'); |
||
| 247 | $table->addUpdatedWhere('dosmiley', 1, '=0'); |
||
| 248 | $table->addUpdatedWhere('dosmiley', 0, '=2'); |
||
| 249 | |||
| 250 | $table->addUpdatedWhere('doxcode', 2, '=1'); |
||
| 251 | $table->addUpdatedWhere('doxcode', 1, '=0'); |
||
| 252 | $table->addUpdatedWhere('doxcode', 0, '=2'); |
||
| 253 | |||
| 254 | $table->addUpdatedWhere('doimage', 2, '=1'); |
||
| 255 | $table->addUpdatedWhere('doimage', 1, '=0'); |
||
| 256 | $table->addUpdatedWhere('doimage', 0, '=2'); |
||
| 257 | $ret = $dbupdater->updateTable($table); |
||
| 258 | } |
||
| 259 | |||
| 260 | return $ret; |
||
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Updates a table by comparing correct fields with existing ones |
||
| 265 | * |
||
| 266 | * @param array $new_fields |
||
| 267 | * @param array $existing_fields |
||
| 268 | * @param Wfdownloads\DbupdaterTable $table |
||
| 269 | * @return void |
||
| 270 | */ |
||
| 271 | function update_table($new_fields, $existing_fields, &$table) |
||
| 272 | { |
||
| 273 | foreach ($new_fields as $field => $fieldinfo) { |
||
| 274 | $type = $fieldinfo['Type']; |
||
| 275 | if (!in_array($field, array_keys($existing_fields))) { |
||
| 276 | //Add field as it is missing |
||
| 277 | $table->addNewField($field, $type); |
||
| 278 | //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type); |
||
| 279 | //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br>"; |
||
| 280 | } elseif ($existing_fields[$field] != $type) { |
||
| 281 | $table->addAlteredField($field, $field . ' ' . $type); |
||
| 282 | // check $fields[$field]['type'] for things like "int(10) unsigned" |
||
| 283 | //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type); |
||
| 284 | //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br>"; |
||
| 285 | } else { |
||
| 286 | //echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br>"; |
||
| 287 | } |
||
| 288 | } |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Get column information for a table - we'll need to send along an array of fields to determine |
||
| 293 | * whether the "Default" index value should be appended |
||
| 294 | * |
||
| 295 | * @param string $table |
||
| 296 | * @param array $default_fields |
||
| 297 | * @return array |
||
| 298 | */ |
||
| 299 | function get_table_info($table, $default_fields) |
||
| 300 | { |
||
| 301 | global $xoopsDB; |
||
| 302 | $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table); |
||
| 303 | while (false !== ($existing_field = $xoopsDB->fetchArray($result))) { |
||
| 304 | $fields[$existing_field['Field']] = $existing_field['Type']; |
||
| 305 | if ('YES' !== $existing_field['Null']) { |
||
| 306 | $fields[$existing_field['Field']] .= ' NOT NULL'; |
||
| 307 | } |
||
| 308 | if ($existing_field['Extra']) { |
||
| 309 | $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
||
| 310 | } |
||
| 311 | if ($default_fields[$existing_field['Field']]['Default']) { |
||
| 312 | $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
||
| 313 | } |
||
| 314 | } |
||
| 315 | |||
| 316 | return $fields; |
||
|
0 ignored issues
–
show
The variable
$fields does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Renames fields in a table and updates the existing fields array to reflect it. |
||
| 321 | * |
||
| 322 | * @param Wfdownloads\DbupdaterTable $table |
||
| 323 | * @param array $renamed_fields |
||
| 324 | * @param array $fields |
||
| 325 | * @param array $new_fields |
||
| 326 | * @return void |
||
| 327 | */ |
||
| 328 | function rename_fields(&$table, $renamed_fields, &$fields, $new_fields) |
||
| 329 | { |
||
| 330 | foreach (array_keys($fields) as $field) { |
||
| 331 | if (in_array($field, array_keys($renamed_fields))) { |
||
| 332 | $new_field_name = $renamed_fields[$field]; |
||
| 333 | $new_field_type = $new_fields[$new_field_name]['Type']; |
||
| 334 | $table->addAltered($field, $new_field_name . ' ' . $new_field_type); |
||
| 335 | //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type); |
||
| 336 | //echo $field." Renamed to ".$new_field_name."<br>"; |
||
| 337 | $fields[$new_field_name] = $new_field_type; |
||
| 338 | } |
||
| 339 | } |
||
| 340 | //return $fields; |
||
| 341 | } |
||
| 342 | |||
| 343 | $op = \Xmf\Request::getInt('op', 0, 'REQUEST'); |
||
| 344 | switch ($op) { |
||
| 345 | case 1: |
||
| 346 | // Make sure that nohtml is properly changed to dohtml |
||
| 347 | invert_nohtm_dohtml_values(); |
||
| 348 | // Ensure that the proper tables are present |
||
| 349 | update_tables_to_300(); |
||
| 350 | // Import data from MyDownloads |
||
| 351 | import_mydownloads_to_wfdownloads(); |
||
| 352 | break; |
||
| 353 | |||
| 354 | case 2: |
||
| 355 | // Update WF-Downloads |
||
| 356 | $log = invert_nohtm_dohtml_values(); |
||
| 357 | update_tables_to_300(); |
||
| 358 | break; |
||
| 359 | |||
| 360 | default: |
||
| 361 | //ask what to do |
||
| 362 | include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 363 | $form = new \XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']); |
||
| 364 | |||
| 365 | //Is MyDownloads installed? |
||
| 366 | /** @var XoopsModuleHandler $moduleHandler */ |
||
| 367 | $moduleHandler = xoops_getHandler('module'); |
||
| 368 | $mydownloadsModule = $moduleHandler->getByDirname('mydownloads'); |
||
| 369 | if (is_object($mydownloadsModule)) { |
||
| 370 | $mydownloadsButton = new \XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit'); |
||
| 371 | $mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'"); |
||
| 372 | $form->addElement($mydownloadsButton); |
||
| 373 | } |
||
| 374 | |||
| 375 | if (!wfdownloads_TableExists('wfdownloads_meta')) { |
||
| 376 | $updateButton = new \XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit'); |
||
| 377 | $updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'"); |
||
| 378 | $form->addElement($updateButton); |
||
| 379 | } |
||
| 380 | |||
| 381 | $form->addElement(new \XoopsFormHidden('op', 0)); |
||
| 382 | $form->display(); |
||
| 383 | break; |
||
| 384 | } |
||
| 385 | //wfdownloads_modFooter(); |
||
| 386 | //xoops_cp_footer(); |
||
| 387 | require_once __DIR__ . '/admin_footer.php'; |
||
| 388 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: