tripal_core.module 11 KB

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