tripal.install 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions used to install/uninstall tripal.
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal
  10. */
  11. function tripal_install() {
  12. // On upgrade from Tv2 to Tv3 we need to add a new field to the tripal_jobs
  13. // table it's missing.
  14. if (!db_field_exists('tripal_jobs', 'includes')) {
  15. db_add_field('tripal_jobs', 'includes', array(
  16. 'type' => 'text',
  17. 'description' => 'A serialized array of file paths that should be included prior to executing the job.',
  18. 'not null' => FALSE,
  19. ));
  20. }
  21. $menu = array(
  22. 'menu_name' => 'data_search',
  23. 'title' => t('Data Search'),
  24. 'description' => 'The Data Search menu contains links to search tools for finding biological data.',
  25. );
  26. menu_save($menu);
  27. }
  28. /**
  29. * Adds variables for bundles.
  30. */
  31. function tripal_add_variables() {
  32. // Add tripal bundle variables needed for storing additional settings for
  33. // Tripal Bundles.
  34. tripal_insert_variable(
  35. 'title_format',
  36. 'A pattern including tokens that can be used to generate tripal entity titles.'
  37. );
  38. tripal_insert_variable(
  39. 'url_format',
  40. 'A pattern including tokens that can be used to generate tripal entity url aliases.'
  41. );
  42. tripal_insert_variable(
  43. 'description',
  44. 'The description of a Tripal Entity type/bundle.'
  45. );
  46. tripal_insert_variable(
  47. 'hide_empty_field',
  48. 'Structure->Tripal Content Type->edit checkbox to hide empty fields for that bundle.'
  49. );
  50. tripal_insert_variable(
  51. 'ajax_field',
  52. 'Structure->Tripal Content Type->edit checkbox for ajax fields for that bundle.'
  53. );
  54. }
  55. /**
  56. *
  57. */
  58. function tripal_uninstall() {
  59. /*
  60. // So somehow I was able to uninstall this module without deleting the bundles. This
  61. // caused aweful errors because fields weren't deleted so when I re-installed, the code
  62. // tried to create fields that were inactive (despite checking if the field exists
  63. // before creating). The following code was meant to ensure that all content was deleted
  64. // before uninstall so these errors would not occur. Unfortunatly I am now unable to
  65. // test this because the Field API module is disabling uninstall of Tripal Chado until
  66. // all the content is deleted. Thus ensuring the errors described above don't occur.
  67. // But I'm Sure I was able to uninstall with content before...
  68. // **I am slowly going crazy; Crazy going slowly am I**
  69. // Anyway, I'll leaving the solution code here in case I am able to repeat it in
  70. // the future.
  71. // @see https://www.drupal.org/node/1262092
  72. // @see https://www.drupal.org/node/1861710
  73. // First delete all TripalEntities.
  74. $entity_ids = (new EntityFieldQuery)->entityCondition("entity_type", "TripalEntity")->execute();
  75. $entity_ids = reset($entity_ids);
  76. entity_delete_multiple("TripalEntity", array_keys($entity_ids));
  77. // Then delete all TripalBundles.
  78. $bundle_ids = (new EntityFieldQuery)->entityCondition("entity_type", "TripalBundle")->execute();
  79. $bundle_ids = reset($bundle_ids);
  80. entity_delete_multiple("TripalBundle", array_keys($bundle_ids));
  81. // @TODO: Should we delete all TripalVocabularies and TripalTerms?
  82. // Finally purge all fields that are no longer used.
  83. field_purge_batch(100);
  84. */
  85. }
  86. /**
  87. *
  88. */
  89. function tripal_enable() {
  90. // If Tripal v2 is already installed, the installation of this module
  91. // will try and recreate some of the tables created with tripal_core and the
  92. // installation will fail. Therefore, in the install we renamed it. Now
  93. // we want to move it back.
  94. if (db_table_exists('tripal_jobs2')) {
  95. $sql = "DROP TABLE tripal_jobs";
  96. db_query($sql);
  97. db_rename_table('tripal_jobs2', 'tripal_jobs');
  98. }
  99. if (db_table_exists('tripal_token_formats2')) {
  100. $sql = "DROP TABLE tripal_token_formats";
  101. db_query($sql);
  102. db_rename_table('tripal_token_formats2', 'tripal_token_formats');
  103. }
  104. if (db_table_exists('tripal_variables2')) {
  105. $sql = "DROP TABLE tripal_variables";
  106. db_query($sql);
  107. db_rename_table('tripal_variables2', 'tripal_variables');
  108. }
  109. if (db_table_exists('tripal_custom_quota2')) {
  110. $sql = "DROP TABLE tripal_custom_quota";
  111. db_query($sql);
  112. db_rename_table('tripal_custom_quota2', 'tripal_custom_quota');
  113. }
  114. if (db_table_exists('tripal_expiration_files2')) {
  115. $sql = "DROP TABLE tripal_expiration_files";
  116. db_query($sql);
  117. db_rename_table('tripal_expiration_files2', 'tripal_expiration_files');
  118. }
  119. // schema change
  120. if (!db_field_exists('tripal_jobs', 'includes')) {
  121. $sql = "ALTER TABLE tripal_jobs ADD COLUMN includes text";
  122. db_query($sql);
  123. }
  124. tripal_add_variables();
  125. }
  126. /**
  127. * Implementation of hook_schema().
  128. *
  129. * @ingroup tripal
  130. */
  131. function tripal_schema() {
  132. // If Tripal v2 is already installed, the installation of this module
  133. // will try and recreate some of the tables created with tripal_core and the
  134. // installation will fail. Therefore, we need to temporarily move those
  135. // tables out of the way, let the module install and then move them back.
  136. $migrated = variable_get ('tripal_v2_upgrade_v3_check', FALSE);
  137. if (!$migrated) {
  138. if (db_table_exists('tripal_jobs')) {
  139. db_rename_table('tripal_jobs', 'tripal_jobs2');
  140. }
  141. if (db_table_exists('tripal_token_formats')) {
  142. db_rename_table('tripal_token_formats', 'tripal_token_formats2');
  143. }
  144. if (db_table_exists('tripal_variables')) {
  145. db_rename_table('tripal_variables', 'tripal_variables2');
  146. }
  147. if (db_table_exists('tripal_custom_quota')) {
  148. db_rename_table('tripal_custom_quota', 'tripal_custom_quota2');
  149. }
  150. if (db_table_exists('tripal_expiration_files')) {
  151. db_rename_table('tripal_expiration_files', 'tripal_expiration_files2');
  152. }
  153. variable_set ('tripal_v2_upgrade_v3_check', TRUE);
  154. }
  155. $schema = array();
  156. $schema['tripal_jobs'] = tripal_tripal_jobs_schema();
  157. $schema['tripal_token_formats'] = tripal_tripal_token_formats_schema();
  158. $schema['tripal_variables'] = tripal_tripal_variables_schema();
  159. $schema['tripal_expiration_files'] = tripal_tripal_expiration_files_schema();
  160. $schema['tripal_custom_quota'] = tripal_tripal_custom_quota_schema();
  161. // Adds a table for managing TripalEntity entities.
  162. $schema['tripal_vocab'] = tripal_tripal_vocab_schema();
  163. $schema['tripal_term'] = tripal_tripal_term_schema();
  164. $schema['tripal_entity'] = tripal_tripal_entity_schema();
  165. $schema['tripal_bundle'] = tripal_tripal_bundle_schema();
  166. $schema['tripal_import'] = tripal_tripal_import_schema();
  167. $schema['tripal_collection'] = tripal_tripal_collection_schema();
  168. $schema['tripal_collection_bundle'] = tripal_tripal_collection_bundle_schema();
  169. // Adds a table for additional information related to bundles.
  170. $schema['tripal_bundle_variables'] = tripal_tripal_bundle_variables_schema();
  171. // Adds a table for administrative notifications on the dashboard.
  172. $schema['tripal_admin_notfications'] = tripal_tripal_admin_notifications_schema();
  173. return $schema;
  174. }
  175. /**
  176. * Returns the Drupal Schema API array for the tripal_jobs table.
  177. */
  178. function tripal_tripal_jobs_schema() {
  179. return array(
  180. 'fields' => array(
  181. 'job_id' => array(
  182. 'type' => 'serial',
  183. 'unsigned' => TRUE,
  184. 'not null' => TRUE
  185. ),
  186. 'uid' => array(
  187. 'type' => 'int',
  188. 'unsigned' => TRUE,
  189. 'not null' => TRUE,
  190. 'description' => 'The Drupal userid of the submitee'
  191. ),
  192. 'job_name' => array(
  193. 'type' => 'varchar',
  194. 'length' => 255,
  195. 'not null' => TRUE
  196. ),
  197. 'modulename' => array(
  198. 'type' => 'varchar',
  199. 'length' => 50,
  200. 'not null' => TRUE,
  201. 'description' => 'The module name that provides the callback for this job'
  202. ),
  203. 'callback' => array(
  204. 'type' => 'varchar',
  205. 'length' => 255,
  206. 'not null' => TRUE
  207. ),
  208. 'arguments' => array(
  209. 'type' => 'text',
  210. 'size' => 'normal',
  211. 'not null' => FALSE
  212. ),
  213. 'progress' => array(
  214. 'type' => 'int',
  215. 'unsigned' => TRUE,
  216. 'default' => 0,
  217. 'not null' => FALSE,
  218. 'description' => 'a value from 0 to 100 indicating percent complete'
  219. ),
  220. 'status' => array(
  221. 'type' => 'varchar',
  222. 'length' => 50,
  223. 'not null' => TRUE
  224. ),
  225. 'submit_date' => array(
  226. 'type' => 'int',
  227. 'not null' => TRUE,
  228. 'description' => 'UNIX integer submit time'
  229. ),
  230. 'start_time' => array(
  231. 'type' => 'int',
  232. 'not null' => FALSE,
  233. 'description' => 'UNIX integer start time'
  234. ),
  235. 'end_time' => array(
  236. 'type' => 'int',
  237. 'not null' => FALSE,
  238. 'description' => 'UNIX integer end time'
  239. ),
  240. 'error_msg' => array(
  241. 'type' => 'text',
  242. 'size' => 'normal',
  243. 'not null' => FALSE
  244. ),
  245. 'pid' => array(
  246. 'type' => 'int',
  247. 'unsigned' => TRUE,
  248. 'not null' => FALSE,
  249. 'description' => 'The process id for the job'
  250. ),
  251. 'priority' => array(
  252. 'type' => 'int',
  253. 'unsigned' => TRUE,
  254. 'not null' => TRUE,
  255. 'default' => '0',
  256. 'description' => 'The job priority'
  257. ),
  258. 'mlock' => array(
  259. 'type' => 'int',
  260. 'unsigned' => TRUE,
  261. 'not null' => FALSE,
  262. 'description' => 'If set to 1 then all jobs for the module are held until this one finishes'
  263. ),
  264. 'lock' => array(
  265. 'type' => 'int',
  266. 'unsigned' => TRUE,
  267. 'not null' => FALSE,
  268. 'description' => 'If set to 1 then all jobs are held until this one finishes'
  269. ),
  270. 'includes' => array(
  271. 'type' => 'text',
  272. 'description' => 'A serialized array of file paths that should be included prior to executing the job.',
  273. 'not null' => FALSE,
  274. )
  275. ),
  276. 'indexes' => array(
  277. 'job_id' => array('job_id'),
  278. 'job_name' => array('job_name')
  279. ),
  280. 'primary key' => array('job_id'),
  281. );
  282. }
  283. /**
  284. * Returns the Drupal Schema API array for the tripal_jobs table.
  285. */
  286. function tripal_tripal_collection_schema() {
  287. return array(
  288. 'fields' => array(
  289. 'collection_id' => array(
  290. 'type' => 'serial',
  291. 'unsigned' => TRUE,
  292. 'not null' => TRUE
  293. ),
  294. 'collection_name' => array(
  295. 'type' => 'varchar',
  296. 'length' => 1024,
  297. 'not null' => TRUE
  298. ),
  299. 'description' => array(
  300. 'type' => 'text',
  301. 'not null' => FALSE
  302. ),
  303. 'uid' => array(
  304. 'type' => 'int',
  305. 'not null' => TRUE,
  306. 'description' => 'The user Id of the person who created the collection.'
  307. ),
  308. 'create_date' => array(
  309. 'type' => 'int',
  310. 'not null' => TRUE,
  311. 'description' => 'UNIX integer start time'
  312. ),
  313. ),
  314. 'indexes' => array(
  315. 'uid' => array('uid')
  316. ),
  317. 'unique keys' => array(
  318. 'user_collection' => array('uid', 'collection_name'),
  319. ),
  320. 'primary key' => array('collection_id'),
  321. );
  322. }
  323. /**
  324. * Returns the Drupal Schema API array for the tripal_jobs table.
  325. */
  326. function tripal_tripal_collection_bundle_schema() {
  327. return array(
  328. 'fields' => array(
  329. 'collection_bundle_id' => array(
  330. 'type' => 'serial',
  331. 'unsigned' => TRUE,
  332. 'not null' => TRUE
  333. ),
  334. 'collection_id' => array(
  335. 'type' => 'int',
  336. 'unsigned' => TRUE,
  337. 'not null' => TRUE
  338. ),
  339. 'bundle_name' => array(
  340. 'type' => 'varchar',
  341. 'length' => 1024,
  342. 'not null' => TRUE
  343. ),
  344. 'ids' => array(
  345. 'type' => 'text',
  346. 'size' => 'normal',
  347. 'not null' => TRUE,
  348. 'description' => 'An array of entity IDs.'
  349. ),
  350. 'fields' => array(
  351. 'type' => 'text',
  352. 'size' => 'normal',
  353. 'not null' => TRUE,
  354. 'description' => 'An array of numeric field IDs.'
  355. ),
  356. 'site_id' => array(
  357. 'type' => 'int',
  358. 'size' => 'normal',
  359. 'not null' => FALSE,
  360. 'description' => 'The ID of the site from the Tripal Sites table.'
  361. ),
  362. ),
  363. 'indexes' => array(
  364. 'collection_id' => array('collection_id')
  365. ),
  366. 'primary key' => array('collection_bundle_id'),
  367. );
  368. }
  369. /**
  370. * Returns the Drupal Schema API array for the tripal_jobs table.
  371. */
  372. function tripal_tripal_import_schema() {
  373. return array(
  374. 'fields' => array(
  375. 'import_id' => array(
  376. 'type' => 'serial',
  377. 'unsigned' => TRUE,
  378. 'not null' => TRUE
  379. ),
  380. 'uid' => array(
  381. 'type' => 'int',
  382. 'unsigned' => TRUE,
  383. 'not null' => TRUE,
  384. 'description' => 'The Drupal userid of the submitee.'
  385. ),
  386. 'class' => array(
  387. 'type' => 'varchar',
  388. 'length' => 256,
  389. 'not null' => TRUE,
  390. ),
  391. 'fid' => array(
  392. 'type' => 'text',
  393. 'not null' => FALSE,
  394. 'description' => 'The file IDs of the to import. This only applies if the file was uploaded (i.e. not already on the server) and is mangaged by Drupal. Multiple fids are separated using a | character.'
  395. ),
  396. 'arguments' => array(
  397. 'type' => 'text',
  398. 'size' => 'normal',
  399. 'not null' => FALSE,
  400. 'description' => 'Holds a serialized PHP array containing the key/value paris that are used for arguments of the job.'
  401. ),
  402. 'submit_date' => array(
  403. 'type' => 'int',
  404. 'not null' => TRUE,
  405. 'description' => 'UNIX integer submit time'
  406. ),
  407. ),
  408. 'indexes' => array(
  409. 'class' => array('class'),
  410. ),
  411. 'foreign keys' => array(
  412. 'tripal_jobs' => array(
  413. 'table' => 'tripal_jobs',
  414. 'columns' => array(
  415. 'job_id' => 'job_id',
  416. ),
  417. ),
  418. 'users' => array(
  419. 'table' => 'users',
  420. 'columns' => array(
  421. 'uid' => 'uid',
  422. ),
  423. ),
  424. 'file_managed' => array(
  425. 'table' => 'file_managed',
  426. 'columns' => array(
  427. 'fid' => 'fid',
  428. ),
  429. ),
  430. ),
  431. 'primary key' => array('import_id'),
  432. );
  433. }
  434. /**
  435. *
  436. * @return
  437. */
  438. function tripal_tripal_token_formats_schema() {
  439. return array(
  440. 'fields' => array(
  441. 'tripal_format_id' => array(
  442. 'type' => 'serial',
  443. 'unsigned' => TRUE,
  444. 'not null' => TRUE
  445. ),
  446. 'content_type' => array(
  447. 'type' => 'varchar',
  448. 'length' => 255,
  449. 'not null' => TRUE
  450. ),
  451. 'application' => array(
  452. 'type' => 'varchar',
  453. 'length' => 255,
  454. 'not null' => TRUE
  455. ),
  456. 'format' => array(
  457. 'type' => 'text',
  458. 'not null' => TRUE
  459. ),
  460. 'tokens' => array(
  461. 'type' => 'text',
  462. 'not null' => TRUE
  463. ),
  464. ),
  465. 'unique keys' => array(
  466. 'type_application' => array('content_type', 'application'),
  467. ),
  468. 'primary key' => array('tripal_format_id'),
  469. );
  470. }
  471. function tripal_tripal_variables_schema() {
  472. return array(
  473. 'description' => 'This table houses a list of unique variable names that ' .
  474. 'can be used in the tripal_node_variables table.',
  475. 'fields' => array(
  476. 'variable_id' => array (
  477. 'type' => 'serial',
  478. 'not null' => TRUE,
  479. ),
  480. 'name' => array(
  481. 'type' => 'varchar',
  482. 'length' => 255,
  483. 'not null' => TRUE,
  484. ),
  485. 'description' => array(
  486. 'type' => 'text',
  487. 'not null' => TRUE,
  488. ),
  489. ),
  490. 'primary key' => array (
  491. 0 => 'variable_id',
  492. ),
  493. 'unique keys' => array (
  494. 'tripal_variables_c1' => array (
  495. 0 => 'name',
  496. ),
  497. ),
  498. 'indexes' => array (
  499. 'tripal_variable_names_idx1' => array (
  500. 0 => 'variable_id',
  501. ),
  502. ),
  503. );
  504. return $schema;
  505. }
  506. /**
  507. * @section
  508. * Schema Definitions.
  509. */
  510. /**
  511. * The base table for Biological Data Entities.
  512. *
  513. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  514. * this table will have 15 records and include both genes and mRNA's.
  515. */
  516. function tripal_tripal_entity_schema() {
  517. $schema = array(
  518. 'description' => 'The base table for Tripal Vocabulary-based entities.',
  519. 'fields' => array(
  520. 'id' => array(
  521. 'description' => 'The primary identifier for a vocabulary entity.',
  522. 'type' => 'serial',
  523. 'unsigned' => TRUE,
  524. 'not null' => TRUE,
  525. ),
  526. 'type' => array(
  527. 'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
  528. 'type' => 'varchar',
  529. 'length' => 64,
  530. 'not null' => TRUE,
  531. 'default' => '',
  532. ),
  533. 'bundle' => array(
  534. 'description' => 'The type of bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
  535. 'type' => 'varchar',
  536. 'length' => 1024,
  537. 'not null' => TRUE,
  538. 'default' => '',
  539. ),
  540. 'term_id' => array(
  541. 'description' => 'The term_id for the type of entity. This term_id corresponds to a TripalTerm record.',
  542. 'type' => 'int',
  543. 'not null' => TRUE,
  544. ),
  545. 'title' => array(
  546. 'description' => 'The title of this node, always treated as non-markup plain text.',
  547. 'type' => 'text',
  548. 'not null' => TRUE,
  549. 'default' => '',
  550. ),
  551. 'uid' => array(
  552. 'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
  553. 'type' => 'int',
  554. 'not null' => TRUE,
  555. 'default' => 0,
  556. ),
  557. 'status' => array(
  558. 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
  559. 'type' => 'int',
  560. 'not null' => TRUE,
  561. 'default' => 1,
  562. ),
  563. 'created' => array(
  564. 'description' => 'The Unix timestamp when the node was created.',
  565. 'type' => 'int',
  566. 'not null' => TRUE,
  567. 'default' => 0,
  568. ),
  569. 'changed' => array(
  570. 'description' => 'The Unix timestamp when the node was most recently saved.',
  571. 'type' => 'int',
  572. 'not null' => TRUE,
  573. 'default' => 0,
  574. ),
  575. ),
  576. 'indexes' => array(
  577. 'term_id' => array('term_id'),
  578. 'entity_changed' => array('changed'),
  579. 'entity_created' => array('created'),
  580. 'type' => array('type'),
  581. 'uid' => array('uid'),
  582. 'bundle' => array('bundle'),
  583. ),
  584. 'unique keys' => array(),
  585. 'primary key' => array('id'),
  586. );
  587. return $schema;
  588. }
  589. /**
  590. * The base table for TripalVocab schema.
  591. *
  592. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  593. * this table will have 15 records and include both genes and mRNA's.
  594. */
  595. function tripal_tripal_vocab_schema() {
  596. // This schema only provides enough information to assign a unique ID
  597. // to the vocabulary. Any additonal information is added to the Entity object
  598. // by the selected database back-end.
  599. $schema = array(
  600. 'description' => 'The base table for TripalVocab entities.',
  601. 'fields' => array(
  602. 'id' => array(
  603. 'description' => 'The primary identifier for a vocab entity.',
  604. 'type' => 'serial',
  605. 'unsigned' => TRUE,
  606. 'not null' => TRUE,
  607. ),
  608. 'vocabulary' => array(
  609. 'description' => 'The short name for the vocabulary (e.g. SO, PATO, etc.).',
  610. 'type' => 'varchar',
  611. 'length' => 128,
  612. 'not null' => TRUE,
  613. ),
  614. 'created' => array(
  615. 'description' => 'The Unix timestamp when the entity was created.',
  616. 'type' => 'int',
  617. 'not null' => TRUE,
  618. 'default' => 0,
  619. ),
  620. 'changed' => array(
  621. 'description' => 'The Unix timestamp when the entity was most recently saved.',
  622. 'type' => 'int',
  623. 'not null' => TRUE,
  624. 'default' => 0,
  625. ),
  626. ),
  627. 'indexes' => array(
  628. 'vocabulary' => array('vocabulary'),
  629. 'entity_changed' => array('changed'),
  630. 'entity_created' => array('created'),
  631. ),
  632. 'unique keys' => array('vocabulary' => array('vocabulary')),
  633. 'primary key' => array('id'),
  634. );
  635. return $schema;
  636. }
  637. /**
  638. * The base table for TripalTerm entities.
  639. *
  640. * This contains the actual data. For example, if you have a 5 genes and 10 mRNA then
  641. * this table will have 15 records and include both genes and mRNA's.
  642. */
  643. function tripal_tripal_term_schema() {
  644. // This schema only provides enough information to assign a unique ID
  645. // to the term and associate it to it's vocabulary. Any additonal information
  646. // is added to the Entity object by the selected database back-end.
  647. $schema = array(
  648. 'description' => 'The base table for TripalTerm entities.',
  649. 'fields' => array(
  650. 'id' => array(
  651. 'description' => 'The primary identifier for a term entity.',
  652. 'type' => 'serial',
  653. 'unsigned' => TRUE,
  654. 'not null' => TRUE,
  655. ),
  656. 'vocab_id' => array(
  657. 'description' => 'The vocabulary_id of the TripalVocab entity to which this term belongs.',
  658. 'type' => 'int',
  659. 'not null' => TRUE,
  660. ),
  661. 'accession' => array(
  662. 'description' => 'The id (or accession) of this term in the vocabulary.',
  663. 'type' => 'varchar',
  664. 'length' => 1024,
  665. 'not null' => TRUE,
  666. 'default' => '',
  667. ),
  668. 'name' => array(
  669. 'description' => 'The human readable name for this term.',
  670. 'type' => 'varchar',
  671. 'length' => 1024,
  672. 'not null' => TRUE,
  673. 'default' => '',
  674. ),
  675. 'created' => array(
  676. 'description' => 'The Unix timestamp when the entity was created.',
  677. 'type' => 'int',
  678. 'not null' => TRUE,
  679. 'default' => 0,
  680. ),
  681. 'changed' => array(
  682. 'description' => 'The Unix timestamp when the entity was most recently saved.',
  683. 'type' => 'int',
  684. 'not null' => TRUE,
  685. 'default' => 0,
  686. ),
  687. ),
  688. 'indexes' => array(
  689. 'vocab_id' => array('vocab_id'),
  690. 'accession' => array('accession'),
  691. 'entity_changed' => array('changed'),
  692. 'entity_created' => array('created'),
  693. ),
  694. 'foreign keys' => array(
  695. 'tripal_vocab' => array(
  696. 'table' => 'tripal_vocab',
  697. 'columns' => array(
  698. 'vocab_id' => 'vocab_id',
  699. ),
  700. ),
  701. ),
  702. 'unique keys' => array('vocab_term' => array('vocab_id', 'accession')),
  703. 'primary key' => array('id'),
  704. );
  705. return $schema;
  706. }
  707. /**
  708. * The base table for TripalEntity entities.
  709. *
  710. * This table contains a list of Biological Data Types.
  711. * For the example above (5 genes and 10 mRNAs), there would only be two records in
  712. * this table one for "gene" and another for "mRNA".
  713. */
  714. function tripal_tripal_bundle_schema() {
  715. $schema = array(
  716. 'description' => 'Stores information about defined tripal data types.',
  717. 'fields' => array(
  718. 'id' => array(
  719. 'type' => 'serial',
  720. 'not null' => TRUE,
  721. 'description' => 'Primary Key: Unique numeric ID.',
  722. ),
  723. 'type' => array(
  724. 'description' => 'The type of entity (e.g. TripalEntity).',
  725. 'type' => 'varchar',
  726. 'length' => 64,
  727. 'not null' => TRUE,
  728. 'default' => '',
  729. ),
  730. 'term_id' => array(
  731. 'description' => 'The term_id for the type of entity. This term_id corresponds to a TripalTerm record.',
  732. 'type' => 'int',
  733. 'not null' => TRUE,
  734. ),
  735. 'name' => array(
  736. 'description' => 'The name of the bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
  737. 'type' => 'varchar',
  738. 'length' => 1024,
  739. 'not null' => TRUE,
  740. 'default' => '',
  741. ),
  742. 'label' => array(
  743. 'description' => 'The human-readable name of this bundle.',
  744. 'type' => 'varchar',
  745. 'length' => 255,
  746. 'not null' => TRUE,
  747. 'default' => '',
  748. ),
  749. ),
  750. 'indexes' => array(
  751. 'name' => array('name'),
  752. 'term_id' => array('term_id'),
  753. 'label' => array('label'),
  754. ),
  755. 'primary key' => array('id'),
  756. 'unique keys' => array(
  757. 'name' => array('name'),
  758. ),
  759. );
  760. return $schema;
  761. }
  762. /**
  763. * Additional Tripal Bundle Information.
  764. *
  765. * This table is used for storing any additonal information describing
  766. * a tripal bundle. For example, this is a good place to store title/url formats.
  767. */
  768. function tripal_tripal_bundle_variables_schema() {
  769. $schema = array(
  770. 'description' => 'This table is used for storing any additonal information describing
  771. a tripal bundle. For example, this is a good place to store title/url formats.',
  772. 'fields' => array (
  773. 'bundle_variable_id' => array (
  774. 'type' => 'serial',
  775. 'not null' => TRUE,
  776. ),
  777. 'bundle_id' => array (
  778. 'type' => 'int',
  779. 'not null' => TRUE,
  780. ),
  781. 'variable_id' => array (
  782. 'type' => 'int',
  783. 'not null' => TRUE,
  784. ),
  785. 'value' => array (
  786. 'type' => 'text',
  787. 'not null' => FALSE,
  788. ),
  789. 'rank' => array (
  790. 'type' => 'int',
  791. 'not null' => TRUE,
  792. 'default' => 0,
  793. ),
  794. ),
  795. 'primary key' => array (
  796. 0 => 'bundle_variable_id',
  797. ),
  798. 'unique keys' => array (
  799. 'tripal_bundle_variables_c1' => array (
  800. 0 => 'bundle_id',
  801. 1 => 'variable_id',
  802. 2 => 'rank',
  803. ),
  804. ),
  805. 'indexes' => array (
  806. 'tripal_bundle_variables_idx1' => array (
  807. 0 => 'variable_id',
  808. ),
  809. ),
  810. 'foreign keys' => array (
  811. 'tripal_variables' => array (
  812. 'table' => 'tripal_variables',
  813. 'columns' => array (
  814. 'variable_id' => 'variable_id',
  815. ),
  816. ),
  817. ),
  818. );
  819. return $schema;
  820. }
  821. /**
  822. * Provides the schema for the tripal_custom_quota table.
  823. */
  824. function tripal_tripal_custom_quota_schema() {
  825. $schema = array(
  826. 'table' => 'tripal_custom_quota',
  827. 'fields' => array(
  828. 'uid' => array(
  829. 'type' => 'int',
  830. 'size' => 'big',
  831. 'not NULL' => TRUE,
  832. ),
  833. 'custom_quota' => array(
  834. 'type' => 'int',
  835. 'size' => 'big',
  836. 'not NULL' => TRUE,
  837. ),
  838. 'custom_expiration' => array(
  839. 'type' => 'int',
  840. 'size' => 'big',
  841. 'not NULL' => TRUE,
  842. ),
  843. ),
  844. 'primary key' => array('uid'),
  845. 'unique keys' => array(
  846. 'tripal_custom_quota_uq1' => array('uid'),
  847. ),
  848. 'indexes' => array(
  849. 'tripal_custom_quota_idx1' => array('uid'),
  850. ),
  851. );
  852. return $schema;
  853. }
  854. /**
  855. * Provides the schema for the tripal_expiration_files table.
  856. */
  857. function tripal_tripal_expiration_files_schema() {
  858. $schema = array (
  859. 'table' => 'tripal_expiration_files',
  860. 'fields' => array (
  861. 'fid' => array(
  862. 'type' => 'int',
  863. 'not NULL' => TRUE
  864. ),
  865. 'expiration_date' => array(
  866. 'type' => 'int',
  867. 'size' => 'big',
  868. 'not NULL' => TRUE
  869. ),
  870. ),
  871. 'primary key' => array(
  872. 0 => 'fid'
  873. ),
  874. 'unique keys' => array(
  875. 'tripal_expiration_files_uq1' => array('fid'),
  876. ),
  877. 'indexes' => array(
  878. 'tripal_expiration_files_idx1' => array('fid'),
  879. ),
  880. );
  881. return $schema;
  882. }
  883. /**
  884. * Additional Tripal Admin Notification Information.
  885. *
  886. * This table is used for information describing administrative
  887. * notifications. For example, when new fields are available.
  888. */
  889. function tripal_tripal_admin_notifications_schema() {
  890. $schema = array(
  891. 'description' => 'This table is used for information describing administrative
  892. notifications. For example, when new fields are available.',
  893. 'fields' => array (
  894. 'note_id' => array (
  895. 'type' => 'serial',
  896. 'not null' => TRUE,
  897. ),
  898. 'details' => array (
  899. 'description' => 'Description and additional information relating to the notification.',
  900. 'type' => 'text',
  901. 'not null' => TRUE,
  902. ),
  903. 'title' => array (
  904. 'description' => 'Title of the notification.',
  905. 'type' => 'text',
  906. 'not null' => TRUE,
  907. ),
  908. 'actions' => array (
  909. 'description' => 'Actions that can be performed on the notification, like disimissal or import.',
  910. 'type' => 'text',
  911. 'not null' => FALSE,
  912. ),
  913. 'submitter_id' => array (
  914. 'description' => 'A unique id that should be specific to the notification to ensure notifications are not duplicated.',
  915. 'type' => 'text',
  916. 'not null' => TRUE,
  917. ),
  918. 'enabled' => array (
  919. 'description' => 'Boolean indicating whether the notification is enabled or disabled (disabled will not be shown on the dashboard).',
  920. 'type' => 'int',
  921. 'not null' => TRUE,
  922. 'default' => 1,
  923. ),
  924. 'type' => array (
  925. 'description' => 'Type of the notification, relating to what tripal function the notification belongs to, IE Fields, Jobs, Vocabulary.',
  926. 'type' => 'text',
  927. 'not null' => FALSE,
  928. ),
  929. ),
  930. 'primary key' => array (
  931. 0 => 'note_id',
  932. ),
  933. );
  934. return $schema;
  935. }
  936. /**
  937. * Change tripal_vocab.vocabulary to varchar(128)
  938. */
  939. function tripal_update_7300() {
  940. try {
  941. $spec = array(
  942. 'description' => 'The short name for the vocabulary (e.g. SO, PATO, etc.).',
  943. 'type' => 'varchar',
  944. 'length' => 128,
  945. 'not null' => TRUE
  946. );
  947. db_change_field('tripal_vocab', 'vocabulary', 'vocabulary',$spec);
  948. }
  949. catch (\PDOException $e) {
  950. $error = $e->getMessage();
  951. throw new DrupalUpdateException('Could not perform update: '. $error);
  952. }
  953. }
  954. /**
  955. * Create new admin notifications table.
  956. */
  957. function tripal_update_7301() {
  958. $transaction = db_transaction();
  959. try {
  960. $schema['tripal_admin_notfications'] = tripal_tripal_admin_notifications_schema();
  961. db_create_table('tripal_admin_notfications', $schema['tripal_admin_notfications']);
  962. }
  963. catch (\PDOException $e) {
  964. $transaction->rollback();
  965. $error = $e->getMessage();
  966. throw new DrupalUpdateException('Could not perform update: '. $error);
  967. }
  968. }
  969. /**
  970. * Create new tripal import table.
  971. */
  972. function tripal_update_7302() {
  973. $transaction = db_transaction();
  974. try {
  975. $schema['tripal_import'] = tripal_tripal_import_schema();
  976. db_create_table('tripal_import', $schema['tripal_import']);
  977. }
  978. catch (\PDOException $e) {
  979. $transaction->rollback();
  980. $error = $e->getMessage();
  981. throw new DrupalUpdateException('Could not perform update: '. $error);
  982. }
  983. }
  984. /**
  985. * Remove the job_id from the tripal import table.
  986. */
  987. function tripal_update_7303() {
  988. $transaction = db_transaction();
  989. try {
  990. if (db_field_exists('tripal_import', 'job_id')) {
  991. db_drop_field('tripal_import', 'job_id');
  992. }
  993. }
  994. catch (\PDOException $e) {
  995. $transaction->rollback();
  996. $error = $e->getMessage();
  997. throw new DrupalUpdateException('Could not perform update: '. $error);
  998. }
  999. }
  1000. /**
  1001. * Adds a variable for the bundles to manage hiding of empty fields.
  1002. */
  1003. function tripal_update_7304() {
  1004. $transaction = db_transaction();
  1005. try {
  1006. tripal_insert_variable(
  1007. 'hide_empty_field',
  1008. 'Structure->Tripal Content Type->edit checkbox to hide empty fields for that bundle.'
  1009. );
  1010. }
  1011. catch (\PDOException $e) {
  1012. $transaction->rollback();
  1013. $error = $e->getMessage();
  1014. throw new DrupalUpdateException('Could not perform update: ' . $error);
  1015. }
  1016. }
  1017. /**
  1018. * Adjusts the tripal_import table to support multiple file uploads.
  1019. */
  1020. function tripal_update_7305() {
  1021. $transaction = db_transaction();
  1022. try {
  1023. db_change_field('tripal_import', 'fid', 'fid', array(
  1024. 'type' => 'text',
  1025. 'not null' => FALSE,
  1026. 'description' => 'The file IDs of the to import. This only applies if the file was uploaded (i.e. not already on the server) and is mangaged by Drupal. Multiple fids are separated using a | character.'
  1027. ));
  1028. }
  1029. catch (\PDOException $e) {
  1030. $transaction->rollback();
  1031. $error = $e->getMessage();
  1032. throw new DrupalUpdateException('Could not perform update: ' . $error);
  1033. }
  1034. }
  1035. /**
  1036. * Adds the tripal_collection table.
  1037. */
  1038. function tripal_update_7306() {
  1039. $transaction = db_transaction();
  1040. try {
  1041. $schema = array();
  1042. $schema['tripal_collection'] = tripal_tripal_collection_schema();
  1043. db_create_table('tripal_collection', $schema['tripal_collection']);
  1044. }
  1045. catch (\PDOException $e) {
  1046. $transaction->rollback();
  1047. $error = $e->getMessage();
  1048. throw new DrupalUpdateException('Could not add the tripal_collection table:' . $error);
  1049. }
  1050. }
  1051. /**
  1052. * Adds a new Data search menu for the Tripal created search tools. If you
  1053. * have customized any of the Tripal content search forms then those forms will
  1054. * remain unchanged. All other default search pages will be moved to the
  1055. * new Data Search menu item available at Admin > Stucture > Menu > Data Search.
  1056. */
  1057. function tripal_update_7307() {
  1058. $menu = array(
  1059. 'menu_name' => 'data_search',
  1060. 'title' => t('Data Search'),
  1061. 'description' => 'The Data Search menu contains links to search tools for finding biological data.',
  1062. );
  1063. menu_save($menu);
  1064. }
  1065. /**
  1066. * Remove the bundle_name, ids, fields from the tripal collections table.
  1067. * And add the new tripal_tripal_collection_bundle_schema
  1068. */
  1069. function tripal_update_7308() {
  1070. $transaction = db_transaction();
  1071. try {
  1072. if (db_field_exists('tripal_collection', 'bundle_name')) {
  1073. db_drop_field('tripal_collection', 'bundle_name');
  1074. }
  1075. if (db_field_exists('tripal_collection', 'ids')) {
  1076. db_drop_field('tripal_collection', 'ids');
  1077. }
  1078. if (db_field_exists('tripal_collection', 'fields')) {
  1079. db_drop_field('tripal_collection', 'fields');
  1080. }
  1081. $schema = array();
  1082. $schema['tripal_collection_bundle'] = tripal_tripal_collection_bundle_schema();
  1083. db_create_table('tripal_collection_bundle', $schema['tripal_collection_bundle']);
  1084. }
  1085. catch (\PDOException $e) {
  1086. $transaction->rollback();
  1087. $error = $e->getMessage();
  1088. throw new DrupalUpdateException('Could not add the tripal_collection table:' . $error);
  1089. }
  1090. }
  1091. /**
  1092. * Add the site_id field to the tripal_collection_bundle table.
  1093. */
  1094. function tripal_update_7309() {
  1095. $transaction = db_transaction();
  1096. try {
  1097. if (!db_field_exists('tripal_collection_bundle', 'site_id')) {
  1098. $field = array(
  1099. 'type' => 'int',
  1100. 'size' => 'normal',
  1101. 'not null' => FALSE,
  1102. 'description' => 'The ID of the site from the Tripal Sites table.',
  1103. );
  1104. db_add_field('tripal_collection_bundle', 'site_id', $field);
  1105. }
  1106. }
  1107. catch (\PDOException $e) {
  1108. $transaction->rollback();
  1109. $error = $e->getMessage();
  1110. throw new DrupalUpdateException('Could not add the tripal_collection table:' . $error);
  1111. }
  1112. }
  1113. /**
  1114. * Adds the missing tripal_collection_bundle table
  1115. * @throws DrupalUpdateException
  1116. */
  1117. function tripal_update_7310() {
  1118. $transaction = db_transaction();
  1119. try {
  1120. if (!db_table_exists('tripal_collection_bundle')) {
  1121. $schema = array();
  1122. $schema['tripal_collection_bundle'] = tripal_tripal_collection_bundle_schema();
  1123. db_create_table('tripal_collection_bundle', $schema['tripal_collection_bundle']);
  1124. }
  1125. }
  1126. catch (\PDOException $e) {
  1127. $transaction->rollback();
  1128. $error = $e->getMessage();
  1129. throw new DrupalUpdateException('Could not add the tripal_collection_bundle table:' . $error);
  1130. }
  1131. }
  1132. /**
  1133. * Adds support for file quotas.
  1134. */
  1135. function tripal_update_7311() {
  1136. try {
  1137. $schema = array();
  1138. $schema['tripal_custom_quota'] = tripal_tripal_custom_quota_schema();
  1139. $schema['tripal_expiration_files'] = tripal_tripal_expiration_files_schema();
  1140. db_create_table('tripal_custom_quota', $schema['tripal_custom_quota']);
  1141. db_create_table('tripal_expiration_files', $schema['tripal_expiration_files']);
  1142. }
  1143. catch (\PDOException $e) {
  1144. $error = $e->getMessage();
  1145. throw new DrupalUpdateException('Could not perform update: '. $error);
  1146. }
  1147. }
  1148. /**
  1149. * Adds a tripal_storage_api setting to all field storage details
  1150. */
  1151. function tripal_update_7312() {
  1152. $transaction = db_transaction();
  1153. try {
  1154. $fields = db_select('field_config', 'fc')
  1155. ->fields('fc', ['id', 'storage_type', 'data'])
  1156. ->where("fc.storage_type = 'field_chado_storage' or fc.storage_type = 'tripal_no_storage'")
  1157. ->execute();
  1158. while ($field = $fields->fetchObject()) {
  1159. $data = unserialize($field->data);
  1160. $data['storage']['settings']['tripal_storage_api'] = TRUE;
  1161. db_update('field_config')
  1162. ->fields([
  1163. 'data' => serialize($data)
  1164. ])
  1165. ->condition('id', $field->id)
  1166. ->execute();
  1167. }
  1168. }
  1169. catch (\PDOException $e) {
  1170. $transaction->rollback();
  1171. $error = $e->getMessage();
  1172. throw new DrupalUpdateException('Could not perform update: '. $error);
  1173. }
  1174. }
  1175. /**
  1176. * Adds a tripal_storage_api setting to all field storage details
  1177. */
  1178. function tripal_update_7313() {
  1179. $transaction = db_transaction();
  1180. try {
  1181. tripal_insert_variable(
  1182. 'ajax_field',
  1183. 'Structure->Tripal Content Type->edit checkbox ajax fields for that bundle.'
  1184. );
  1185. } catch (\PDOException $e) {
  1186. $transaction->rollback();
  1187. $error = $e->getMessage();
  1188. throw new DrupalUpdateException('Could not perform update: ' . $error);
  1189. }
  1190. }