Browse Source

Nightly check-in

Stephen Ficklin 8 years ago
parent
commit
ce857afcbc

+ 29 - 3
tripal/api/tripal.jobs.api.inc

@@ -173,9 +173,9 @@ function tripal_get_job($job_id) {
   $job = db_query('SELECT j.* FROM {tripal_jobs} j WHERE j.job_id=:job_id', array(':job_id' => $job_id))
     ->fetchObject();
 
-  $job->submit_date_string = format_date($job->submit_date);
-  $job->start_time_string = format_date($job->start_time);
-  $job->end_time_string = format_date($job->end_time);
+  $job->submit_date_string = $job->submit_date ? format_date($job->submit_date) : '';
+  $job->start_time_string = $job->start_time ? format_date($job->start_time): '';
+  $job->end_time_string = $job->end_time ? format_date($job->end_time): '';
 
   return $job;
 }
@@ -426,6 +426,32 @@ function tripal_set_job_progress($job_id, $percentage) {
 
   return FALSE;
 }
+
+/**
+ * Retrieves the current proress of a job.
+ *
+ * @param $job_id
+ *   The job_id to get the progress for
+ *
+ * @return
+ *   A value between 0 and 100 indicating the percentage complete of the job.
+ */
+function tripal_get_job_progress($job_id) {
+
+  if (!$job_id) {
+    watchdog('tripal', "Must provide a \$$job_id argument to the tripal_get_job_progress() function.");
+    return FALSE;
+  }
+
+  // Get the progress.
+  $progress = db_select('tripal_jobs', 'tj')
+    ->fields('tj', array('progress'))
+    ->condition('job_id', $job_id)
+    ->execute()
+    ->fetchField();
+
+  return $progress;
+}
 /**
  * Returns a list of jobs that are active.
  *

+ 4 - 4
tripal/api/tripal.notice.api.inc

@@ -179,10 +179,10 @@ function tripal_set_message($message, $importance = TRIPAL_INFO, $options = arra
 
   // Mark-up the Message
   $full_message =
-     '<div class="tripal-site-admin-message">'
-       . '<span class="tripal-severity-string ' . strtolower($importance_string) . '">' . $importance_string . ': </span>'
-       . $message
-   . '</div>';
+     '<div class="tripal-site-admin-message">' .
+       '<span class="tripal-severity-string ' . strtolower($importance_string) . '">' . $importance_string . ': </span>' .
+       $message .
+   '</div>';
 
   // Handle whether to return the HTML & let the caller deal with it
   // or to use drupal_set_message to put it near the top of the page  & let the theme deal with it

+ 46 - 0
tripal/includes/tripal.jobs.inc

@@ -328,3 +328,49 @@ function tripal_jobs_view($job_id) {
   $output .= theme_table($table);
   return $output;
 }
+
+/**
+ * Runs a Tripal job from within the request.
+ *
+ * @param $job_id
+ */
+function tripal_jobs_status_view($job_id) {
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  $breadcrumb[] = l('Tripal', 'admin/tripal');
+  $breadcrumb[] = l('Jobs', 'admin/tripal/tripal_jobs');
+  drupal_set_breadcrumb($breadcrumb);
+
+  $job = tripal_get_job($job_id);
+
+  drupal_add_css(drupal_get_path ('module', 'tripal') . '/theme/css/tripal_jobs.css');
+  drupal_add_js(drupal_get_path ('module', 'tripal') . '/theme/js/tripal_jobs.js');
+
+  $markup  = "<h2>Job Progress</h2>";
+  $markup .=  "<p>Job: " . $job->job_name . ' (' . $job->progress . '% Complete)';
+  $markup .= '<br>Status: ' . $job->status . '</p>';
+  $markup .= '<div id="tripal-jobs-progress-bar"><div></div></div>';
+  $markup .= '<p>' . l('Refresh Page', 'admin/tripal/tripal_jobs/status/' . $job_id) . '</p>';
+
+  drupal_add_js('var progress_percent = ' . $job->progress . ';', array('type' => 'inline'));
+
+  // Reload the page every 30 seconds.
+  $meta = array(
+    '#tag' => 'meta',
+    '#attributes' => array(
+      'http-equiv' => 'refresh',
+      'content' =>  '30',
+    )
+  );
+  drupal_add_html_head($meta, 'tripal_job_status_page');
+
+  $page = array(
+    '#type' => 'markup',
+    '#markup' => $markup,
+  );
+
+  return $page;
+}
+

+ 4 - 4
tripal/theme/css/tripal.css

@@ -69,12 +69,12 @@ div.messages.tripal-site-admin-only{
 }
 
 
- /******************************************************************************
-  * Spinner for paginated elements
-  *****************************************************************************/
+/******************************************************************************
+ * Spinner for paginated elements
+ *****************************************************************************/
  #spinner {
    position: absolute;
    display: none;
    left: 24%;
    bottom: 7%;
- }
+ }

+ 17 - 0
tripal/theme/css/tripal_jobs.css

@@ -0,0 +1,17 @@
+#tripal-jobs-progress-bar {
+    width: 400px;
+    height: 22px;
+    border: 1px solid #111;
+    border-radius: 5px;
+    background-color: #292929;
+    box-shadow: 0 0 5px #333;
+}
+
+#tripal-jobs-progress-bar div {
+    height: 100%;
+    color: #fff;
+    text-align: right;
+    line-height: 22px; /* same as #progressBar height if we want text middle aligned */
+    width: 0;
+    background-color: #0099ff;
+}

+ 19 - 0
tripal/theme/js/tripal_jobs.js

@@ -0,0 +1,19 @@
+// Using the closure to map jQuery to $. 
+(function ($) {
+  // Store our function as a property of Drupal.behaviors.
+  Drupal.behaviors.tripalJobs = {
+    attach: function (context, settings) {
+
+      function tripal_job_progress(percent, element) {
+        var bar = $(element);
+        var percent_width = percent * bar.width() / 100;
+        bar.find('div').animate({ width: percent_width }, 500).html(percent + "% ");
+      }
+      
+      // The progress_percent value is provided by the
+      // tripal_jobs_run_job() function as inline code that gets
+      // added to the page on load.
+      tripal_job_progress(progress_percent, '#tripal-jobs-progress-bar');
+    }
+  }
+}) (jQuery);

+ 9 - 0
tripal/tripal.module

@@ -197,6 +197,13 @@ function tripal_menu() {
     'page arguments' => array(4),
     'access arguments' => array('administer tripal'),
     'type' => MENU_CALLBACK,
+    'file' => 'api/tripal.jobs.api.inc',
+  );
+  $items['admin/tripal/tripal_jobs/status/%'] = array(
+    'page callback' => 'tripal_jobs_status_view',
+    'page arguments' => array(4),
+    'access arguments' => array('administer tripal'),
+    'type' => MENU_CALLBACK,
     'file' => 'includes/tripal.jobs.inc',
   );
   $items['admin/tripal/tripal_jobs/rerun/%'] = array(
@@ -226,6 +233,8 @@ function tripal_menu() {
     'file' => 'includes/tripal.jobs.inc',
   );
 
+
+
   /*
    * AJAX Callbacks.
    */

+ 27 - 47
tripal_chado/api/tripal_chado.api.inc

@@ -1,44 +1,5 @@
 <?php
 
-/**
- * Retrieves an entity that matches the given table and record id.
- *
- * @param $table
- *   The name of the Chado table.
- * @param $record_id
- *   The record's primary key in the table specified by $table.
- *
- * @return
- *   A chado_entity object.
- */
-function tripal_load_chado_entity($table, $record_id) {
-   $entity_id = db_select('chado_entity', 'ce')
-     ->fields('ce', array('entity_id'))
-     ->condition('ce.record_id', $record_id)
-     ->condition('ce.data_table', $table)
-     ->execute()
-     ->fetchField();
-   if ($entity_id) {
-     $entity = entity_load('TripalEntity', array($entity_id));
-     return reset($entity);
-   }
-   return NULL;
-}
-
-/**
- * Retrieves the entity ID using a record ID.
- *
- * @param unknown $data_table
- * @param unknown $record_id
- */
-function tripal_get_chado_entity_id($data_table, $record_id) {
-   return db_select('chado_entity', 'ce')
-     ->fields('ce', array('entity_id'))
-     ->condition('data_table', $data_table)
-     ->condition('record_id', $record_id)
-     ->execute()
-     ->fetchField();
-}
 
 /**
  * Publishes content in Chado as a new TripalEntity entity.
@@ -81,10 +42,23 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   }
   $chado_entity_table = tripal_chado_get_bundle_entity_table($bundle);
 
-  $table = $bundle->data_table;
-  $type_column = $bundle->type_column;
-  $type_linker_table = $bundle->type_linker_table;
-  $cvterm_id  = $bundle->type_id;
+
+  // Get the mapping of the bio data type to the Chado table.
+  $chado_bundle = db_select('chado_bundle', 'cb')
+    ->fields('cb')
+    ->condition('bundle_id', $bundle->id)
+    ->execute()
+    ->fetchObject();
+  if(!$chado_bundle) {
+    tripal_report_error('tripal_chado', TRIPAL_ERROR,
+        "Cannot find mapping of bundle to Chado tables. Could not publish record.");
+    return FALSE;
+  }
+
+  $table = $chado_bundle->data_table;
+  $type_column = $chado_bundle->type_column;
+  $type_linker_table = $chado_bundle->type_linker_table;
+  $cvterm_id  = $chado_bundle->type_id;
 
   // Get the table information for the Chado table.
   $table_schema = chado_get_schema($table);
@@ -105,7 +79,6 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
     $from .= " INNER JOIN public.chado_$table CT ON CT.$pkey_field = T.$pkey_field";
   }
   $where = " WHERE CE.record_id IS NULL ";
-  $args[':table'] = $table;
 
   // Handle bundles that use a linker property table for identifying the type
   // of record to publish.
@@ -154,7 +127,6 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   $result = chado_query($sql, $args);
   $count = $result->fetchField();
 
-
   // calculate the interval for updates
   $interval = intval($count / 1000);
   if ($interval < 1) {
@@ -164,7 +136,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   // Perform the query.
   $sql = $select . $from . $where;
   $records = chado_query($sql, $args);
-  //$transaction = db_transaction();
+  $transaction = db_transaction();
 
   print "\nNOTE: publishing records is performed using a database transaction. \n" .
       "If the load fails or is terminated prematurely then the entire set of \n" .
@@ -188,6 +160,9 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
       $entity = $ec->create(array(
         'bundle' => $bundle_name,
         'term_id' => $bundle->term_id,
+        // Add in the Chaod details for when the hook_entity_create()
+        // is called and our tripal_cahdo_entity_create() implementation
+        // can deal with it.
         'chado_record' => chado_generate_var($table, array($pkey_field => $record_id)),
         'chado_record_id' => $record_id,
       ));
@@ -207,7 +182,12 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
       if (property_exists($record, 'nid')) {
         $entity_record['nid'] = $record->nid;
       }
-      $success = drupal_write_record($chado_entity_table, $entity_record);
+      $result = db_insert($chado_entity_table)
+        ->fields($entity_record)
+        ->execute();
+      if(!$result){
+        throw new Exception('Could not create mapping of entity to Chado record.');
+      }
 
       $i++;
     }

+ 1 - 0
tripal_chado/api/tripal_chado.entity.api.inc

@@ -43,3 +43,4 @@ function tripal_chado_get_bundle_entity_table($bundle) {
   }
   return 'chado_' . $bundle->name;
 }
+

+ 18 - 9
tripal_chado/api/tripal_chado.variables.api.inc

@@ -309,15 +309,24 @@ function chado_generate_var($table, $values, $base_options = array()) {
         }
       }
 
-      // Check to see if the current record maps to an entity
-      $entity_id = db_select('chado_entity', 'ce')
-        ->fields('ce', array('entity_id'))
-        ->condition('data_table', $table)
-        ->condition('record_id', $object->{$table_primary_key})
-        ->execute()
-        ->fetchField();
-      if ($entity_id) {
-        $object->entity_id = $entity_id;
+      // Check to see if the current record maps to an entity.  Because
+      // multiple bundles can map to the same table we have to check
+      // all bundles for this table.
+      $bundles = db_select('chado_bundle', 'cb');
+      $bundles->fields('tb', array('name'));
+      $bundles->join('tripal_bundle', 'tb', 'tb.id = cb.bundle_id');
+      $bundles->condition('cb.data_table', $table);
+      $bundles->execute();
+      foreach ($bundles as $bundle) {
+        $cbundle_table = tripal_chado_get_bundle_entity_table($bundle);
+        $record = $db_select($cbundle_table, 'ce')
+          ->fields('ce', 'entity_id')
+          ->condition('record_id', $object->{$table_primary_key})
+          ->execute()
+          ->fetchObject();
+        if ($record) {
+          $object->entity_id = $record->entity_id;
+        }
       }
 
       // remove any fields where criteria needs to be evalulated---------------------------------------

+ 1 - 1
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -119,7 +119,7 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
 
     $table = array(
       'header' => $headers,
-      'rows' => $chunks[$current_page],
+      'rows' => $current_page ? $chunks[$current_page] : array(),
       'attributes' => array(
         'id' => 'sbo--relationship-table',
       ),

+ 1 - 3
tripal_chado/includes/TripalFields/schema__publication/schema__publication_formatter.inc

@@ -51,9 +51,7 @@ class schema__publication_formatter extends ChadoFieldFormatter {
       );
       $list = theme_item_list($list);
     }
-    else {
-      $list = $list_items[0];
-    }
+
     $element[0] = array(
       '#type' => 'markup',
       '#markup' => $list,

+ 7 - 0
tripal_chado/includes/tripal_chado.bundle.inc

@@ -75,6 +75,10 @@ function tripal_chado_create_bundle_table($bundle) {
   $schema = array(
     'description' => 'The linker table that associates TripalEntities with Chado records for entities of type ' . $bundle->name . '.',
     'fields' => array(
+      'mapping_id' => array(
+        'type' => 'serial',
+        'not null' => TRUE
+      ),
       'entity_id' => array(
         'description' => 'The unique entity id.',
         'type' => 'int',
@@ -90,6 +94,9 @@ function tripal_chado_create_bundle_table($bundle) {
         'type' => 'int',
       )
     ),
+    'primary key' => array(
+      'mapping_id',
+    ),
     'indexes' => array(
       'record_id' => array('record_id'),
       'entity_id' => array('entity_id'),

+ 2 - 0
tripal_chado/includes/tripal_chado.entity.inc

@@ -125,7 +125,9 @@ function tripal_chado_entity_update($entity, $type) {
  * Implements hook_entity_delete().
  */
 function tripal_chado_entity_delete($entity, $type) {
+  if ($type == 'TripalEntity') {
 
+  }
 }
 
 /**

+ 1 - 12
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -57,18 +57,7 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
 
   // If this is an insert then add the chado_entity record.
   if ($op == FIELD_STORAGE_INSERT) {
-    // Add a record to the chado_entity table so that the data for the
-    // fields can be pulled from Chado when loaded the next time.
-    $record = array(
-      'entity_id' => $entity->id,
-      'record_id' => $base_record_id,
-      'data_table' => $base_table,
-    );
-    $success = drupal_write_record('chado_entity', $record);
-    if (!$success) {
-      drupal_set_message('Unable to insert new Chado entity.', 'error');
-    }
-    // Add the record to the proper chado entity table too
+    // Add the record to the proper chado entity table
     $chado_entity_table = tripal_chado_get_bundle_entity_table($bundle);
     $record = array(
       'entity_id' => $entity->id,

+ 3 - 54
tripal_chado/tripal_chado.install

@@ -155,7 +155,6 @@ function tripal_chado_schema() {
   }
 
   // Links TripalEntity entities to the chado record.
-  $schema['chado_entity'] = tripal_chado_chado_entity_schema();
   $schema['chado_bundle'] = tripal_chado_chado_bundle_schema();
   $schema['chado_semweb'] = tripal_chado_chado_semweb_schema();
 
@@ -564,59 +563,6 @@ function tripal_chado_tripal_mviews_schema() {
   );
 }
 
-/**
- * Links Biological Data Entities to the chado "base" table the data is stored in.
- * This is where we would specify that a particular gene maps to the record in the
- * chado.feature table with a feature_id=2432;
- */
-function tripal_chado_chado_entity_schema() {
-
-  $schema = array(
-    'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
-    'fields' => array(
-      'chado_entity_id' => array(
-        'description' => 'The primary identifier for this table.',
-        'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-      ),
-      'entity_id' => array(
-        'description' => 'The unique entity id.',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'data_table' => array(
-        'description' => 'The table in that this record belongs to',
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE,
-        'default' => '',
-      ),
-      'record_id' => array(
-        'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
-        'type' => 'int',
-        'not null' => TRUE,
-      ),
-      'nid' => array(
-        'description' => 'Optional. For linking nid to the entity when migrating Tripal v2 content',
-        'type' => 'int',
-      )
-    ),
-    'indexes' => array(
-      'record_id' => array('record_id'),
-      'entity_id' => array('entity_id'),
-      'data_table' => array('data_table'),
-      'nid' => array('nid'),
-    ),
-    'unique keys' => array(
-      'table_record' => array('data_table', 'record_id'),
-      'entity_id' => array('entity_id'),
-    ),
-    'primary key' => array('chado_entity_id'),
-  );
-  return $schema;
-}
-
 /**
  * Links Biological Data Entities to the chado "base" table the data is stored in.
  * This is where we would specify that a particular gene maps to the record in the
@@ -786,6 +732,9 @@ function tripal_chado_update_7201() {
         db_query($sql, array(':bundle' => $cbundle->name));
       }
     }
+
+    // Now remove the chado_entity table.
+    db_drop_table('chado_entity');
   }
   catch (\PDOException $e) {
     $transaction->rollback();

+ 1 - 0
tripal_chado/tripal_chado.module

@@ -8,6 +8,7 @@
 require_once "api/tripal_chado.api.inc";
 require_once 'api/tripal_chado.property.api.inc';
 require_once 'api/tripal_chado.query.api.inc';
+require_once 'api/tripal_chado.entity.api.inc';
 require_once 'api/tripal_chado.variables.api.inc';
 require_once 'api/tripal_chado.schema.api.inc';
 require_once 'api/tripal_chado.custom_tables.api.inc';