Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00014 function tripal_core_drush_help($command) { 00015 switch ($command) { 00016 // Tripal Materialized Views 00017 case 'drush:tripal-update-mview': 00018 return dt('Updates the specified materialized view.'); 00019 00020 // Tripal Jobs 00021 case 'drush:tripal-launch-jobs': 00022 return dt('Launches any Tripal jobs waiting in the queue.'); 00023 case 'drush:tripal-current-job': 00024 return dt('Returns details about the currently running tripal job including percent complete.'); 00025 case 'drush:tripal-rerun-job': 00026 return dt('Rerun any tripal job in the queue.'); 00027 00028 // Chado-specific 00029 case 'drush:tripal-chado-version': 00030 return dt('Returns the current version of chado associated with this drupal site.'); 00031 case 'drush:tripal-chadotable-desc': 00032 return dt('Returns the table description as specified in the Tripal Schema API for the supplied table.'); 00033 00034 } 00035 } 00036 00043 function tripal_core_drush_command() { 00044 $items = array(); 00045 00046 // Materialized Views 00047 $items['tripal-mview-update'] = array( 00048 // used by drush help 00049 'description' => dt('Updates the specified materialized view.'), 00050 'arguments' => array( 00051 'mview_id' => dt('The ID of the materialized view to update'), 00052 'table_name' => dt('The name of the materialized view table to update.'), 00053 ), 00054 'examples' => array( 00055 'By Materialized View ID' => 'drush tripal-update-mview --mview_id=5', 00056 'By Table Name' => 'drush tripal-update-mview --table_name=organism_feature_count' 00057 ), 00058 // supply options 00059 'options' => array( 00060 'mview_id', 00061 'table_name' 00062 ), 00063 'aliases' => array('trpmv-up', 'tripal-update-mview') 00064 ); 00065 00066 // Jobs 00067 $items['tripal-jobs-current'] = array( 00068 'description' => dt('Returns details about the currently running tripal job including percent complete.'), 00069 'arguments' => array( 00070 ), 00071 'examples' => array( 00072 'Standard example' => 'drush tripal-jobs-current', 00073 ), 00074 'aliases' => array('trpjob-cur','tripal-current-job'), 00075 ); 00076 $items['tripal-jobs-launch'] = array( 00077 // used by drush help 00078 'description' => dt('Lauches any jobs waiting in the queue.'), 00079 'examples' => array( 00080 'Normal Job' => 'drush tripal-jobs-launch admin', 00081 'Parallel Job' => 'drush tripal-jobs-launch admin --parallel=1' 00082 ), 00083 'arguments' => array( 00084 'user' => dt('The Drupal username under which the job should be run. The permissions for this user will be used.'), 00085 ), 00086 // supply options 00087 'options' => array( 00088 'parallel' => dt('Normally jobs are executed one at a time. But if you are certain no conflicts will occur with other currently running jobs you may set this argument to a value of 1 to make the job run in parallel with other running jobs.'), 00089 'job_id' => dt('Provide a job_id to run a specific job. Only jobs that have not been run already can be used'), 00090 ), 00091 'aliases' => array('trpjob-run','tripal-launch-jobs') 00092 ); 00093 $items['tripal-jobs-rerun'] = array( 00094 // used by drush help 00095 'description' => dt('Rerun any job in the queue.'), 00096 'examples' => array( 00097 'Normal Job' => 'drush tripal-jobs-rerun admin 2', 00098 'Parallel Job' => 'drush tripal-jobs-rerun admin 2 --parallel=1' 00099 ), 00100 'arguments' => array( 00101 'user' => dt('The Drupal username under which the job should be run. The permissions for this user will be used.'), 00102 'job_id' => dt('The job ID to run.'), 00103 ), 00104 // supply options 00105 'options' => array( 00106 'parallel' => dt('Normally jobs are executed one at a time. But if you are certain no conflicts will occur with other currently running jobs you may set this argument to a value of 1 to make the job run in parallel with other running jobs.'), 00107 ), 00108 'aliases' => array('trpjob-rerun','tripal-rerun-job') 00109 ); 00110 00111 // Chado-specific 00112 $items['tripal-chado-version'] = array( 00113 // used by drush help 00114 'description' => dt('Returns the current version of chado associated with this drupal site.'), 00115 'arguments' => array( 00116 ), 00117 'examples' => array( 00118 'Standard Example' => 'drush tripal-chado-version', 00119 ), 00120 'aliases' => array('trpchado-ver') 00121 ); 00122 $items['tripal-chadotable-desc'] = array( 00123 // used by drush help 00124 'description' => dt('Returns the table description as specified in the Tripal Schema API for the supplied table.'), 00125 'arguments' => array( 00126 'table_name' => dt('The name of the chado table.'), 00127 ), 00128 'examples' => array( 00129 'By Table Name' => 'drush tripal-chadotable-desc --table_name=feature' 00130 ), 00131 // supply options 00132 'options' => array( 00133 'section' => dt('Only return the specified section of the schema table description. Possible sections include: description, fields, primary key, unique keys, foreign keys, indexes, referring_tables.'), 00134 ), 00135 'aliases' => array('trpschema-tbl') 00136 ); 00137 00138 // Tripal Node-Module Specific 00139 $items['tripal-node-sync'] = array( 00140 // used by drush help 00141 'description' => dt('Sync\'s chado records with drupal creating nodes for the given chado-centric module.'), 00142 'arguments' => array( 00143 'module' => dt('The name of the chado-centric module to sync.'), 00144 ), 00145 'examples' => array( 00146 'By Module' => 'drush tripal-node-sync feature' 00147 ), 00148 // supply options 00149 'options' => array( 00150 ), 00151 'aliases' => array('trpnode-sync') 00152 ); 00153 $items['tripal-node-clean'] = array( 00154 // used by drush help 00155 'description' => dt('Clean-up orphaned Drupal nodes and chado records.'), 00156 'arguments' => array( 00157 'module' => dt('The name of the chado-centric module to clean-up.'), 00158 ), 00159 'examples' => array( 00160 'By Table Name' => 'drush tripal-node-clean feature' 00161 ), 00162 // supply options 00163 'options' => array( 00164 ), 00165 'aliases' => array('trpnode-cln') 00166 ); 00167 00168 return $items; 00169 } 00170 00176 function drush_tripal_core_tripal_jobs_launch($username) { 00177 $parallel = drush_get_option('parallel'); 00178 $job_id = drush_get_option('job_id'); 00179 00180 if ($username) { 00181 global $user; 00182 $user = user_load(array('name' => $username)); 00183 } 00184 else { 00185 drush_print('ERROR: Please provide a username for running this job.'); 00186 return; 00187 } 00188 00189 if ($parallel) { 00190 drush_print("Tripal Job Launcher (in parallel)"); 00191 drush_print("Running as user '$username'"); 00192 drush_print("-------------------"); 00193 tripal_jobs_launch($parallel, $job_id); 00194 } 00195 else { 00196 drush_print("Tripal Job Launcher"); 00197 drush_print("Running as user '$username'"); 00198 drush_print("-------------------"); 00199 tripal_jobs_launch(0, $job_id); 00200 } 00201 } 00202 00208 function drush_tripal_core_tripal_jobs_rerun($username, $job_id) { 00209 00210 $new_job_id = tripal_jobs_rerun($job_id, FALSE); 00211 drush_tripal_core_tripal_jobs_launch($username, $new_job_id); 00212 00213 } 00214 00220 function drush_tripal_core_tripal_jobs_current() { 00221 $sql = "SELECT * FROM {tripal_jobs} TJ ". 00222 "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL "; 00223 $jobs = db_query($sql); 00224 while ($job = db_fetch_object($jobs)) { 00225 $job_pid = $job->pid; 00226 $output = "Name: " . $job->job_name . "\n" 00227 ."Submitted: " . date(DATE_RFC822, $job->submit_date) . "\n" 00228 ."Started: " . date(DATE_RFC822, $job->start_time) . "\n" 00229 ."Module: " . $job->modulename . "\n" 00230 ."Callback: " . $job->callback . "\n" 00231 ."Process ID: " . $job->pid . "\n" 00232 ."Progress: " . $job->progress . "%\n"; 00233 drush_print($output); 00234 } 00235 if (!$job_pid) { 00236 drush_print('There are currently no running jobs.'); 00237 } 00238 //log to the command line with an OK status 00239 drush_log('Running tripal-current-job', 'ok'); 00240 } 00241 00252 function drush_tripal_core_tripal_update_mview() { 00253 $mview_id = drush_get_option('mview_id'); 00254 $table_name = drush_get_option('table_name'); 00255 00256 // Either table_name or mview is required 00257 if (!$mview_id) { 00258 if ($table_name) { 00259 // if table_name supplied use that to get mview_id 00260 $sql = "SELECT mview_id FROM {tripal_mviews} WHERE mv_table='%s'"; 00261 $r = db_fetch_object(db_query($sql, $table_name)); 00262 if (!$r->mview_id) { 00263 drush_set_error('No Materialized View associated with that table_name.'); 00264 } 00265 $mview_id=$r->mview_id; 00266 } 00267 else { 00268 drush_set_error('Either mview_id OR table_name are required.'); 00269 } 00270 } 00271 00272 drush_print('Updating the Materialized View with ID=' . $mview_id); 00273 $status = tripal_update_mview($mview_id); 00274 if ($status) { 00275 drush_log('Materialized View Updated', 'ok'); 00276 } 00277 else { 00278 drush_set_error('Update failed.'); 00279 } 00280 } 00281 00285 function drush_tripal_core_tripal_chado_version() { 00286 $version = tripal_core_get_chado_version(); 00287 drush_print('Current Chado Version: '.$version); 00288 } 00289 00296 function drush_tripal_core_tripal_chadotable_desc($table_name) { 00297 $section = drush_get_option('section'); 00298 00299 drush_print("Schema API Description for $table_name:"); 00300 $desc = tripal_core_get_chado_table_schema($table_name); 00301 00302 if (!empty($section)) { 00303 drush_print("$section = ".print_r($desc[$section],TRUE)); 00304 } 00305 else { 00306 drush_print(print_r($desc,TRUE)); 00307 } 00308 } 00309 00316 function drush_tripal_core_tripal_node_sync($module) { 00317 switch($module) { 00318 case 'analysis': 00319 call_user_func('tripal_analysis_sync_analyses'); 00320 break; 00321 case 'feature': 00322 call_user_func('tripal_feature_sync_features'); 00323 break; 00324 case 'featuremap': 00325 call_user_func('tripal_featuremap_sync_featuremaps'); 00326 break; 00327 case 'library': 00328 call_user_func('tripal_library_sync_libraries'); 00329 break; 00330 case 'organism': 00331 call_user_func('tripal_organism_sync_organisms'); 00332 break; 00333 case 'project': 00334 call_user_func('tripal_project_sync_all_projects'); 00335 break; 00336 case 'stock': 00337 call_user_func('tripal_stock_sync_stocks'); 00338 break; 00339 } 00340 } 00341 00348 function drush_tripal_core_tripal_node_clean($module) { 00349 tripal_core_clean_orphaned_nodes($module, 0); 00350 }