Conditions | 21 |
Paths | > 20000 |
Total Lines | 153 |
Code Lines | 101 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
54 | function wggithub_check_db($module) |
||
55 | { |
||
56 | $ret = true; |
||
57 | //insert here code for database check |
||
58 | |||
59 | // update table (add new field) |
||
60 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_repositories'); |
||
61 | $field = 'repo_release'; |
||
62 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
63 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
64 | if (!$numRows) { |
||
65 | $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`;"; |
||
66 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
67 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
68 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
69 | $ret = false; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | // update table (add new field) |
||
74 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_repositories'); |
||
75 | $field = 'repo_prerelease'; |
||
76 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
77 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
78 | if (!$numRows) { |
||
79 | $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`;"; |
||
80 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
81 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
82 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
83 | $ret = false; |
||
84 | } |
||
85 | } |
||
86 | // update table (add new field) |
||
87 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_repositories'); |
||
88 | $field = 'repo_readme'; |
||
89 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
90 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
91 | if (!$numRows) { |
||
92 | $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_htmlurl`;"; |
||
93 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
94 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
95 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
96 | $ret = false; |
||
97 | } |
||
98 | } |
||
99 | |||
100 | // update table (add new field) |
||
101 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_directories'); |
||
102 | $field = 'dir_filterrelease'; |
||
103 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
104 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
105 | if (!$numRows) { |
||
106 | $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `dir_online`;"; |
||
107 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
108 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
109 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
110 | $ret = false; |
||
111 | } |
||
112 | } |
||
113 | |||
114 | // create new table |
||
115 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_logs'); |
||
116 | $check = $GLOBALS['xoopsDB']->queryF("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='$table'"); |
||
117 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
118 | if (!$numRows) { |
||
119 | // create new table |
||
120 | $sql = "CREATE TABLE `$table` ( |
||
121 | `log_id` INT(8) UNSIGNED NOT NULL AUTO_INCREMENT, |
||
122 | `log_type` INT(1) NOT NULL DEFAULT '0', |
||
123 | `log_details` VARCHAR(255) NOT NULL DEFAULT '', |
||
124 | `log_result` TEXT NOT NULL , |
||
125 | `log_datecreated` INT(11) NOT NULL DEFAULT '0', |
||
126 | `log_submitter` INT(10) NOT NULL DEFAULT '0', |
||
127 | PRIMARY KEY (`log_id`) |
||
128 | ) ENGINE=InnoDB;"; |
||
129 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
130 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
131 | $module->setErrors("Error when creating table '$table'."); |
||
132 | $ret = false; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | // update table (add new field) |
||
137 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_directories'); |
||
138 | $field = 'dir_content'; |
||
139 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
140 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
141 | if (!$numRows) { |
||
142 | $sql = "ALTER TABLE `$table` ADD `$field` INT(10) NOT NULL DEFAULT '0' AFTER `dir_type`;"; |
||
143 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
144 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
145 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
146 | $ret = false; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | // update table (add new field) |
||
151 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_directories'); |
||
152 | $field = 'dir_descr'; |
||
153 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
154 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
155 | if (!$numRows) { |
||
156 | $sql = "ALTER TABLE `$table` ADD `$field` TEXT NOT NULL AFTER `dir_type`;"; |
||
157 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
158 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
159 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
160 | $ret = false; |
||
161 | } |
||
162 | } |
||
163 | |||
164 | // update table (add new field) |
||
165 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_readmes'); |
||
166 | $field = 'rm_baseurl'; |
||
167 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
168 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
169 | if (!$numRows) { |
||
170 | $sql = "ALTER TABLE `$table` ADD `$field` VARCHAR(255) NOT NULL DEFAULT '' AFTER `rm_downloadurl`;"; |
||
171 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
172 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
173 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
174 | $ret = false; |
||
175 | } |
||
176 | } |
||
177 | |||
178 | // update table (add new field) |
||
179 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_directories'); |
||
180 | $field = 'dir_weight'; |
||
181 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
182 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
183 | if (!$numRows) { |
||
184 | $sql = "ALTER TABLE `$table` ADD `$field` INT(10) NOT NULL DEFAULT '0' AFTER `dir_filterrelease`;"; |
||
185 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
186 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
187 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
188 | $ret = false; |
||
189 | } |
||
190 | } |
||
191 | |||
192 | // update table (add new field) |
||
193 | $table = $GLOBALS['xoopsDB']->prefix('wggithub_repositories'); |
||
194 | $field = 'repo_approved'; |
||
195 | $check = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'"); |
||
196 | $numRows = $GLOBALS['xoopsDB']->getRowsNum($check); |
||
197 | if (!$numRows) { |
||
198 | $sql = "ALTER TABLE `$table` ADD `$field` INT(1) NOT NULL DEFAULT '0' AFTER `repo_release`;"; |
||
199 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
||
200 | xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql); |
||
201 | $module->setErrors("Error when adding '$field' to table '$table'."); |
||
202 | $ret = false; |
||
203 | } |
||
204 | } |
||
205 | |||
206 | return $ret; |
||
207 | } |
||
208 |