-
Notifications
You must be signed in to change notification settings - Fork 5
/
backdrop_upgrade_status.overview.inc
528 lines (476 loc) · 18.9 KB
/
backdrop_upgrade_status.overview.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
<?php
/**
* @file
* Backdrop upgrade Overview Report.
*/
/**
* Generates an informational report showing everything you'll need to upgrade
* your site from Drupal to Backdrop CMS.
*
* @return array
* Renderable tables with all the info!
*/
function backdrop_upgrade_status_report() {
$welcome = array(
t('This information should prove useful as you are evaluating an upgrade to Backdrop CMS for this site.'),
);
$renderable['welcome'] = array(
'#type' => 'markup',
'#markup' => '<p>' . implode('</p><p>', $welcome) . '</p>',
);
// Add the checklist as a separate form.
$renderable = backdrop_upgrade_status_report_checklist_form($renderable);
// Add the profile data.
$profile = drupal_get_profile();
$info = system_get_info('module', $profile);
// Get current state. Defaults to FALSE / open.
$profile_collapsed = backdrop_upgrade_status_get_state('profile');
$recommendation = '';
$backdrop_status = t('Supported');
$drupal_status = db_query("SELECT status FROM {system} WHERE name = :profile", array(':profile' => $profile))->fetchField();
if ($drupal_status) {
$enabled = t('Enabled');
}
else {
$enabled = t('Disabled');
$class = 'warning';
}
if ($info['distribution_name'] == 'Drupal') {
// @todo, don't collapse when set not reviewed?
$profile_collapsed = TRUE;
}
else {
$recommendation = t('Check if the distribution is available for Backdrop, or use the <a href="!url">profile switcher</a> module to change to the Standard profile.', array('!url' => 'https://www.drupal.org/project/profile_switcher'));
$backdrop_status = t('Unknown');
$class = 'warning';
}
$profile_rows = array(
array(
'data' => array(
'name' => $info['name'],
'status' => $enabled,
'distro' => $info['distribution_name'],
'backdrop' => $backdrop_status,
'rec' => $recommendation,
),
'class' => isset($class) ? array($class) : array(),
),
);
$profile_data = array(
'machine' => 'profile',
'title' => t('Install Profile / Distribution'),
'info' => t('This is the Install Profile or Distribution that was used when the site was first installed.'),
'header' => array(t('Profile name'), t('Enabled'), t('Distribution'), t('Backdrop status'), t('Recommendation')),
'rows' => $profile_rows,
'collapsed' => $profile_collapsed,
);
$renderable['profile'] = backdrop_upgrade_status_report_data($profile_data);
// Get all module data.
$projects = system_rebuild_module_data();
// Get list of core modules removed from Backdrop.
$include_me = 'includes/backdrop_upgrade_status.';
module_load_include('inc', 'backdrop_upgrade_status', $include_me . 'core.removed');
$removed_modules = _backdrop_upgrade_status_removed_core_modules();
// Get backdrop project data.
if ($available = backdrop_upgrade_status_get_available()) {
module_load_include('inc', 'backdrop_upgrade_status', $include_me . 'compare');
$backdrop_data = backdrop_upgrade_status_calculate_project_data($available);
}
$core_modules = array();
$core_module_rows = array();
$core_collapsed = backdrop_upgrade_status_get_state('core_modules');
$contrib_modules = array();
$contrib_module_rows = array();
$contrib_collapsed = backdrop_upgrade_status_get_state('contrib_modules');
$last_project = '';
foreach ($projects as $project) {
$to_skip = array('views_ui', 'backdrop_upgrade_status');
if (in_array($project->name, $to_skip)) {
continue;
}
if ($project->type == 'module' && $project->status == 1) {
// Core modules.
if ($project->info['package'] == 'Core') {
$core_modules[$project->name] = $project;
if (array_key_exists($project->name, $removed_modules)) {
$backdrop_status = t('Removed from core');
$recommendation = $removed_modules[$project->name]['rec'];
if (!empty($removed_modules[$project->name]['class'])) {
$class = $removed_modules[$project->name]['class'];
// @todo, don't collapse when set not reviewed?
$core_collapsed = FALSE;
}
}
else {
$backdrop_status = t('In core');
$recommendation = '';
$class = '';
}
$row = array(
'data' => array(
'name' => $project->info['name'],
'drupal' => t('In core'),
'backdrop' => $backdrop_status,
'rec' => t($recommendation, array(':module' => $project->info['name'])),
),
'class' => isset($class) ? array($class) : array(),
);
$core_module_rows[] = $row;
}
// Contrib modules.
elseif (isset($project->info['version'])) {
if (isset($project->info['project']) && $project->info['project'] != $last_project) {
$drupal_version = $project->info['version'];
$backdrop_version = '';
$recommendation = '';
$class = '';
if ($available && array_key_exists($project->name, $backdrop_data)) {
switch ($backdrop_data[$project->name]['status']) {
case BACKDROP_UPGRADE_STATUS_CORE:
$backdrop_version = '';
if (isset($backdrop_data[$project->name]['in_core_note'])) {
$backdrop_version .= $backdrop_data[$project->name]['in_core_note'] . '<br>';
}
if (isset($backdrop_data[$project->name]['in_core_warning'])) {
$backdrop_version .= $backdrop_data[$project->name]['in_core_warning'];
}
$status = '';
if (isset($backdrop_data[$project->name]['in_core_upgrade_status'])) {
$status = $backdrop_data[$project->name]['in_core_upgrade_status'];
}
$rec_translated = '';
if (isset($backdrop_data[$project->name]['in_core_upgrade'])) {
$rec_translated = $backdrop_data[$project->name]['in_core_upgrade'];
}
break;
case BACKDROP_UPGRADE_STATUS_STABLE;
$project_name = $backdrop_data[$project->name]['title'];
if (isset($backdrop_data[$project->name]['link'])) {
$project_name = l($project_name, $backdrop_data[$project->name]['link']);
}
$backdrop_version = $project_name . ' -- ' . t('Stable') . ': ';
$backdrop_version .= $backdrop_data[$project->name]['latest_version'];
$status = t('Leave enabled.');
$recommendation = 'Before upgrade: Add the stable contrib version of :module to Backdrop.';
break;
case BACKDROP_UPGRADE_STATUS_DEVELOPMENT:
$project_name = $backdrop_data[$project->name]['title'];
if (isset($backdrop_data[$project->name]['link'])) {
$project_name = l($project_name, $backdrop_data[$project->name]['link']);
}
$backdrop_version = $project_name . ' -- ' . t('In Development') . ': ';
$backdrop_version .= $backdrop_data[$project->name]['latest_version'];
$recommendation = 'Before upgrade: Add the development contrib version of :module to Backdrop.';
$class = 'warning';
break;
case UPDATE_UNKNOWN:
// fall-through intentional.
default:
$backdrop_version = t('Unknown');
$status = t('Leave enabled.');
$recommendation = 'Port :module to Backdrop.';
$class = 'error';
break;
}
}
$note = '';
if (isset($status)) {
$note .= '<strong>' . $status . '</strong><br>';
}
if (isset($recommendation)) {
$note .= t($recommendation, array(':module' => $project->info['name']));
}
elseif (isset($rec_translated)) {
$node .= $rec_translated;
}
$row = array(
'data' => array(
'name' => $project->info['name'],
'drupal' => $drupal_version,
'backdrop' => $backdrop_version,
'note' => $note,
),
'class' => isset($class) ? array($class) : array(),
);
$contrib_module_rows[] = $row;
}
}
// Custom modules.
else {
$custom_modules[$project->name] = $project;
$row = array(
'data' => array(
'name' => $project->info['name'],
'drupal' => t('Custom'),
'backdrop' => t('Unknown'),
'rec' => t('Port :module to Backdrop.', array(':module' => $project->info['name'])),
),
'class' => array('error'),
);
$custom_module_rows[] = $row;
}
// Save the last project so we don't include sub-modules in this list.
if (isset($project->info['project'])) {
$last_project = $project->info['project'];
}
else {
$last_project = $project->name;
}
}
}
$core_module_data = array(
'title' => t('Enabled Core Modules'),
'info' => t('This is a summary of enabled core modules.'),
'header' => array(t('Module name'), t('Drupal status'), t('Backdrop status'), t('Recommendation')),
'rows' => $core_module_rows,
'collapsed' => $core_collapsed,
);
$renderable['core_modules'] = backdrop_upgrade_status_report_data($core_module_data);
$prefix = 'No contributed modules detected.';
$help = _backdrop_upgrade_status_help($prefix);
$contrib_module_data = array(
'title' => t('Enabled Contrib Modules'),
'info' => t('This is a summary of enabled contributed modules.'),
'header' => array(t('Module name'), t('Drupal version'), t('Backdrop status'), t('Recommendation')),
'empty' => $help,
'collapsed' => $contrib_collapsed,
);
if ($available) {
$contrib_module_data['rows'] = $contrib_module_rows;
}
else {
$contrib_module_data['rows'] = array(array(array('data' => $help, 'colspan' => 4)));
}
$renderable['contrib_modules'] = backdrop_upgrade_status_report_data($contrib_module_data);
// Get current state, don't try to guess.
$custom_collapsed = backdrop_upgrade_status_get_state('custom_modules');
$custom_module_data = array(
'title' => t('Enabled Custom Modules'),
'info' => t('This is a summary of enabled custom modules.'),
'header' => array(t('Module name'), t('Drupal status'), t('Backdrop status'), t('Recommendation')),
'rows' => $custom_module_rows,
'empty' => t('No enabled custom modules have been detected.'),
'collapsed' => $custom_collapsed,
);
$renderable['custom_modules'] = backdrop_upgrade_status_report_data($custom_module_data);
// Add fieldsets for all modules that provide one.
foreach (module_implements('backdrop_upgrade_status_report') as $module) {
$module_data = module_invoke($module, 'backdrop_upgrade_status_report');
// Use machine for the fieldset name only.
$machine = $module_data['machine'];
unset($module_data['machine']);
// Add fieldset for module data.
$renderable[$machine] = backdrop_upgrade_status_report_data($module_data);
}
// Allow other modules to add things to the reports page.
drupal_alter('backdrop_upgrade_status_report', $renderable);
return system_settings_form($renderable);
}
// Include all the
$path = drupal_get_path('module', 'backdrop_upgrade_status') . '/includes/modules/';
include_once(DRUPAL_ROOT . '/' . $path . 'backdrop_upgrade_status.node.inc');
include_once(DRUPAL_ROOT . '/' . $path . 'backdrop_upgrade_status.field.inc');
include_once(DRUPAL_ROOT . '/' . $path . 'backdrop_upgrade_status.image.inc');
include_once(DRUPAL_ROOT . '/' . $path . 'backdrop_upgrade_status.taxonomy.inc');
include_once(DRUPAL_ROOT . '/' . $path . 'backdrop_upgrade_status.user.inc');
include_once(DRUPAL_ROOT . '/' . $path . 'backdrop_upgrade_status.paragraphs.inc');
include_once(DRUPAL_ROOT . '/' . $path . 'backdrop_upgrade_status.views.inc');
include_once(DRUPAL_ROOT . '/' . $path . 'backdrop_upgrade_status.features.inc');
/**
* Creates a fieldset with tabular data for the reports page.
*
* @param array $variables
* Contains the following keys:
* - title: The content for fieldset label, as passed through t().
* - info: The content for the introductary paragraph, passed through t().
* - header: Array of columnn headers for data, each passed through t().
* - rows: Table of data (must match column headers), sanitized.
* - collapsed: Whether or not the fieldset should be collapsed.
* - empty: Text to display when there are no rows.
*
* Note: the key 'machine' should not be included in $variables.
*
* @return array
* Renderable fieldset.
*/
function backdrop_upgrade_status_report_data($variables) {
$defaults = array(
'title' => '',
'info' => '',
'header' => '',
'rows' => '',
'collapsed' => '',
'empty' => '',
);
$variables = array_merge($defaults , $variables);
$title = $variables['title'];
$info = $variables['info'];
$header = $variables['header'];
$rows = $variables['rows'];
$collapsed = $variables['collapsed'];
$empty = $variables['empty'];
$fieldset = array(
'#type' => 'fieldset',
'#title' => $title,
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
);
$fieldset['info'] = array(
'#type' => 'markup',
'#markup' => $info,
);
$fieldset['table'] = array(
'#type' => 'markup',
'#markup' => theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array('class' => array('backdrop-upgrade-table')),
'empty' => $empty,
)),
);
return $fieldset;
}
/**
* Generates an informational report showing everything you'll need to upgrade
* your site from Drupal to Backdrop CMS.
*
* @see backdrop_upgrade_status_report_checklist_form_submit().
*
* @return array
* Renderable tables with all the info!
*/
function backdrop_upgrade_status_report_checklist_form($form = array()) {
$form['intro'] = array(
'#type' => 'fieldset',
'#title' => t('Backdrop Upgrade to-do list'),
'#description' => t('When you are ready to perform the upgrade, this list should walk you through the steps necessary to prepare your Drupal 7 database.'),
'#collapsible' => TRUE,
);
// Here's the list of possible overvoew options. Let's make this pluggable?
$todo_items = array(
'profile' => array(
'review' => 'system profile',
'description' => 'Check that a Backdrop version is available.',
'weight' => -10,
),
'core_modules' => array(
'review' => 'core modules',
'description' => 'Disable and uninstall anything not in use.',
'weight' => -10,
),
'contrib_modules' => array(
'review' => 'contrib modules',
'description' => 'Disable and uninstall anything not in use, or no longer necessary.',
'weight' => -10,
),
'custom_modules' => array(
'review' => 'custom modules',
'description' => 'Disable and uninstall anything not in use, or no longer necessary.',
'weight' => -10,
),
'bartik' => array(
'description' => 'Switch to the Bartik theme for the upgrade (Useful if you have not yet ported your Drupal 7 theme to Backdrop).',
'optional' => TRUE,
'weight' => 100, // Ensure this comes last.
),
);
// Add checkboxes for all modules that provide one.
foreach (module_implements('backdrop_upgrade_status_todo') as $module) {
$module_todos = module_invoke($module, 'backdrop_upgrade_status_todo');
foreach ($module_todos as $machine => $item) {
// Move optional items to the bottom of the list.
if (isset($item['optional']) && $item['optional'] === TRUE) {
if (isset($item['weight'])) {
$item['weight'] = $item['weight'] + 100;
}
else {
$item['weight'] = 100;
}
}
$todo_items[$machine] = $item;
}
}
drupal_alter('backdrop_upgrade_status_todo', $todo_items);
uasort($todo_items, 'drupal_sort_weight');
$todo_options = array();
foreach ($todo_items as $machine => $item) {
$output = '';
if (isset($item['optional']) && $item['optional']) {
$output .= t('(optional)') . ' ';
}
if (isset($item['review'])) {
$id = drupal_clean_css_identifier('#edit-' . $machine);
$output .= t('Review <a href="#' . $id . '">' . $item['review'] . '</a>:') . ' ';
}
if (isset($item['description'])) {
$output .= t($item['description']);
}
$todo_options[$machine] = $output;
}
// Set the starting default value based on whats in the database.
$todo_status = variable_get('backdrop_upgrade_status_todo', array());
$form['intro']['backdrop_upgrade_status_todo'] = array(
'#type' => 'checkboxes',
'#title' => t('Prepare for upgrading to Backdrop CMS:'),
'#options' => $todo_options,
'#default_value' => $todo_status,
);
$form['intro']['save'] = array(
'#type' => 'submit',
'#value' => t('Save Progress'),
'#attributes' => array('class' => array('button-primary')),
'#submit' => array('backdrop_upgrade_status_report_checklist_form_submit'),
);
$form['intro']['scan'] = array(
'#type' => 'submit',
'#value' => t('Scan this site - coming soon'),
'#submit' => array('backdrop_upgrade_status_report_checklist_form_scan'),
'#disabled' => TRUE,
);
$form['intro']['clear'] = array(
'#type' => 'submit',
'#value' => t('Clear progress'),
'#submit' => array('backdrop_upgrade_status_report_checklist_form_clear'),
);
return $form;
}
/**
* Submit handler for backdrop_upgrade_status_report_checklist_form().
*/
function backdrop_upgrade_status_report_checklist_form_submit($form, &$form_state) {
if (isset($form_state['values']['backdrop_upgrade_status_todo'])) {
$save_me = array();
foreach ($form_state['values']['backdrop_upgrade_status_todo'] as $key => $value) {
if ($value !== 0) {
$save_me[] = $key;
}
}
variable_set('backdrop_upgrade_status_todo', $save_me);
}
drupal_set_message(t('The checklist has been saved.'));
}
/**
* Submit handler for backdrop_upgrade_status_report_checklist_form().
*/
function backdrop_upgrade_status_report_checklist_form_scan($form, &$form_state) {
$todo_status = variable_get('backdrop_upgrade_status_todo', array());
$checklist_data = array();
foreach (module_implements('backdrop_upgrade_status_scan') as $module) {
$checklist_data += module_invoke($module, 'backdrop_upgrade_status_scan');
}
// Add additional checks, but do not remove.
foreach ($checklist_data as $key => $value) {
if ($value) {
$todo_status[] = $key;
}
}
variable_set('backdrop_upgrade_status_todo', $todo_status);
drupal_set_message(t('This site has been scanned. Additional items may have been cheked off if we believe they are ready for upgrade.'));
}
/**
* Submit handler for backdrop_upgrade_status_report_checklist_form().
*/
function backdrop_upgrade_status_report_checklist_form_clear($form, &$form_state) {
variable_set('backdrop_upgrade_status_todo', array());
drupal_set_message(t('The checklist has been cleared.'));
}