Issues (1839)

boinc/modules/boincimport/boincimport.pages.inc (3 issues)

1
<?php
2
// $Id$
3
4
/**
5
 * Callback admin/boinc/import/settings
6
 */
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';
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
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
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $input_formats does not seem to be defined for all execution paths leading up to this point.
Loading history...
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
}
333
334
/**
335
 * Callback admin/boinc/import/post_configuration
336
 */
337
function boincimport_post_configuration() {
338
  $output = '<p>'. t('This page will help to tie up any loose ends following
339
    the BOINC data import process. Before continuing, it may be best to have
340
    already:') .'</p>';
341
  $output .= '<ul>';
342
  $output .= '<li>'. t('Imported users, teams, and forums using the BOINC
343
    import module') .'</li>';
344
  $output .= '<li>'. t('Imported any additional data using add on modules if
345
    available.') .'</li>';
346
  $output .= '</ul>';
347
  //User Set up
348
  $output .= '<h2>'. t('User settings') .'</h2>';
349
  $output .= '<p>'. t('Make sure your !user_settings are correct. Specifically,
350
    you can enable or disable signatures there. ', array(
351
      '!user_settings' => l(t('user settings'), 'admin/user/settings')
352
    )) .'</p>';
353
  $output .= '<p>' . t('Note that avatar/picture support is not tied to user
354
    settings Picture support at this time.') . '</p>';
355
  /*$output .= '<p>' . t('In order to activate avatar/picture support, you need to
356
    enable pictures on this page and also:') . '</p>';
357
  $output .= '<ul>';
358
  $output .= '<li>'. t('Tick the checkboxes to allow "User pictures in posts" and/or
359
    "User pictures in comments" on the !theme_config page.', array(
360
      '!theme_config' => l(t('theme configuration'), 'admin/build/themes/settings')
361
    )) .'</li>';
362
  $output .= '<li>'. t('Manually copy the avatars from the boinc/images/avatars/
363
    directory to the @files directory.', array(
364
      '@files' => file_directory_path(). '/pictures'
365
    )) .'</li>';
366
  $output .= '</ul>'; */
367
368
  // Forum Set up
369
  $output .= '<h2>'. t('Forum settings') .'</h2>';
370
  $output .= '<p>'. t('Check any additional changes to make on the
371
    !forum_settings page.', array(
372
      '!forum_settings' =>  l(t('forum settings'), 'admin/content/forum/settings')
373
    )) .'</p>';
374
  $output .= '<p>'. t('It also may be a good idea to look at the !forum_list to
375
    verify that all necessary containers and forums are in place.', array(
376
      '!forum_list' =>  l(t('forum list'), 'admin/content/forum')
377
    )) .'</p>';
378
  /*$output .= '<p>'. t('If need be, set up the private forums as explained in the
379
    !documentation.', array(
380
      '!documentation' => l(t('documentation'), 'http://drupal.org/node/58969', array('attributes' => array('target' => '_blank')))
381
    )) .'</p>';
382
    */
383
  /*
384
  // Redirection from old URLs:
385
  $output .= '<h2>'. t('Redirection from BOINC forum URLs to new Drupal forum URLs') .'</h2>';
386
  $output .= '<p>'. t('Enable the boincforum_redirect.module. This way, users
387
    accessing URLs from your old BOINC installation will be redirected to your new
388
    Drupal forum.') .'</p>';
389
  */
390
  // BBcode
391
  $bbcode = variable_get('boincimport_bbcode', 0);
392
  if ($bbcode) {
393
    $output .= '<h2>'. t('Remove BBcode module') .'</h2>';
394
    $output .= '<p>'. t('The BBcode has been cleaned from the posts. You shouldn\'t
395
      need the bbcode module anymore. You can disable it.') .'</p>';
396
  } else {
397
    $output .= '<h2>'. t('Configure BBcode module') .'</h2>';
398
    $output .= '<p>'. t('Most likely, there are many BOINC forum postings
399
      formatted in BBcode. It would be a good idea to verify that BBcode is
400
      being formatted correctly in the imported posts. Have a look around
401
      !the_forum.', array(
402
        '!the_forum' =>  l(t('the forum'), 'community')
403
      )) . '</p>';
404
  }
405
406
  return $output;
407
}
408
409
/**
410
 * Callback admin/boinc/import
411
 */
412
function boincimport_main() {
413
  // Start with a quick sanity check on the BOINC environment
414
  boinc_get_path();
415
  // If that's ok, on with the show
416
  $output .= t('You may want to !check_documentation before starting.', array(
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $output seems to be never defined.
Loading history...
417
    '!check_documentation' => l(t('check the documentation'), 'http://boinc.berkeley.edu/trac/wiki/InstallDrupal', array('attributes' =>array('target' => '_blank')))
418
  ));
419
  $output = '<ol><li>';
420
  $output .= l(t('Configure the migration'), 'admin/boinc/import/settings');
421
  $output .= '</li>';
422
  $output .= '<li>';
423
  $output .= l(t('Execute the migration'), 'admin/boinc/import/process');
424
  $output .= '</li>';
425
  $output .= '<li>';
426
  $output .= l(t('Post migration configuration'), 'admin/boinc/import/post_configuration');
427
  $output .= '</li>';
428
  $output .= '<li>';
429
  $output .= t('!cleanup (Accessing this link will delete all the saved BOINC forum
430
    conversion settings: click only when you\'re done with all the above.)', array(
431
      '!cleanup' => l(t('Cleanup'), 'admin/boinc/import/cleanup')
432
    ));
433
  $output .= '</li>';
434
  /*$output .= '<li>';
435
  $output .= t('Enable the boincforum_redirect module for seamless redirection
436
    from the old forums to the new. This module requires !clean_urls to be active.', array(
437
      '!clean_urls' => l(t('Clean URLs'), 'admin/settings/clean-urls')
438
    ));
439
  $output .= '</li>';
440
  $output .= '<li>';
441
  $output .= t('If you decide to use the boincforum_redirect module, do NOT
442
    uninstall BOINC forum - This will delete tables necessary for redirection. You can,
443
    however, deactivate the module safely.');
444
  $output .= '</li>';*/
445
  $output .= '</ol>';
446
447
  // process will die() if the link to the BOINC database is wrong:
448
  $output .= '<p>'. t('If the BOINC data is in another database, but you made a
449
    mistake while setting up the data base url, you may be unable to access the
450
    setting page due to some limitations of the core of Drupal. !reset_db_url.', array(
451
      '!reset_db_url' => l(t('Click here to reset the database url'), 'admin/boinc/import/reset')
452
    )) .'</p>';
453
454
  return $output;
455
}
456