tripal_core.drush.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. /**
  3. * @file
  4. * Contains function relating to drush-integration of this module.
  5. */
  6. /**
  7. * @defgroup tripal_drush Tripal Drush Integration
  8. * @{
  9. * Contains function relating to drush-integration of various tripal modules.
  10. * @}
  11. */
  12. /**
  13. * Describes each drush command implemented by the module
  14. *
  15. * @return
  16. * The first line of description when executing the help for a given command
  17. *
  18. * @ingroup tripal_drush
  19. */
  20. function tripal_core_drush_help($command) {
  21. switch ($command) {
  22. // Deprecated functions
  23. case 'drush:tripal-launch-jobs':
  24. return dt('DEPRECATED. Please use: trp-run-jobs.');
  25. break;
  26. case 'drush:tripal-current-job':
  27. return dt('DEPRECATED. Please use: trp-get-currjob.');
  28. break;
  29. case 'drush:tripal-rerun-job':
  30. return dt('DEPRECATED. Please use: trp-rerun-job.');
  31. break;
  32. }
  33. }
  34. /**
  35. * Registers a drush command and constructs the full help for that command.
  36. *
  37. * @return
  38. * And array of command descriptions
  39. *
  40. * @ingroup tripal_drush
  41. */
  42. function tripal_core_drush_command() {
  43. $items = array();
  44. $items['trp-clean-nodes'] = array(
  45. 'description' => dt('Removes orphaned Drupal nodes.'),
  46. 'arguments' => array(),
  47. 'examples' => array(
  48. 'Standard Example' => 'drush trp-clean-nodes table=feature'
  49. ),
  50. 'options' => array(
  51. 'table' => array(
  52. 'description' => dt('The name of the table that corresonds to the node type to ' .
  53. 'clean up. (e.g organism, feature, stock, library, analysis, pub, etc.)'),
  54. 'required' => TRUE,
  55. ),
  56. ),
  57. );
  58. // DEPRECATED COMMANDS. Deprecated as of Tripal v2.0-rc
  59. $items['tripal-mview-update'] = array(
  60. 'description' => dt('DEPRECATED. Please see: trp-refresh-mview.'),
  61. 'arguments' => array(),
  62. 'examples' => array(
  63. 'By Materialized View ID' => 'drush tripal-update-mview --mview_id=5',
  64. 'By Table Name' => 'drush tripal-update-mview --table_name=organism_feature_count'
  65. ),
  66. 'options' => array(
  67. 'mview_id' => dt('The ID of the materialized view to update'),
  68. 'table_name' => dt('The name of the materialized view table to update.'),
  69. ),
  70. 'aliases' => array('trpmv-up')
  71. );
  72. $items['tripal-jobs-current'] = array(
  73. 'description' => dt('DEPRECATED. Please see: trp-get-currjob.'),
  74. 'arguments' => array(),
  75. 'examples' => array(
  76. 'Standard example' => 'drush tripal-jobs-current',
  77. ),
  78. 'aliases' => array('trpjob-cur'),
  79. );
  80. $items['tripal-jobs-launch'] = array(
  81. 'description' => dt('DEPRECATED. Please see: trp-run-jobs. '),
  82. 'examples' => array(
  83. 'Normal Job' => 'drush tripal-jobs-launch admin',
  84. 'Parallel Job' => 'drush tripal-jobs-launch admin --parallel=1'
  85. ),
  86. 'arguments' => array(
  87. 'username' => dt('The Drupal username under which the job should be run. The permissions for this user will be used.'),
  88. ),
  89. 'options' => array(
  90. '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.'),
  91. 'job_id' => dt('Provide a job_id to run a specific job. Only jobs that have not been run already can be used'),
  92. ),
  93. 'aliases' => array('trpjob-run')
  94. );
  95. $items['tripal-jobs-rerun'] = array(
  96. 'description' => dt('DEPRECATED. Please see: trp-rerun-job. '),
  97. 'examples' => array(
  98. 'Normal Job' => 'drush tripal-jobs-rerun admin 2',
  99. 'Parallel Job' => 'drush tripal-jobs-rerun admin 2 --parallel=1'
  100. ),
  101. 'arguments' => array(
  102. 'username' => dt('The Drupal username under which the job should be run. The permissions for this user will be used.'),
  103. 'job_id' => dt('The job ID to run.'),
  104. ),
  105. 'options' => array(
  106. '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.'),
  107. ),
  108. 'aliases' => array('trpjob-rerun')
  109. );
  110. $items['tripal-chado-version'] = array(
  111. 'description' => dt('DEPRECATED. Please see: trp-get-cversion. '),
  112. 'arguments' => array(),
  113. 'examples' => array(
  114. 'Standard Example' => 'drush tripal-chado-version',
  115. ),
  116. 'aliases' => array('trpchado-ver')
  117. );
  118. $items['tripal-chadotable-desc'] = array(
  119. 'description' => dt('DEPRECATED. Please see: trp-get-table. '),
  120. 'arguments' => array(
  121. 'table_name' => dt('The name of the chado table.'),
  122. ),
  123. 'examples' => array(
  124. 'By Table Name' => 'drush tripal-chadotable-desc --table_name=feature'
  125. ),
  126. 'options' => array(
  127. '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.'),
  128. ),
  129. 'aliases' => array('trpschema-tbl')
  130. );
  131. $items['tripal-node-clean'] = array(
  132. 'description' => dt('DEPRECATED. Please see: trp-clean-nodes.'),
  133. 'arguments' => array(
  134. 'module' => dt('The name of the chado-centric module to clean-up.'),
  135. ),
  136. 'examples' => array(
  137. 'By Table Name' => 'drush tripal-node-clean feature'
  138. ),
  139. 'options' => array(),
  140. 'aliases' => array('trpnode-cln')
  141. );
  142. return $items;
  143. }
  144. /**
  145. * Set the user to run a drush job.
  146. *
  147. * @ingroup tripal_drush
  148. */
  149. function drush_tripal_core_set_user($username) {
  150. drush_tripal_set_user($username);
  151. }
  152. /**
  153. * DEPRECATED. Executes jobs in the Tripal Jobs Queue.
  154. *
  155. * Executed when drush 'trpjob-run' or 'drush tripal-launch-jobs' is called.
  156. *
  157. * @ingroup tripal_drush
  158. */
  159. function drush_tripal_core_tripal_jobs_launch($username) {
  160. $parallel = drush_get_option('parallel');
  161. $job_id = drush_get_option('job_id');
  162. drush_tripal_core_set_user($username);
  163. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  164. "continue to work but please consider using the 'trp-run-jobs' command.\n\n");
  165. if ($parallel) {
  166. drush_print("Tripal Job Launcher (in parallel)");
  167. drush_print("Running as user '$username'");
  168. drush_print("-------------------");
  169. tripal_launch_job($parallel, $job_id);
  170. }
  171. else {
  172. drush_print("Tripal Job Launcher");
  173. drush_print("Running as user '$username'");
  174. drush_print("-------------------");
  175. tripal_launch_job(0, $job_id);
  176. }
  177. }
  178. /**
  179. * DEPRECATED. Executes jobs in the Tripal Jobs Queue.
  180. *
  181. * Executed when 'drush tripal-jobs-rerun' is called.
  182. *
  183. * @ingroup tripal_drush
  184. */
  185. function drush_tripal_core_tripal_jobs_rerun($username, $job_id) {
  186. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  187. "continue to work but please consider using the 'trp-rerun-job' command.\n\n");
  188. drush_tripal_core_set_user($username);
  189. $new_job_id = tripal_rerun_job($job_id, FALSE);
  190. drush_tripal_core_tripal_jobs_launch($username, $new_job_id);
  191. }
  192. /**
  193. * DEPRECATED. Prints details about the current running job.
  194. *
  195. * Executed when 'drush trpjob-curr' or 'drush tripal-current-job' is called.
  196. *
  197. * @ingroup tripal_drush
  198. */
  199. function drush_tripal_core_tripal_jobs_current() {
  200. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  201. "continue to work but please consider using the 'trp-get-currjob' command.\n\n");
  202. drush_tripal_core_trp_get_currjob();
  203. }
  204. /**
  205. * DEPRECATED. Updates the specified materialized view.
  206. *
  207. * @ingroup tripal_drush
  208. */
  209. function drush_tripal_core_tripal_update_mview() {
  210. $mview_id = drush_get_option('mview_id');
  211. $table_name = drush_get_option('table_name');
  212. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  213. "continue to work but please consider using the 'trp-refresh-mview' command.\n\n");
  214. // Either table_name or mview is required
  215. if (!$mview_id) {
  216. if ($table_name) {
  217. // if table_name supplied use that to get mview_id
  218. $sql = "SELECT mview_id FROM {tripal_mviews} WHERE mv_table = :mv_table";
  219. $results = db_query($sql, array(':mv_table' => $table_name));
  220. $r = $resuls->fetchObject();
  221. if (!$r->mview_id) {
  222. drush_set_error('No Materialized View associated with that table_name.');
  223. }
  224. $mview_id=$r->mview_id;
  225. }
  226. else {
  227. drush_set_error('Either mview_id OR table_name are required.');
  228. }
  229. }
  230. drush_print('Updating the Materialized View with ID=' . $mview_id);
  231. $status = tripal_populate_mview($mview_id);
  232. if ($status) {
  233. drush_log('Materialized View Updated', 'ok');
  234. }
  235. else {
  236. drush_set_error('Update failed.');
  237. }
  238. }
  239. /**
  240. * DEPRECATED. Returns the current version of chado.
  241. *
  242. * @ingroup tripal_drush
  243. */
  244. function drush_tripal_core_tripal_chado_version() {
  245. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  246. "continue to work but please consider using the 'trp-get-cversion' command.\n\n");
  247. drush_tripal_core_trp_get_cversion();
  248. }
  249. /**
  250. * DEPRECATED. Returns the Tripal Schema API Description of the given table.
  251. *
  252. * @param $table_name
  253. * The name of the table to return the description of
  254. *
  255. * @ingroup tripal_drush
  256. */
  257. function drush_tripal_core_tripal_chadotable_desc($table_name) {
  258. $section = drush_get_option('section');
  259. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  260. "continue to work but please consider using the 'trp-get-table' command.\n\n");
  261. drush_print("Schema API Description for $table_name:");
  262. $desc = chado_get_schema($table_name);
  263. if (!empty($section)) {
  264. drush_print("$section = " . print_r($desc[$section], TRUE));
  265. }
  266. else {
  267. drush_print(print_r($desc, TRUE));
  268. }
  269. }
  270. /**
  271. * Clean-up orphaned Drupal nodes and chado records.
  272. *
  273. * @ingroup tripal_drush
  274. */
  275. function drush_tripal_core_trp_clean_nodes() {
  276. $table = drush_get_option('table');
  277. chado_cleanup_orphaned_nodes($table, 0);
  278. }
  279. /**
  280. * DEPRECATED. Clean-up orphaned Drupal nodes and chado records.
  281. *
  282. * @param $module
  283. * The name of a module with nodes associated with it. For example, feature
  284. *
  285. * @ingroup tripal_drush
  286. */
  287. function drush_tripal_core_tripal_node_clean($module) {
  288. chado_cleanup_orphaned_nodes($module, 0);
  289. }
  290. /**
  291. * Clean-up orphaned Drupal nodes and chado records.
  292. *
  293. * @ingroup tripal_drush
  294. */
  295. function drush_tripal_chado_trp_clean_nodes() {
  296. $table = drush_get_option('table');
  297. chado_cleanup_orphaned_nodes($table, 0);
  298. }