tripal_core.module 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. require_once "includes/jobs.php";
  3. require_once "includes/mviews.php";
  4. require_once "includes/custom_tables.php";
  5. require_once "includes/chado_install.php";
  6. require_once "api/tripal_core.api.inc";
  7. /**
  8. * @defgroup tripal_modules Tripal Modules
  9. * @{
  10. * All documented functions for the various Tripal Modules
  11. * @}
  12. *
  13. * @defgroup tripal_core Core Tripal Module
  14. * @ingroup tripal_modules
  15. */
  16. /**
  17. * Implements hook_init().
  18. * Used to set the search_path, create default content and set default variables.
  19. *
  20. * @ingroup tripal_core
  21. */
  22. function tripal_core_init() {
  23. global $base_url;
  24. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  25. // only if the chado database is present.
  26. if (tripal_core_is_chado_installed()) {
  27. // make sure the current version of chado is set
  28. tripal_core_set_chado_version();
  29. if (!db_fetch_object(chado_query("SELECT * FROM {cv} WHERE name = 'tripal'"))) {
  30. $results = chado_query(
  31. "INSERT INTO {cv} (name,definition) ".
  32. "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  33. }
  34. if (!db_fetch_object(chado_query("SELECT * FROM {db} WHERE name = 'tripal'"))) {
  35. $results = chado_query(
  36. "INSERT INTO {db} (name,description) ".
  37. "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  38. }
  39. }
  40. // add some variables for all javasript to use for building URLs
  41. global $base_url;
  42. $theme_dir = drupal_get_path('theme', 'tripal');
  43. $clean_urls = variable_get('clean_url', 0);
  44. drupal_add_js(
  45. " var baseurl = '$base_url';
  46. var themedir = '$theme_dir';
  47. var isClean = $clean_urls;",
  48. 'inline', 'header');
  49. // make sure the date time settings are the way Tripal will insert them
  50. // otherwise PostgreSQL version that may have a different datestyle setting
  51. // will fail when inserting or updating a date column in a table.
  52. db_query("SET DATESTYLE TO '%s'", 'MDY');
  53. // in the event that an errant Tripal or extension function fails to
  54. // set the postgres search_path back to noraml we do it here on
  55. // init of the core
  56. tripal_db_set_default_search_path();
  57. }
  58. /**
  59. * Implements hook_menu().
  60. * Defines all menu items needed by Tripal Core
  61. *
  62. * @ingroup tripal_core
  63. */
  64. function tripal_core_menu() {
  65. $items = array();
  66. // Triapl setting groups
  67. $items['admin/tripal'] = array(
  68. 'title' => 'Tripal Management',
  69. 'description' => "Manage the behavior or Tripal and its various modules.",
  70. 'position' => 'right',
  71. 'weight' => -5,
  72. 'page callback' => 'system_admin_menu_block_page',
  73. 'access arguments' => array('administer site configuration'),
  74. 'file' => 'system.admin.inc',
  75. 'file path' => drupal_get_path('module', 'system'),
  76. );
  77. $items['tripal_toggle_box_menu/%/%/%'] = array(
  78. 'title' => 'Toggle Box',
  79. 'page callback' => 'tripal_toggle_box_menu',
  80. 'page arguments' => array(1, 2, 3),
  81. 'access arguments' => array('access administration pages'),
  82. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  83. );
  84. $items['admin/tripal/chado_install'] = array(
  85. 'title' => 'Install Chado Schema',
  86. 'description' => 'Installs the Chado database tables, views, etc., inside the current Drupal database',
  87. 'page callback' => 'drupal_get_form',
  88. 'page arguments' => array('tripal_core_chado_load_form'),
  89. 'access arguments' => array('access administration pages'),
  90. 'type' => MENU_NORMAL_ITEM,
  91. );
  92. // Jobs Management
  93. $items['admin/tripal/tripal_jobs'] = array(
  94. 'title' => 'Jobs',
  95. 'description' => 'Jobs managed by Tripal',
  96. 'page callback' => 'tripal_jobs_report',
  97. 'access arguments' => array('access administration pages'),
  98. 'type' => MENU_NORMAL_ITEM,
  99. );
  100. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  101. 'title' => 'Jobs',
  102. 'description' => 'Cancel a pending job',
  103. 'page callback' => 'tripal_jobs_cancel',
  104. 'page arguments' => array(4),
  105. 'access arguments' => array('access administration pages'),
  106. 'type' => MENU_CALLBACK,
  107. );
  108. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  109. 'title' => 'Jobs',
  110. 'description' => 'Re-run an existing job.',
  111. 'page callback' => 'tripal_jobs_rerun',
  112. 'page arguments' => array(4),
  113. 'access arguments' => array('access administration pages'),
  114. 'type' => MENU_CALLBACK,
  115. );
  116. $items['admin/tripal/tripal_jobs/view/%'] = array(
  117. 'title' => 'Jobs Details',
  118. 'description' => 'View job details.',
  119. 'page callback' => 'tripal_jobs_view',
  120. 'page arguments' => array(4),
  121. 'access arguments' => array('access administration pages'),
  122. 'type' => MENU_CALLBACK,
  123. );
  124. // Materialized Views
  125. $items['admin/tripal/mviews'] = array(
  126. 'title' => 'MViews',
  127. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  128. 'page callback' => 'tripal_mviews_report',
  129. 'access arguments' => array('access administration pages'),
  130. 'type' => MENU_NORMAL_ITEM,
  131. );
  132. $items['admin/tripal/mviews/report/%'] = array(
  133. 'title' => 'Materialized View',
  134. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  135. 'page callback' => 'tripal_mview_report',
  136. 'page arguments' => array(4),
  137. 'access arguments' => array('access administration pages'),
  138. 'type' => MENU_NORMAL_ITEM,
  139. );
  140. $items['admin/tripal/mviews/new'] = array(
  141. 'title' => 'Create MView',
  142. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  143. 'page callback' => 'drupal_get_form',
  144. 'page arguments' => array('tripal_mviews_form'),
  145. 'access arguments' => array('access administration pages'),
  146. 'type' => MENU_CALLBACK,
  147. );
  148. $items['admin/tripal/mviews/edit/%'] = array(
  149. 'title' => 'Edit MView',
  150. 'page callback' => 'drupal_get_form',
  151. 'page arguments' => array('tripal_mviews_form', 4),
  152. 'access arguments' => array('access administration pages'),
  153. 'type' => MENU_NORMAL_ITEM,
  154. );
  155. $items['admin/tripal/mviews/action/%/%'] = array(
  156. 'title' => 'Create MView',
  157. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  158. 'page callback' => 'tripal_mviews_action',
  159. 'page arguments' => array(4, 5, "1"),
  160. 'access arguments' => array('access administration pages'),
  161. 'type' => MENU_CALLBACK,
  162. );
  163. // Custom Tables
  164. $items['admin/tripal/custom_tables'] = array(
  165. 'title' => 'Custom Tables',
  166. 'description' => 'Custom tables are added to Chado.',
  167. 'page callback' => 'tripal_custom_tables_list',
  168. 'access arguments' => array('access administration pages'),
  169. 'type' => MENU_NORMAL_ITEM,
  170. );
  171. $items['admin/tripal/custom_tables/view/%'] = array(
  172. 'title' => 'Custom Tables',
  173. 'description' => 'Custom tables are added to Chado.',
  174. 'page callback' => 'tripal_custom_table_view',
  175. 'page arguments' => array(4),
  176. 'access arguments' => array('access administration pages'),
  177. 'type' => MENU_NORMAL_ITEM,
  178. );
  179. $items['admin/tripal/custom_tables/new'] = array(
  180. 'title' => 'Create Custom Table',
  181. 'description' => 'Custom tables are added to Chado.',
  182. 'page callback' => 'drupal_get_form',
  183. 'page arguments' => array('tripal_custom_tables_form'),
  184. 'access arguments' => array('access administration pages'),
  185. 'type' => MENU_CALLBACK,
  186. );
  187. $items['admin/tripal/custom_tables/edit/%'] = array(
  188. 'title' => 'Edit Custom Table',
  189. 'page callback' => 'drupal_get_form',
  190. 'page arguments' => array('tripal_custom_tables_form', 4),
  191. 'access arguments' => array('access administration pages'),
  192. 'type' => MENU_NORMAL_ITEM,
  193. );
  194. $items['admin/tripal/custom_tables/action/%/%'] = array(
  195. 'title' => 'Create Custom TAble',
  196. 'description' => 'Custom tables are added to Chado.',
  197. 'page callback' => 'tripal_custom_tables_action',
  198. 'page arguments' => array(4, 5, "1"),
  199. 'access arguments' => array('access administration pages'),
  200. 'type' => MENU_CALLBACK,
  201. );
  202. return $items;
  203. }
  204. /**
  205. * Set the permission types that the chado module uses. Essentially we
  206. * want permissionis that protect creation, editing and deleting of chado
  207. * data objects
  208. *
  209. * @ingroup tripal_core
  210. */
  211. function tripal_core_perm() {
  212. return array();
  213. }
  214. /**
  215. * Implements hook_theme().
  216. * Registers template files/functions used by this module.
  217. *
  218. * @ingroup tripal_core
  219. */
  220. function tripal_core_theme() {
  221. return array(
  222. 'tripal_core_job_view' => array(
  223. 'arguments' => array('job_id' => NULL),
  224. 'template' => 'tripal_core_job_view',
  225. ),
  226. );
  227. }
  228. /**
  229. * Implements hook_job_describe_args().
  230. * Describes the arguements for the tripal_update_mview job to allow for greater
  231. * readability in the jobs details pages.
  232. *
  233. * @param $callback
  234. * The callback of the current tripal job (this is the function that will be executed
  235. * when tripal_launch_jobs.php is run.
  236. * @param $args
  237. * An array of arguments passed in when the job was registered.
  238. *
  239. * @return
  240. * A more readable $args array
  241. *
  242. * @ingroup tripal_core
  243. */
  244. function tripal_core_job_describe_args($callback, $args) {
  245. $new_args = array();
  246. if ($callback == 'tripal_update_mview') {
  247. // get this mview details
  248. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
  249. $mview = db_fetch_object(db_query($sql, $args[0]));
  250. $new_args['View Name'] = $mview->name;
  251. }
  252. elseif ($callback == 'tripal_core_install_chado') {
  253. $new_args['Action'] = $args[0];
  254. }
  255. return $new_args;
  256. }
  257. /**
  258. * this is just a wrapper for backwards compatibility with a naming mistake.
  259. * it can go away in the future as it only is useful for jobs created by v0.3b
  260. *
  261. * @todo remove this function
  262. */
  263. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  264. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  265. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  266. $update, $refresh, $remove, $job);
  267. }
  268. /**
  269. * Implements hook_coder_ignore().
  270. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  271. */
  272. function tripal_core_coder_ignore() {
  273. return array(
  274. 'path' => drupal_get_path('module', 'tripal_core'),
  275. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  276. );
  277. }