Преглед изворни кода

Code for migrating tripal v2 content types

ccheng пре 9 година
родитељ
комит
275f1f4914
2 измењених фајлова са 108 додато и 0 уклоњено
  1. 93 0
      tripal_chado/includes/tripal_chado.migrate.inc
  2. 15 0
      tripal_chado/tripal_chado.module

+ 93 - 0
tripal_chado/includes/tripal_chado.migrate.inc

@@ -0,0 +1,93 @@
+<?php
+
+function tripal_chado_migrate_form($form, &$form_state) {
+
+  $form['field'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Migrate to Tripal v3',
+    '#description' => t('The following Tripal v2 content types are available. Select the content type to migrate.'),
+  );
+  
+  // Migrate all checkbox
+  $form['field']['all'] = array(
+    '#type' => 'checkbox',
+    '#title' => 'All',
+    '#description' => 'All of the following content types'
+  );
+  
+  // Get all available Tripal v2 chado tables
+  $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'chado_%'";
+  $result = db_query($sql);
+  $tables = array();
+  while ($field = $result->fetchField()) {
+    array_push($tables, $field);
+  }
+  
+  // List all available Tripal v2 content types
+  $result = db_select('node_type', 'nt')
+    ->fields('nt', array('type', 'name', 'description'))
+    ->condition('type', 'chado_%', 'LIKE')
+    ->execute();
+  while ($obj = $result->fetchObject()) {
+    if (in_array($obj->type, $tables)) {
+      $form['field'][$obj->type] = array(
+        '#type' => 'checkbox',
+        '#title' => $obj->name,
+        '#description' => $obj->description,
+      );
+    }
+  }
+  $form['migrate_btn'] = array(
+    '#type' => 'submit',
+    '#name' => 'migrate_btn',
+    '#value' => 'migrate',
+  );
+
+  $form['#prefix'] = '<div id="tripal-chado-migrate-form">';
+  $form['#suffix'] = '</div>';
+  return $form;
+}
+
+function tripal_chado_migrate_form_validate($form, &$form_state) {
+
+}
+
+function tripal_chado_migrate_form_submit($form, &$form_state) {
+  if ($form_state['clicked_button']['#name'] == 'migrate_btn') {
+    global $user;
+    $values = $form_state['values'];
+    $all = $form_state['values']['all'];
+    $migration = array();
+    foreach ($values AS $key => $value) {
+      if ($all) {
+        if (preg_match('/^chado_/', $key)) {
+          array_push($migration, $key);
+        }
+      } else {
+        if (preg_match('/^chado_/', $key) && $value) {
+          array_push($migration, $key);
+        }
+      }
+    }
+    
+    // Submit a job to migrate content
+    dpm($migration);
+    /* $term_id = $form_state['values']['term_id'];
+    $bundle_name = 'bio-data_' . $term_id;
+    $bundle = tripal_load_bundle_entity(array('name' => $bundle_name)); */
+
+  }
+}
+/**
+ *
+ */
+function tripal_chado_migrate_form_ajax_callback($form, $form_state) {
+  return $form;
+}
+
+/**
+ *
+ */
+function tripal_chado_migrate_records($bundle_name, $job_id = NULL) {
+
+}

+ 15 - 0
tripal_chado/tripal_chado.module

@@ -427,6 +427,21 @@ function tripal_chado_menu() {
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
   );
+  
+  //////////////////////////////////////////////////////////////////////////////
+  //                           Migrate Content
+  //////////////////////////////////////////////////////////////////////////////
+  $items['admin/tripal/storage/chado/migrate'] = array(
+    'title' => 'Migrate',
+    'description' => t('Migrate Tripal v2 content to Tripal v3'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_chado_migrate_form'),
+    'type' => MENU_NORMAL_ITEM,
+    'access arguments' => array('administer tripal'),
+    'file' => 'includes/tripal_chado.migrate.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'weight' => 10
+  );
 
   //////////////////////////////////////////////////////////////////////////////
   //                           Auto Completes