tripal_core.drush.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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. // TRIPAL JOBS
  23. case 'trp-run-jobs':
  24. return dt('Launches pending jobs waiting in the queue.');
  25. break;
  26. case 'trp-rerun-job':
  27. return dt('Rerun a job in the queue.');
  28. break;
  29. case 'trp-get-currjob':
  30. return dt('Returns details about the currently running tripal job including percent complete.');
  31. break;
  32. // Placeholders for unimplmeneted jobs
  33. case 'trp-show-job':
  34. break;
  35. case 'trp-revert-jobs':
  36. break;
  37. case 'trp-cancel-job':
  38. break;
  39. case 'trp-list-jobs':
  40. break;
  41. // Deprecated functions
  42. case 'drush:tripal-launch-jobs':
  43. return dt('DEPRECATED. Please use: trp-run-jobs.');
  44. break;
  45. case 'drush:tripal-current-job':
  46. return dt('DEPRECATED. Please use: trp-get-currjob.');
  47. break;
  48. case 'drush:tripal-rerun-job':
  49. return dt('DEPRECATED. Please use: trp-rerun-job.');
  50. break;
  51. // Tripal Materialized Views
  52. case 'drush:tripal-update-mview':
  53. return dt('Updates the specified materialized view.');
  54. break;
  55. // Chado Specific
  56. case 'drush:tripal-chado-version':
  57. return dt('Returns the current version of chado associated with this drupal site.');
  58. break;
  59. case 'drush:tripal-chadotable-desc':
  60. return dt('Returns the table description as specified in the Tripal Schema API for the supplied table.');
  61. break;
  62. }
  63. }
  64. /**
  65. * Registers a drush command and constructs the full help for that command.
  66. *
  67. * @return
  68. * And array of command descriptions
  69. *
  70. * @ingroup tripal_drush
  71. */
  72. function tripal_core_drush_command() {
  73. $items = array();
  74. $items['trp-refresh-mview'] = array(
  75. 'description' => dt('Refreshes the contents of the specified materialized view.'),
  76. 'arguments' => array(),
  77. 'examples' => array(
  78. 'By Materialized View ID' => 'drush trp-refresh-mview --mview=5',
  79. 'By Table Name' => 'drush trp-refresh-mview --table=organism_feature_count'
  80. ),
  81. 'options' => array(
  82. 'mview' => dt('The ID of the materialized view to update'),
  83. 'table' => dt('The name of the materialized view table to update.'),
  84. ),
  85. );
  86. $items['trp-get-currjob'] = array(
  87. 'description' => dt('Returns details about the currently running job including percent complete.'),
  88. 'arguments' => array(),
  89. 'examples' => array(
  90. 'Standard example' => 'drush trp-get-currjob',
  91. ),
  92. );
  93. $items['trp-run-jobs'] = array(
  94. 'description' => dt('Launches jobs waiting in the queue. Only one job can execute at a time unless the --parllel=1 option is provided.'),
  95. 'examples' => array(
  96. 'Single Job' => 'drush trp-run-jobs --username=administrator',
  97. 'Parallel Job' => 'drush trp-run-jobs --username=administrator --parallel=1',
  98. 'Max-jobs Job' => 'drush trp-run-jobs --username=administrator --parallel=1 --max_jobs=10',
  99. ),
  100. 'arguments' => array(),
  101. 'options' => array(
  102. 'user' => array(
  103. 'description' => dt('DEPRECATED. Conflicts with Drush 7.x --user argument. Please use the --username argument.'),
  104. ),
  105. 'username' => array(
  106. 'description' => dt('The Drupal user name for which the job should be run. The permissions for this user will be used.'),
  107. ),
  108. '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.'),
  109. 'job_id' => dt('Provide a job_id to run a specific job. Only jobs that have not been run already can be used'),
  110. 'max_jobs' => dt('Indicate the maximum number of concurrent jobs. Default is -1 (unlimited). Ignore if not running parallel jobs'),
  111. 'single' => dt('Execute only one queued job'),
  112. ),
  113. );
  114. $items['trp-rerun-job'] = array(
  115. 'description' => dt('Re-run a specific job from the queue.'),
  116. 'examples' => array(
  117. 'Single Job' => 'drush trp-rerun-job --username=administrator --job_id=2',
  118. 'Parallel Job' => 'drush trp-rerun-job --username=administrator --job_id=2 --parallel=1'
  119. ),
  120. 'arguments' => array(),
  121. 'options' => array(
  122. 'user' => array(
  123. 'description' => dt('DEPRECATED. Conflicts with Drush 7.x --user argument. Please use the --username argument.'),
  124. ),
  125. 'username' => array(
  126. 'description' => dt('The Drupal user name for which the job should be run. The permissions for this user will be used.'),
  127. ),
  128. 'job_id' => array(
  129. 'description' => dt('The job ID to run.'),
  130. 'required' => TRUE,
  131. ),
  132. '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.'),
  133. 'max_jobs' => dt('Indicate the maximum number of concurrent jobs. Default is -1 (unlimited). Ignore if not running parallel jobs'),
  134. 'single' => dt('Execute only one queued job'),
  135. ),
  136. );
  137. $items['trp-get-cversion'] = array(
  138. 'description' => dt('Returns the current installed version of Chado.'),
  139. 'arguments' => array(),
  140. 'examples' => array(
  141. 'Standard Example' => 'drush trp-get-cversion',
  142. ),
  143. );
  144. $items['trp-get-table'] = array(
  145. 'description' => dt('Returns a table description in Drupal Schema API format.'),
  146. 'arguments' => array(),
  147. 'examples' => array(
  148. 'By Table Name' => 'drush trp-get-table --table=feature',
  149. 'By Section' => 'drush trp-get-table --table=feature --section=fields'
  150. ),
  151. 'options' => array(
  152. 'table' => array(
  153. 'description' => dt('The name of the table. The table can be a true Chado table or a custom Chado table.'),
  154. 'required' => TRUE,
  155. ),
  156. 'section' => dt('Only return the specified section of the schema array. Possible sections include: description, fields, primary key, unique keys, foreign keys, indexes, referring_tables.'),
  157. ),
  158. );
  159. $items['trp-clean-nodes'] = array(
  160. 'description' => dt('Removes orphaned Drupal nodes.'),
  161. 'arguments' => array(),
  162. 'examples' => array(
  163. 'Standard Example' => 'drush trp-clean-nodes table=feature'
  164. ),
  165. 'options' => array(
  166. 'table' => array(
  167. 'description' => dt('The name of the table that corresonds to the node type to ' .
  168. 'clean up. (e.g organism, feature, stock, library, analysis, pub, etc.)'),
  169. 'required' => TRUE,
  170. ),
  171. ),
  172. );
  173. // DEPRECATED COMMANDS. Deprecated as of Tripal v2.0-rc
  174. $items['tripal-mview-update'] = array(
  175. 'description' => dt('DEPRECATED. Please see: trp-refresh-mview.'),
  176. 'arguments' => array(),
  177. 'examples' => array(
  178. 'By Materialized View ID' => 'drush tripal-update-mview --mview_id=5',
  179. 'By Table Name' => 'drush tripal-update-mview --table_name=organism_feature_count'
  180. ),
  181. 'options' => array(
  182. 'mview_id' => dt('The ID of the materialized view to update'),
  183. 'table_name' => dt('The name of the materialized view table to update.'),
  184. ),
  185. 'aliases' => array('trpmv-up')
  186. );
  187. $items['tripal-jobs-current'] = array(
  188. 'description' => dt('DEPRECATED. Please see: trp-get-currjob.'),
  189. 'arguments' => array(),
  190. 'examples' => array(
  191. 'Standard example' => 'drush tripal-jobs-current',
  192. ),
  193. 'aliases' => array('trpjob-cur'),
  194. );
  195. $items['tripal-jobs-launch'] = array(
  196. 'description' => dt('DEPRECATED. Please see: trp-run-jobs. '),
  197. 'examples' => array(
  198. 'Normal Job' => 'drush tripal-jobs-launch admin',
  199. 'Parallel Job' => 'drush tripal-jobs-launch admin --parallel=1'
  200. ),
  201. 'arguments' => array(
  202. 'username' => dt('The Drupal username under which the job should be run. The permissions for this user will be used.'),
  203. ),
  204. 'options' => array(
  205. '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.'),
  206. 'job_id' => dt('Provide a job_id to run a specific job. Only jobs that have not been run already can be used'),
  207. ),
  208. 'aliases' => array('trpjob-run')
  209. );
  210. $items['tripal-jobs-rerun'] = array(
  211. 'description' => dt('DEPRECATED. Please see: trp-rerun-job. '),
  212. 'examples' => array(
  213. 'Normal Job' => 'drush tripal-jobs-rerun admin 2',
  214. 'Parallel Job' => 'drush tripal-jobs-rerun admin 2 --parallel=1'
  215. ),
  216. 'arguments' => array(
  217. 'username' => dt('The Drupal username under which the job should be run. The permissions for this user will be used.'),
  218. 'job_id' => dt('The job ID to run.'),
  219. ),
  220. 'options' => array(
  221. '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.'),
  222. ),
  223. 'aliases' => array('trpjob-rerun')
  224. );
  225. $items['tripal-chado-version'] = array(
  226. 'description' => dt('DEPRECATED. Please see: trp-get-cversion. '),
  227. 'arguments' => array(),
  228. 'examples' => array(
  229. 'Standard Example' => 'drush tripal-chado-version',
  230. ),
  231. 'aliases' => array('trpchado-ver')
  232. );
  233. $items['tripal-chadotable-desc'] = array(
  234. 'description' => dt('DEPRECATED. Please see: trp-get-table. '),
  235. 'arguments' => array(
  236. 'table_name' => dt('The name of the chado table.'),
  237. ),
  238. 'examples' => array(
  239. 'By Table Name' => 'drush tripal-chadotable-desc --table_name=feature'
  240. ),
  241. 'options' => array(
  242. '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.'),
  243. ),
  244. 'aliases' => array('trpschema-tbl')
  245. );
  246. $items['tripal-node-clean'] = array(
  247. 'description' => dt('DEPRECATED. Please see: trp-clean-nodes.'),
  248. 'arguments' => array(
  249. 'module' => dt('The name of the chado-centric module to clean-up.'),
  250. ),
  251. 'examples' => array(
  252. 'By Table Name' => 'drush tripal-node-clean feature'
  253. ),
  254. 'options' => array(),
  255. 'aliases' => array('trpnode-cln')
  256. );
  257. return $items;
  258. }
  259. /**
  260. * Set the user to run a drush job.
  261. *
  262. * @ingroup tripal_drush
  263. */
  264. function drush_tripal_core_set_user($username) {
  265. if ($username) {
  266. $sql = "SELECT uid FROM {users} WHERE name = :name";
  267. $results = db_query($sql, array(':name' => $username));
  268. $u = $results->fetchObject();
  269. if (!$u) {
  270. drush_print(date('Y-m-d H:i:s'));
  271. drush_print('ERROR: Please provide a valid username (--username argument) for running this job.');
  272. exit;
  273. }
  274. global $user;
  275. $user = user_load($u->uid);
  276. return $u->uid;
  277. }
  278. else {
  279. drush_print(date('Y-m-d H:i:s'));
  280. drush_print('ERROR: Please provide a username (--username argument) for running this job.');
  281. exit;
  282. }
  283. }
  284. /**
  285. * Executes jobs in the Tripal Jobs Queue.
  286. *
  287. * Executed when 'drush trp-run-job' is called.
  288. *
  289. * @ingroup tripal_drush
  290. */
  291. function drush_tripal_core_trp_run_jobs() {
  292. $parallel = drush_get_option('parallel');
  293. $job_id = drush_get_option('job_id');
  294. $max_jobs = drush_get_option('max_jobs', -1);
  295. $single = drush_get_option('single', 0);
  296. // Unfortunately later versions of Drush use the '--user' argument which
  297. // makes it incompatible with how Tripal was using it. For backwards
  298. // compatabiliy we will accept --user with a non numeric value only. The
  299. // numeric value should be for Drush. Tripal will instead use the
  300. // --username argument for the fture.
  301. $user = drush_get_option('user');
  302. $uname = drush_get_option('username');
  303. if ($user and is_numeric($user)) {
  304. }
  305. elseif ($user) {
  306. print "\nNOTE: Use of the --user argument is deprecated as it conflicts with the --user argument of Drush 7.x. Please now use --username instead.\n\n";
  307. $username = $user;
  308. }
  309. if ($uname) {
  310. $username = $uname;
  311. }
  312. drush_tripal_core_set_user($username);
  313. drush_print("/n" . date('Y-m-d H:i:s'));
  314. if ($parallel) {
  315. drush_print("Tripal Job Launcher (in parallel)");
  316. drush_print("Running as user '$username'");
  317. drush_print("-------------------");
  318. tripal_launch_job($parallel, $job_id, $max_jobs, $single);
  319. }
  320. else {
  321. drush_print("Tripal Job Launcher");
  322. drush_print("Running as user '$username'");
  323. drush_print("-------------------");
  324. tripal_launch_job(0, $job_id);
  325. }
  326. }
  327. /**
  328. * DEPRECATED. Executes jobs in the Tripal Jobs Queue.
  329. *
  330. * Executed when drush 'trpjob-run' or 'drush tripal-launch-jobs' is called.
  331. *
  332. * @ingroup tripal_drush
  333. */
  334. function drush_tripal_core_tripal_jobs_launch($username) {
  335. $parallel = drush_get_option('parallel');
  336. $job_id = drush_get_option('job_id');
  337. drush_tripal_core_set_user($username);
  338. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  339. "continue to work but please consider using the 'trp-run-jobs' command.\n\n");
  340. if ($parallel) {
  341. drush_print("Tripal Job Launcher (in parallel)");
  342. drush_print("Running as user '$username'");
  343. drush_print("-------------------");
  344. tripal_launch_job($parallel, $job_id);
  345. }
  346. else {
  347. drush_print("Tripal Job Launcher");
  348. drush_print("Running as user '$username'");
  349. drush_print("-------------------");
  350. tripal_launch_job(0, $job_id);
  351. }
  352. }
  353. /**
  354. * Executes jobs in the Tripal Jobs Queue.
  355. *
  356. * Executed when 'drush trp-rerun-job' is called.
  357. *
  358. * @ingroup tripal_drush
  359. */
  360. function drush_tripal_core_trp_rerun_job() {
  361. // Unfortunately later versions of Drush use the '--user' argument which
  362. // makes it incompatible with how Tripal was using it. For backwards
  363. // compatabiliy we will accept --user with a non numeric value only. The
  364. // numeric value should be for Drush. Tripal will instead use the
  365. // --username argument for the fture.
  366. $user = drush_get_option('user');
  367. $uname = drush_get_option('username');
  368. print date('Y-m-d H:i:s') . ": USER: '$user', UNAME: '$uname'\n";
  369. if ($user and is_numeric($user)) {
  370. }
  371. elseif ($user) {
  372. print "\nNOTE: Use of the --user argument is deprecated as it conflicts with the --user argument of Drush 7.x. Please now use --username instead.\n\n";
  373. $username = $user;
  374. }
  375. if ($uname) {
  376. $username = $uname;
  377. }
  378. $parallel = drush_get_option('parallel');
  379. $job_id = drush_get_option('job_id');
  380. $max_jobs = drush_get_option('max_jobs', -1);
  381. $single = drush_get_option('single', 0);
  382. drush_tripal_core_set_user($username);
  383. $new_job_id = tripal_rerun_job($job_id, FALSE);
  384. drush_print("/n" . date('Y-m-d H:i:s'));
  385. if ($parallel) {
  386. drush_print("Tripal Job Launcher (in parallel)");
  387. drush_print("Running as user '$username'");
  388. drush_print("-------------------");
  389. tripal_launch_job($parallel, $new_job_id, $max_jobs, $single);
  390. }
  391. else {
  392. drush_print("Tripal Job Launcher");
  393. drush_print("Running as user '$username'");
  394. drush_print("-------------------");
  395. tripal_launch_job(0, $new_job_id);
  396. }
  397. }
  398. /**
  399. * DEPRECATED. Executes jobs in the Tripal Jobs Queue.
  400. *
  401. * Executed when 'drush tripal-jobs-rerun' is called.
  402. *
  403. * @ingroup tripal_drush
  404. */
  405. function drush_tripal_core_tripal_jobs_rerun($username, $job_id) {
  406. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  407. "continue to work but please consider using the 'trp-rerun-job' command.\n\n");
  408. drush_tripal_core_set_user($username);
  409. $new_job_id = tripal_rerun_job($job_id, FALSE);
  410. drush_tripal_core_tripal_jobs_launch($username, $new_job_id);
  411. }
  412. /**
  413. * Prints details about the current running job.
  414. *
  415. * Executed when 'drush trp-get-currjob' is called.
  416. *
  417. * @ingroup tripal_drush
  418. */
  419. function drush_tripal_core_trp_get_currjob() {
  420. $sql = "
  421. SELECT *
  422. FROM {tripal_jobs} TJ
  423. WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL
  424. ";
  425. $jobs = db_query($sql);
  426. foreach ($jobs as $job) {
  427. $job_pid = $job->pid;
  428. $output = "Name: " . $job->job_name . "\n" .
  429. "Submitted: " . date(DATE_RFC822, $job->submit_date) . "\n" .
  430. "Started: " . date(DATE_RFC822, $job->start_time) . "\n" .
  431. "Module: " . $job->modulename . "\n" .
  432. "Callback: " . $job->callback . "\n" .
  433. "Process ID: " . $job->pid . "\n" .
  434. "Progress: " . $job->progress . "%\n";
  435. drush_print(date('Y-m-d H:i:s'));
  436. drush_print($output);
  437. }
  438. if (!$job_pid) {
  439. drush_print(date('Y-m-d H:i:s'));
  440. drush_print('There are currently no running jobs.');
  441. }
  442. //log to the command line with an OK status
  443. drush_log('Running tripal-current-job', 'ok');
  444. }
  445. /**
  446. * DEPRECATED. Prints details about the current running job.
  447. *
  448. * Executed when 'drush trpjob-curr' or 'drush tripal-current-job' is called.
  449. *
  450. * @ingroup tripal_drush
  451. */
  452. function drush_tripal_core_tripal_jobs_current() {
  453. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  454. "continue to work but please consider using the 'trp-get-currjob' command.\n\n");
  455. drush_tripal_core_trp_get_currjob();
  456. }
  457. /**
  458. * Updates the specified materialized view
  459. *
  460. * @ingroup tripal_drush
  461. */
  462. function drush_tripal_core_trp_refresh_mview() {
  463. $mview_id = drush_get_option('mview');
  464. $table_name = drush_get_option('table');
  465. // Either table_name or mview is required
  466. if (!$mview_id) {
  467. if ($table_name) {
  468. // if table_name supplied use that to get mview_id
  469. $sql = "SELECT mview_id FROM {tripal_mviews} WHERE mv_table = :mv_table";
  470. $results = db_query($sql, array(':mv_table' => $table_name));
  471. $r = $resuls->fetchObject();
  472. if (!$r->mview_id) {
  473. drush_set_error('No Materialized View associated with that table_name.');
  474. }
  475. $mview_id=$r->mview_id;
  476. }
  477. else {
  478. drush_set_error('Plese provide one option of --mview or --table.');
  479. }
  480. }
  481. drush_print('Updating the Materialized View with ID=' . $mview_id);
  482. $status = tripal_populate_mview($mview_id);
  483. if ($status) {
  484. drush_log('Materialized View Updated', 'ok');
  485. }
  486. else {
  487. drush_set_error('Update failed.');
  488. }
  489. }
  490. /**
  491. * DEPRECATED. Updates the specified materialized view.
  492. *
  493. * @ingroup tripal_drush
  494. */
  495. function drush_tripal_core_tripal_update_mview() {
  496. $mview_id = drush_get_option('mview_id');
  497. $table_name = drush_get_option('table_name');
  498. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  499. "continue to work but please consider using the 'trp-refresh-mview' command.\n\n");
  500. // Either table_name or mview is required
  501. if (!$mview_id) {
  502. if ($table_name) {
  503. // if table_name supplied use that to get mview_id
  504. $sql = "SELECT mview_id FROM {tripal_mviews} WHERE mv_table = :mv_table";
  505. $results = db_query($sql, array(':mv_table' => $table_name));
  506. $r = $resuls->fetchObject();
  507. if (!$r->mview_id) {
  508. drush_set_error('No Materialized View associated with that table_name.');
  509. }
  510. $mview_id=$r->mview_id;
  511. }
  512. else {
  513. drush_set_error('Either mview_id OR table_name are required.');
  514. }
  515. }
  516. drush_print('Updating the Materialized View with ID=' . $mview_id);
  517. $status = tripal_populate_mview($mview_id);
  518. if ($status) {
  519. drush_log('Materialized View Updated', 'ok');
  520. }
  521. else {
  522. drush_set_error('Update failed.');
  523. }
  524. }
  525. /**
  526. * DEPRECATED. Returns the current version of chado.
  527. *
  528. * @ingroup tripal_drush
  529. */
  530. function drush_tripal_core_tripal_chado_version() {
  531. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  532. "continue to work but please consider using the 'trp-get-cversion' command.\n\n");
  533. drush_tripal_core_trp_get_cversion();
  534. }
  535. /**
  536. * Returns the current version of chado.
  537. *
  538. * @ingroup tripal_drush
  539. */
  540. function drush_tripal_core_trp_get_cversion() {
  541. $version = $GLOBALS["exact_chado_version"];
  542. drush_print('Current Chado Version: ' . $version);
  543. }
  544. /**
  545. * Returns the Tripal Schema API Description of the given table
  546. *
  547. * @ingroup tripal_drush
  548. */
  549. function drush_tripal_core_trp_get_table() {
  550. $section = drush_get_option('section');
  551. $table_name = drush_get_option('table');
  552. drush_print("Schema API Description for $table_name:");
  553. $desc = chado_get_schema($table_name);
  554. if (!empty($section)) {
  555. drush_print("$section = " . print_r($desc[$section], TRUE));
  556. }
  557. else {
  558. drush_print(print_r($desc, TRUE));
  559. }
  560. }
  561. /**
  562. * DEPRECATED. Returns the Tripal Schema API Description of the given table.
  563. *
  564. * @param $table_name
  565. * The name of the table to return the description of
  566. *
  567. * @ingroup tripal_drush
  568. */
  569. function drush_tripal_core_tripal_chadotable_desc($table_name) {
  570. $section = drush_get_option('section');
  571. drush_print("\n\nDEPRECATED: This drush command is outdated.\nIt will ".
  572. "continue to work but please consider using the 'trp-get-table' command.\n\n");
  573. drush_print("Schema API Description for $table_name:");
  574. $desc = chado_get_schema($table_name);
  575. if (!empty($section)) {
  576. drush_print("$section = " . print_r($desc[$section], TRUE));
  577. }
  578. else {
  579. drush_print(print_r($desc, TRUE));
  580. }
  581. }
  582. /**
  583. * Clean-up orphaned Drupal nodes and chado records.
  584. *
  585. * @ingroup tripal_drush
  586. */
  587. function drush_tripal_core_trp_clean_nodes() {
  588. $table = drush_get_option('table');
  589. chado_cleanup_orphaned_nodes($table, 0);
  590. }
  591. /**
  592. * DEPRECATED. Clean-up orphaned Drupal nodes and chado records.
  593. *
  594. * @param $module
  595. * The name of a module with nodes associated with it. For example, feature
  596. *
  597. * @ingroup tripal_drush
  598. */
  599. function drush_tripal_core_tripal_node_clean($module) {
  600. chado_cleanup_orphaned_nodes($module, 0);
  601. }