Conditions | 11 |
Paths | 384 |
Total Lines | 122 |
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 |
||
62 | function xoops_module_update_xnewsletter_130() |
||
63 | { |
||
64 | // change module dirname to lowercase |
||
65 | $path = dirname(__DIR__); |
||
66 | $dirname = basename(dirname(__DIR__)); |
||
67 | rename($path, mb_strtolower($dirname)); |
||
68 | // update module dirname field in database to lowercase |
||
69 | global $xoopsDB; |
||
70 | $sql = "UPDATE `{$xoopsDB->prefix('modules')}` SET `dirname` = '" . mb_strtolower($dirname) . "'"; |
||
71 | $sql .= " WHERE LOWER(`dirname`) = '" . mb_strtolower($dirname) . "';"; |
||
72 | $result = $xoopsDB->queryF($sql); |
||
73 | if (!$result) { |
||
74 | echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": UPDATE 'modules' SET `dirname` = '" . mb_strtolower($dirname) . "'"; |
||
75 | } |
||
76 | |||
77 | // reverse 'mod_' prefix on tables |
||
78 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_accounts'); |
||
79 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_attachment'); |
||
80 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_bmh'); |
||
81 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_cat'); |
||
82 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_catsubscr'); |
||
83 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_import'); |
||
84 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_letter'); |
||
85 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_mailinglist'); |
||
86 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_protocol'); |
||
87 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_subscr'); |
||
88 | xoops_module_update_xnewsletter_rename_mod_table('xnewsletter_task'); |
||
89 | $sql = sprintf('DROP TABLE IF EXISTS `' . $xoopsDB->prefix('xnewsletter_template') . '`'); |
||
90 | |||
91 | // create 'xnewsletter_template' table |
||
92 | global $xoopsDB; |
||
93 | $sql = sprintf('DROP TABLE IF EXISTS `' . $xoopsDB->prefix('xnewsletter_template') . '`'); |
||
94 | $result = $xoopsDB->queryF($sql); |
||
95 | if (!$result) { |
||
96 | echo '<br>' . _AM_XNEWSLETTER_UPGRADEFAILED . ": 'DROP TABLE 'xnewsletter_template'"; |
||
97 | } |
||
98 | |||
99 | $sql = ' |
||
100 | CREATE TABLE `' . $xoopsDB->prefix('xnewsletter_template') . "` ( |
||
101 | `template_id` INT (8) NOT NULL AUTO_INCREMENT, |
||
102 | `template_title` VARCHAR (100) NOT NULL DEFAULT '', |
||
103 | `template_description` TEXT NOT NULL DEFAULT '', |
||
104 | `template_content` TEXT NOT NULL DEFAULT '', |
||
105 | `template_submitter` INT (8) NOT NULL DEFAULT '0', |
||
106 | `template_created` INT (8) NOT NULL DEFAULT '0', |
||
107 | PRIMARY KEY (`template_id`) |
||
108 | ) ENGINE=MyISAM;"; |
||
109 | $result = $xoopsDB->queryF($sql); |
||
110 | if (!$result) { |
||
111 | echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": CREATE TABLE 'xnewsletter_template'"; |
||
112 | } |
||
113 | |||
114 | // add fields to 'xnewsletter_cat' table |
||
115 | global $xoopsDB; |
||
116 | $sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_cat') . '`'; |
||
117 | $sql .= " ADD COLUMN `dohtml` tinyint(1) NOT NULL default '0',"; |
||
118 | $sql .= " ADD COLUMN `dosmiley` tinyint(1) NOT NULL default '1',"; |
||
119 | $sql .= " ADD COLUMN `doxcode` tinyint(1) NOT NULL default '1',"; |
||
120 | $sql .= " ADD COLUMN `doimage` tinyint(1) NOT NULL default '1',"; |
||
121 | $sql .= " ADD COLUMN `dobr` tinyint(1) NOT NULL default '1';"; |
||
122 | $result = $xoopsDB->queryF($sql); |
||
123 | if (!$result) { |
||
124 | echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_cat' ADD"; |
||
125 | } |
||
126 | |||
127 | // add fields to 'xnewsletter_letter' table |
||
128 | global $xoopsDB; |
||
129 | $sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_letter') . '`'; |
||
130 | $sql .= " ADD COLUMN `letter_sender` int(8) NOT NULL default '0',"; |
||
131 | $sql .= " ADD COLUMN `letter_sent` int(10) NOT NULL default '0';"; |
||
132 | $result = $xoopsDB->queryF($sql); |
||
133 | if (!$result) { |
||
134 | echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_letter' ADD"; |
||
135 | } |
||
136 | |||
137 | // add fields to 'xnewsletter_attachment' table |
||
138 | global $xoopsDB; |
||
139 | $sql = 'ALTER TABLE `' . $xoopsDB->prefix('xnewsletter_attachment') . '`'; |
||
140 | $sql .= " ADD COLUMN `attachment_size` int(8) NOT NULL default '0',"; |
||
141 | $sql .= " ADD COLUMN `attachment_mode` int(8) NOT NULL default '0';"; |
||
142 | $result = $xoopsDB->queryF($sql); |
||
143 | if (!$result) { |
||
144 | echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_attachment' ADD"; |
||
145 | } |
||
146 | |||
147 | // update fields 'xnewsletter_attachment' table |
||
148 | global $xoopsDB; |
||
149 | $sql = 'UPDATE `' . $xoopsDB->prefix('xnewsletter_letter') . '`'; |
||
150 | $sql .= " SET `letter_sent` = '1';"; |
||
151 | $result = $xoopsDB->queryF($sql); |
||
152 | if (!$result) { |
||
153 | echo '<br>' . _MI_XNEWSLETTER_UPGRADEFAILED . ": ALTER TABLE 'xnewsletter_attachment' ADD"; |
||
154 | } |
||
155 | |||
156 | // delete old html template files |
||
157 | $templateDirectory = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/'; |
||
158 | $template_list = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
||
159 | foreach ($template_list as $k => $v) { |
||
160 | $fileinfo = new \SplFileInfo($templateDirectory . $v); |
||
161 | if ('html' === $fileinfo->getExtension() && 'index.html' !== $fileinfo->getFilename()) { |
||
162 | @unlink($templateDirectory . $v); |
||
163 | } |
||
164 | } |
||
165 | // Load class XoopsFile |
||
166 | xoops_load('xoopsfile'); |
||
167 | |||
168 | //delete /images directory |
||
169 | $imagesDirectory = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/images/'; |
||
170 | $folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
||
171 | $folderHandler->delete($imagesDirectory); |
||
172 | |||
173 | //delete /templates/style.css file |
||
174 | $cssFile = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/style.css'; |
||
175 | $folderHandler = XoopsFile::getHandler('file', $cssFile); |
||
176 | $folderHandler->delete($cssFile); |
||
177 | |||
178 | //delete .html entries from the tpl table |
||
179 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE LOWER(`tpl_module`) = '" . mb_strtolower($dirname) . "' AND `tpl_file` LIKE '%.html%'"; |
||
180 | $GLOBALS['xoopsDB']->queryF($sql); |
||
181 | |||
182 | return true; |
||
183 | } |
||
184 | |||
341 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.