tripal_chado.migrate.inc 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. <?php
  2. /**
  3. * Implements hook_form()
  4. *
  5. * Provide a form to select Tripal v2 content types for migration
  6. *
  7. * @param $form
  8. * @param $form_state
  9. */
  10. function tripal_chado_migrate_form($form, &$form_state) {
  11. $form['overview_vert_tabs'] = array(
  12. '#type' => 'vertical_tabs'
  13. );
  14. $form['overview_vert_tabs']['#default_tab'] = key_exists('tripal_migrate_current_tab', $_SESSION) ? $_SESSION['tripal_migrate_current_tab'] : 'edit-step1';
  15. $form['instructions'] = array(
  16. '#type' => 'item',
  17. '#markup' => t('Here you may migrate Tripal v2 content types to Tripal v3
  18. content types. The migration process is divided into four steps that
  19. allow you to migrate your site as your own pace. Please click each
  20. step below for details as to the purpose of the step. When all steps
  21. are completed your site will be fully Tripal v3 compatible.'),
  22. '#weight' => -100
  23. );
  24. // Step 1
  25. $form['step1'] = array(
  26. '#type' => 'fieldset',
  27. '#title' => 'Step1',
  28. '#description' => '<b>Enable Legacy Support</b>',
  29. '#collapsible' => TRUE,
  30. '#collapsed' => TRUE,
  31. '#group' => 'overview_vert_tabs'
  32. );
  33. global $base_url;
  34. $mod_url = '/admin/modules';
  35. $form['step1']['step1_content'] = array(
  36. '#markup' => 'Tripal legacy modules are needed to support the display of Tripal v2
  37. content types. Review and ' . l('enable modules', $mod_url) . ' in the \'Tripal v2 Legacy\' category
  38. for legacy content support. Only content types for enabled legacy
  39. moodules can be migrated'
  40. );
  41. // Step 2
  42. $form['step2'] = array(
  43. '#type' => 'fieldset',
  44. '#title' => 'Step2',
  45. '#description' => '<b>Migrate Content</b>',
  46. '#collapsible' => TRUE,
  47. '#collapsed' => TRUE,
  48. '#group' => 'overview_vert_tabs'
  49. );
  50. $form['step2']['step2_container'] = array(
  51. '#type' => 'container',
  52. '#collapsible' => FALSE,
  53. '#prefix' => '<div id="tripal-chado-migrate-form-step2">',
  54. '#suffix' => '</div>'
  55. );
  56. $form['step2']['step2_container']['instructions'] = array(
  57. '#type' => 'item',
  58. '#markup' => t('Here you can migrate Tripal v2 content types to Tripal v3
  59. content types. This will not destroy or remove existing Tripal v2 pages
  60. but will creatte new Tripal v3 pages. This allows you to keep existing
  61. pages while reviewing and customizing the Tripal v3 content types. Site
  62. visitors can continue to visit the Tripal v2 pages. Tripal
  63. v3 content types may remain private while customization is underway.
  64. Once customization is completed a subsequent step will allow you to
  65. swap out Tripal v2 pages for the newer Tripal v3 pages. If you would like to
  66. use Trial v3 web services you must migrate content types.'),
  67. );
  68. $tv2_content_type = 'all';
  69. if (array_key_exists('values', $form_state)) {
  70. $tv2_content_type = $form_state['values']['tv2_content_type'];
  71. }
  72. $tv2_options = tripal_chado_get_tripal_v2_content_type_options(TRUE);
  73. $form['step2']['step2_container']['tv2_content_type'] = array(
  74. '#type' => 'select',
  75. '#title' => 'Tripal v2 Content Type',
  76. '#description' => t('Select the Tripal v2 content type to migrate.'),
  77. '#options' => $tv2_options,
  78. '#default_value' => $tv2_content_type,
  79. '#ajax' => array(
  80. 'callback' => "tripal_chado_migrate_form_step2_ajax_callback",
  81. 'wrapper' => "tripal-chado-migrate-form-step2",
  82. 'effect' => 'fade',
  83. 'method' => 'replace'
  84. ),
  85. );
  86. // Add a review button that allows reviewing migratable content types
  87. if ($tv2_content_type != 'all') {
  88. $table = str_replace('chado_', '', $tv2_content_type);
  89. $schema = chado_get_schema($table);
  90. $pkey = $schema['primary key'][0];
  91. $fkeys = $schema['foreign keys'];
  92. $form['step2']['step2_container']['tv3_content_type'] = array(
  93. '#type' => 'fieldset',
  94. '#title' => 'Tripal v3 Content Type',
  95. '#description' => "Click the 'Get Tripal v3 Types' button to retrieve a list of Tripal v3
  96. content types to which this Tripal v2 type can be converted. This may take a while
  97. depending on the size of your database. The number of items to be converted is
  98. shown beside the type."
  99. );
  100. $form['step2']['step2_container']['tv3_content_type']['get_v3_type_btn'] = array(
  101. '#type' => 'button',
  102. '#name' => 'get_v3_type_btn',
  103. '#value' => "Get Tripal v3 Types",
  104. '#ajax' => array(
  105. 'callback' => "tripal_chado_migrate_form_step2_ajax_callback",
  106. 'wrapper' => "tripal-chado-migrate-form-step2",
  107. 'effect' => 'fade',
  108. 'method' => 'replace'
  109. ),
  110. );
  111. $no_data = TRUE;
  112. if ($form_state['clicked_button']['#name'] == 'get_v3_type_btn') {
  113. // Migrate all
  114. $form['step2']['step2_container']['tv3_content_type']['tv3_migrate_all'] = array(
  115. '#type' => 'checkbox',
  116. '#title' => 'Migrate All'
  117. );
  118. // Migrate selection only
  119. if ($table == 'organism') {
  120. $sql =
  121. "SELECT count(*)
  122. FROM {organism} O
  123. INNER JOIN public.chado_organism CO ON O.organism_id = CO.organism_id
  124. ";
  125. $org_count = chado_query($sql)->fetchField();
  126. if ($org_count > 0) {
  127. $key = urldecode('tv3_content_type--OBI--0100026--organism');
  128. $form['step2']['step2_container']['tv3_content_type'][$key] = array(
  129. '#type' => 'checkbox',
  130. '#title' => 'Organism (' . $org_count . ')',
  131. );
  132. $no_data = FALSE;
  133. }
  134. }
  135. else if ($table == 'analysis') {
  136. $sql =
  137. "SELECT count(*)
  138. FROM {analysis} A
  139. INNER JOIN public.chado_analysis CA ON A.analysis_id = CA.analysis_id
  140. ";
  141. $ana_count = chado_query($sql)->fetchField();
  142. if ($ana_count > 0) {
  143. $key = urlencode('tv3_content_type--local--analysis--analysis');
  144. $form['step2']['step2_container']['tv3_content_type'][$key] = array(
  145. '#type' => 'checkbox',
  146. '#title' => 'Analysis (' . $ana_count . ')',
  147. );
  148. $no_data = FALSE;
  149. }
  150. }
  151. else if ($table == 'project') {
  152. $sql =
  153. "SELECT count(*)
  154. FROM {project} P
  155. INNER JOIN public.chado_project CP ON P.project_id = CP.project_id
  156. ";
  157. $proj_count = chado_query($sql)->fetchField();
  158. if ($proj_count > 0) {
  159. $key = urlencode('tv3_content_type--local--project--project');
  160. $form['step2']['step2_container']['tv3_content_type'][$key] = array(
  161. '#type' => 'checkbox',
  162. '#title' => 'Project (' . $proj_count . ')',
  163. );
  164. $no_data = FALSE;
  165. }
  166. }
  167. else if ($table == 'featuremap') {
  168. $sql =
  169. "SELECT count(*)
  170. FROM {featuremap} M
  171. INNER JOIN public.chado_featuremap CM ON M.featuremap_id = CM.featuremap_id
  172. ";
  173. $map_count = chado_query($sql)->fetchField();
  174. if ($map_count > 0) {
  175. $key = urlencode('tv3_content_type--data--1274--map');
  176. $form['step2']['step2_container']['tv3_content_type'][$key] = array(
  177. '#type' => 'checkbox',
  178. '#title' => 'Map (' . $map_count . ')',
  179. );
  180. $no_data = FALSE;
  181. }
  182. }
  183. else if ($table == 'pub') {
  184. $sql =
  185. "SELECT count(*)
  186. FROM {pub} P
  187. INNER JOIN public.chado_pub CP ON P.pub_id = CP.pub_id
  188. ";
  189. $proj_count = chado_query($sql)->fetchField();
  190. if ($proj_count > 0) {
  191. $key = urlencode('tv3_content_type--TPUB--0000002--Publication');
  192. $form['step2']['step2_container']['tv3_content_type'][$key] = array(
  193. '#type' => 'checkbox',
  194. '#title' => 'Publication (' . $proj_count . ')',
  195. );
  196. $no_data = FALSE;
  197. }
  198. }
  199. else if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
  200. // Get all Tripal v2 node types from the chad_* linking table
  201. $sql =
  202. "SELECT V.name AS type, X.accession, db.name AS vocabulary , count(*) AS num
  203. FROM {" . $table . "} T
  204. INNER JOIN public.$tv2_content_type CT ON T.$pkey = CT.$pkey
  205. INNER JOIN {cvterm} V ON V.cvterm_id = T.type_id
  206. INNER JOIN {dbxref} X ON X.dbxref_id = V.dbxref_id
  207. INNER JOIN {db} ON db.db_id = X.db_id
  208. GROUP BY V.name, X.accession, db.name";
  209. $tv3_content_types = chado_query($sql);
  210. while($tv3_content_type = $tv3_content_types->fetchObject()) {
  211. // We need to store vocabulary/accession/type for each checkbox in the key becuase
  212. // the value only allows 1 or 0
  213. $key = urlencode(
  214. 'tv3_content_type--' .
  215. $tv3_content_type->vocabulary . '--' .
  216. $tv3_content_type->accession . '--' .
  217. $tv3_content_type->type);
  218. $form['step2']['step2_container']['tv3_content_type'][$key] = array(
  219. '#type' => 'checkbox',
  220. '#title' => $tv3_content_type->type . ' (' . $tv3_content_type->num . ')',
  221. );
  222. $no_data = FALSE;
  223. }
  224. }
  225. if ($no_data) {
  226. unset($form['step2']['step2_container']['tv3_content_type']['tv3_migrate_all']);
  227. drupal_set_message('No data for migration or all have been migrated.', 'warning');
  228. }
  229. }
  230. }
  231. // Migrate button
  232. if ($tv2_content_type == 'all' || key_exists('tv3_migrate_all', $form['step2']['step2_container']['tv3_content_type'])) {
  233. $form['step2']['step2_container']['migrate_btn'] = array(
  234. '#type' => 'submit',
  235. '#name' => 'migrate_btn',
  236. '#value' => "Migrate $tv2_options[$tv2_content_type]",
  237. );
  238. // Disable the migration if all have been done
  239. if (count($tv2_options) == 1 && key_exists('all', $tv2_options)) {
  240. $form['step2']['step2_container']['migrate_btn']['#disabled'] = 1;
  241. }
  242. }
  243. // Step 3
  244. $form['step3'] = array(
  245. '#type' => 'fieldset',
  246. '#title' => 'Step3',
  247. '#description' => '<b>Use Legacy Templates (optional)</b>',
  248. '#collapsible' => TRUE,
  249. '#collapsed' => TRUE,
  250. '#group' => 'overview_vert_tabs'
  251. );
  252. $form['step3']['instructions'] = array(
  253. '#type' => 'item',
  254. '#markup' => t('Once content types have been migrated you have the option
  255. to use the Tripal v2 display templates. Tripal v3 allows you to
  256. customize the page layout using a web interface whereas Tripal v2
  257. required programatic changes to template files. If your site has
  258. considerable Tripal v2 customizations that you do not
  259. want to lose you can use the legacy templates by checking the box
  260. for the desired content types below.'),
  261. );
  262. // Get a list of enabled legacy modules with tv2 templates
  263. $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array());
  264. $info = module_invoke_all('node_info');
  265. $options = tripal_chado_get_tripal_v2_content_type_options(FALSE, TRUE);
  266. foreach ($options AS $type_name => $type_label) {
  267. $title = $type_label;
  268. if ($type_name != 'all' and !key_exists($type_name, $info)) {
  269. $title .= " <strong>(please enable the $type_name legacy module).</strong>";
  270. }
  271. $form ['step3']['legacy_template--' . $type_name] = array (
  272. '#type' => 'checkbox',
  273. '#title' => $title,
  274. '#default_value' => key_exists('legacy_template--' . $type_name, $enabled_templates) ? $enabled_templates['legacy_template--' . $type_name] : 0,
  275. );
  276. }
  277. $form['step3']['save_btn'] = array(
  278. '#type' => 'submit',
  279. '#name' => 'save_enabled_template_btn',
  280. '#value' => "Save",
  281. );
  282. // Step 4
  283. $form['step4'] = array(
  284. '#type' => 'fieldset',
  285. '#title' => 'Step4',
  286. '#description' => '<b>Complete Migration</b>',
  287. '#collapsible' => TRUE,
  288. '#collapsed' => TRUE,
  289. '#group' => 'overview_vert_tabs'
  290. );
  291. $form['step4']['instructions'] = array(
  292. '#type' => 'item',
  293. '#markup' => t('This step allows you to fully switch to Tripal v3 pages.
  294. You can move URLs and titles from Tripal v2 pages to their
  295. corresponding Tripal v3 pages. This ensures user bookmarks and external
  296. links to your site are not broken. Here you can also unpublish Tripal
  297. v2 content types or completely remove them if desired. You can
  298. perform these action in stages such as first moving titles and URLs,
  299. then unpublishing Tripal v2 pages and once the migration has been
  300. verified you can finally delete the Tripal v2 pages to free space.
  301. Deleting the Tripal v2 content will not delete the data in Chado.
  302. The page is simply removed from the site.'),
  303. );
  304. $form['step4']['warning'] = array(
  305. '#type' => 'item',
  306. '#markup' => tripal_set_message('Any of the following options cannot be
  307. undone. Also, please be sure you have migrated all
  308. desired content types in Step 2 prior to deleting the Tripal v2
  309. contents.', TRIPAL_WARNING, array('return_html' => TRUE)),
  310. );
  311. $opt_complete_migration = array (
  312. 'cp_title' => 'Copy Title over to Tripal v3 Content',
  313. 'mv_url' => 'Migrate URL Alias to Tripal v3 Content',
  314. 'unpublish' => 'Unpublish Tripal v2 Content',
  315. 'delete' => 'Delete Tripal v2 Content',
  316. );
  317. if (count($tv2_options) == 1 && key_exists('all', $tv2_options)) {
  318. $form['step4']['complete'] = array(
  319. '#markup' => 'Migration completed. All content have been migrated.'
  320. );
  321. }
  322. else {
  323. foreach ($tv2_options AS $opt_key => $opt) {
  324. $form['step4'][$opt_key . '_title'] = array(
  325. '#markup' => "<b>$opt</b>"
  326. );
  327. $form['step4']['complete_migration--' . $opt_key] = array(
  328. '#type' => 'checkboxes',
  329. '#options' => $opt_complete_migration,
  330. );
  331. }
  332. $form['step4']['submit_btn'] = array(
  333. '#type' => 'submit',
  334. '#name' => 'complete_migration_btn',
  335. '#value' => "Submit",
  336. );
  337. }
  338. return $form;
  339. }
  340. /**
  341. * Implements hook_validate()
  342. *
  343. * @param $form
  344. * @param $form_state
  345. */
  346. function tripal_chado_migrate_form_validate($form, &$form_state) {
  347. }
  348. /**
  349. * Implements hook_submit()
  350. *
  351. * By submiting the form, a Tripal job to migrate Tripal v2 content is submitted
  352. *
  353. * @param $form
  354. * @param $form_state
  355. */
  356. function tripal_chado_migrate_form_submit($form, &$form_state) {
  357. // Store the legacy template setting in a Drupal variable
  358. if ($form_state['clicked_button']['#name'] == 'save_enabled_template_btn') {
  359. $values = $form_state['values'];
  360. $enabled_templates = array();
  361. foreach ($values AS $key => $value) {
  362. if (preg_match('/^legacy_template--/', $key)) {
  363. $enabled_templates[$key] = $value;
  364. }
  365. }
  366. variable_set('tripal_chado_enabled_legacy_templates', $enabled_templates);
  367. drupal_theme_rebuild();
  368. $_SESSION['tripal_migrate_current_tab'] = 'edit-step3';
  369. }
  370. // Complete migration
  371. else if ($form_state['clicked_button']['#name'] == 'complete_migration_btn') {
  372. $values = $form_state['values'];
  373. $config = array (
  374. 'delete' => array(),
  375. 'unpublish' => array(),
  376. 'cp_title' => array(),
  377. 'mv_url' => array()
  378. );
  379. $all = array();
  380. $all_types = array();
  381. // Gather checked checkboxes and store in the $config array
  382. foreach ($values AS $key => $value) {
  383. if (preg_match('/^complete_migration--/', $key)) {
  384. $type = str_replace('complete_migration--', '', $key);
  385. if ($type != 'all') {
  386. array_push($all_types, $type);
  387. }
  388. foreach ($value AS $key_op => $op) {
  389. if ($type == 'all') {
  390. if ($op) {
  391. array_push($all, $key_op);
  392. }
  393. }
  394. else {
  395. if ($op) {
  396. array_push($config[$key_op], $type);
  397. }
  398. }
  399. }
  400. }
  401. }
  402. foreach($all AS $a) {
  403. $config[$a] = $all_types;
  404. }
  405. // Submit jobs to complete the migration
  406. global $user;
  407. $includes = array(
  408. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.migrate'),
  409. );
  410. if (count($config['cp_title']) > 0) {
  411. $args = array($config['cp_title']);
  412. tripal_add_job("Copy Title over to Tripal v3 Content", 'tripal_chado',
  413. 'tripal_chado_copy_title_for_selected_types', $args, $user->uid, 10, $includes);
  414. }
  415. if (count($config['mv_url']) > 0) {
  416. $args = array($config['mv_url']);
  417. tripal_add_job(" Migrate URL Alias to Tripal v3 Content ", 'tripal_chado',
  418. 'tripal_chado_migrate_url_alias_for_selected_types', $args, $user->uid, 10, $includes);
  419. }
  420. if (count($config['unpublish']) > 0) {
  421. $args = array($config['unpublish']);
  422. tripal_add_job(" Unpublish Tripal v2 Content ", 'tripal_chado',
  423. 'tripal_chado_unpublish_selected_types', $args, $user->uid, 10, $includes);
  424. }
  425. if (count($config['delete']) > 0) {
  426. $args = array($config['delete']);
  427. tripal_add_job("Delete Tripal v2 Content ", 'tripal_chado',
  428. 'tripal_chado_delete_selected_types', $args, $user->uid, 10, $includes);
  429. }
  430. $_SESSION['tripal_migrate_current_tab'] = 'edit-step4';
  431. return;
  432. }
  433. // Migrate tv2 content to tv3 content
  434. else if ($form_state['clicked_button']['#name'] == 'migrate_btn') {
  435. global $user;
  436. $values = $form_state['values'];
  437. $tv2_content_type = $form_state['values']['tv2_content_type'];
  438. $tv3_content_type = array();
  439. foreach ($values AS $key => $value) {
  440. if ($tv2_content_type != 'all') {
  441. $key = urldecode($key);
  442. if (preg_match('/^tv3_content_type--(.+)--(.+)--(.+)/', $key, $matches) &&
  443. ($value == 1 || $values['tv3_migrate_all'] == 1)) {
  444. $vocabulary = $matches[1];
  445. $accession = $matches[2];
  446. $type = $matches[3];
  447. $table = str_replace('chado_', '', $tv2_content_type);
  448. $tv3_content_type [] = array(
  449. 'vocabulary' => $vocabulary,
  450. 'accession' => $accession,
  451. 'term_name' => $type,
  452. 'storage_args' => array (
  453. 'data_table' => $table,
  454. 'type_column' => db_field_exists('chado.' . $table, 'type_id') ? 'type_id' : ''
  455. )
  456. );
  457. }
  458. }
  459. }
  460. // Submit a job to migrate content
  461. global $user;
  462. $args = array(
  463. array(
  464. 'tv2_content_type' => $tv2_content_type,
  465. 'tv3_content_type' => $tv3_content_type
  466. )
  467. );
  468. $includes = array(
  469. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.migrate'),
  470. );
  471. if ($tv2_content_type == 'all' || count($tv3_content_type) != 0) {
  472. return tripal_add_job("Migrate $tv2_content_type Tripal v2 content.",
  473. 'tripal_chado', 'tripal_chado_migrate_records', $args, $user->uid, 10, $includes);
  474. }
  475. else {
  476. return drupal_set_message('Nothing to do. All data have been migrated or no data for migration.');
  477. }
  478. $_SESSION['tripal_migrate_current_tab'] = 'edit-step2';
  479. }
  480. }
  481. /**
  482. * Ajax call back that returns the entire form
  483. *
  484. * The callback is triggered by ajax elements on the form which leads to the update of
  485. * entire form according to the values set on the form
  486. *
  487. * @param $form
  488. * @param $form_state
  489. * @return $form
  490. */
  491. function tripal_chado_migrate_form_step2_ajax_callback(&$form, &$form_state) {
  492. return $form['step2']['step2_container'];
  493. }
  494. /**
  495. * Get available Tripal v2 content types
  496. *
  497. * @param boolean $all_option
  498. * Include an 'all' option in the returned array
  499. * @param boolean $has_template
  500. * Return TV2 content types only if it has a base template. This will exclude TV2 content
  501. * types such as Blast/Kegg/Interpro/Unigene which are all converted into the TV3
  502. * 'Analysis' entity type
  503. * @return string[]
  504. * Return a string array keyed by the node type
  505. */
  506. function tripal_chado_get_tripal_v2_content_type_options($all_option = FALSE, $has_template = FALSE) {
  507. // Get all available Tripal v2 chado tables
  508. $sql = "
  509. SELECT table_name
  510. FROM information_schema.tables
  511. WHERE table_schema = 'public' AND table_name LIKE 'chado_%'
  512. ";
  513. $result = db_query($sql);
  514. // Store 'chado_*' tables that has at least one node
  515. $tables = array();
  516. while ($field = $result->fetchField()) {
  517. $count = db_query("SELECT count(*) FROM $field LIMIT 1")->fetchField();
  518. if ($count != 0) {
  519. array_push($tables, $field);
  520. }
  521. }
  522. // List all available Tripal v2 content types
  523. $result = db_select('node_type', 'nt')
  524. ->fields('nt', array('type', 'name', 'description'))
  525. ->condition('type', 'chado_%', 'LIKE')
  526. ->execute();
  527. $options = array();
  528. if ($all_option) {
  529. $options['all'] = 'All';
  530. }
  531. while ($obj = $result->fetchObject()) {
  532. if ($has_template) {
  533. $mod = str_replace('chado_', 'tripal_', $obj->type);
  534. $mod_dir = drupal_get_path('module', $mod);
  535. if (file_exists($mod_dir . '/theme/templates/' . $mod . '_base.tpl.php')) {
  536. $options[$obj->type] = $obj->name;
  537. }
  538. }
  539. else {
  540. if (in_array($obj->type, $tables)) {
  541. $options[$obj->type] = $obj->name;
  542. }
  543. }
  544. }
  545. return $options;
  546. }
  547. /**
  548. * Tripal job callback to migrate Tripal v2 content into Tripal v3 content
  549. *
  550. * @param $migration
  551. * @param $job_id
  552. */
  553. function tripal_chado_migrate_records($migration, $job_id = NULL) {
  554. $tv2_content_type = $migration['tv2_content_type'];
  555. $tv3_content_type = $migration['tv3_content_type'];
  556. // If tv2_content_type is 'all', migrate all existing Tripal v2 content
  557. if ($tv2_content_type == 'all') {
  558. print "Migrating all Tripal v2 content...\n";
  559. tripal_chado_migrate_all_types();
  560. }
  561. // Otherwise, migrate only selected Tripal v2 content
  562. else {
  563. print "Migrating selected Tripal v2 content...\n";
  564. tripal_chado_migrate_selected_types($tv3_content_type);
  565. }
  566. }
  567. /**
  568. * Migrate all Tripal v2 content types
  569. *
  570. * Gather all available Tripal v2 content types and store the result in an
  571. * associated array with values of vocabulary, accession, term_name. The array
  572. * is then pass to the function tripal_chado_migrate_selected_types() that
  573. * handles the migration.
  574. */
  575. function tripal_chado_migrate_all_types() {
  576. // Get all available Tripal v2 content types
  577. $tv2_content_types = tripal_chado_get_tripal_v2_content_type_options();
  578. $types = tripal_chado_migrate_map_types($tv2_content_types);
  579. tripal_chado_migrate_selected_types($types);
  580. }
  581. /**
  582. * Map all tv2_content_type to tv3_content_type
  583. *
  584. * @param unknown $tv2_content_type
  585. * return $tv3_content_type
  586. */
  587. function tripal_chado_migrate_map_types($tv2_content_types) {
  588. $types = array();
  589. foreach($tv2_content_types AS $tv2_content_type => $value) {
  590. $table = str_replace('chado_', '', $tv2_content_type);
  591. $schema = chado_get_schema($table);
  592. $pkey = $schema['primary key'][0];
  593. $fkeys = $schema['foreign keys'];
  594. if ($table == 'organism') {
  595. array_push($types, array(
  596. 'vocabulary' => 'OBI',
  597. 'accession' => '0100026',
  598. 'term_name' => 'organism',
  599. 'storage_args' => array (
  600. 'data_table' => $table
  601. )
  602. ));
  603. }
  604. else if ($table == 'analysis') {
  605. array_push($types, array(
  606. 'vocabulary' => 'local',
  607. 'accession' => 'analysis',
  608. 'term_name' => 'analysis',
  609. 'storage_args' => array (
  610. 'data_table' => $table
  611. )
  612. ));
  613. }
  614. else if ($table == 'project') {
  615. array_push($types, array(
  616. 'vocabulary' => 'local',
  617. 'accession' => 'project',
  618. 'term_name' => 'project',
  619. 'storage_args' => array (
  620. 'data_table' => $table
  621. )
  622. ));
  623. }
  624. else if ($table == 'featuremap') {
  625. array_push($types, array(
  626. 'vocabulary' => 'data',
  627. 'accession' => '1274',
  628. 'term_name' => 'map',
  629. 'storage_args' => array (
  630. 'data_table' => $table
  631. )
  632. ));
  633. }
  634. else if ($table == 'pub') {
  635. array_push($types, array(
  636. 'vocabulary' => 'TPUB',
  637. 'accession' => '0000002',
  638. 'term_name' => 'Publication',
  639. 'storage_args' => array (
  640. 'data_table' => $table
  641. )
  642. ));
  643. }
  644. else if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
  645. // Get all Tripal v2 node types from the chad_* linking table
  646. $sql = "
  647. SELECT V.name AS type, X.accession, db.name AS vocabulary
  648. FROM {" . $table . "} T
  649. INNER JOIN public.$tv2_content_type CT ON T.$pkey = CT.$pkey
  650. INNER JOIN {cvterm} V ON V.cvterm_id = T.type_id
  651. INNER JOIN {dbxref} X ON X.dbxref_id = V.dbxref_id
  652. INNER JOIN {db} ON db.db_id = X.db_id
  653. GROUP BY V.name, X.accession, db.name
  654. ";
  655. $tv3_content_types = chado_query($sql);
  656. while($tv3_content_type = $tv3_content_types->fetchObject()) {
  657. array_push($types, array(
  658. 'vocabulary' => $tv3_content_type->vocabulary,
  659. 'accession' => $tv3_content_type->accession,
  660. 'term_name' => $tv3_content_type->type,
  661. 'storage_args' => array (
  662. 'data_table' => $table,
  663. 'type_column' => db_field_exists('chado.' . $table, 'type_id') ? 'type_id' : ''
  664. )
  665. ));
  666. }
  667. }
  668. }
  669. return $types;
  670. }
  671. /**
  672. * Migrate only selected Tripal v2 content types
  673. *
  674. * @param unknown $tv3_content_type
  675. */
  676. function tripal_chado_migrate_selected_types($tv3_content_types) {
  677. // Initialize the population of the chado_cvterm_mapping table before migration.
  678. tripal_chado_map_cvterms();
  679. foreach ($tv3_content_types AS $tv3_content_type) {
  680. // Check if the term already exists
  681. $term = tripal_load_term_entity($tv3_content_type);
  682. // If term doesn't exist, create a new bundle for this term
  683. if (!$term) {
  684. print("Creating bundle for term '" . $tv3_content_type['term_name'] . "'...\n");
  685. $success = tripal_create_bundle($tv3_content_type);
  686. $term = tripal_load_term_entity($tv3_content_type);
  687. }
  688. // Create bundle name
  689. $bundle_name = 'bio_data_' . $term->id;
  690. // Publish records for the bundle
  691. $value = array(
  692. 'sync_node' => 1,
  693. 'bundle_name' => $bundle_name
  694. );
  695. tripal_chado_publish_records($value);
  696. // Migrate Resource Titles/Blocks or Resource Links if available
  697. tripal_chado_migrate_resource_blocks($bundle_name);
  698. tripal_chado_migrate_resource_links($bundle_name);
  699. // Migrate organism images
  700. if ($term->name == 'organism') {
  701. tripal_chado_migrate_organism_images($bundle_name);
  702. }
  703. }
  704. }
  705. /**
  706. * Delete selected Tripal v2 content
  707. *
  708. * Delete all records from chado_* table then call the cleanup orphan nodes function
  709. *
  710. * @param unknown $tv2_content_types
  711. */
  712. function tripal_chado_delete_selected_types($tv2_content_types = array()) {
  713. foreach ($tv2_content_types AS $type) {
  714. $sql = "DELETE FROM $type";
  715. db_query($sql);
  716. chado_cleanup_orphaned_nodes(str_replace('chado_', '', $type));
  717. }
  718. }
  719. /**
  720. * Unpublish selected Tripal v2 content
  721. *
  722. * Set status = 0 (unpublished) for all nodes of selected Tripal v2 content types
  723. *
  724. * @param unknown $tv2_content_types
  725. */
  726. function tripal_chado_unpublish_selected_types($tv2_content_types = array()) {
  727. foreach ($tv2_content_types AS $type) {
  728. $sql = "UPDATE node SET status = 0 WHERE nid IN (SELECT nid FROM $type)";
  729. db_query($sql);
  730. $sql = "UPDATE node_revision SET status = 0 WHERE nid IN (SELECT nid FROM $type)";
  731. db_query($sql);
  732. }
  733. }
  734. /**
  735. * Copy titles for selected Tripal v2 content
  736. *
  737. * Copy tiltles for all nodes of selected Tripal v2 content types
  738. *
  739. * @param unknown $tv2_content_types
  740. */
  741. function tripal_chado_copy_title_for_selected_types($tv2_content_types = array()) {
  742. foreach ($tv2_content_types AS $type) {
  743. $chado_table = str_replace('chado_', '', $type);
  744. $bio_data_tables = tripal_chado_migrate_get_biodata_tables($chado_table);
  745. foreach($bio_data_tables AS $bio_data_table) {
  746. $sql = "SELECT nid, entity_id FROM $bio_data_table WHERE nid IN (SELECT nid FROM $type)";
  747. $result = db_query($sql);
  748. while ($entity = $result->fetchObject()) {
  749. $usql = "
  750. UPDATE tripal_entity
  751. SET title = (SELECT title FROM node WHERE nid = :nid)
  752. WHERE id = :entity_id";
  753. db_query($usql, array(
  754. ':nid' => $entity->nid,
  755. ':entity_id' => $entity->entity_id)
  756. );
  757. }
  758. }
  759. }
  760. }
  761. /**
  762. * Migrate URL alias for selected Tripal v2 content
  763. *
  764. * Migrate URL alias for all nodes of selected Tripal v2 content types
  765. *
  766. * @param unknown $tv2_content_types
  767. */
  768. function tripal_chado_migrate_url_alias_for_selected_types($tv2_content_types = array()) {
  769. foreach ($tv2_content_types AS $type) {
  770. $chado_table = str_replace('chado_', '', $type);
  771. $bio_data_tables = tripal_chado_migrate_get_biodata_tables($chado_table);
  772. foreach($bio_data_tables AS $bio_data_table) {
  773. $sql = "SELECT nid, entity_id FROM $bio_data_table WHERE nid IN (SELECT nid FROM $type)";
  774. $result = db_query($sql);
  775. while ($entity = $result->fetchObject()) {
  776. $usql = "
  777. UPDATE url_alias
  778. SET source = 'bio_data/" . $entity->entity_id .
  779. "' WHERE source = 'node/" . $entity->nid . "'";
  780. db_query($usql);
  781. }
  782. }
  783. }
  784. }
  785. /**
  786. * Migrate images for Tripal v2 organism content
  787. *
  788. * Migrate images for all chado_organism
  789. *
  790. */
  791. function tripal_chado_migrate_organism_images () {
  792. // Get all organism entities
  793. $bio_data_table = array_pop(tripal_chado_migrate_get_biodata_tables('organism'));
  794. $results =
  795. db_select($bio_data_table, 'ce')
  796. ->fields('ce', array('entity_id', 'record_id', 'nid'))
  797. ->execute();
  798. // Iterate through each organism entity
  799. while ($organism = $results->fetchObject()) {
  800. $nid = $organism->nid;
  801. $entity_id = $organism->entity_id;
  802. // check if there is a file record for the organism node
  803. $fid = db_select('file_usage', 'fu')
  804. ->fields('fu', array('fid'))
  805. ->condition('module', 'tripal_organism')
  806. ->condition('type', 'organism_image')
  807. ->condition('id', $nid)
  808. ->execute()
  809. ->fetchField();
  810. // check if the image was added using the old interface.
  811. if (!$fid) {
  812. $sql =
  813. "SELECT genus,species,nid
  814. FROM {organism} O
  815. INNER JOIN chado_organism CO ON O.organism_id = CO.organism_id
  816. WHERE O.organism_id = :organism_id";
  817. $chado_org = chado_query($sql, array(':organism_id' => $organism->record_id))->fetchObject();
  818. if ($chado_org) {
  819. $base_path = realpath('.');
  820. $image_dir = tripal_get_files_dir('tripal_organism') . "/images";
  821. $image_name = $chado_org->genus . "_" . $chado_org->species . ".jpg";
  822. $image_path = "$base_path/$image_dir/$image_name";
  823. // image files are stored as 'genus_species.jpg'
  824. $file =NULL;
  825. if (file_exists($image_path)) {
  826. $handle = fopen($image_path, 'r');
  827. $file = file_save_data($handle, "public://$image_name");
  828. fclose($handle);
  829. }
  830. // last possible case: image files are stored as 'organism_id.jpg'
  831. else {
  832. $image_name = $chado_org->nid . ".jpg";
  833. $image_path = "$base_path/$image_dir/$image_name";
  834. if (file_exists($image_path)) {
  835. $handle = fopen($image_path, 'r');
  836. $file = file_save_data($handle, "public://$image_name");
  837. fclose($handle);
  838. }
  839. }
  840. if($file){
  841. tripal_chado_migrate_organism_image_add_file($file->fid, $entity_id);
  842. }
  843. }
  844. }
  845. else {
  846. // If there is an image, add it to the organism entity
  847. tripal_chado_migrate_organism_image_add_file ($fid, $entity_id);
  848. }
  849. }
  850. }
  851. /**
  852. *
  853. * Add image file for the organism entity
  854. *
  855. * @param unknown $fid
  856. */
  857. function tripal_chado_migrate_organism_image_add_file ($fid, $entity_id) {
  858. if ($fid && $entity_id) {
  859. $file = file_load($fid);
  860. // Add a record to the file_usage table
  861. file_usage_add($file, 'file', 'TripalEntity', $entity_id);
  862. // Attached it to the entity
  863. $entities = entity_load('TripalEntity', array($entity_id));
  864. $entity = $entities[$entity_id];
  865. $image_file = (array) $file;
  866. $image = array(
  867. 'und' => array(
  868. 0 =>$image_file
  869. )
  870. );
  871. $entity->data__image = $image;
  872. field_attach_update('TripalEntity', $entity);
  873. entity_get_controller('TripalEntity')->resetCache(array($entity_id));
  874. // Add a record to the field_data_data__image table
  875. }
  876. }
  877. /**
  878. * Retrieve chado_biodata_* table name
  879. *
  880. * @param string $chado_table
  881. * the chado_table where the record is stored
  882. *
  883. * @return
  884. * Return all chado_biodata_* table names mapping to a chado_table
  885. */
  886. function tripal_chado_migrate_get_biodata_tables ($chado_table) {
  887. // To find the bundle_table, check if type_column is used for the chado_table
  888. $query = db_select('chado_bundle', 'cb');
  889. $query->join('tripal_bundle', 'tb', 'tb.id = cb.bundle_id');
  890. $query->fields('cb', array('data_table'));
  891. $query->fields('tb', array('name'));
  892. $query->condition('cb.data_table', $chado_table);
  893. $bundles = $query->execute();
  894. $tables = array();
  895. while ($bundle = $bundles->fetchObject()) {
  896. array_push($tables, 'chado_' . $bundle->name);
  897. }
  898. return $tables;
  899. }
  900. function tripal_chado_migrate_resource_blocks($bundle_name) {
  901. $entites =
  902. db_select('chado_' . $bundle_name, 'B')
  903. ->fields('B', array('nid'))
  904. ->execute();
  905. while ($nid = $entites->fetchField()) {
  906. // Only the latest revision is migrated
  907. $sql = "
  908. SELECT
  909. entity_id,
  910. max(revision_id) AS vid,
  911. delta,
  912. (SELECT field_resource_titles_value
  913. FROM field_revision_field_resource_titles
  914. WHERE entity_id = RT.entity_id
  915. AND revision_id = max(RT.revision_id)
  916. AND delta = RT.delta
  917. ),
  918. (SELECT field_resource_blocks_value
  919. FROM field_revision_field_resource_blocks
  920. WHERE entity_id = RT.entity_id
  921. AND revision_id = max(RT.revision_id)
  922. AND delta = RT.delta
  923. )
  924. FROM field_revision_field_resource_titles RT
  925. WHERE RT.entity_id = :nid
  926. GROUP BY entity_id, delta
  927. ORDER BY RT.delta
  928. ";
  929. $results = db_query($sql, array(':nid' => $nid));
  930. while ($resource = $results->fetchObject()) {
  931. $title = $resource->field_resource_titles_value;
  932. $content = $resource->field_resource_blocks_value;
  933. $delta = $resource->delta;
  934. $nid = $resource->entity_id;
  935. $entity_id =
  936. db_select('chado_' . $bundle_name, 'B')
  937. ->fields('B', array('entity_id'))
  938. ->condition('nid', $nid)
  939. ->execute()
  940. ->fetchField()
  941. ;
  942. // field name: (can not be longer than 32 chars)
  943. // bio_data_<i>_resource_<title to lower case/space replaced with _/first 10 chars>
  944. $field_name = $bundle_name . '_rsc_' . substr(preg_replace('/\s+/', '_', strtolower($title)), 0, 15);
  945. // Create a field if it does not exist
  946. if (!field_info_field($field_name)) {
  947. field_create_field(array(
  948. 'field_name' => $field_name,
  949. 'type' => 'text',
  950. 'cardinality' => 1,
  951. 'locked' => FALSE,
  952. 'storage' => array(
  953. 'type' => 'field_sql_storage',
  954. ),
  955. 'settings' => array(
  956. 'max_length' => 10485760,
  957. 'text_processing' => 1
  958. )
  959. ));
  960. }
  961. // Create field instance for the bundle if it does not exist
  962. if (!field_info_instance('TripalEntity', $field_name, $bundle_name)) {
  963. field_create_instance(array(
  964. 'field_name' => $field_name,
  965. 'entity_type' => 'TripalEntity',
  966. 'bundle' => $bundle_name,
  967. 'label' => $title,
  968. 'widget' => array(
  969. 'type' => 'text_textarea',
  970. ),
  971. 'display' => array(
  972. 'default' => array(
  973. 'label' => 'hidden',
  974. ),
  975. ),
  976. 'settings' => array(
  977. 'text_processing' => 1,
  978. 'format' => 'full_html',
  979. 'term_vocabulary' => 'schema',
  980. 'term_name' => 'comment',
  981. 'term_accession' => 'comment',
  982. ),
  983. ));
  984. }
  985. // Migrate the field content
  986. $ftable = 'field_data_' . $field_name;
  987. $frtable = 'field_revision_' . $field_name;
  988. $fvalue = $field_name . '_value';
  989. $fformat = $field_name . '_format';
  990. try {
  991. $sql = "
  992. INSERT INTO $ftable (entity_type, bundle, entity_id, revision_id, language, delta, $fvalue, $fformat)
  993. VALUES (:entity_type, :bundle, :entity_id, :revision_id, :language, :delta, :value, :format)
  994. ";
  995. db_query($sql,
  996. array (
  997. ':entity_type' => 'TripalEntity',
  998. ':bundle' => $bundle_name,
  999. ':entity_id' => $entity_id,
  1000. 'revision_id' => $entity_id,
  1001. ':language' => 'und',
  1002. ':delta' => 0,
  1003. ':value' => $content,
  1004. ':format' => 'full_html'
  1005. )
  1006. );
  1007. $rsql = "
  1008. INSERT INTO $frtable (entity_type, bundle, entity_id, revision_id, language, delta, $fvalue, $fformat)
  1009. VALUES (:entity_type, :bundle, :entity_id, :revision_id, :language, :delta, :value, :format)
  1010. ";
  1011. db_query($rsql,
  1012. array (
  1013. ':entity_type' => 'TripalEntity',
  1014. ':bundle' => $bundle_name,
  1015. ':entity_id' => $entity_id,
  1016. 'revision_id' => $entity_id,
  1017. ':language' => 'und',
  1018. ':delta' => 0,
  1019. ':value' => $content,
  1020. ':format' => 'full_html'
  1021. )
  1022. );
  1023. } catch (\PDOException $e) {
  1024. $error = $e->getMessage();
  1025. watchdog_exception('tripal_chado', $e);
  1026. }
  1027. }
  1028. }
  1029. }
  1030. function tripal_chado_migrate_resource_links($bundle_name) {
  1031. $entites =
  1032. db_select('chado_' . $bundle_name, 'B')
  1033. ->fields('B', array('nid'))
  1034. ->execute();
  1035. while ($nid = $entites->fetchField()) {
  1036. // Only the latest revision is migrated
  1037. $sql = "
  1038. SELECT
  1039. entity_id,
  1040. max(revision_id) AS vid,
  1041. delta,
  1042. (SELECT field_resource_links_value
  1043. FROM field_revision_field_resource_links
  1044. WHERE entity_id = RT.entity_id
  1045. AND revision_id = max(RT.revision_id)
  1046. AND delta = RT.delta
  1047. )
  1048. FROM field_revision_field_resource_links RT
  1049. WHERE RT.entity_id = :nid
  1050. GROUP BY entity_id, delta
  1051. ORDER BY RT.delta
  1052. ";
  1053. $results = db_query($sql, array(':nid' => $nid));
  1054. while ($resource = $results->fetchObject()) {
  1055. $values = explode('|', $resource->field_resource_links_value);
  1056. $title = $values[0];
  1057. $link = $values[1];
  1058. $delta = $resource->delta;
  1059. $nid = $resource->entity_id;
  1060. $entity_id =
  1061. db_select('chado_' . $bundle_name, 'B')
  1062. ->fields('B', array('entity_id'))
  1063. ->condition('nid', $nid)
  1064. ->execute()
  1065. ->fetchField();
  1066. // field name: (can not be longer than 32 chars)
  1067. // bio_data_<i>_resource_<title to lower case/space replaced with _/first 10 chars>
  1068. $field_name = $bundle_name . '_resource_links';
  1069. // Create a field if it does not exist
  1070. if (!field_info_field($field_name)) {
  1071. field_create_field(array(
  1072. 'field_name' => $field_name,
  1073. 'type' => 'link_field',
  1074. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1075. 'locked' => FALSE,
  1076. 'storage' => array(
  1077. 'type' => 'field_sql_storage',
  1078. ),
  1079. 'settings' => array(
  1080. )
  1081. ));
  1082. }
  1083. // Create field instance for the bundle if it does not exist.
  1084. if (!field_info_instance('TripalEntity', $field_name, $bundle_name)) {
  1085. field_create_instance(array(
  1086. 'field_name' => $field_name,
  1087. 'entity_type' => 'TripalEntity',
  1088. 'bundle' => $bundle_name,
  1089. 'label' => 'Links',
  1090. 'widget' => array(
  1091. 'type' => 'link_field',
  1092. ),
  1093. 'display' => array(
  1094. 'default' => array(
  1095. 'label' => 'hidden',
  1096. ),
  1097. ),
  1098. 'settings' => array(
  1099. 'term_vocabulary' => 'schema',
  1100. 'term_name' => 'url',
  1101. 'term_accession' => 'url',
  1102. 'absolute_url' => 0,
  1103. 'validate_url' => 0
  1104. ),
  1105. ));
  1106. }
  1107. // Migrate the field content
  1108. $ftable = 'field_data_' . $field_name;
  1109. $frtable = 'field_revision_' . $field_name;
  1110. $furl = $field_name . '_url';
  1111. $ftitle = $field_name . '_title';
  1112. try {
  1113. $sql = "
  1114. INSERT INTO $ftable (entity_type, bundle, entity_id, revision_id, language, delta, $furl, $ftitle)
  1115. VALUES (:entity_type, :bundle, :entity_id, :revision_id, :language, :delta, :url, :title)
  1116. ";
  1117. db_query($sql,
  1118. array (
  1119. ':entity_type' => 'TripalEntity',
  1120. ':bundle' => $bundle_name,
  1121. ':entity_id' => $entity_id,
  1122. 'revision_id' => $entity_id,
  1123. ':language' => 'und',
  1124. ':delta' => $delta,
  1125. ':url' => $link,
  1126. ':title' => $title
  1127. )
  1128. );
  1129. $rsql = "
  1130. INSERT INTO $frtable (entity_type, bundle, entity_id, revision_id, language, delta, $furl, $ftitle)
  1131. VALUES (:entity_type, :bundle, :entity_id, :revision_id, :language, :delta, :url, :title)
  1132. ";
  1133. db_query($rsql,
  1134. array (
  1135. ':entity_type' => 'TripalEntity',
  1136. ':bundle' => $bundle_name,
  1137. ':entity_id' => $entity_id,
  1138. 'revision_id' => $entity_id,
  1139. ':language' => 'und',
  1140. ':delta' => $delta,
  1141. ':url' => $link,
  1142. ':title' => $title
  1143. )
  1144. );
  1145. } catch (\PDOException $e) {
  1146. $error = $e->getMessage();
  1147. watchdog_exception('tripal_chado', $e);
  1148. }
  1149. }
  1150. }
  1151. }