Browse Source

Bug fixes and commit enablable feature module

spficklin 11 năm trước cách đây
mục cha
commit
aa68dbec7d

+ 52 - 52
tripal_analysis/tripal_analysis.install

@@ -4,6 +4,24 @@
  * Implements hooks from the Schema API
  */
 
+/**
+ * Implementation of hook_requirements(). 
+ */
+function tripal_analysis_requirements($phase) {
+  $requirements = array();
+  if ($phase == 'install') {
+    // make sure chado is installed
+    if (!tripal_core_is_chado_installed()) {
+      $requirements ['tripal_analysis'] = array(
+            'title' => "tripal_analysis",
+            'value' => "ERROR: Chado most be installed before this module can be enabled",
+            'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
+}
+
 /**
  * Implementation of hook_install().
  */
@@ -22,6 +40,22 @@ function tripal_analysis_install() {
   tripal_analysis_add_mview_analysis_organism();
 }
 
+/**
+ * Implementation of hook_uninstall().
+ */
+function tripal_analysis_uninstall() {
+
+  // Remove analysis nodes from drupal.
+  $sql_ana_id = "
+    SELECT nid, vid
+    FROM {node}
+    WHERE type like 'chado_analysi%'
+  ";
+  $result = db_query($sql_ana_id);
+  while ($ana = $result->fetchObject()) {
+    node_delete($ana->nid);
+  }
+}
 /*
  * 
  */
@@ -29,17 +63,17 @@ function tripal_analysis_create_analysisfeatureprop() {
   
   // Create analysisfeatureprop table in chado.  This is needed for Chado 
   // version 1.11, the table exists in Chado 1.2. 
-  if (!db_table_exists('analysisfeatureprop')) {
-    $sql = "CREATE TABLE analysisfeatureprop (" .
-            "  analysisfeatureprop_id SERIAL PRIMARY KEY, " .
-            "  analysisfeature_id     INTEGER NOT NULL REFERENCES analysisfeature(analysisfeature_id) " .
-            "    ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, " .
-            "  type_id                INTEGER NOT NULL REFERENCES cvterm(cvterm_id) " .
-            "    ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, " .
-            "  value                  TEXT, " .
-            "  rank                   INTEGER NOT NULL, " .
-            "  CONSTRAINT analysisfeature_id_type_id_rank UNIQUE(analysisfeature_id, type_id, rank)" .
-            ")";
+  if (!db_table_exists('chado.analysisfeatureprop')) {
+    $sql = "
+      CREATE TABLE chado.analysisfeatureprop (
+        analysisfeatureprop_id SERIAL PRIMARY KEY, 
+        analysisfeature_id     INTEGER NOT NULL REFERENCES chado.analysisfeature(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
+        type_id                INTEGER NOT NULL REFERENCES chdo.cvterm(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, 
+        value                  TEXT, 
+        rank                   INTEGER NOT NULL, 
+        CONSTRAINT analysisfeature_id_type_id_rank UNIQUE(analysisfeature_id, type_id, rank)
+      )
+    ";
     chado_query($sql);
   } 
 }
@@ -84,22 +118,6 @@ function tripal_analysis_add_cvterms() {
   tripal_cv_add_cvterm(array('name' => 'Analysis Type', 'def' => 'The type of analysis was performed.'), 
      'analysis_property', 0, 1, 'tripal');
 }
-/**
- * Implementation of hook_uninstall().
- */
-function tripal_analysis_uninstall() {
-
-  // Remove analysis nodes from drupal.
-  $sql_ana_id = "
-    SELECT nid, vid 
-    FROM {node} 
-    WHERE type like 'chado_analysi%'
-  ";
-  $result = db_query($sql_ana_id);
-  while ($ana = $result->fetchObject()) {
-    node_delete($ana->nid);
-  }
-}
 
 /**
  * Implementation of hook_schema() creates two tables.
@@ -111,6 +129,7 @@ function tripal_analysis_uninstall() {
  *     with this module.
  */
 function tripal_analysis_schema() {
+  
   // chado_analysis table
   $schema['chado_analysis'] = array(
     'fields' => array(
@@ -161,29 +180,13 @@ function tripal_analysis_schema() {
   return $schema;
 }
 
-/**
- * Implementation of hook_requirements(). 
- */
-function tripal_analysis_requirements($phase) {
-  $requirements = array();
-  if ($phase == 'install') {
-    // make sure chado is installed
-    if (!tripal_core_is_chado_installed()) {
-      $requirements ['tripal_analysis'] = array(
-            'title' => "tripal_analysis",
-            'value' => "ERROR: Chado most be installed before this module can be enabled",
-            'severity' => REQUIREMENT_ERROR,
-      );
-    }
-  }
-  return $requirements;
-}
-
 /*
  * 
  * @ingroup tripal_network
  */
 function tripal_analysis_add_mview_analysis_organism() {
+  $view_name = 'analysis_organism';
+  $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.');
   
   // this is the SQL used to identify the organism to which an analsysis
   // has been used.  This is obtained though the analysisfeature -> feature -> organism
@@ -198,7 +201,8 @@ function tripal_analysis_add_mview_analysis_organism() {
   
   // the schema array for describing this view
   $schema = array(
-    'table' => 'analysis_organism',
+    'table' => $view_name,
+    'description' => $comment,
     'fields' => array(  
       'analysis_id' => array(
         'type' => 'int',
@@ -229,10 +233,6 @@ function tripal_analysis_add_mview_analysis_organism() {
     ),
   );
   
-  // add a comment to make sure this view makes sense to the site administator
-  $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.');
-  
   // add the view
-  tripal_add_mview('analysis_organism', 'tripal_analysis', NULL, NULL, NULL,
-    $sql, NULL, $comment, $schema);
-}
+  tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment);
+}

+ 3 - 9
tripal_core/api/tripal_core_custom_tables.api.inc

@@ -117,14 +117,11 @@ function tripal_core_create_custom_table($table, $schema, $skip_creation = 1) {
   
   // if the table does not exist then create it
   if (!$exists) { 
-    $previous_db = tripal_db_set_active('chado');  // use chado database   
-    try {      
-      $ret = db_create_table($table, $schema);
-      tripal_db_set_active($previous_db);  // now use drupal database
+    try {
+      $ret = db_create_table('chado.' . $table, $schema);
       $created = 1;
     }
     catch (Exception $e) {
-      tripal_db_set_active($previous_db);  // now use drupal database
       $error = $e->getMessage();
       watchdog('tripal_core', "Error adding custom table: @message", array('@message' => $error), WATCHDOG_ERROR);
       drupal_set_message("Could not add custom table. $error.", "error");
@@ -139,13 +136,10 @@ function tripal_core_create_custom_table($table, $schema, $skip_creation = 1) {
     // drop the table we'll recreate it with the new schema    
     try {      
       chado_query('DROP TABLE {' . $table . '}');
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-      db_create_table($table, $schema);
-      tripal_db_set_active($previous_db);  // now use drupal database    
+      db_create_table('chado.' . $table, $schema);
       $recreated = 1;
     }
     catch (Exception $e) {
-      tripal_db_set_active('default');  // now use drupal database
       $error = $e->getMessage();
       watchdog('tripal_core', "Error adding custom table: @message",
         array('@message' => $error), WATCHDOG_ERROR);

+ 5 - 1
tripal_core/api/tripal_core_jobs.api.inc

@@ -180,17 +180,21 @@ function tripal_jobs_get_end_time($job) {
  *
  * @param $job_id
  *   The job_id of the job to be re-ran
+ * @param $goto_jobs_page
+ *   If set to TRUE then after the re run job is added Drupal will redirect to the jobs page
  *
  * @ingroup tripal_jobs_api
  */
 function tripal_jobs_rerun($job_id, $goto_jobs_page = TRUE) {
   global $user;
+  
+  $user_id = $user->uid;
 
   $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = :job_id";
   $results = db_query($sql, array(':job_id' => $job_id));
   $job = $results->fetchObject();
   $args = explode("::", $job->arguments);
-  $job_id = tripal_add_job($job->job_name, $job->modulename, $job->callback, $args, $user->uid, $job->priority);
+  $job_id = tripal_add_job($job->job_name, $job->modulename, $job->callback, $args, $user_id, $job->priority);
 
   if ($goto_jobs_page) {
     drupal_goto("admin/tripal/tripal_jobs");

+ 9 - 5
tripal_core/api/tripal_core_mviews.api.inc

@@ -336,18 +336,22 @@ function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
     tripal_add_job("Populate materialized view '$mview->name'", 'tripal_core',
        'tripal_update_mview', $args, $user->uid);
   }
+  
+  // if op is to delete then do so
   if ($op == 'delete') {
+    
     // remove the mview from the tripal_mviews table
-    $sql = "DELETE FROM {tripal_mviews} " .
-           "WHERE mview_id = $mview_id";
+    $sql = "DELETE FROM {tripal_mviews} WHERE mview_id = $mview_id";
     db_query($sql);
+    
+    // does the table already exist?
+    $mview_exists = db_table_exists('chado.' . $mview->mv_table);
+    
     // drop the table from chado if it exists
-    $previous_db = tripal_db_set_active('chado');  // use chado database
-    if (db_table_exists($mview->mv_table)) {
+    if ($mview_exists) {
       $sql = "DROP TABLE {" . $mview->mv_table . "}";
       chado_query($sql);
     }
-    tripal_db_set_active($previous_db);  // now use drupal database
   }
 
   // Redirect the user

+ 1 - 3
tripal_core/includes/custom_tables.inc

@@ -296,9 +296,7 @@ function tripal_custom_tables_form_validate($form, &$form_state) {
         $results = db_query($sql, array(':table_id' => $table_id));
         $ct = $results->fetchObject();
         if ($ct->table_name != $schema_array['table']) {
-          $previous_db = tripal_db_set_active('chado');
-          $exists = db_table_exists($schema_array['table']);
-          tripal_db_set_active($previous_db);        
+          $exists = db_table_exists('chado.' . $schema_array['table']);
           if ($exists) {
             form_set_error($form_state['values']['schema'],
               t("The table name already exists, please choose a different name."));  

+ 32 - 18
tripal_core/tripal_core.drush.inc

@@ -169,29 +169,38 @@ function tripal_core_drush_command() {
 }
 
 /**
- * Executes jobs in the Tripal Jobs Queue
- *
- * NOTE: The following code is executed when drush 'trpjob-run' or 'drush tripal-launch-jobs' is called
+ * 
+ * @param $username
  */
-function drush_tripal_core_tripal_jobs_launch($username) {
-  $parallel = drush_get_option('parallel');
-  $job_id = drush_get_option('job_id');
-
+function drush_tripal_core_set_user($username) {
   if ($username) {
     $sql = "SELECT uid FROM {users} WHERE name = :name";
     $results = db_query($sql, array(':name' => $username));
     $u = $results->fetchObject();
     if (!$u) {
-      drush_print('ERROR: Please provide a valid username for running this job.'); 
-      exit; 
+      drush_print('ERROR: Please provide a valid username for running this job.');
+      exit;
     }
     global $user;
     $user = user_load($u->uid);
+    return $u->uid;
   }
   else {
     drush_print('ERROR: Please provide a username for running this job.');
     return;
   }
+}
+
+/**
+ * Executes jobs in the Tripal Jobs Queue
+ *
+ * NOTE: The following code is executed when drush 'trpjob-run' or 'drush tripal-launch-jobs' is called
+ */
+function drush_tripal_core_tripal_jobs_launch($username) {
+  $parallel = drush_get_option('parallel');
+  $job_id = drush_get_option('job_id');  
+  
+  drush_tripal_core_set_user($username);
 
   if ($parallel) {
     drush_print("Tripal Job Launcher (in parallel)");
@@ -214,6 +223,7 @@ function drush_tripal_core_tripal_jobs_launch($username) {
  */
 function drush_tripal_core_tripal_jobs_rerun($username, $job_id) {
 
+  drush_tripal_core_set_user($username);  
   $new_job_id = tripal_jobs_rerun($job_id, FALSE);
   drush_tripal_core_tripal_jobs_launch($username, $new_job_id);
 
@@ -225,18 +235,22 @@ function drush_tripal_core_tripal_jobs_rerun($username, $job_id) {
  * NOTE: The following code is executed when 'drush trpjob-curr' or 'drush tripal-current-job' is called
  */
 function drush_tripal_core_tripal_jobs_current() {
-  $sql =  "SELECT * FROM {tripal_jobs} TJ " .
-            "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
+  $sql =  "
+    SELECT * 
+    FROM {tripal_jobs} TJ 
+    WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL 
+  ";
   $jobs = db_query($sql);
+  
   foreach ($jobs as $job) {
     $job_pid = $job->pid;
-    $output = "Name: " . $job->job_name . "\n"
-             . "Submitted: " . date(DATE_RFC822, $job->submit_date) . "\n"
-             . "Started: " . date(DATE_RFC822, $job->start_time) . "\n"
-             . "Module: " . $job->modulename . "\n"
-             . "Callback: " . $job->callback . "\n"
-             . "Process ID: " . $job->pid . "\n"
-             . "Progress: " . $job->progress . "%\n";
+    $output = "Name: " . $job->job_name . "\n" .
+              "Submitted: " . date(DATE_RFC822, $job->submit_date) . "\n" .
+              "Started: " . date(DATE_RFC822, $job->start_time) . "\n" .
+              "Module: " . $job->modulename . "\n" .
+              "Callback: " . $job->callback . "\n" .
+              "Process ID: " . $job->pid . "\n" .
+              "Progress: " . $job->progress . "%\n";
     drush_print($output);
   }
   if (!$job_pid) {

+ 164 - 31
tripal_core/tripal_core.install

@@ -97,18 +97,67 @@ function tripal_core_mviews_schema() {
 
   $schema['tripal_mviews'] = array(
     'fields' => array(
-      'mview_id'      => array('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
-      'name'          => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
-      'modulename'    => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE, 'description' => 'The module name that provides the callback for this job'),
-      'mv_table'      => array('type' => 'varchar', 'length' => 128, 'not NULL' => FALSE),
-      'mv_specs'      => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
-      'mv_schema'     => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
-      'indexed'       => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
-      '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),
+      'mview_id' => array(
+        'type' => 'serial', 
+        'unsigned' => TRUE, 
+        'not NULL' => TRUE
+      ),
+      'name' => array(
+        'type' => 'varchar', 
+        'length' => 255, 
+        'not NULL' => TRUE
+      ),
+      'modulename' => array(
+        'type' => 'varchar', 
+        'length' => 50, 
+        'not NULL' => TRUE, 
+        'description' => 'The module name that provides the callback for this job'
+      ),    
+      'mv_table' => array(
+        'type' => 'varchar', 
+        'length' => 128, 
+        'not NULL' => FALSE
+      ),
+      'mv_specs' => array(
+        'type' => 'text', 
+        'size' => 'normal', 
+        'not NULL' => FALSE
+      ),
+      'mv_schema' => array(
+        'type' => 'text', 
+        'size' => 'normal', 
+        'not NULL' => FALSE
+      ),
+      'indexed' => array(
+        'type' => 'text', 
+        'size' => 'normal', 
+        'not NULL' => FALSE
+      ),
+      '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')
@@ -134,22 +183,95 @@ function tripal_core_jobs_schema() {
   $schema = array();
   $schema['tripal_jobs'] = array(
     'fields' => array(
-      'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
-      'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'description' => 'The Drupal userid of the submitee'),
-      'job_name' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
-      'modulename' => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE, 'description' => 'The module name that provides the callback for this job'),
-      'callback' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
-      'arguments' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
-      'progress' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'not NULL' => FALSE, 'description' => 'a value from 0 to 100 indicating percent complete'),
-      'status' => array('type' => 'varchar', 'length' => 50, 'not NULL' => TRUE),
-      'submit_date' => array('type' => 'int', 'not NULL' => TRUE, 'description' => 'UNIX integer submit time'),
-      'start_time' => array('type' => 'int', 'not NULL' => FALSE, 'description' => 'UNIX integer start time'),
-      'end_time' => array('type' => 'int', 'not NULL' => FALSE, 'description' => 'UNIX integer end time'),
-      'error_msg' => array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE),
-      'pid' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => FALSE, 'description' => 'The process id for the job'),
-      'priority' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => TRUE, 'default' => '0', 'description' => 'The job priority'),
-      'mlock' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => FALSE, 'description' => 'If set to 1 then all jobs for the module are held until this one finishes'),
-      'lock' => array('type' => 'int', 'unsigned' => TRUE, 'not NULL' => FALSE, 'description' => 'If set to 1 then all jobs are held until this one finishes'),
+      'job_id' => array(
+        'type' => 'serial', 
+        'unsigned' => TRUE, 
+        'not NULL' => TRUE
+      ),
+      'uid' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not NULL' => TRUE, 
+        'description' => 'The Drupal userid of the submitee'
+      ),
+      'job_name' => array(
+        'type' => 'varchar', 
+        'length' => 255, 
+        'not NULL' => TRUE
+      ),
+      'modulename' => array(
+        'type' => 'varchar', 
+        'length' => 50, 
+        'not NULL' => TRUE, 
+        'description' => 'The module name that provides the callback for this job'
+      ),
+      'callback' => array(
+        'type' => 'varchar', 
+        'length' => 255, 
+        'not NULL' => TRUE
+      ),
+      'arguments' => array(
+        'type' => 'text', 
+        'size' => 'normal', 
+        'not NULL' => FALSE
+      ),
+      'progress' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'default' => 0, 
+        'not NULL' => FALSE, 
+        'description' => 'a value from 0 to 100 indicating percent complete'
+      ),
+      'status' => array(
+        'type' => 'varchar', 
+        'length' => 50, 
+        'not NULL' => TRUE
+      ),
+      'submit_date' => array(
+        'type' => 'int', 
+        'not NULL' => TRUE, 
+        'description' => 'UNIX integer submit time'
+      ),
+      'start_time' => array(
+        'type' => 'int', 
+        'not NULL' => FALSE, 
+        'description' => 'UNIX integer start time'
+      ),
+      'end_time' => array(
+        'type' => 'int', 
+        'not NULL' => FALSE, 
+        'description' => 'UNIX integer end time'
+      ),
+      'error_msg' => array(
+        'type' => 'text', 
+        'size' => 'normal', 
+        'not NULL' => FALSE
+      ),
+      'pid' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not NULL' => FALSE, 
+        'description' => 'The process id for the job'
+      ),
+      'priority' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not NULL' => TRUE, 
+        'default' => '0', 
+        'description' => 'The job priority'
+      ),
+      'mlock' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not NULL' => FALSE, 
+        'description' => 'If set to 1 then all jobs for the module are held until this one finishes'
+      ),
+      'lock' => array(
+        'type' => 'int', 
+        'unsigned' => TRUE, 
+        'not NULL' => FALSE, 
+        'description' => 'If set to 1 then all jobs are held until this one finishes'
+      ),
     ),
     'indexes' => array(
       'job_id' => array('job_id'),
@@ -172,9 +294,20 @@ function tripal_core_custom_tables_schema() {
   $schema = array();
   $schema['tripal_custom_tables'] = array(
     'fields' => array(
-      'table_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not NULL' => TRUE),
-      'table_name' => array('type' => 'varchar', 'length' => 255, 'not NULL' => TRUE),
-      'schema' => array('type' => 'text', 'not NULL' => TRUE),
+      'table_id' => array(
+        'type' => 'serial', 
+        'unsigned' => TRUE, 
+        'not NULL' => TRUE
+      ),
+      'table_name' => array(
+        'type' => 'varchar', 
+        'length' => 255, 
+        'not NULL' => TRUE
+      ),
+      'schema' => array(
+        'type' => 'text', 
+        'not NULL' => TRUE
+      ),
     ),
     'indexes' => array(
       'table_id' => array('table_id'),

+ 4 - 0
tripal_feature/tripal_feature.install

@@ -133,6 +133,10 @@ function tripal_feature_add_organism_count_mview() {
         'type' => 'int',
         'not null' => TRUE,
       ),
+      'cvterm_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
       'feature_type' => array(
         'type' => 'varchar',
         'length' => '255',