| Conditions | 9 |
| Paths | 42 |
| Total Lines | 53 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 53 | function update_tdmcreate_v191(&$module) |
||
| 54 | { |
||
| 55 | global $xoopsDB; |
||
|
|
|||
| 56 | $result = $xoopsDB->query( |
||
| 57 | 'SELECT t1.tpl_id FROM '.$xoopsDB->prefix('tplfile').' t1, '.$xoopsDB->prefix('tplfile') |
||
| 58 | .' 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' |
||
| 59 | ); |
||
| 60 | $tplids = array(); |
||
| 61 | while (list($tplid) = $xoopsDB->fetchRow($result)) { |
||
| 62 | $tplids[] = $tplid; |
||
| 63 | } |
||
| 64 | if (count($tplids) > 0) { |
||
| 65 | $tplfile_handler = &xoops_getHandler('tplfile'); |
||
| 66 | $duplicate_files = $tplfile_handler->getObjects( |
||
| 67 | new Criteria('tpl_id', '('.implode(',', $tplids).')', 'IN') |
||
| 68 | ); |
||
| 69 | |||
| 70 | if (count($duplicate_files) > 0) { |
||
| 71 | foreach (array_keys($duplicate_files) as $i) { |
||
| 72 | $tplfile_handler->delete($duplicate_files[$i]); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | $sql = 'SHOW INDEX FROM '.$xoopsDB->prefix('tplfile')." WHERE KEY_NAME = 'tpl_refid_module_set_file_type'"; |
||
| 77 | if (!$result = $xoopsDB->queryF($sql)) { |
||
| 78 | xoops_error($this->db->error().'<br />'.$sql); |
||
| 79 | |||
| 80 | return false; |
||
| 81 | } |
||
| 82 | $ret = array(); |
||
| 83 | while ($myrow = $xoopsDB->fetchArray($result)) { |
||
| 84 | $ret[] = $myrow; |
||
| 85 | } |
||
| 86 | if (!empty($ret)) { |
||
| 87 | $module->setErrors( |
||
| 88 | "'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." |
||
| 89 | ); |
||
| 90 | |||
| 91 | return true; |
||
| 92 | } |
||
| 93 | $sql = 'ALTER TABLE '.$xoopsDB->prefix('tplfile') |
||
| 94 | .' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )'; |
||
| 95 | if (!$result = $xoopsDB->queryF($sql)) { |
||
| 96 | xoops_error($xoopsDB->error().'<br />'.$sql); |
||
| 97 | $module->setErrors( |
||
| 98 | "'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." |
||
| 99 | ); |
||
| 100 | |||
| 101 | return false; |
||
| 102 | } |
||
| 103 | |||
| 104 | return true; |
||
| 105 | } |
||
| 106 | // irmtfan bug fix: solve templates duplicate issue |
||
| 108 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state