Browse Source

updates to loader, fixed type in core

spficklin 12 năm trước cách đây
mục cha
commit
7e587c447d

+ 20 - 14
tripal_bulk_loader/tripal_bulk_loader.admin.templates.inc

@@ -569,13 +569,9 @@ function tripal_bulk_loader_import_export_template_form($form_state = NULL, $mod
       '#options'       => $templates,
       '#default_value' => $form_state['storage']['template_id'],
       '#weight'        => 0,
-      '#required'      => TRUE,
+      '#required'      => TRUE,     
     );
   }
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => 'Submit',
-  );
 
   $form['template_array'] = array(
     '#type' => 'textarea',
@@ -583,15 +579,16 @@ function tripal_bulk_loader_import_export_template_form($form_state = NULL, $mod
     '#default_value' => $form_state['storage']['template_array'],
     '#description' => t('Use this serialized array for import.'),
     '#rows' => 15,
+    '#weight' => 5,
+  
   );
-  $form['template_array_no_serial'] = array(
-    '#type' => 'textarea',
-    '#title' => 'Template Array (Unsearialized)',
-    '#default_value' => $form_state['storage']['template_array_no_serial'],
-    '#rows' => 25,
+  
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => 'Submit',
+    '#weight' => 10,
   );
 
-
   return $form;
 }
 
@@ -607,14 +604,23 @@ function tripal_bulk_loader_import_export_template_form_submit($form, &$form_sta
   switch ($form_state['values']['mode']) {
     case 'export':
       $record = db_fetch_object(db_query("SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d", $form_state['values']['template_id']));
-      $form_state['storage']['template_array'] = $record->template_array;
-      $form_state['storage']['template_array_no_serial'] = var_export(unserialize($record->template_array), TRUE);
+      //$form_state['storage']['template_array'] = $record->template_array;
+      $t = var_export(unserialize($record->template_array), TRUE);
+      $t = preg_replace("/\n\s+array/","array", $t); // move array( to previous line
+      $t = preg_replace("/true/","TRUE", $t); // upper case true
+      $t = preg_replace("/false/","FALSE", $t); // upper case false
+      $t = preg_replace("/array\(/","array (", $t); // put a space between array and paren      
+    
+      $form_state['storage']['template_array'] = $t; 
       $form_state['storage']['template_id'] = $form_state['values']['template_id'];
     break;
     case 'import':
+      // get the template array, and convert from text into an array.
+      $t = array();
+      eval("\$t = " . $form_state['values']['template_array'] . ";");
       $record = array(
         'name' => $form_state['values']['new_template_name'],
-        'template_array' => $form_state['values']['template_array'],
+        'template_array' => serialize($t),
       );
       drupal_write_record('tripal_bulk_loader_template', $record);
       if ($record->template_id) {

+ 0 - 5
tripal_bulk_loader/tripal_bulk_loader.loader.inc

@@ -125,11 +125,6 @@ function tripal_bulk_loader_add_loader_job_form_submit($form, $form_state) {
  */
 function tripal_bulk_loader_load_data($nid, $job_id) {
 
-  // we need to get a persistent connection.  If one exists this function
-  // will not recreate it, but if not it will create one and store it in
-  // a Drupal variable for reuse later.
-  $connection = tripal_db_persistent_chado();
-	
   // ensure no timeout
   set_time_limit(0);
 

+ 8 - 8
tripal_core/api/tripal_core.api.inc

@@ -1876,7 +1876,7 @@ function chado_query($sql) {
 
   // Execute the query on the chado database/schema
   // Use the persistent chado connection if it already exists
-  $persistent_connection = unserialize(variable_get('tripal_perisistent_chado', NULL));
+  $persistent_connection = unserialize(variable_get('tripal_persistent_chado', NULL));
   if ($persistent_connection) {
 
     $query = $sql;
@@ -2371,7 +2371,7 @@ function tripal_core_is_sql_prepared($statement_name) {
   // has been prepared. If it has then we won't do the database
   // query to find out.  If it hasn't then we'll query the database
   // to see if it is prepared.
-  $connection = variable_get('tripal_perisistent_chado', NULL);
+  $connection = variable_get('tripal_persistent_chado', NULL);
   if (!isset($_SESSION[$connection])) {
     $_SESSION[$connection] = array();
   }
@@ -2408,7 +2408,7 @@ function tripal_core_is_sql_prepared($statement_name) {
  *   be the type of value needed (ie: text, int, etc.)
  */
 function tripal_core_chado_prepare($statement_name, $psql, $args) {
-  $connection = variable_get('tripal_perisistent_chado', NULL);
+  $connection = variable_get('tripal_persistent_chado', NULL);
 
   // Check to see if this statement was already prepared
   if (tripal_core_is_sql_prepared($statement_name)) {
@@ -2452,7 +2452,7 @@ function tripal_core_chado_prepare($statement_name, $psql, $args) {
  *   An array of values in the execute sql statement
  */
 function tripal_core_chado_execute_prepared($statement_name, $sql, $values) {
-  $connection = variable_get('tripal_perisistent_chado', NULL);
+  $connection = variable_get('tripal_persistent_chado', NULL);
 
   if (!tripal_core_is_sql_prepared($statement_name)) {
      watchdog('tripal_core', "tripal_core_chado_execute_prepared: Cannot execute an unprepared statement: '%name'", array('%name' => $statement_name), WATCHDOG_ERROR);
@@ -2519,7 +2519,7 @@ function tripal_db_persistent_chado() {
 
   // get connection if it already exists
   // Otherwise we need to set it
-  $connection = unserialize(variable_get('tripal_perisistent_chado', NULL));
+  $connection = unserialize(variable_get('tripal_persistent_chado', NULL));
 
   if ($connection) {
     return $connection;
@@ -2527,11 +2527,11 @@ function tripal_db_persistent_chado() {
   else {
     if (is_array($db_url) && isset($db_url['chado'])) {
       $connection = db_connect($db_url['chado']);
-      variable_set('tripal_perisistent_chado', $connection);
+      variable_set('tripal_persistent_chado', $connection);
     }
     else {
       $connection = db_connect($db_url);
-      variable_set('tripal_perisistent_chado', serialize($connection));
+      variable_set('tripal_persistent_chado', serialize($connection));
     }
     return $connection;
   }
@@ -2542,7 +2542,7 @@ function tripal_db_persistent_chado() {
  * Release a persistent chado connection
  */
 function tripal_db_release_persistent_chado() {
-  variable_del('tripal_perisistent_chado');
+  variable_del('tripal_persistent_chado');
 }
 
 /**