tripal_chado.migrate.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. function tripal_chado_migrate_form($form, &$form_state) {
  3. $form['field'] = array(
  4. '#type' => 'fieldset',
  5. '#title' => 'Migrate to Tripal v3',
  6. '#description' => t('The following Tripal v2 content types are available. Select the content type to migrate.'),
  7. );
  8. // Migrate all checkbox
  9. $form['field']['all'] = array(
  10. '#type' => 'checkbox',
  11. '#title' => 'All',
  12. '#description' => 'All of the following content types'
  13. );
  14. // Get all available Tripal v2 chado tables
  15. $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'chado_%'";
  16. $result = db_query($sql);
  17. $tables = array();
  18. while ($field = $result->fetchField()) {
  19. array_push($tables, $field);
  20. }
  21. // List all available Tripal v2 content types
  22. $result = db_select('node_type', 'nt')
  23. ->fields('nt', array('type', 'name', 'description'))
  24. ->condition('type', 'chado_%', 'LIKE')
  25. ->execute();
  26. while ($obj = $result->fetchObject()) {
  27. if (in_array($obj->type, $tables)) {
  28. $form['field'][$obj->type] = array(
  29. '#type' => 'checkbox',
  30. '#title' => $obj->name,
  31. '#description' => $obj->description,
  32. );
  33. }
  34. }
  35. $form['migrate_btn'] = array(
  36. '#type' => 'submit',
  37. '#name' => 'migrate_btn',
  38. '#value' => 'migrate',
  39. );
  40. $form['#prefix'] = '<div id="tripal-chado-migrate-form">';
  41. $form['#suffix'] = '</div>';
  42. return $form;
  43. }
  44. function tripal_chado_migrate_form_validate($form, &$form_state) {
  45. }
  46. function tripal_chado_migrate_form_submit($form, &$form_state) {
  47. if ($form_state['clicked_button']['#name'] == 'migrate_btn') {
  48. global $user;
  49. $values = $form_state['values'];
  50. $all = $form_state['values']['all'];
  51. $migration = array();
  52. foreach ($values AS $key => $value) {
  53. if ($all) {
  54. if (preg_match('/^chado_/', $key)) {
  55. array_push($migration, $key);
  56. }
  57. } else {
  58. if (preg_match('/^chado_/', $key) && $value) {
  59. array_push($migration, $key);
  60. }
  61. }
  62. }
  63. // Submit a job to migrate content
  64. dpm($migration);
  65. /* $term_id = $form_state['values']['term_id'];
  66. $bundle_name = 'bio-data_' . $term_id;
  67. $bundle = tripal_load_bundle_entity(array('name' => $bundle_name)); */
  68. }
  69. }
  70. /**
  71. *
  72. */
  73. function tripal_chado_migrate_form_ajax_callback($form, $form_state) {
  74. return $form;
  75. }
  76. /**
  77. *
  78. */
  79. function tripal_chado_migrate_records($bundle_name, $job_id = NULL) {
  80. }