'datasync_drush_job_list', 'description' => 'List all jobs' ); $items['datasync job add'] = array( 'callback' => 'datasync_drush_job_add', 'description' => 'Queue new job', 'arguments' => array( 'job type' => 'job type', ' ..' => 'list of arguments to give to job object') ); $items['datasync job remove'] = array( 'callback' => 'datasync_drush_job_remove', 'description' => 'Cancel and remove job(s)', 'arguments' => array( 'jobs' => 'list of space separated job ids') ); $items['datasync type list'] = array( 'callback' => 'datasync_drush_type_list', 'description' => 'List all types' ); $items['datasync type activate'] = array( 'callback' => 'datasync_drush_type_activate', 'description' => 'Activate type', 'arguments' => array( 'type' => 'job type') ); $items['datasync type suspend'] = array( 'callback' => 'datasync_drush_type_suspend', 'description' => 'Suspend type', 'arguments' => array( 'types' => 'list of space separated job types') ); $items['datasync host list'] = array( 'callback' => 'datasync_drush_host_list', 'description' => 'List supported hosts' ); $items['datasync host add'] = array( 'callback' => 'datasync_drush_host_add', 'description' => 'Add host', 'arguments' => array( 'job' => 'job name') ); $items['datasync host remove'] = array( 'callback' => 'datasync_drush_host_remove', 'description' => 'Remove host', 'arguments' => array( 'job' => 'job name') ); // TODO scheduler return $items; } /** * Implementation of hook_drush_help(). */ /* function datasync_drush_help($section) { switch ($section) { case 'drush:datasync job list': return dt("List all known jobs, with their status"); case 'drush:datasync type list': return dt("List all known jobs types, with their status"); case 'drush:datasync job add': return dt("Queue a new job"); } } */ /** * Check Yamm server is a valid installation * * @return boolean */ function _datasync_drush_check_install($views = FALSE) { $success = TRUE; if ($views) { $success = module_exists('datasync') && module_exists('views'); } else { $success = module_exists('datasync'); } if (! $success) { drush_die('the datasync module does not seems to be present or activated'); } } /* * Job handling functions */ function datasync_drush_job_list() { _datasync_drush_check_install(TRUE); $view = views_get_view('datasync_jobs'); $view->preview('default', array()); if (empty($view->result)) { drush_print(dt('no clients configured', array('@name' => $name))); } else { $rows = array(); $rows[] = array(dt('Id'), dt('Type'), dt('Phase'), dt('Next phase'), dt('Started/completed')); foreach ($view->result as &$result) { $row = array( $result->datasync_jobs_job_id, $result->datasync_jobs_type, $result->datasync_jobs_phase, ($result->datasync_jobs_phase == 'datasync_done' ? '' : $result->datasync_jobs_next_phase), ($result->datasync_jobs_phase == 'datasync_done' ? date('d/m/Y H:i', $result->datasync_jobs_completed) : date('d/m/Y H:i', $result->datasync_jobs_started))); $rows[] = $row; } drush_print_table($rows, TRUE); } } function datasync_drush_job_add($name) { _datasync_drush_check_install(); $args = func_get_args(); $name = array_shift($args); if (empty($name)) { drush_print(dt('missing job type parameter')); } else if (datasync_job_add($name, $args)) { drush_print(dt('new @name job queued', array('@name' => $name))); } else { drush_print(dt('error during @name job queueing, see watchdog', array('@name' => $name))); } } function datasync_drush_job_remove() { _datasync_drush_check_install(); $jobs = func_get_args(); $unknown = array(); $unfinished = array(); $do_it = TRUE; foreach ($jobs as $key => $job_id) { if (! $job = db_fetch_object(db_query("SELECT * FROM {datasync_jobs} WHERE job_id = %d", $job_id))) { $unknown[] = $job_id; unset($jobs[$key]); } else if ($job->phase != 'datasync_done') { $unfinished[] = $job_id; } } if (! empty($unknown)) { drush_print(dt('jobs @jobs are unknown', array('@jobs' => implode(', ', $unknown)))); } if (! empty($unfinished)) { $do_id = drush_confirm(dt('jobs @jobs are unfinished, are you sure you want to proceed?', array('@jobs' => implode(', ', $unfinished)))); } if ($do_it) { foreach ($jobs as $job_id) { db_query("DELETE FROM {datasync_jobs} WHERE job_id = %d", $job_id); ds_variable_del('ds_extra_data_' . $job_id); } drush_print(dt('jobs @jobs removed', array('@jobs' => implode(', ', $jobs)))); } else { drush_print(dt('user aborted')); } } /* * Type handling functions */ function datasync_drush_type_list() { _datasync_drush_check_install(); drush_print(dt('Not implemented yet')); } function datasync_drush_type_suspend($name) { _datasync_drush_check_install(); drush_print(dt('Not implemented yet')); } function datasync_drush_type_activate($name) { _datasync_drush_check_install(); drush_print(dt('Not implemented yet')); } /* * Host handling functions */ function datasync_drush_host_list() { _datasync_drush_check_install(); drush_print(dt('Not implemented yet')); } function datasync_drush_host_add($host) { _datasync_drush_check_install(); drush_print(dt('Not implemented yet')); } function datasync_drush_host_remove($host) { _datasync_drush_check_install(); drush_print(dt('Not implemented yet')); }