/[drupal]/contributions/modules/hosting/task.hosting.inc
ViewVC logotype

Contents of /contributions/modules/hosting/task.hosting.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (show annotations) (download) (as text)
Sat Oct 24 05:54:15 2009 UTC (4 weeks, 4 days ago) by anarcat
Branch: MAIN
CVS Tags: DRUPAL-6--0-4-ALPHA3, HEAD
Changes since 1.14: +6 -0 lines
File MIME type: text/x-php
mark the task as processing even if called directly

the previous patch here assumed wrongly that tasks were always called through the dispatch
1 <?php
2
3 function _hosting_task_log($entry) {
4 $task = drush_get_context('HOSTING_TASK');
5 if ($task->vid) {
6 hosting_task_log($task->vid, $entry['type'], $entry['message'], $entry['error'], $entry['timestamp']);
7 }
8 else {
9 return _drush_print_log($entry);
10 }
11 if (drush_get_option('debug', FALSE)) {
12 return _drush_print_log($entry);
13 }
14 }
15
16 function drush_hosting_hosting_task_validate($task) {
17 drush_set_option('user', 1);
18 drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_LOGIN);
19 if (is_numeric($task)) {
20 $task = node_load($task);
21 }
22 if ($task->type == 'task') {
23 $task->ref = node_load($task->rid);
24 $task->options = array();
25 $task->args = array();
26 $task->changed = mktime();
27 $task->executed = mktime();
28 // remove the task from the queue at the start of execution
29 // this is to avoid concurrent task runs
30 $task->task_status = HOSTING_TASK_PROCESSING;
31 node_save($task);
32 drush_set_context('HOSTING_TASK', $task);
33 drush_set_context('DRUSH_LOG_CALLBACK', '_hosting_task_log');
34 drush_log(dt("Task starts processing"), 'queue');
35 }
36 else {
37 drush_set_error('HOSTING_INVALID_TASK', t("This task is not valid"));
38 }
39 }
40
41 function drush_hosting_hosting_task() {
42 $task =& drush_get_context('HOSTING_TASK');
43 $hostname = null;
44 $username = null;
45 if (isset($task->options['web_id']) && ($task->options['web_id'] != HOSTING_OWN_WEB_SERVER)) {
46 $username = $task->options['script_user'];
47 $hostname = $task->options['web_host'];
48 }
49 $drush_path = $task->options['drush_path'];
50 $task->options['root'] = $task->options['publish_path'];
51
52 // make sure argument order is correct
53 ksort($task->args);
54 $data = array_merge($task->args, $task->options);
55 $data['uri'] = null; // provision commands do not need the url passed to them.
56 $mode = drush_get_option('debug', FALSE) ? 'GET' : 'POST';
57 $output = drush_backend_invoke("provision " . $task->task_type, $data, $mode, TRUE, $drush_path, $hostname, $username);
58
59 drush_set_context('HOSTING_DRUSH_OUTPUT', $output);
60 $code = drush_get_error();
61 // record status
62 // We return 0 on success, so anything else is an error.
63 $task->task_status = ($code) ? HOSTING_TASK_ERROR : HOSTING_TASK_SUCCESS;
64
65 // New revision is created at the beginning of function.
66 $task->revision = FALSE;
67 $task->delta = mktime() - $task->executed;
68 node_save($task);
69 }
70
71 function drush_hosting_hosting_task_rollback() {
72 $task =& drush_get_context('HOSTING_TASK');
73 module_invoke_all(sprintf("hosting_%s_task_rollback", $task->task_type), $task, drush_get_context('HOSTING_DRUSH_OUTPUT'));
74 }
75
76
77 function drush_hosting_post_hosting_task($task) {
78 $task =& drush_get_context('HOSTING_TASK');
79 module_invoke_all(sprintf("post_hosting_%s_task", $task->task_type), $task, drush_get_context('HOSTING_DRUSH_OUTPUT'));
80 }

  ViewVC Help
Powered by ViewVC 1.1.2