-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrushd.drush.inc
98 lines (87 loc) · 2.61 KB
/
drushd.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
<?php
function drushd_drush_init() {
if (!($command = &drush_get_context('command'))) {
return;
}
if (isset($command['daemon'])) {
$class = isset($command['daemon']['class']) ? $command['daemon']['class'] : 'DrushDaemon';
drushd_include_files($command);
// Necessary evil for simple callbacks.
global $daemon;
$daemon = new $class($command);
// If we're in the backend, assume this is the daemon process.
if (drush_get_context('DRUSH_BACKEND')) {
$daemon->backendInvoke();
}
// If this is not a forking command, or debugging is on, run the command directly.
else if (!$daemon->commandRequiresFork() || drush_get_option('debug', FALSE)) {
$daemon->callCommandMethod();
}
// Otherwise, summon the daemon!
else {
$daemon->summon();
}
$daemon->drushExit();
}
}
/**
* Just a dummy callback so Drush doesn't whine at us. If your drush command is
* extending the DrushDaemon command and has it's own process method, you
* probably want to set the callback-hook to 'drushd' in hook_drush_command, so
* that you don't get whined at either! ;)
*
* @see drushd_example.drush.inc.
*/
function drush_drushd() {
drush_log(dt('drush_drushd() was called. You probably want to create your own process method in your DrushDaemon extension.'), 'warning');
}
function _drushd_print_log($entry) {
$dt_args = array(
'@date' => date('[d-M-Y G:i:s]', time()),
'@type' => $entry['type'],
'@message' => $entry['message'],
);
$message = wordwrap(dt('@date [@type] @message', $dt_args));
$verbose = drush_get_context('DRUSH_VERBOSE');
$debug = drush_get_context('DRUSH_DEBUG');
$return = TRUE;
switch ($entry['type']) {
case 'failed' :
case 'error' :
$return = FALSE;
break;
case 'warning' :
case 'ok' :
case 'completed' :
case 'success' :
// Pass through to printing.
break;
case 'notice' :
case 'message' :
case 'info' :
if (!$verbose) {
// print nothing. exit cleanly.
return TRUE;
}
break;
default :
if (!$debug) {
// print nothing. exit cleanly.
return TRUE;
}
break;
}
drush_print($message);
return $return;
}
function drushd_include_files($command) {
require_once 'drushdaemon.inc';
require_once 'processitemsdaemon.inc';
require_once 'outputhandler.inc';
require_once 'statushandler.inc';
if (isset($command['daemon']['file'])) {
$path = isset($command['daemon']['file path']) ? $command['daemon']['file path'] : $command['path'];
$path .= '/'. $command['daemon']['file'];
require_once $path;
}
}