forked from backdrop-contrib/backdrop-drush-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backdrop.drush.inc
135 lines (119 loc) · 3.58 KB
/
backdrop.drush.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
<?php
/**
* @file
* Core drush commands.
*/
include_once __DIR__ . '/BackdropBoot.php';
/**
* Implements hook_bootstrap_candidates().
*
* This returns an array of classes that may be used to bootstrap Drush. Right
* now there is only a single Backdrop version, but in the future if newer
* versions required separate bootstrap classes per version, we would add them
* here.
*/
function backdrop_bootstrap_candidates() {
return array('Drush\Boot\BackdropBoot');
}
/**
* Adjust the contents of any command structure prior to dispatch.
*
* @see core_drush_command_alter()
*/
function backdrop_drush_command_alter(&$command) {
$bootstrap = drush_get_bootstrap_object();
if (!is_a($bootstrap, 'Drush\Boot\BackdropBoot')) {
return;
}
$backdrop_command = NULL;
// Commands that need replacements with Backdrop versions.
// @todo: Automate this based on the contents of the commands directory.
switch ($command['command']) {
case 'core-cron':
$backdrop_command = 'backdrop-cron';
break;
case 'updatedb':
$backdrop_command = 'backdrop-updatedb';
break;
case 'updatedb-batch-process':
$backdrop_command = 'backdrop-updatedb-batch-process';
break;
case 'updatedb-status':
$backdrop_command = 'backdrop-updatedb-status';
break;
case 'pm-download':
$backdrop_command = 'backdrop-pm-download';
break;
case 'user-login':
$backdrop_command = 'backdrop-user-login';
break;
case 'core-status':
$backdrop_command = 'backdrop-core-status';
break;
case 'pm-update':
$backdrop_command = 'backdrop-pm-update';
break;
case 'pm-enable':
$backdrop_command = 'backdrop-pm-enable';
break;
}
// Commands that work with Backdrop with no adjustments.
$safe_commands = array(
'cache-get',
'cache-set',
'core-exec',
'help',
'topic',
'php-eval',
'php-script',
'sql-cli',
'sql-conf',
'sql-connect',
'sql-create',
'sql-drop',
'sql-dump',
'sql-query',
'sql-sanitize',
);
$compatible_commands = array(
'cache-clear',
);
// Commands native to Backdrop.
if (strpos($command['command'], 'backdrop') !== FALSE) {
return;
}
// Commands that work as-is.
if (in_array($command['command'], $safe_commands)) {
return;
}
// Commands that are fine to be run through the compatibility layer.
if (in_array($command['command'], $compatible_commands)) {
require_once BACKDROP_ROOT . '/core/includes/drupal.inc';
$GLOBALS['settings']['backdrop_drupal_compatibility'] = TRUE;
$backdrop_command = $command['command'];
}
// And finally commands that are not supported (yet) use the fallback command.
$commands = drush_get_commands();
if (!isset($backdrop_command) || !array_key_exists($backdrop_command, $commands)) {
$backdrop_command = 'backdrop-unsupported';
}
// Replace the command with a Backdrop-supported one.
$arguments = $command['arguments'];
$command = $commands[$backdrop_command];
drush_set_command($command);
$command['arguments'] = $arguments;
// Add command-specific options, if applicable.
drush_command_default_options($command);
}
/**
* Implements hook_module_implements_alter().
*
* This is a hack to remove core Drush's implementation of hook_watchdog() from
* the hook registry. See system_watchdog() in Drush core.
*/
function system_module_implements_alter(&$implementations, $hook) {
// Remove system_watchdog() from being called.
if ($hook === 'watchdog') {
$implementations = array_diff_key($implementations, array('system' => NULL));
}
}