| Conditions | 12 |
| Paths | 226 |
| Total Lines | 130 |
| Code Lines | 110 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 154 | function importWfdownloads($shots = '', $catimg = '') |
||
| 155 | { |
||
| 156 | $ok = \Xmf\Request::getInt('ok', 0, 'POST'); |
||
| 157 | global $xoopsDB; |
||
| 158 | if (1 === $ok) { |
||
| 159 | //Vider les tables |
||
| 160 | $myTables = ['tdmdownloads_broken', 'tdmdownloads_cat', 'tdmdownloads_downloads', 'tdmdownloads_fielddata', 'tdmdownloads_modfielddata', 'tdmdownloads_votedata']; |
||
| 161 | $table = new \Xmf\Database\TableLoad(); |
||
| 162 | $tables = new \Xmf\Database\Tables(); |
||
| 163 | foreach ($myTables as $myTable) { |
||
| 164 | if ($tables->useTable($myTable)) { // if this returns false, there is no table |
||
| 165 | $table::truncateTable($myTable); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | //Inserer les données des catégories |
||
| 170 | $query_topic = $xoopsDB->query('SELECT cid, pid, title, imgurl, description, total, summary, spotlighttop, spotlighthis, dohtml, dosmiley, doxcode, doimage, dobr, weight, formulize_fid FROM ' . $xoopsDB->prefix('wfdownloads_cat')); |
||
| 171 | while (false !== ($donnees = $xoopsDB->fetchArray($query_topic))) { |
||
| 172 | if ('' === $donnees['imgurl']) { |
||
| 173 | $img = 'blank.gif'; |
||
| 174 | } else { |
||
| 175 | $img = $donnees['imgurl']; |
||
| 176 | @copy($catimg . $img, XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/cats/' . $img); |
||
| 177 | } |
||
| 178 | $insert = $xoopsDB->queryF('INSERT INTO ' |
||
| 179 | . $xoopsDB->prefix('tdmdownloads_cat') |
||
| 180 | . " (cat_cid, cat_pid, cat_title, cat_imgurl, cat_description_main, cat_weight ) VALUES ('" |
||
| 181 | . $donnees['cid'] |
||
| 182 | . "', '" |
||
| 183 | . $donnees['pid'] |
||
| 184 | . "', '" |
||
| 185 | . addcslashes($donnees['title'], "'") |
||
| 186 | . "', '" |
||
| 187 | . $img |
||
| 188 | . "', '" |
||
| 189 | . addcslashes($donnees['description'], "'") |
||
| 190 | . "', '" |
||
| 191 | . $donnees['weight'] |
||
| 192 | . "')"); |
||
| 193 | if (!$insert) { |
||
| 194 | echo '<span style="color: #ff0000; ">' . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA . ': </span> ' . $donnees['title'] . '<br>'; |
||
| 195 | } |
||
| 196 | echo sprintf(_AM_TDMDOWNLOADS_IMPORT_CAT_IMP . '<br>', $donnees['title']); |
||
| 197 | } |
||
| 198 | echo '<br>'; |
||
| 199 | |||
| 200 | //Inserer les données des téléchargemnts |
||
| 201 | $query_links = $xoopsDB->query('SELECT lid, cid, title, url, filename, filetype, homepage, version, size, platform, screenshot, screenshot2, screenshot3, screenshot4, submitter, publisher, status, date, hits, rating, votes, comments, license, mirror, price, paypalemail, features, requirements, homepagetitle, forumid, limitations, versiontypes, dhistory, published, expired, updated, offline, summary, description, ipaddress, notifypub, formulize_idreq FROM ' |
||
| 202 | . $xoopsDB->prefix('wfdownloads_downloads')); |
||
| 203 | while (false !== ($donnees = $xoopsDB->fetchArray($query_links))) { |
||
| 204 | if ('' === $donnees['url']) { |
||
| 205 | $newurl = XOOPS_URL . '/uploads/' . $donnees['filename']; |
||
| 206 | } else { |
||
| 207 | $newurl = $donnees['url']; |
||
| 208 | } |
||
| 209 | $insert = $xoopsDB->queryF('INSERT INTO ' |
||
| 210 | . $xoopsDB->prefix('tdmdownloads_downloads') |
||
| 211 | . " ( |
||
| 212 | lid, cid, title, url, homepage, version, size, platform, description, logourl, submitter, status, date, hits, rating, votes, comments, top) VALUES |
||
| 213 | ('" |
||
| 214 | . $donnees['lid'] |
||
| 215 | . "', '" |
||
| 216 | . $donnees['cid'] |
||
| 217 | . "', '" |
||
| 218 | . addcslashes($donnees['title'], "'") |
||
| 219 | . "', '" |
||
| 220 | . $newurl |
||
| 221 | . "', '" |
||
| 222 | . $donnees['homepage'] |
||
| 223 | . "', '" |
||
| 224 | . $donnees['version'] |
||
| 225 | . "', '" |
||
| 226 | . $donnees['size'] |
||
| 227 | . "', '" |
||
| 228 | . $donnees['platform'] |
||
| 229 | . "', '" |
||
| 230 | . addcslashes($donnees['description'], "'") |
||
| 231 | . "', '" |
||
| 232 | . $donnees['screenshot'] |
||
| 233 | . "', '" |
||
| 234 | . $donnees['submitter'] |
||
| 235 | . "', '" |
||
| 236 | . $donnees['status'] |
||
| 237 | . "', '" |
||
| 238 | . $donnees['date'] |
||
| 239 | . "', '" |
||
| 240 | . $donnees['hits'] |
||
| 241 | . "', '" |
||
| 242 | . $donnees['rating'] |
||
| 243 | . "', '" |
||
| 244 | . $donnees['votes'] |
||
| 245 | . "', '0', '0' )"); |
||
| 246 | |||
| 247 | if (!$insert) { |
||
| 248 | echo '<span style="color: #ff0000; ">' . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA . ': </span> ' . $donnees['title'] . '<br>'; |
||
| 249 | } |
||
| 250 | echo sprintf(_AM_TDMDOWNLOADS_IMPORT_DOWNLOADS_IMP . '<br>', $donnees['title']); |
||
| 251 | @copy($shots . $donnees['screenshot'], XOOPS_ROOT_PATH . '/uploads/' . $moduleDirName . '/images/shots/' . $donnees['screenshot']); |
||
| 252 | } |
||
| 253 | echo '<br>'; |
||
| 254 | |||
| 255 | //Inserer les données des votes |
||
| 256 | $query_vote = $xoopsDB->query('SELECT ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ' . $xoopsDB->prefix('wfdownloads_votedata')); |
||
| 257 | while (false !== ($donnees = $xoopsDB->fetchArray($query_vote))) { |
||
| 258 | $insert = $xoopsDB->queryF('INSERT INTO ' |
||
| 259 | . $xoopsDB->prefix('tdmdownloads_votedata') |
||
| 260 | . " (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp ) VALUES ('" |
||
| 261 | . $donnees['ratingid'] |
||
| 262 | . "', '" |
||
| 263 | . $donnees['lid'] |
||
| 264 | . "', '" |
||
| 265 | . $donnees['ratinguser'] |
||
| 266 | . "', '" |
||
| 267 | . $donnees['rating'] |
||
| 268 | . "', '" |
||
| 269 | . $donnees['ratinghostname'] |
||
| 270 | . "', '" |
||
| 271 | . $donnees['ratingtimestamp'] |
||
| 272 | . "')"); |
||
| 273 | if (!$insert) { |
||
| 274 | echo '<span style="color: #ff0000; ">' . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA . ': </span> ' . $donnees['ratingid'] . '<br>'; |
||
| 275 | } |
||
| 276 | echo sprintf(_AM_TDMDOWNLOADS_IMPORT_VOTE_IMP . '<br>', $donnees['ratingid']); |
||
| 277 | } |
||
| 278 | echo '<br><br>'; |
||
| 279 | echo "<div class='errorMsg'>"; |
||
| 280 | echo _AM_TDMDOWNLOADS_IMPORT_OK; |
||
| 281 | echo '</div>'; |
||
| 282 | } else { |
||
| 283 | xoops_confirm(['op' => 'importWfdownloads', 'ok' => 1, 'shots' => $shots, 'catimg' => $catimg], 'import.php', _AM_TDMDOWNLOADS_IMPORT_CONF_WFDOWNLOADS . '<br>'); |
||
| 284 | } |
||
| 393 |
If you suppress an error, we recommend checking for the error condition explicitly: