tripal_core.module 10 KB

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