tripal_core.module 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. require_once "jobs.php";
  3. require_once "mviews.php";
  4. require_once "chado_install.php";
  5. require_once "tripal_core.api.inc";
  6. /**
  7. * @defgroup tripal_modules Tripal Modules
  8. * @{
  9. * All documented functions for the various Tripal Modules
  10. * @}
  11. *
  12. * @defgroup tripal_core Core Tripal Module
  13. * @ingroup tripal_modules
  14. */
  15. /**
  16. *
  17. *
  18. * @ingroup tripal_core
  19. */
  20. function tripal_core_init() {
  21. // the two lines below are necessary to ensure that the search_path
  22. // variable is always set. In the case where a view needs to query the
  23. // chado schema when it is local to the Drupal database. Otherwise the
  24. // search_path isn't set. When tripal_db_set_active is called it
  25. // automatically sets the serach path if chado is local to the
  26. // Drupal database
  27. $previous = tripal_db_set_active('chado');
  28. tripal_db_set_active($previous);
  29. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  30. // only if the chado database is present.
  31. if (tripal_core_is_chado_installed()) {
  32. $previous_db = tripal_db_set_active('chado'); // use chado database
  33. if (!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))) {
  34. $results = db_query("INSERT INTO {cv} (name,definition) ".
  35. "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  36. }
  37. if (!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))) {
  38. $results = db_query("INSERT INTO {db} (name,description) ".
  39. "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  40. }
  41. tripal_db_set_active($previous_db); // now use drupal database
  42. }
  43. // add some variables for all javasript to use for building URLs
  44. global $base_url;
  45. $theme_dir = drupal_get_path('theme', 'tripal');
  46. $clean_urls = variable_get('clean_url', 0);
  47. drupal_add_js(
  48. "var baseurl = '$base_url';
  49. var themedir = '$theme_dir';
  50. var isClean = $clean_urls;",
  51. 'inline');
  52. // make sure the date time settings are the way Tripal will insert them
  53. // otherwise PostgreSQL version that may have a different datestyle setting
  54. // will fail when inserting or updating a date column in a table.
  55. db_query("SET DATESTYLE TO '%s'", 'MDY');
  56. }
  57. /**
  58. *
  59. *
  60. * @ingroup tripal_core
  61. */
  62. function tripal_core_menu() {
  63. $items = array();
  64. // Triapl setting groups
  65. $items['admin/tripal'] = array(
  66. 'title' => 'Tripal Management',
  67. 'description' => "Manage the behavior or Tripal and its various modules.",
  68. 'position' => 'right',
  69. 'weight' => -5,
  70. 'page callback' => 'system_admin_menu_block_page',
  71. 'access arguments' => array('administer site configuration'),
  72. 'file' => 'system.admin.inc',
  73. 'file path' => drupal_get_path('module', 'system'),
  74. );
  75. $items['tripal_toggle_box_menu/%/%/%'] = array(
  76. 'title' => 'Toggle Box',
  77. 'page callback' => 'tripal_toggle_box_menu',
  78. 'page arguments' => array(1, 2, 3),
  79. 'access arguments' => array('access administration pages'),
  80. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  81. );
  82. $items['admin/tripal/chado_1_11_install'] = array(
  83. 'title' => 'Install Chado v1.11',
  84. 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
  85. 'page callback' => 'drupal_get_form',
  86. 'page arguments' => array('tripal_core_chado_v1_11_load_form'),
  87. 'access arguments' => array('access administration pages'),
  88. 'type' => MENU_NORMAL_ITEM,
  89. );
  90. // Jobs Management
  91. $items['admin/tripal/tripal_jobs'] = array(
  92. 'title' => 'Jobs',
  93. 'description' => 'Jobs managed by Tripal',
  94. 'page callback' => 'tripal_jobs_report',
  95. 'access arguments' => array('access administration pages'),
  96. 'type' => MENU_NORMAL_ITEM,
  97. );
  98. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  99. 'title' => 'Jobs',
  100. 'description' => 'Cancel a pending job',
  101. 'page callback' => 'tripal_jobs_cancel',
  102. 'page arguments' => array(4),
  103. 'access arguments' => array('access administration pages'),
  104. 'type' => MENU_CALLBACK,
  105. );
  106. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  107. 'title' => 'Jobs',
  108. 'description' => 'Re-run an existing job.',
  109. 'page callback' => 'tripal_jobs_rerun',
  110. 'page arguments' => array(4),
  111. 'access arguments' => array('access administration pages'),
  112. 'type' => MENU_CALLBACK,
  113. );
  114. $items['admin/tripal/tripal_jobs/view/%'] = array(
  115. 'title' => 'Jobs Details',
  116. 'description' => 'View job details.',
  117. 'page callback' => 'tripal_jobs_view',
  118. 'page arguments' => array(4),
  119. 'access arguments' => array('access administration pages'),
  120. 'type' => MENU_CALLBACK,
  121. );
  122. // Materialized Views
  123. $items['admin/tripal/mviews'] = array(
  124. 'title' => 'MViews',
  125. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  126. 'page callback' => 'tripal_mviews_report',
  127. 'access arguments' => array('access administration pages'),
  128. 'type' => MENU_NORMAL_ITEM,
  129. );
  130. $items['admin/tripal/mviews/report/%'] = array(
  131. 'title' => 'Materialized View',
  132. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  133. 'page callback' => 'tripal_mview_report',
  134. 'page arguments' => array(4),
  135. 'access arguments' => array('access administration pages'),
  136. 'type' => MENU_NORMAL_ITEM,
  137. );
  138. $items['admin/tripal/mviews/new'] = array(
  139. 'title' => 'Create MView',
  140. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  141. 'page callback' => 'drupal_get_form',
  142. 'page arguments' => array('tripal_mviews_form'),
  143. 'access arguments' => array('access administration pages'),
  144. 'type' => MENU_CALLBACK,
  145. );
  146. $items['admin/tripal/mviews/edit/%'] = array(
  147. 'title' => 'Edit MView',
  148. 'page callback' => 'drupal_get_form',
  149. 'page arguments' => array('tripal_mviews_form', 4),
  150. 'access arguments' => array('access administration pages'),
  151. 'type' => MENU_NORMAL_ITEM,
  152. );
  153. $items['admin/tripal/mviews/action/%/%'] = array(
  154. 'title' => 'Create MView',
  155. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  156. 'page callback' => 'tripal_mviews_action',
  157. 'page arguments' => array(4, 5, "1"),
  158. 'access arguments' => array('access administration pages'),
  159. 'type' => MENU_CALLBACK,
  160. );
  161. return $items;
  162. }
  163. /**
  164. * Set the permission types that the chado module uses. Essentially we
  165. * want permissionis that protect creation, editing and deleting of chado
  166. * data objects
  167. *
  168. * @ingroup tripal_core
  169. */
  170. function tripal_core_perm() {
  171. return array();
  172. }
  173. /**
  174. *
  175. *
  176. * @param $dbname
  177. * The name of the database to switch to as indicated in settings.php
  178. * Should be either default or chado
  179. *
  180. * @return
  181. * The name of the previously set database
  182. *
  183. * @ingroup tripal_chado_api
  184. */
  185. function tripal_core_is_chado_installed() {
  186. global $db_url, $db_type;
  187. // first check if chado is in the db_url of the
  188. // settings.php file
  189. if (is_array($db_url)) {
  190. if (isset($db_url['chado'])) {
  191. return TRUE;
  192. }
  193. }
  194. // check to make sure the chado schema exists
  195. return tripal_core_chado_schema_exists();
  196. }
  197. /**
  198. *
  199. * @ingroup tripal_core
  200. */
  201. function tripal_core_theme() {
  202. return array(
  203. 'tripal_core_job_view' => array(
  204. 'arguments' => array('job_id' => NULL),
  205. 'template' => 'tripal_core_job_view',
  206. ),
  207. );
  208. }
  209. /**
  210. *
  211. * @ingroup tripal_core
  212. */
  213. function tripal_core_job_describe_args($callback, $args) {
  214. $new_args = array();
  215. if ($callback == 'tripal_update_mview') {
  216. // get this mview details
  217. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
  218. $mview = db_fetch_object(db_query($sql, $args[0]));
  219. $new_args['View Name'] = $mview->name;
  220. }
  221. return $new_args;
  222. }
  223. // this is just a wrapper for backwards compatibility with a naming mistake.
  224. // it can go away in the future as it only is useful for jobs created by v0.3b
  225. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  226. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  227. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  228. $update, $refresh, $remove, $job);
  229. }
  230. /**
  231. * Implements hook_coder_ignore().
  232. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  233. */
  234. function tripal_core_coder_ignore() {
  235. return array(
  236. 'path' => drupal_get_path('module', 'tripal_core'),
  237. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  238. );
  239. }