| Conditions | 14 |
| Paths | 408 |
| Total Lines | 124 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 70 | function DefinitionImport($delete) |
||
|
|
|||
| 71 | { |
||
| 72 | global $xoopsConfig, $xoopsDB, $xoopsModule; |
||
| 73 | $sqlQuery = $xoopsDB->query('SELECT count(id) AS count FROM ' . $xoopsDB->prefix('glossaire')); |
||
| 74 | [$count] = $xoopsDB->fetchRow($sqlQuery); |
||
| 75 | if ($count < 1) { |
||
| 76 | redirect_header('import.php', 1, _AM_LEXIKON_MODULEIMPORTEMPTY10); |
||
| 77 | } |
||
| 78 | |||
| 79 | $delete = 0; |
||
| 80 | $glocounter = 0; |
||
| 81 | $errorcounter = 0; |
||
| 82 | |||
| 83 | if (isset($delete)) { |
||
| 84 | $delete = \Xmf\Request::getInt('delete', 0, 'POST'); |
||
| 85 | } else { |
||
| 86 | if (isset($delete)) { |
||
| 87 | $delete = \Xmf\Request::getInt('delete', 0, 'POST'); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | /**** |
||
| 92 | * delete all entries and categories without comments |
||
| 93 | ****/ |
||
| 94 | if ($delete) { |
||
| 95 | // delete notifications |
||
| 96 | xoops_notification_deletebymodule($xoopsModule->getVar('mid')); |
||
| 97 | //get all entries |
||
| 98 | $result3 = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . ' '); |
||
| 99 | //delete comments for each entry |
||
| 100 | while (list($entryID) = $xoopsDB->fetchRow($result3)) { |
||
| 101 | xoops_comment_delete($xoopsModule->getVar('mid'), $entryID); |
||
| 102 | } |
||
| 103 | $resultC = $xoopsDB->query('SELECT categoryID FROM ' . $xoopsDB->prefix('lxcategories') . ' '); |
||
| 104 | while (list($categoryID) = $xoopsDB->fetchRow($resultC)) { |
||
| 105 | // delete permissions |
||
| 106 | xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'lexikon_view', $categoryID); |
||
| 107 | xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'lexikon_submit', $categoryID); |
||
| 108 | xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'lexikon_approve', $categoryID); |
||
| 109 | xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'lexikon_request', $categoryID); |
||
| 110 | } |
||
| 111 | // delete everything |
||
| 112 | $sqlquery1 = $xoopsDB->queryF('TRUNCATE TABLE ' . $xoopsDB->prefix('lxentries')); |
||
| 113 | $sqlquery2 = $xoopsDB->queryF('TRUNCATE TABLE ' . $xoopsDB->prefix('lxcategories')); |
||
| 114 | } |
||
| 115 | |||
| 116 | /**** |
||
| 117 | * Import ENTRIES |
||
| 118 | ****/ |
||
| 119 | $sqlQuery = $xoopsDB->query( |
||
| 120 | 'SELECT id, lettre, nom, definition, affiche |
||
| 121 | FROM ' . $xoopsDB->prefix('glossaire') |
||
| 122 | ); |
||
| 123 | $fecha = time() - 1; |
||
| 124 | while (false !== ($sqlfetch = $xoopsDB->fetchArray($sqlQuery))) { |
||
| 125 | $glo = []; |
||
| 126 | $glo['id'] = $sqlfetch['id']; |
||
| 127 | $glo['lettre'] = $sqlfetch['lettre']; |
||
| 128 | $glo['nom'] = import2db($sqlfetch['nom']); |
||
| 129 | $glo['definition'] = import2db($sqlfetch['definition']); |
||
| 130 | $glo['affiche'] = ++$fecha; |
||
| 131 | |||
| 132 | ++$glocounter; |
||
| 133 | |||
| 134 | if ($delete) { |
||
| 135 | $insert = $xoopsDB->queryF( |
||
| 136 | ' |
||
| 137 | INSERT INTO ' . $xoopsDB->prefix('lxentries') . " |
||
| 138 | (entryID, init, term, definition, url, submit, datesub, offline, comments) |
||
| 139 | VALUES ('" . $glo['id'] . "','" . $glo['lettre'] . "','" . $glo['nom'] . "','" . $glo['definition'] . "','','','" . $glo['affiche'] . "','','')" |
||
| 140 | ); |
||
| 141 | } else { |
||
| 142 | $insert = $xoopsDB->queryF( |
||
| 143 | ' |
||
| 144 | INSERT INTO ' . $xoopsDB->prefix('lxentries') . " |
||
| 145 | (entryID, init, term, definition, url, submit, datesub, offline, comments) |
||
| 146 | VALUES ('','" . $glo['lettre'] . "','" . $glo['nom'] . "','" . $glo['definition'] . "','','','" . $glo['affiche'] . "','','')" |
||
| 147 | ); |
||
| 148 | } |
||
| 149 | if (!$insert) { |
||
| 150 | ++$errorcounter; |
||
| 151 | showerror('<br>' . _AM_LEXIKON_IMPORT_ERROR_IMPORT_TERM . ': <span style="color:red">entryID: ' . $glo['id'] . '</span>: ' . $glo['nom'] . ' ...'); |
||
| 152 | } |
||
| 153 | // update user posts count |
||
| 154 | if ($ret1) { |
||
| 155 | if ($uid) { |
||
| 156 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 157 | $memberHandler = xoops_getHandler('member'); |
||
| 158 | $submitter = $memberHandler->getUser($uid); |
||
| 159 | if (is_object($submitter)) { |
||
| 160 | $submitter->setVar('posts', $submitter->getVar('posts') + 1); |
||
| 161 | $res = $memberHandler->insertUser($submitter, true); |
||
| 162 | unset($submitter); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | } |
||
| 167 | |||
| 168 | $sqlQuery = $xoopsDB->query( |
||
| 169 | ' |
||
| 170 | SELECT mid |
||
| 171 | FROM ' . $xoopsDB->prefix('modules') . " |
||
| 172 | WHERE dirname = 'glossaire'" |
||
| 173 | ); |
||
| 174 | [$gloID] = $xoopsDB->fetchRow($sqlQuery); |
||
| 175 | echo '<p>' . _AM_LEXIKON_IMPORT_MODULE_ID . ': ' . $gloID . '</p>'; |
||
| 176 | echo '<p>' . _AM_LEXIKON_IMPORT_MODULE_LEX_ID . ': ' . $xoopsModule->getVar('mid') . '<br>'; |
||
| 177 | |||
| 178 | $comentario = $xoopsDB->queryF( |
||
| 179 | 'UPDATE ' . $xoopsDB->prefix('xoopscomments') . " |
||
| 180 | SET com_modid = '" . $xoopsModule->getVar('mid') . "' |
||
| 181 | WHERE com_modid = '" . $gloID . "'" |
||
| 182 | ); |
||
| 183 | if (!$comentario) { |
||
| 184 | showerror(_AM_LEXIKON_IMPORT_ERROR_IMPORT_COMMENT . ': ...'); |
||
| 185 | } else { |
||
| 186 | showerror(_AM_LEXIKON_IMPORT_COMMENT . ': '); |
||
| 187 | } |
||
| 188 | echo '<p>' . _AM_LEXIKON_IMPORT_UPDATE_COUNT . '</p>'; |
||
| 189 | echo "<p><span style='color:red'>" . _AM_LEXIKON_IMPORT_INCORRECTLY . ': ' . $errorcounter . '</span></p>'; |
||
| 190 | echo '<p>' . _AM_LEXIKON_IMPORT_PROCESSED . ': ' . $glocounter . '</p>'; |
||
| 191 | echo '<h3>' . _AM_LEXIKON_IMPORT_FINISH . '</h3>'; |
||
| 192 | echo "<br><b><a href='import.php'>" . _AM_LEXIKON_IMPORT_TO_ADMIN . '</a></b><p>'; |
||
| 193 | require_once __DIR__ . '/admin_footer.php'; |
||
| 194 | } |
||
| 246 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.