| Conditions | 9 |
| Paths | 42 |
| Total Lines | 52 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 55 | function update_tdmcreate_v191(&$module) |
||
| 56 | { |
||
| 57 | global $xoopsDB; |
||
| 58 | $result = $xoopsDB->query( |
||
| 59 | 'SELECT t1.tpl_id FROM ' . $xoopsDB->prefix('tplfile') . ' t1, ' . $xoopsDB->prefix('tplfile') |
||
| 60 | . ' t2 WHERE t1.tpl_refid = t2.tpl_refid AND t1.tpl_module = t2.tpl_module AND t1.tpl_tplset=t2.tpl_tplset AND t1.tpl_file = t2.tpl_file AND t1.tpl_type = t2.tpl_type AND t1.tpl_id > t2.tpl_id' |
||
| 61 | ); |
||
| 62 | $tplids = []; |
||
| 63 | while (list($tplid) = $xoopsDB->fetchRow($result)) { |
||
| 64 | $tplids[] = $tplid; |
||
| 65 | } |
||
| 66 | if (count($tplids) > 0) { |
||
| 67 | $tplfileHandler = xoops_getHandler('tplfile'); |
||
| 68 | $duplicate_files = $tplfileHandler->getObjects( |
||
| 69 | new \Criteria('tpl_id', '(' . implode(',', $tplids) . ')', 'IN') |
||
| 70 | ); |
||
| 71 | |||
| 72 | if (count($duplicate_files) > 0) { |
||
| 73 | foreach (array_keys($duplicate_files) as $i) { |
||
| 74 | $tplfileHandler->delete($duplicate_files[$i]); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | $sql = 'SHOW INDEX FROM ' . $xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'"; |
||
| 79 | if (!$result = $xoopsDB->queryF($sql)) { |
||
| 80 | xoops_error($this->db->error() . '<br />' . $sql); |
||
| 81 | |||
| 82 | return false; |
||
| 83 | } |
||
| 84 | $ret = []; |
||
| 85 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 86 | $ret[] = $myrow; |
||
| 87 | } |
||
| 88 | if (!empty($ret)) { |
||
| 89 | $module->setErrors( |
||
| 90 | "'tpl_refid_module_set_file_type' unique index is exist. Note: check 'tplfile' table to be sure this index is UNIQUE because XOOPS CORE need it." |
||
| 91 | ); |
||
| 92 | |||
| 93 | return true; |
||
| 94 | } |
||
| 95 | $sql = 'ALTER TABLE ' . $xoopsDB->prefix('tplfile') |
||
| 96 | . ' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )'; |
||
| 97 | if (!$result = $xoopsDB->queryF($sql)) { |
||
| 98 | xoops_error($xoopsDB->error() . '<br />' . $sql); |
||
| 99 | $module->setErrors( |
||
| 100 | "'tpl_refid_module_set_file_type' unique index is not added to 'tplfile' table. Warning: do not use XOOPS until you add this unique index." |
||
| 101 | ); |
||
| 102 | |||
| 103 | return false; |
||
| 104 | } |
||
| 105 | |||
| 106 | return true; |
||
| 107 | } |
||
| 109 |