Przeglądaj źródła

Merge branch '6.x-0.4-dev' of git.drupal.org:sandbox/spficklin/1337878 into 6.x-0.4-dev

Stephen Ficklin 13 lat temu
rodzic
commit
7cb96fac68
2 zmienionych plików z 52 dodań i 9 usunięć
  1. 34 8
      base/tripal_core/mviews.php
  2. 18 1
      base/tripal_core/tripal_core.install

+ 34 - 8
base/tripal_core/mviews.php

@@ -30,7 +30,7 @@
  *
  * @ingroup tripal_mviews_api
  */
-function tripal_add_mview ($name,$modulename,$mv_table,$mv_specs,$indexed,$query,$special_index){
+function tripal_add_mview ($name,$modulename,$mv_table,$mv_specs,$indexed,$query,$special_index,$comment=NULL){
 
    $record = new stdClass();
    $record->name = $name;
@@ -41,6 +41,7 @@ function tripal_add_mview ($name,$modulename,$mv_table,$mv_specs,$indexed,$query
    $record->indexed = $indexed;
    $record->query = $query;
    $record->special_index = $special_index;
+   $record->comment = $comment;
 
    // add the record to the tripal_mviews table and if successful
    // create the new materialized view in the chado schema
@@ -96,7 +97,7 @@ function tripal_add_mview ($name,$modulename,$mv_table,$mv_specs,$indexed,$query
  *
  * @ingroup tripal_mviews_api
  */
-function tripal_edit_mview ($mview_id,$name,$modulename,$mv_table,$mv_specs,$indexed,$query,$special_index){
+function tripal_edit_mview ($mview_id,$name,$modulename,$mv_table,$mv_specs,$indexed,$query,$special_index,$comment){
 
    $record = new stdClass();
    $record->mview_id = $mview_id;
@@ -109,6 +110,8 @@ function tripal_edit_mview ($mview_id,$name,$modulename,$mv_table,$mv_specs,$ind
    $record->query = $query;
    $record->special_index = $special_index;
    $record->last_update = 0;
+   $record->status = '';
+   $record->comment = $comment;
 
    // drop the table from chado if it exists
    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = $mview_id ";
@@ -235,14 +238,22 @@ function tripal_update_mview ($mview_id){
       $results = db_query("INSERT INTO $mview->mv_table ($mview->query)");
       tripal_db_set_active($previous_db);  // now use drupal database
       if($results){
+         $sql = "SELECT count(*) as cnt FROM $mview->mv_table";
+         $count = db_fetch_object(db_query($sql));
 	      $record = new stdClass();
          $record->mview_id = $mview_id;
          $record->last_update = time();
+         $record->status = "Populated with " . $count->cnt . " rows";
 		   drupal_write_record('tripal_mviews',$record,'mview_id');
 		   return 1;
       } else {
-	     // TODO -- error handling
-	     return 0;
+         # print and save the error message
+	      $record = new stdClass();
+         $record->mview_id = $mview_id;
+         $record->status = "ERROR populating. See Drupal's recent log entries for details.";
+         print $record->status . "\n";
+		   drupal_write_record('tripal_mviews',$record,'mview_id');
+	      return 0;
 	  }
    }
 }
@@ -340,7 +351,7 @@ function tripal_mview_report ($mview_id) {
 */
 function tripal_mviews_report () {
 
-   $header = array('','MView Name','Last Update','');
+   $header = array('','MView Name','Last Update','Status','Description','');
    $rows = array();
 
    $mviews = db_query("SELECT * FROM {tripal_mviews} ORDER BY name");  
@@ -356,13 +367,15 @@ function tripal_mviews_report () {
          l('Populate',"admin/tripal/mviews/action/update/$mview->mview_id"),
          $mview->name,
          $update,
+         $mview->status,
+         $mview->comment,
          l('Delete',"admin/tripal/mviews/action/delete/$mview->mview_id"),
       );
    }
    $rows[] = array(
       'data' => array( 
          array('data' => l('Create a new materialized view.',"admin/tripal/mviews/new"), 
-               'colspan' => 4),
+               'colspan' => 6),
          )
    );
    $page = theme('table', $header, $rows);
@@ -396,6 +409,7 @@ function tripal_mviews_form(&$form_state = NULL,$mview_id = NULL){
       $default_indexed = $form_state['values']['indexed'];
       $default_mvquery = $form_state['values']['mvquery'];
       $default_special_index = $form_state['values']['special_index'];
+      $default_comment = $form_state['values']['cpmment'];
       if(!$default_name){
          $default_name = $mview->name;
       }
@@ -414,6 +428,9 @@ function tripal_mviews_form(&$form_state = NULL,$mview_id = NULL){
       if(!$default_special_index){
          $default_special_index = $mview->special_index;
       }
+      if(!$default_comment){
+         $default_comment = $mview->comment;
+      }
    }
    // Build the form
    $form['action'] = array(
@@ -465,6 +482,14 @@ function tripal_mviews_form(&$form_state = NULL,$mview_id = NULL){
       '#default_value' => $default_mvquery,
       '#weight'        => 6
    );
+   $form['comment']= array(
+      '#type'          => 'textarea',
+      '#title'         => t('MView Description'),
+      '#description'   => t('Optional.  Please provide a description of the purpose for this materialized vieww.'),
+      '#required'      => FALSE,
+      '#default_value' => $default_comment,
+      '#weight'        => 6
+   );
 /**
    $form['special_index']= array(
       '#type'          => 'textarea',
@@ -506,12 +531,13 @@ function tripal_mviews_form_submit($form, &$form_state){
    $indexed = $form_state['values']['indexed'];
    $query = $form_state['values']['mvquery'];
    $special_index = $form_state['values']['special_index'];
+   $comment = $form_state['values']['comment'];
 
    if(strcmp($action,'Edit')==0){
-      tripal_edit_mview($mview_id,$name, 'tripal_core',$mv_table, $mv_specs,$indexed,$query,$special_index);
+      tripal_edit_mview($mview_id,$name, 'tripal_core',$mv_table, $mv_specs,$indexed,$query,$special_index,$comment);
    }
    else if(strcmp($action,'Add')==0){
-      tripal_add_mview ($name, 'tripal_core',$mv_table, $mv_specs,$indexed,$query,$special_index);
+      tripal_add_mview ($name, 'tripal_core',$mv_table, $mv_specs,$indexed,$query,$special_index,$comment);
    }
    else {
         drupal_set_message("No action performed.");

+ 18 - 1
base/tripal_core/tripal_core.install

@@ -21,7 +21,22 @@ function tripal_core_install(){
   drupal_install_schema('tripal_core');
 
 }
-
+/**
+*  Update for Drupal 6.x, Tripal 0.4
+*  This update adjusts the materialized view by adding a 'cvterm_id' column
+*
+* @ingroup tripal_feature
+*/
+function tripal_core_update_6000(){
+   // recreate the materialized view
+   db_add_field($ret, 'tripal_mviews', 'status', array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
+   db_add_field($ret, 'tripal_mviews', 'comment', array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
+   $ret = array(
+      '#finished' => 1,
+   );
+   
+   return $ret;
+}
 /************************************************************************
 * Implementation of hook_schema().
 *
@@ -81,6 +96,8 @@ function tripal_core_mviews_schema(){
          'query'         => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
          'special_index' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
          'last_update'   => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer time'),
+         'status'        => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
+         'comment'       => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
       ),
       'indexes' => array(
          'mview_id' => array('mview_id')