tripal_chado.migrate.inc 2.6 KB

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