tripal_core.module 11 KB

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