Conditions | 21 |
Paths | > 20000 |
Total Lines | 325 |
Code Lines | 221 |
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 |
||
7 | function boincimport_admin_settings() { |
||
8 | global $conf ; |
||
|
|||
9 | global $db_url; |
||
10 | global $base_url; |
||
11 | $stage = variable_get('boincimport_config_stage', 0); |
||
12 | |||
13 | // Start with a quick sanity check on the BOINC environment |
||
14 | boinc_get_path(); |
||
15 | |||
16 | //We'll be checking that the setup is complete. |
||
17 | //If it is not complete, the migration will not go ahead. |
||
18 | $ready_for_migration = 1; |
||
19 | |||
20 | // Checking that the migration has been tested on a copy first. |
||
21 | $form['test'] = array( |
||
22 | '#type' => 'fieldset', |
||
23 | '#title' => t('Test on copy first'), |
||
24 | '#collapsible' => TRUE, |
||
25 | '#collapsed' => TRUE, |
||
26 | ); |
||
27 | |||
28 | $output = ''; |
||
29 | if (!variable_get('boincimport_tested', 0)) { |
||
30 | $form['test']['#collapsed']= FALSE; |
||
31 | $output = '<span class="marker">'; |
||
32 | $ready_for_migration = 0; |
||
33 | } |
||
34 | $output .= '<p>' . t('The migration will modify and even destroy some data. You |
||
35 | must test this module on a copy of your data first, several times if necessary. |
||
36 | Only use this module on your live data when you are familiar with the procedure |
||
37 | and you\'re confident everything will run smoothly.') . '</p><p>' . t('Also, you |
||
38 | should make a full backup of your database just prior to performing the |
||
39 | migration on the live data. It is better to turn off both the BOINC site and the |
||
40 | Drupal site during the migration.') . '</p>'; |
||
41 | if (!variable_get('boincimport_tested', 0)) { |
||
42 | $output .= '</span>'; |
||
43 | } |
||
44 | $form['test']['intro'] = array('#value' => $output); |
||
45 | |||
46 | $form['test']['boincimport_tested'] = array( |
||
47 | '#type' => 'checkbox', |
||
48 | '#title' => t('I am running a trial migration on a disposable copy of the database |
||
49 | OR I have already done so and I am running this on my live site, confident that |
||
50 | the migration will proceed smoothly'), |
||
51 | '#return_value' => 1, |
||
52 | '#default_value' => variable_get('boincimport_tested', 0), |
||
53 | '#description' => '', |
||
54 | ); |
||
55 | |||
56 | // Where is BOINC data? |
||
57 | $pre = variable_get('boincimport_table_prefix', ''); |
||
58 | $tables = array($pre .'forum', $pre .'post', $pre .'thread', $pre .'user'); |
||
59 | $db = (is_array($db_url) AND isset($db_url['boinc_rw'])) ? 'boinc_rw' : 'default'; |
||
60 | $result = _boincimport_check_tables($tables, $db, 0); |
||
61 | |||
62 | $config_path = conf_path(); |
||
63 | $form['boinc_data'] = array( |
||
64 | '#type' => 'fieldset', |
||
65 | '#title' => t('Location of BOINC data'), |
||
66 | '#collapsible' => TRUE, |
||
67 | '#collapsed' => TRUE, |
||
68 | ); |
||
69 | $form['boinc_data']['boincimport_db_configured'] = array( |
||
70 | '#type' => 'checkbox', |
||
71 | '#title' => t('There is a \'boinc\' database connection string configured in %file', |
||
72 | array('%file' => "{$config_path}/settings.php")), |
||
73 | '#return_value' => 1, |
||
74 | '#default_value' => variable_get('boincimport_db_configured', 1), |
||
75 | '#description' => '', |
||
76 | '#disabled' => ($result['result']) ? TRUE : FALSE |
||
77 | ); |
||
78 | if (variable_get('boincimport_db_configured', 1) != 1) { |
||
79 | $default_db_url = is_array($db_url) ? end($db_url) : $db_url; |
||
80 | $url = variable_get('boincimport_db_url', $default_db_url); |
||
81 | if (!preg_match('{(mysql|pgsql):\/\/(.+):(.*?)@(.+)/(\w+)}i', $url)) { |
||
82 | $output = '<p class="marker">'. t('Set the address of the BOINC database |
||
83 | according to the following format:') . '<br /><pre> |
||
84 | mysql://boinc_username:boinc_password@localhost/boinc_database |
||
85 | </pre></p>'; |
||
86 | $ready_for_migration = 0; |
||
87 | $form['boinc_data']['#collapsed'] = FALSE; |
||
88 | $form['boinc_data']['db_connect_string_note'] = array('#value' => $output); |
||
89 | } |
||
90 | |||
91 | $form['boinc_data']['boincimport_db_url'] = array( |
||
92 | '#type' => 'textfield', |
||
93 | '#title' => t('BOINC database location'), |
||
94 | '#default_value' => variable_get('boincimport_db_url', $default_db_url), |
||
95 | '#size' => 80, |
||
96 | '#maxlength' => 255, |
||
97 | '#description' => '', |
||
98 | ); |
||
99 | } |
||
100 | |||
101 | $output = '<p>' . t('Note that due to a limitation within Drupal core, we cannot |
||
102 | import messages from one database type to another database type. E.g, we |
||
103 | cannot import BOINC from a myqsl DB, to a postgresql DB. You need to import |
||
104 | the data into the same type of database first (import all the BOINC data, as is, |
||
105 | from mysql to postgresql).') . '</p><p>' . t('If both BOINC and Drupal are on |
||
106 | postgresql, see !this_issue.', array('!this_issue' => l(t('this issue'), |
||
107 | 'http://drupal.org/node/64877', array('attributes' => array('target' => '_blank'))))) . '</p>'; |
||
108 | $form['boinc_data']['note'] = array('#value' => $output); |
||
109 | |||
110 | // BOINC table prefix |
||
111 | $form['boinc_data']['boincimport_table_prefix'] = array( |
||
112 | '#type' => 'textfield', |
||
113 | '#title' => t('BOINC table prefix'), |
||
114 | '#default_value' => variable_get('boincimport_table_prefix', ''), |
||
115 | '#size' => 20, |
||
116 | '#maxlength' => 255, |
||
117 | '#description' => t('What prefix is used for your BOINC tables?'), |
||
118 | '#disabled' => ($result['result']) ? TRUE : FALSE |
||
119 | ); |
||
120 | |||
121 | $output = $result['html']; |
||
122 | if ($result['result'] != 1) { |
||
123 | $ready_for_migration = 0; |
||
124 | $form['boinc_data']['#collapsed']= FALSE; |
||
125 | $output .= '<span class="marker">'; |
||
126 | $output .= t('Some tables couldn\'t be found. Are the database settings correct? |
||
127 | Please correct the errors so that the BOINC tables can be accessed.'); |
||
128 | $output .= '</span>'; |
||
129 | } |
||
130 | |||
131 | $form['boinc_data']['result'] = array('#value' => $output); |
||
132 | |||
133 | // USERS settings |
||
134 | $form['users'] = array( |
||
135 | '#type' => 'fieldset', |
||
136 | '#title' => t('User import'), |
||
137 | '#collapsible' => TRUE, |
||
138 | '#collapsed' => TRUE, |
||
139 | ); |
||
140 | |||
141 | // User import batch size |
||
142 | $form['users']['boincimport_user_batch_size'] = array( |
||
143 | '#type' => 'textfield', |
||
144 | '#title' => t('Number of accounts to process at a time'), |
||
145 | '#default_value' => variable_get('boincimport_user_batch_size', 50), |
||
146 | '#size' => 10, |
||
147 | '#maxlength' => 10, |
||
148 | '#description' => t('Due to memory intensive API calls, this value may have to |
||
149 | be adjusted to avoid exhausting system resources. The default value is a |
||
150 | balance between performance and reliability.') |
||
151 | ); |
||
152 | |||
153 | // Import users who have never posted? |
||
154 | $form['users']['boincimport_import_lurkers'] = array( |
||
155 | '#type' => 'checkbox', |
||
156 | '#title' => t('Import users who have never posted?'), |
||
157 | '#return_value' => 1, |
||
158 | '#default_value' => variable_get('boincimport_import_lurkers', 0), |
||
159 | '#description' => t('Do you want to import users with no community |
||
160 | involvement? This may not be desired, as it can take a very long time to |
||
161 | import tens or hundreds of thousands of accounts. (note that users who |
||
162 | are not imported now will still be imported on-the-fly upon login)'), |
||
163 | ); |
||
164 | |||
165 | // Input format settings |
||
166 | $form['input'] = array( |
||
167 | '#type' => 'fieldset', |
||
168 | '#title' => t('Input format settings'), |
||
169 | '#collapsible' => TRUE, |
||
170 | '#collapsed' => TRUE |
||
171 | ); |
||
172 | $output = '<p>'. t('Select which !input_format should be used for the imported |
||
173 | messages. It is highly-recommended that this value be left as it is, as the |
||
174 | Full HTML and PHP code formats can be very dangerous!', |
||
175 | array('!input_format' => l(t('input format'), 'admin/settings/filters'))) .'</p>'; |
||
176 | $form['input']['intro'] = array('#value' => $output); |
||
177 | |||
178 | $formats = db_query('SELECT format, name FROM {filter_formats}'); |
||
179 | while ($format = db_fetch_array($formats)) { |
||
180 | $input_formats[$format['format']]= $format['name']; |
||
181 | } |
||
182 | |||
183 | // By default, use the format named "Rich text"; fall back to Filtered HTML |
||
184 | $default_input_format = db_result(db_query(" |
||
185 | SELECT format FROM {filter_formats} WHERE name = '%s'", 'Rich text')); |
||
186 | if (!$default_input_format) $default_input_format = 1; |
||
187 | |||
188 | $input_format = variable_get('boincimport_input_format', $default_input_format); |
||
189 | $form['input']['boincimport_input_format'] = array( |
||
190 | '#type' => 'radios', |
||
191 | '#title' => t('Input format'), |
||
192 | '#default_value' => $input_format, |
||
193 | '#options' => $input_formats |
||
194 | ); |
||
195 | if (!$input_format) { |
||
196 | $ready_for_migration = 0; |
||
197 | $form['input']['#collapsed']= FALSE; |
||
198 | } |
||
199 | $output = '<p><em>'. t('This setting will be applied to all posts and private |
||
200 | messages.') .'</em></p>'; |
||
201 | $form['input']['result'] = array('#value' => $output); |
||
202 | |||
203 | // BBcode settings |
||
204 | $form['bbcode'] = array( |
||
205 | '#type' => 'fieldset', |
||
206 | '#title' => t('BBcode settings'), |
||
207 | '#collapsible' => TRUE, |
||
208 | '#collapsed' => TRUE, |
||
209 | ); |
||
210 | |||
211 | $output = '<p>' . t('BOINC posts are often formatted in BBcode. During the |
||
212 | import process, BBcode can be handled in two diffent ways') . ':</p>'; |
||
213 | $output .= '<ul><li>' . t('Leave the BBcode as is and use the !bbcode_module |
||
214 | after the migration to filter the imported posts. In this case, the module |
||
215 | is not required during the migration, but will need to be installed and |
||
216 | configured later.', |
||
217 | array('!bbcode_module' => l(t('bbcode module'), 'http://drupal.org/project/bbcode', |
||
218 | array('attributes' => array('target' => '_blank'))))) . '</li>'; |
||
219 | $output .= '<li>' . t('Filter the BBcode now and replace it with plain HTML. |
||
220 | The BBcode module will be required during the migration process, but can |
||
221 | be disabled afterwards.') . '</li></ul>'; |
||
222 | $output .= '<p>' . t('An appropriate input filter should be chosen, as well, |
||
223 | as it will affect how the post is displayed. For example, if BBcode is |
||
224 | removed and replaced by HTML, some HTML tags will be stripped by the |
||
225 | "Filtered HTML" input format unless they are first added to the list of |
||
226 | allowed tags in that format. See the !input_formats page.', |
||
227 | array('!input_formats' => l(t('input formats'), 'admin/settings/filters'))) . '</p>'; |
||
228 | |||
229 | $form['bbcode']['intro'] = array('#value' => $output); |
||
230 | $form['bbcode']['boincimport_bbcode'] = array( |
||
231 | '#type' => 'radios', |
||
232 | '#title' => t('BBcode handling'), |
||
233 | '#default_value' => variable_get('boincimport_bbcode', 0), |
||
234 | '#options' => array(t('Leave BBcode as is.'), t('Transform BBcode into HTML.')), |
||
235 | '#description' => '', |
||
236 | ); |
||
237 | |||
238 | $module_status = _boincimport_check_module('bbcode'); |
||
239 | $bbcode_disabled = ($module_status['result'] == 0) ? true : false; |
||
240 | $output = $module_status['html']; |
||
241 | |||
242 | if (variable_get('boincimport_bbcode', 0)) { |
||
243 | if ($bbcode_disabled) { |
||
244 | $ready_for_migration = 0; |
||
245 | $form['bbcode']['#collapsed'] = FALSE; |
||
246 | $output .= '<p><span class="marker">'; |
||
247 | $output .= t('The !bbcode_module is required to transform BBcode into HTML. |
||
248 | You first need to !enable_bbcode', array( |
||
249 | '!bbcode_module' => l(t('bbcode module'), 'http://drupal.org/project/bbcode', array('attributes' => array('target' => '_blank'))), |
||
250 | '!enable_bbcode' => l(t('enable the bbcode module'), 'admin/build/modules'))); |
||
251 | $output .= '</span></p>'; |
||
252 | } |
||
253 | $sql = "SELECT COUNT(*) FROM {filters} WHERE module = 'bbcode' AND format = %d"; |
||
254 | $result = db_query($sql, $input_format); |
||
255 | if (!db_result($result)) { |
||
256 | $form['bbcode']['#collapsed'] = FALSE; |
||
257 | $output .= '<p class="marker">'. t('You need to !enable_bbcode_input and |
||
258 | then !configure_bbcode_options', array( |
||
259 | '!enable_bbcode_input' => l(t('enable BBcode in the selected input format'), "admin/settings/filters/{$input_format}"), |
||
260 | '!configure_bbcode_options' => l(t('configure BBcode options'), "admin/settings/filters/{$input_format}/configure"))) .'</p>'; |
||
261 | } |
||
262 | $output .= '<p>'. t('For best results, !disable_all_options', |
||
263 | array('!disable_all_options' => l(t('all four BBcode configure options should be disabled'), "admin/settings/filters/{$input_format}/configure"))) . '.</p>'; |
||
264 | } else { |
||
265 | if ($bbcode_disabled) { |
||
266 | $form['bbcode']['#collapsed'] = FALSE; |
||
267 | $output .= '<p>'. t('The !bbcode_module is recommended, but not required. |
||
268 | You may !enable_bbcode after having installed it.', array( |
||
269 | '!bbcode_module' => l(t('bbcode module'), 'http://drupal.org/project/bbcode', array('attributes' => array('target' => '_blank'))), |
||
270 | '!enable_bbcode' => l(t('enable the bbcode module'), 'admin/build/modules'))) .'</p>'; |
||
271 | } |
||
272 | $output .= '<p>' . t('Don\'t forget to !enable_bbcode_input and then !configure_bbcode_options.', array( |
||
273 | '!enable_bbcode_input' => l(t('enable BBcode in the selected input format'), "admin/settings/filters/{$input_format}"), |
||
274 | '!configure_bbcode_options' => l(t('configure BBcode options'), "admin/settings/filters/{$input_format}/configure"))) . '</p>'; |
||
275 | $output .= '<p>' . t('You may want to enable it for other input formats, too.') . '</p>'; |
||
276 | } |
||
277 | $output .= '<p><em>'. t('This setting will be applied to all posts, private |
||
278 | messages and the users\' signature.') .'</em></p>'; |
||
279 | |||
280 | $form['bbcode']['result'] = array('#value' => $output); |
||
281 | |||
282 | // URL transform settings |
||
283 | $form['url_transforms'] = array( |
||
284 | '#type' => 'fieldset', |
||
285 | '#title' => t('URL transforms'), |
||
286 | '#collapsible' => TRUE, |
||
287 | '#collapsed' => TRUE, |
||
288 | ); |
||
289 | if (!variable_get('boincimport_base_url_boinc', 0)) { |
||
290 | $form['url_transforms']['#collapsed']= FALSE; |
||
291 | $output = '<span class="marker">'; |
||
292 | $ready_for_migration = 0; |
||
293 | } |
||
294 | |||
295 | // List of BOINC domains possible in URLs to transform |
||
296 | $form['url_transforms']['boincimport_base_url_boinc'] = array( |
||
297 | '#type' => 'textarea', |
||
298 | '#title' => t('BOINC base URLs to transform'), |
||
299 | '#default_value' => variable_get('boincimport_base_url_boinc', ''), |
||
300 | '#description' => t('List URL bases that should be transformed from |
||
301 | BOINC format to Drupal format (enter one domain per line, including http://).'), |
||
302 | ); |
||
303 | |||
304 | // The Drupal domain to use in URL transform results |
||
305 | $form['url_transforms']['boincimport_base_url_drupal'] = array( |
||
306 | '#type' => 'textfield', |
||
307 | '#title' => t('Target Drupal base URL'), |
||
308 | '#default_value' => variable_get('boincimport_base_url_drupal', ''), |
||
309 | '#description' => t('Specify the URL base to use in transform results. If |
||
310 | left blank, the base_url configured in this Drupal environment will be |
||
311 | used (currently: %url)', array('%url' =>$base_url)), |
||
312 | ); |
||
313 | |||
314 | // Are we ready for migration? |
||
315 | $form['migration'] = array( |
||
316 | '#type' => 'fieldset', |
||
317 | '#title' => 'Migration', |
||
318 | '#collapsible' => TRUE, |
||
319 | '#collapsed' => FALSE, |
||
320 | ); |
||
321 | variable_set('boincimport_ready', $ready_for_migration); |
||
322 | if ($ready_for_migration) { |
||
323 | $output = '<p>'. t('Check the settings above one more time. If everything |
||
324 | is ok, !proceed.', array('!proceed' => l(t('you can now proceed with the migration'), 'admin/boinc/import/process'))) .'</p>'; |
||
325 | } else { |
||
326 | $output = '<p class="marker">'. t('You are not ready for the migration yet. |
||
327 | Please check the settings above.') .'</p>'; |
||
328 | } |
||
329 | |||
330 | $form['migration']['info'] = array('#value' => $output); |
||
331 | return system_settings_form($form); |
||
332 | } |
||
456 |