Prechádzať zdrojové kódy

Tripal Core now matches Drupal coding standards

Lacey Sanderson 12 rokov pred
rodič
commit
fd4a688c69

+ 276 - 248
tripal_core/chado_install.php

@@ -1,278 +1,306 @@
 <?php
 
 /**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_core_chado_v1_11_load_form (){
-   $form['description'] = array(
-       '#type' => 'item',
-       '#value' => t("Click the submit button below to install Chado into the Drupal database. <br><font color=\"red\">WARNING:</font> use this only for a new chado installation or reinstall completely.  This will erase any data currently in the chado database.  If you are 
-using chado in a database external to the Drupal database with a 'chado' entry in the 'settings.php' \$db_url argument then this option will intall chado but it will not be usable.  The external database specified in the settings.php file takes precedence."),
-       '#weight' => 1,
-   );
-   $form['button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Install Chado'),
-      '#weight' => 2,
-   );
-   return $form;
-}
+ * @file
+ * Functions to install chado schema through Drupal
+ */
 
 /**
-*
-* @ingroup tripal_core
-*/
-function tripal_core_chado_v1_11_load_form_submit ($form, &$form_state){
-   global $user;
+ * Load Chado Schema 1.11 Form
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_chado_v1_11_load_form() {
+
+  $form['description'] = array(
+    '#type' => 'item',
+    '#value' => t("Click the submit button below to install Chado into the Drupal "
+      ."database. <br /><font color=\"red\">WARNING:</font> use this only for a new "
+      ."chado installation or reinstall completely.  This will erase any data currently "
+      ."in the chado database.  If you are using chado in a database external to the "
+      ."Drupal database with a 'chado' entry in the 'settings.php' \$db_url argument "
+      ."then this option will intall chado but it will not be usable.  The external "
+      ."database specified in the settings.php file takes precedence."),
+    '#weight' => 1,
+  );
 
-   $args = array();
-   tripal_add_job("Install Chado",'tripal_core',
-      'tripal_core_install_chado',$args,$user->uid);
+  $form['button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Install Chado'),
+    '#weight' => 2,
+  );
 
-   return '';
+  return $form;
 }
+
 /**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_core_install_chado ($dummy = NULL, $job = NULL){
-   $schema_file = drupal_get_path('module', 'tripal_core').'/default_schema.sql';
-   $init_file = drupal_get_path('module', 'tripal_core').'/initialize.sql';
-   if(tripal_core_reset_chado_schema()){
-      tripal_core_install_sql($schema_file);
-      tripal_core_install_sql($init_file);      
-   } else {
-      print "ERROR: cannot install chado.  Please check database permissions\n";
-      exit;
-   }
+ * Submit Load Chado Schema 1.11 Form
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_chado_v1_11_load_form_submit($form, &$form_state) {
+  global $user;
+
+  $args = array();
+  tripal_add_job("Install Chado", 'tripal_core',
+    'tripal_core_install_chado', $args, $user->uid);
+
 }
+
 /**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_core_reset_chado_schema (){
-   global $active_db;
+ * Install Chado Schema
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_install_chado() {
+  $schema_file = drupal_get_path('module', 'tripal_core') . '/default_schema.sql';
+  $init_file = drupal_get_path('module', 'tripal_core') . '/initialize.sql';
 
-   // iterate through the lines of the schema file and rebuild the SQL
-   if(tripal_core_schema_exists('chado')){
-      print "Dropping existing 'chado' schema\n";
-      pg_query($active_db,"drop schema chado cascade");
-   }
-   if(tripal_core_schema_exists('genetic_code')){
-      print "Dropping existing 'genetic_code' schema\n";
-      pg_query($active_db,"drop schema genetic_code cascade");
-   }
-   if(tripal_core_schema_exists('so')){
-      print "Dropping existing 'so' schema\n";
-      pg_query($active_db,"drop schema so cascade");
-   }
-   if(tripal_core_schema_exists('frange')){
-      print "Dropping existing 'frange' schema\n";
-      pg_query($active_db,"drop schema frange cascade");
-   }
-   // create the new chado schema
-   print "Creating 'chado' schema\n";
-   pg_query($active_db,"create schema chado");
-   if(tripal_core_schema_exists('chado')){
-      pg_query($active_db,"create language plpgsql");
-      return 1;
-   }
-   return 0;
+  if (tripal_core_reset_chado_schema()) {
+    tripal_core_install_sql($schema_file);
+    tripal_core_install_sql($init_file);
+  }
+  else {
+    print "ERROR: cannot install chado.  Please check database permissions\n";
+    exit;
+  }
 }
+
 /**
-*
-*
-* @ingroup tripal_core
-*/
+ * Reset the Chado Schema
+ * This drops the current chado and chado-related schema and re-creates it
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_reset_chado_schema() {
+  global $active_db;
+
+  // drop current chado and chado-related schema
+  if (tripal_core_schema_exists('chado')) {
+    print "Dropping existing 'chado' schema\n";
+    pg_query($active_db, "drop schema chado cascade");
+  }
+  if (tripal_core_schema_exists('genetic_code')) {
+    print "Dropping existing 'genetic_code' schema\n";
+    pg_query($active_db, "drop schema genetic_code cascade");
+  }
+  if (tripal_core_schema_exists('so')) {
+    print "Dropping existing 'so' schema\n";
+    pg_query($active_db, "drop schema so cascade");
+  }
+  if (tripal_core_schema_exists('frange')) {
+    print "Dropping existing 'frange' schema\n";
+    pg_query($active_db, "drop schema frange cascade");
+  }
+
+  // create the new chado schema
+  print "Creating 'chado' schema\n";
+  pg_query($active_db, "create schema chado");
+  if (tripal_core_schema_exists('chado')) {
+    pg_query($active_db, "create language plpgsql");
+    return TRUE;
+  }
 
-function tripal_core_schema_exists($schema){
-   // check that the chado schema now exists
-   $sql = "SELECT nspname
-           FROM pg_namespace
-           WHERE has_schema_privilege(nspname, 'USAGE') and nspname = '%s'
-           ORDER BY nspname";
-   $name = db_fetch_object(db_query($sql,$schema));
-   if(strcmp($name->nspname,$schema)!=0){
-      return 0;
-   }
-   return 1;
+  return FALSE;
 }
+
 /**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_core_install_sql ($sql_file){
-   global $active_db;
+ * Check that a given schema exists
+ *
+ * @param $schema
+ *   The name of the schema to check the existence of
+ *
+ * @return
+ *   TRUE/FALSE depending upon whether or not the schema exists
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_schema_exists($schema) {
 
-   pg_query($active_db,"set search_path to chado,public");
+  // check that the chado schema now exists
+  $sql = "SELECT nspname
+         FROM pg_namespace
+         WHERE has_schema_privilege(nspname, 'USAGE') and nspname = '%s'
+         ORDER BY nspname";
+  $name = db_fetch_object(db_query($sql, $schema));
+  if (strcmp($name->nspname, $schema) != 0) {
+    return FALSE;
+  }
 
-   print "Loading $sql_file...\n";
-   $lines = file($sql_file,FILE_SKIP_EMPTY_LINES);
-   if(!$lines){
-      return 'Cannot open $schema_file';
-   }
+  return TRUE;
+}
 
-   $stack = array();
-   $in_string = 0;
+/**
+ * Execute the provided SQL
+ *
+ * @param $sql_file
+ *   Contains SQL statements to be executed
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_install_sql($sql_file) {
+  global $active_db;
 
-   $query = '';
-   $i = 0;
-   foreach ($lines as $line_num => $line) {
-      $i++;
-      $type = '';
+  pg_query($active_db, "set search_path to chado,public");
+  print "Loading $sql_file...\n";
+  $lines = file($sql_file, FILE_SKIP_EMPTY_LINES);
 
-      // find and remove comments except when inside of strings
-      if(preg_match('/--/',$line) and !$in_string and !preg_match("/'.*?--.*?'/",$line)){
-         $line = preg_replace('/--.*$/','',$line);  // remove comments
-      }
-      if(preg_match('/\/\*.*?\*\//',$line)){
-         $line = preg_replace('/\/\*.*?\*\//','',$line);  // remove comments
-      }
-      // skip empty lines
-      if(preg_match('/^\s*$/',$line) or strcmp($line,'')==0){
-         continue;
-      }
+  if (!$lines) {
+    return 'Cannot open $schema_file';
+  }
 
-      // Find SQL for new objects
-      if(preg_match('/^\s*CREATE\s+TABLE/i',$line) and !$in_string){
-         $stack[] = 'table';
-         $line = preg_replace("/public./","chado.",$line);
-      }
-      if(preg_match('/^\s*ALTER\s+TABLE/i',$line) and !$in_string){
-         $stack[] = 'alter table';
-         $line = preg_replace("/public./","chado.",$line);
-      }
-      if(preg_match('/^\s*SET/i',$line) and !$in_string){
-         $stack[] = 'set';
-      }
-      if(preg_match('/^\s*CREATE\s+SCHEMA/i',$line) and !$in_string){
-         $stack[] = 'schema';
-      }
-      if(preg_match('/^\s*CREATE\s+SEQUENCE/i',$line) and !$in_string){
-         $stack[] = 'sequence';
-         $line = preg_replace("/public./","chado.",$line);
-      }
-      if(preg_match('/^\s*CREATE\s+(?:OR\s+REPLACE\s+)*VIEW/i',$line) and !$in_string){
-         $stack[] = 'view';
-         $line = preg_replace("/public./","chado.",$line);
-      }
-      if(preg_match('/^\s*COMMENT/i',$line) and !$in_string and sizeof($stack)==0){
-         $stack[] = 'comment';  
-         $line = preg_replace("/public./","chado.",$line);
-      }
-      if(preg_match('/^\s*CREATE\s+(?:OR\s+REPLACE\s+)*FUNCTION/i',$line) and !$in_string){
-         $stack[] = 'function';
-         $line = preg_replace("/public./","chado.",$line);
-      }
-      if(preg_match('/^\s*CREATE\s+INDEX/i',$line) and !$in_string){
-         $stack[] = 'index';
-      }
-      if(preg_match('/^\s*INSERT\s+INTO/i',$line) and !$in_string){
-         $stack[] = 'insert';
-         $line = preg_replace("/public./","chado.",$line);
-      }
-      if(preg_match('/^\s*CREATE\s+TYPE/i',$line) and !$in_string){
-         $stack[] = 'type';
-      }
-      if(preg_match('/^\s*GRANT/i',$line) and !$in_string){
-         $stack[] = 'grant';
-      }
-      if(preg_match('/^\s*CREATE\s+AGGREGATE/i',$line) and !$in_string){
-         $stack[] = 'aggregate';
-      }
+  $stack = array();
+  $in_string = 0;
+  $query = '';
+  $i = 0;
+  foreach ($lines as $line_num => $line) {
+    $i++;
+    $type = '';
+    // find and remove comments except when inside of strings
+    if (preg_match('/--/', $line) and !$in_string and !preg_match("/'.*?--.*?'/", $line)) {
+      $line = preg_replace('/--.*$/', '', $line);  // remove comments
+    }
+    if (preg_match('/\/\*.*?\*\//', $line)) {
+      $line = preg_replace('/\/\*.*?\*\//', '', $line);  // remove comments
+    }
+    // skip empty lines
+    if (preg_match('/^\s*$/', $line) or strcmp($line, '')==0) {
+      continue;
+    }
+    // Find SQL for new objects
+    if (preg_match('/^\s*CREATE\s+TABLE/i', $line) and !$in_string) {
+      $stack[] = 'table';
+      $line = preg_replace("/public./", "chado.", $line);
+    }
+    if (preg_match('/^\s*ALTER\s+TABLE/i', $line) and !$in_string) {
+      $stack[] = 'alter table';
+      $line = preg_replace("/public./", "chado.", $line);
+    }
+    if (preg_match('/^\s*SET/i', $line) and !$in_string) {
+      $stack[] = 'set';
+    }
+    if (preg_match('/^\s*CREATE\s+SCHEMA/i', $line) and !$in_string) {
+      $stack[] = 'schema';
+    }
+    if (preg_match('/^\s*CREATE\s+SEQUENCE/i', $line) and !$in_string) {
+      $stack[] = 'sequence';
+      $line = preg_replace("/public./", "chado.", $line);
+    }
+    if (preg_match('/^\s*CREATE\s+(?:OR\s+REPLACE\s+)*VIEW/i', $line) and !$in_string) {
+      $stack[] = 'view';
+      $line = preg_replace("/public./", "chado.", $line);
+    }
+    if (preg_match('/^\s*COMMENT/i', $line) and !$in_string and sizeof($stack)==0) {
+      $stack[] = 'comment';
+      $line = preg_replace("/public./", "chado.", $line);
+    }
+    if (preg_match('/^\s*CREATE\s+(?:OR\s+REPLACE\s+)*FUNCTION/i', $line) and !$in_string) {
+      $stack[] = 'function';
+      $line = preg_replace("/public./", "chado.", $line);
+    }
+    if (preg_match('/^\s*CREATE\s+INDEX/i', $line) and !$in_string) {
+      $stack[] = 'index';
+    }
+    if (preg_match('/^\s*INSERT\s+INTO/i', $line) and !$in_string) {
+      $stack[] = 'insert';
+      $line = preg_replace("/public./", "chado.", $line);
+    }
+    if (preg_match('/^\s*CREATE\s+TYPE/i', $line) and !$in_string) {
+      $stack[] = 'type';
+    }
+    if (preg_match('/^\s*GRANT/i', $line) and !$in_string) {
+      $stack[] = 'grant';
+    }
+    if (preg_match('/^\s*CREATE\s+AGGREGATE/i', $line) and !$in_string) {
+      $stack[] = 'aggregate';
+    }
 
-      // determine if we are in a string that spans a line
-      $matches = preg_match_all("/[']/i",$line,$temp);
-      $in_string = $in_string - ($matches % 2);
-      $in_string = abs($in_string);
+    // determine if we are in a string that spans a line
+    $matches = preg_match_all("/[']/i", $line, $temp);
+    $in_string = $in_string - ($matches % 2);
+    $in_string = abs($in_string);
 
-      // if we've reached the end of an object the pop the stack 
-      if(strcmp($stack[sizeof($stack)-1],'table') == 0 and preg_match('/\);\s*$/',$line)){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'alter table') == 0 and preg_match('/;\s*$/',$line) and !$in_string){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'set') == 0 and preg_match('/;\s*$/',$line) and !$in_string){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'schema') == 0 and preg_match('/;\s*$/',$line) and !$in_string){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'sequence') == 0 and preg_match('/;\s*$/',$line) and !$in_string){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'view') == 0 and preg_match('/;\s*$/',$line) and !$in_string){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'comment') == 0 and preg_match('/;\s*$/',$line) and !$in_string){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'function') == 0 and preg_match("/LANGUAGE.*?;\s+$/i",$line)){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'index') == 0 and preg_match('/;\s*$/',$line) and !$in_string){
-         $type = array_pop($stack);
+    // if we've reached the end of an object the pop the stack
+    if (strcmp($stack[sizeof($stack)-1], 'table') == 0 and preg_match('/\);\s*$/', $line)) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'alter table') == 0 and preg_match('/;\s*$/', $line) and !$in_string) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'set') == 0 and preg_match('/;\s*$/', $line) and !$in_string) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'schema') == 0 and preg_match('/;\s*$/', $line) and !$in_string) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'sequence') == 0 and preg_match('/;\s*$/', $line) and !$in_string) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'view') == 0 and preg_match('/;\s*$/', $line) and !$in_string) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'comment') == 0 and preg_match('/;\s*$/', $line) and !$in_string) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'function') == 0 and preg_match("/LANGUAGE.*?;\s+$/i", $line)) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'index') == 0 and preg_match('/;\s*$/', $line) and !$in_string) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'insert') == 0 and preg_match('/\);\s*$/', $line)) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'type') == 0 and preg_match('/\);\s*$/', $line)) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'grant') == 0 and preg_match('/;\s*$/', $line) and !$in_string) {
+      $type = array_pop($stack);
+    }
+    if (strcmp($stack[sizeof($stack)-1], 'aggregate') == 0 and preg_match('/\);\s*$/', $line)) {
+      $type = array_pop($stack);
+    }
+    // if we're in a recognized SQL statement then let's keep track of lines
+    if ($type or sizeof($stack) > 0) {
+      $query .= "$line";
+    }
+    else {
+      print "UNHANDLED $i, $in_string: $line";
+      return tripal_core_chado_install_done();
+    }
+    if (preg_match_all("/\n/", $query, $temp) > 100) {
+      print "SQL query is too long.  Terminating:\n$query\n";
+      return tripal_core_chado_install_done();
+    }
+    if ($type and sizeof($stack) == 0) {
+      print "Adding $type: line $i\n";
+      // rewrite the set serach_path to make 'public' be 'chado'
+      if (strcmp($type, 'set')==0) {
+        $query = preg_replace("/public/m", "chado", $query);
       }
-      if(strcmp($stack[sizeof($stack)-1],'insert') == 0 and preg_match('/\);\s*$/',$line)){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'type') == 0 and preg_match('/\);\s*$/',$line)){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'grant') == 0 and preg_match('/;\s*$/',$line) and !$in_string){
-         $type = array_pop($stack);
-      }
-      if(strcmp($stack[sizeof($stack)-1],'aggregate') == 0 and preg_match('/\);\s*$/',$line)){
-         $type = array_pop($stack);
-      }
-
-
-      // if we're in a recognized SQL statement then let's keep track of lines
-      if($type or sizeof($stack) > 0){
-         $query .= "$line";
-      } else {
-         print "UNHANDLED $i, $in_string: $line";
-         return tripal_core_chado_install_done();
+      $result = pg_query($active_db, $query);
+      if (!$result) {
+        $error  = pg_last_error();
+        print "Installation failed:\nSQL $i, $in_string: $query\n$error\n";
+        pg_query($active_db, "set search_path to public,chado");
+        return tripal_core_chado_install_done();
       }
+      $query = '';
+    }
+  }
+  print "Installation Complete!\n";
+  tripal_core_chado_install_done();
+}
 
-      if(preg_match_all("/\n/",$query,$temp) > 100){
-         print "SQL query is too long.  Terminating:\n$query\n";
-         return tripal_core_chado_install_done();
-      }
+/**
+ * Finish the Chado Schema Installation
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_chado_install_done() {
 
-      if($type and sizeof($stack) == 0){
-         print "Adding $type: line $i\n";
-         // rewrite the set serach_path to make 'public' be 'chado'
-         if(strcmp($type,'set')==0){
-            $query = preg_replace("/public/m","chado",$query);
-         }
-         $result = pg_query($active_db, $query);
-         if(!$result){
-            $error  = pg_last_error();
-            print "Installation failed:\nSQL $i, $in_string: $query\n$error\n";
-            pg_query($active_db,"set search_path to public,chado");  
-            return tripal_core_chado_install_done();
-         }
-         $query = '';
-      }    
-   }
+  // return the search path to normal
+  global $active_db;
+  pg_query($active_db, "set search_path to public,chado");
 
-   print "Installation Complete!\n";
-   tripal_core_chado_install_done(); 
-}
-/**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_core_chado_install_done (){
-   // return the search path to normal
-   global $active_db;
-   pg_query($active_db,"set search_path to public,chado");  
-}
+}

+ 285 - 274
tripal_core/jobs.php

@@ -1,27 +1,30 @@
 <?php
 
-/** 
+/**
+ * @file
+ * Contains functions related to the Tripal Jobs API
+ *
  * @defgroup tripal_jobs_api Core Module Jobs API
  * @{
- * Tripal offers a job management subsystem for managing tasks that may require an extended period of time for 
- * completion.  Drupal uses a UNIX-based cron job to handle tasks such as  checking  the  availability of updates, 
- * indexing new nodes for searching, etc.   Drupal's cron uses the web interface for launching these tasks, however, 
- * Tripal provides several administrative tasks that may time out and not complete due to limitations of the web 
- * server.  Examples including syncing of a large number of features between chado and Drupal.  To circumvent this, 
- * as well as provide more fine-grained control and monitoring, Tripal uses a jobs management sub-system built into 
- * the Tripal Core module.   It is anticipated that this functionality will be used for managing analysis jobs provided by 
- * future tools, with eventual support for distributed computing.   
- *
- * The  Tripal jobs management system allows administrators to submit tasks to be performed which can then  be 
- * launched through a UNIX command-line PHP script or cron job.  This command-line script can be added to a cron 
- * entry along-side the Drupal cron entry for automatic, regular launching of Tripal jobs.  The order of execution of 
- * waiting jobs is determined first by priority and second by the order the jobs were entered.  
+ * Tripal offers a job management subsystem for managing tasks that may require an extended period of time for
+ * completion.  Drupal uses a UNIX-based cron job to handle tasks such as  checking  the  availability of updates,
+ * indexing new nodes for searching, etc.   Drupal's cron uses the web interface for launching these tasks, however,
+ * Tripal provides several administrative tasks that may time out and not complete due to limitations of the web
+ * server.  Examples including syncing of a large number of features between chado and Drupal.  To circumvent this,
+ * as well as provide more fine-grained control and monitoring, Tripal uses a jobs management sub-system built into
+ * the Tripal Core module.   It is anticipated that this functionality will be used for managing analysis jobs provided by
+ * future tools, with eventual support for distributed computing.
+ *
+ * The  Tripal jobs management system allows administrators to submit tasks to be performed which can then  be
+ * launched through a UNIX command-line PHP script or cron job.  This command-line script can be added to a cron
+ * entry along-side the Drupal cron entry for automatic, regular launching of Tripal jobs.  The order of execution of
+ * waiting jobs is determined first by priority and second by the order the jobs were entered.
  *
  * The API functions described below provide a programmatic interface for adding, checking and viewing jobs.
  * @}
  * @ingroup tripal_api
  */
- 
+
 /**
  * Adds a job to the Tripal Jbo queue
  *
@@ -36,7 +39,7 @@
  * @param $uid
  *    The uid of the user adding the job
  * @param $priority
- *    The priority at which to run the job where the highest priority is 10 and the lowest priority 
+ *    The priority at which to run the job where the highest priority is 10 and the lowest priority
  *    is 1. The default priority is 10.
  *
  * @return
@@ -44,30 +47,30 @@
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_add_job ($job_name,$modulename,$callback,$arguments,$uid,$priority = 10){
-
-   # convert the arguments into a string for storage in the database
-   $args = implode("::",$arguments);
-
-   $record = new stdClass();
-   $record->job_name = $job_name;
-   $record->modulename = $modulename;
-   $record->callback = $callback;
-   $record->status = 'Waiting';
-   $record->submit_date = time();
-   $record->uid = $uid;
-   $record->priority = $priority;  # the lower the number the higher the priority
-   if($args){
-      $record->arguments = $args;
-   }
-   if(drupal_write_record('tripal_jobs',$record)){
-      $jobs_url = url("admin/tripal/tripal_jobs");
-      drupal_set_message(t("Job '$job_name' submitted.  Check the <a href='$jobs_url'>jobs page</a> for status"));
-   } else {
-      drupal_set_message("Failed to add job $job_name.");
-   }
-
-   return $record->job_id;
+function tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $priority = 10) {
+
+  // convert the arguments into a string for storage in the database
+  $args = implode("::", $arguments);
+  $record = new stdClass();
+  $record->job_name = $job_name;
+  $record->modulename = $modulename;
+  $record->callback = $callback;
+  $record->status = 'Waiting';
+  $record->submit_date = time();
+  $record->uid = $uid;
+  $record->priority = $priority;  # the lower the number the higher the priority
+  if ($args) {
+    $record->arguments = $args;
+  }
+  if (drupal_write_record('tripal_jobs', $record)) {
+    $jobs_url = url("admin/tripal/tripal_jobs");
+    drupal_set_message(t("Job '%job_name' submitted.  Check the %jobs_link for status", array('%job_name' => $job_name, '%jobs_link' => l($jobs_url, 'jobs page'))));
+  }
+  else {
+    drupal_set_message(t("Failed to add job %job_name.", array('%job_name' => $job_name)), 'error');
+  }
+
+  return $record->job_id;
 }
 
 /**
@@ -83,17 +86,18 @@ function tripal_add_job ($job_name,$modulename,$callback,$arguments,$uid,$priori
  *
  * @ingroup tripal_core
  */
-function tripal_job_set_progress($job_id,$percentage){
+function tripal_job_set_progress($job_id, $percentage) {
 
-   if(preg_match("/^(\d+|100)$/",$percentage)){
-      $record = new stdClass();
-      $record->job_id = $job_id; 
-      $record->progress = $percentage;
-	  if(drupal_write_record('tripal_jobs',$record,'job_id')){
-	     return 1;
-	  }
-   }
-   return 0;
+  if (preg_match("/^(\d+|100)$/", $percentage)) {
+    $record = new stdClass();
+    $record->job_id = $job_id;
+    $record->progress = $percentage;
+    if (drupal_write_record('tripal_jobs', $record, 'job_id')) {
+      return TRUE;
+    }
+  }
+
+  return FALSE;
 }
 
 /**
@@ -107,12 +111,12 @@ function tripal_job_set_progress($job_id,$percentage){
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_get_module_active_jobs ($modulename){
-   $sql =  "SELECT * FROM {tripal_jobs} TJ ".
+function tripal_get_module_active_jobs($modulename) {
+  $sql =  "SELECT * FROM {tripal_jobs} TJ ".
            "WHERE TJ.end_time IS NULL and TJ.modulename = '%s' ";
-  return db_fetch_object(db_query($sql,$modulename));
-
+  return db_fetch_object(db_query($sql, $modulename));
 }
+
 /**
  * Returns the Tripal Job Report
  *
@@ -121,70 +125,69 @@ function tripal_get_module_active_jobs ($modulename){
  *
  * @ingroup tripal_core
  */
-function tripal_jobs_report () {
-   //$jobs = db_query("SELECT * FROM {tripal_jobs} ORDER BY job_id DESC");
-   $jobs = pager_query(
-      "SELECT TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
-              TJ.status as job_status, TJ,submit_date,TJ.start_time,
-              TJ.end_time,TJ.priority,U.name as username
-       FROM {tripal_jobs} TJ 
-         INNER JOIN {users} U on TJ.uid = U.uid 
-       ORDER BY job_id DESC", 10,0,"SELECT count(*) FROM {tripal_jobs}");
-	
-   // create a table with each row containig stats for 
-   // an individual job in the results set.
-   $output .= "Waiting jobs are executed first by priority level (the lower the ".
-              "number the higher the priority) and second by the order they ".
-              "were entered";
-   $output .= "<table class=\"tripal-table tripal-table-horz\">". 
-              "  <tr>".
-              "    <th>Job ID</th>".
-              "    <th>User</th>".
-              "    <th>Job Name</th>".
-              "    <th nowrap>Dates</th>".             
-			     "    <th>Priority</th>".
-			     "    <th>Progress</th>".
-              "    <th>Status</th>".
-              "    <th>Actions</th>".
-              "  </tr>";
-   $i = 0;
-   while($job = db_fetch_object($jobs)){
-      $class = 'tripal-table-odd-row';
-      if($i % 2 == 0 ){
-         $class = 'tripal-table-even-row';
-      }
-      $submit = tripal_jobs_get_submit_date($job);
-      $start = tripal_jobs_get_start_time($job);
-      $end = tripal_jobs_get_end_time($job);
-
-      $cancel_link = '';
-      if($job->start_time == 0 and $job->end_time == 0){
-         $cancel_link = "<a href=\"".url("admin/tripal/tripal_jobs/cancel/".$job->job_id)."\">Cancel</a><br>";
-      }
-      $rerun_link = "<a href=\"".url("admin/tripal/tripal_jobs/rerun/".$job->job_id)."\">Re-run</a><br>";
-      $view_link ="<a href=\"".url("admin/tripal/tripal_jobs/view/".$job->job_id)."\">View</a>";
-      $output .= "  <tr class=\"$class\">";
-      $output .= "    <td>$job->job_id</td>".
-                 "    <td>$job->username</td>".
-                 "    <td>$job->job_name</td>".
-                 "    <td nowrap>Submit Date: $submit".
-                 "    <br>Start Time: $start".
-                 "    <br>End Time: $end</td>".
-                 "    <td>$job->priority</td>".
-				     "    <td>$job->progress%</td>".
-                 "    <td>$job->job_status</td>".
-                 "    <td>$cancel_link $rerun_link $view_link</td>".
-                 "  </tr>";
-      $i++;
-   }
-   $output .= "</table>";
-	$output .= theme_pager();
-   return $output;
+function tripal_jobs_report() {
+
+  //$jobs = db_query("SELECT * FROM {tripal_jobs} ORDER BY job_id DESC");
+  $jobs = pager_query(
+    "SELECT TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
+            TJ.status as job_status, TJ,submit_date,TJ.start_time,
+            TJ.end_time,TJ.priority,U.name as username
+     FROM {tripal_jobs} TJ
+       INNER JOIN {users} U on TJ.uid = U.uid
+     ORDER BY job_id DESC", 10, 0, "SELECT count(*) FROM {tripal_jobs}");
+  // create a table with each row containig stats for
+  // an individual job in the results set.
+  $output .= "Waiting jobs are executed first by priority level (the lower the ".
+            "number the higher the priority) and second by the order they ".
+            "were entered";
+  $output .= "<table class=\"tripal-table tripal-table-horz\">".
+            "  <tr>".
+            "    <th>Job ID</th>".
+            "    <th>User</th>".
+            "    <th>Job Name</th>".
+            "    <th nowrap>Dates</th>".
+         "    <th>Priority</th>".
+         "    <th>Progress</th>".
+            "    <th>Status</th>".
+            "    <th>Actions</th>".
+            "  </tr>";
+  $i = 0;
+  while ($job = db_fetch_object($jobs)) {
+    $class = 'tripal-table-odd-row';
+    if ($i % 2 == 0 ) {
+      $class = 'tripal-table-even-row';
+    }
+    $submit = tripal_jobs_get_submit_date($job);
+    $start = tripal_jobs_get_start_time($job);
+    $end = tripal_jobs_get_end_time($job);
+    $cancel_link = '';
+    if ($job->start_time == 0 and $job->end_time == 0) {
+      $cancel_link = "<a href=\"" . url("admin/tripal/tripal_jobs/cancel/" . $job->job_id) . "\">Cancel</a><br />";
+    }
+    $rerun_link = "<a href=\"" . url("admin/tripal/tripal_jobs/rerun/" . $job->job_id) . "\">Re-run</a><br />";
+    $view_link ="<a href=\"" . url("admin/tripal/tripal_jobs/view/" . $job->job_id) . "\">View</a>";
+    $output .= "  <tr class=\"$class\">";
+    $output .= "    <td>$job->job_id</td>".
+               "    <td>$job->username</td>".
+               "    <td>$job->job_name</td>".
+               "    <td nowrap>Submit Date: $submit".
+               "    <br />Start Time: $start".
+               "    <br />End Time: $end</td>".
+               "    <td>$job->priority</td>".
+           "    <td>$job->progress%</td>".
+               "    <td>$job->job_status</td>".
+               "    <td>$cancel_link $rerun_link $view_link</td>".
+               "  </tr>";
+    $i++;
+  }
+  $output .= "</table>";
+  $output .= theme_pager();
+  return $output;
 }
 
 /**
  * Returns the start time for a given job
- * 
+ *
  * @param $job
  *   An object describing the job
  *
@@ -193,22 +196,25 @@ function tripal_jobs_report () {
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_jobs_get_start_time($job){
-   if($job->start_time > 0){
-      $start = format_date($job->start_time);
-   } else {
-      if(strcmp($job->job_status,'Cancelled')==0){
-         $start = 'Cancelled';
-      } else {
-         $start = 'Not Yet Started';
-      }
-   }
-   return $start;
+function tripal_jobs_get_start_time($job) {
+
+  if ($job->start_time > 0) {
+    $start = format_date($job->start_time);
+  }
+  else {
+    if (strcmp($job->job_status, 'Cancelled')==0) {
+      $start = 'Cancelled';
+    }
+    else {
+      $start = 'Not Yet Started';
+    }
+  }
+  return $start;
 }
 
 /**
  * Returns the end time for a given job
- * 
+ *
  * @param $job
  *   An object describing the job
  *
@@ -217,13 +223,16 @@ function tripal_jobs_get_start_time($job){
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_jobs_get_end_time($job){
-   if($job->end_time > 0){
-      $end = format_date($job->end_time);
-   } else {
-      $end = '';
-   }
-   return $end;
+function tripal_jobs_get_end_time($job) {
+
+  if ($job->end_time > 0) {
+    $end = format_date($job->end_time);
+  }
+  else {
+    $end = '';
+  }
+
+  return $end;
 }
 
 /**
@@ -237,8 +246,8 @@ function tripal_jobs_get_end_time($job){
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_jobs_get_submit_date($job){
-   return format_date($job->submit_date);
+function tripal_jobs_get_submit_date($job) {
+  return format_date($job->submit_date);
 }
 
 /**
@@ -249,101 +258,100 @@ function tripal_jobs_get_submit_date($job){
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_jobs_launch ($do_parallel = 0){
-   
-   // first check if any jobs are currently running
-   // if they are, don't continue, we don't want to have
-   // more than one job script running at a time
-   if(!$do_parallel and tripal_jobs_check_running()){
-      return;
-   }
-   
-   // get all jobs that have not started and order them such that
-   // they are processed in a FIFO manner. 
-   $sql =  "SELECT * FROM {tripal_jobs} TJ ".
-           "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL ".
-           "ORDER BY priority ASC,job_id ASC";
-   $job_res = db_query($sql);
-   while($job = db_fetch_object($job_res)){
-
-		// set the start time for this job
-		$record = new stdClass();
-		$record->job_id = $job->job_id;
-		$record->start_time = time();
-		$record->status = 'Running';
-		$record->pid = getmypid();
-		drupal_write_record('tripal_jobs',$record,'job_id');
-
-		// call the function provided in the callback column.
-		// Add the job_id as the last item in the list of arguments. All
-		// callback functions should support this argument.
-		$callback = $job->callback;
-		$args = split("::",$job->arguments);
-		$args[] = $job->job_id;
-		print "Calling: $callback(" . implode(", ",$args) . ")\n";   
-		call_user_func_array($callback,$args);
-		
-		// set the end time for this job
-		$record->end_time = time();
-		$record->status = 'Completed';
-		$record->progress = '100';
-		drupal_write_record('tripal_jobs',$record,'job_id');
-		
-		// send an email to the user advising that the job has finished
-   }
+function tripal_jobs_launch($do_parallel = 0) {
+
+  // first check if any jobs are currently running
+  // if they are, don't continue, we don't want to have
+  // more than one job script running at a time
+  if (!$do_parallel and tripal_jobs_check_running()) {
+    return;
+  }
+
+  // get all jobs that have not started and order them such that
+  // they are processed in a FIFO manner.
+  $sql =  "SELECT * FROM {tripal_jobs} TJ ".
+         "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL ".
+         "ORDER BY priority ASC,job_id ASC";
+  $job_res = db_query($sql);
+  while ($job = db_fetch_object($job_res)) {
+    // set the start time for this job
+    $record = new stdClass();
+    $record->job_id = $job->job_id;
+    $record->start_time = time();
+    $record->status = 'Running';
+    $record->pid = getmypid();
+    drupal_write_record('tripal_jobs', $record, 'job_id');
+
+    // call the function provided in the callback column.
+    // Add the job_id as the last item in the list of arguments. All
+    // callback functions should support this argument.
+    $callback = $job->callback;
+    $args = split("::", $job->arguments);
+    $args[] = $job->job_id;
+    print "Calling: $callback(" . implode(", ", $args) . ")\n";
+    call_user_func_array($callback, $args);
+    // set the end time for this job
+    $record->end_time = time();
+    $record->status = 'Completed';
+    $record->progress = '100';
+    drupal_write_record('tripal_jobs', $record, 'job_id');
+
+    // send an email to the user advising that the job has finished
+  }
 }
 
 /**
  * Returns a list of running tripal jobs
  *
  * @return
- *    and array of objects where each object describes a running job or false if no jobs are running
+ *    and array of objects where each object describes a running job or FALSE if no jobs are running
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_jobs_check_running () {
-   // iterate through each job that has not ended
-   // and see if it is still running. If it is not
-   // running but does not have an end_time then
-   // set the end time and set the status to 'Error'
-   $sql =  "SELECT * FROM {tripal_jobs} TJ ".
-           "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
-   $jobs = db_query($sql);
-   while($job = db_fetch_object($jobs)){
-      $status = `ps --pid=$job->pid --no-header`;
-      if($job->pid && $status) {
-         // the job is still running so let it go
-		   // we return 1 to indicate that a job is running
-		   print "Job is still running (pid $job->pid)\n";
-		   return 1;
-      } else {
-	      // the job is not running so terminate it
-	      $record = new stdClass();
-         $record->job_id = $job->job_id;
-	      $record->end_time = time();
-         $record->status = 'Error';
-	      $record->error_msg = 'Job has terminated unexpectedly.';
-         drupal_write_record('tripal_jobs',$record,'job_id');
-	   }
-   }
-   // return 1 to indicate that no jobs are currently running.
-   return 0;
-}
+function tripal_jobs_check_running() {
+
+  // iterate through each job that has not ended
+  // and see if it is still running. If it is not
+  // running but does not have an end_time then
+  // set the end time and set the status to 'Error'
+  $sql =  "SELECT * FROM {tripal_jobs} TJ ".
+         "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
+  $jobs = db_query($sql);
+  while ($job = db_fetch_object($jobs)) {
+    $status = `ps --pid=$job->pid --no-header`;
+    if ($job->pid && $status) {
+      // the job is still running so let it go
+      // we return 1 to indicate that a job is running
+      print "Job is still running (pid $job->pid)\n";
+      return TRUE;
+    }
+    else {
+      // the job is not running so terminate it
+      $record = new stdClass();
+      $record->job_id = $job->job_id;
+      $record->end_time = time();
+      $record->status = 'Error';
+      $record->error_msg = 'Job has terminated unexpectedly.';
+      drupal_write_record('tripal_jobs', $record, 'job_id');
+    }
+  }
 
+  // return 1 to indicate that no jobs are currently running.
+  return FALSE;
+}
 /**
  * Returns the HTML code to display a given job
  *
  * @param $job_id
  *   The job_id of the job to display
- * 
+ *
  * @return
  *   The HTML describing the indicated job
  * @ingroup tripal_core
  */
-function tripal_jobs_view ($job_id){
-   return theme('tripal_core_job_view',$job_id);
+function tripal_jobs_view($job_id) {
+  return theme('tripal_core_job_view', $job_id);
 }
-
 /**
  * Registers variables for the tripal_core_job_view themeing function
  *
@@ -352,64 +360,66 @@ function tripal_jobs_view ($job_id){
  *
  * @ingroup tripal_core
  */
-function tripal_core_preprocess_tripal_core_job_view (&$variables){
-   // get the job record
-   $job_id = $variables['job_id'];
-   $sql = 
-      "SELECT TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
-              TJ.status as job_status, TJ,submit_date,TJ.start_time,
-              TJ.end_time,TJ.priority,U.name as username,TJ.arguments,
-              TJ.callback,TJ.error_msg,TJ.pid
-       FROM {tripal_jobs} TJ 
-         INNER JOIN users U on TJ.uid = U.uid 
-       WHERE TJ.job_id = %d";
-   $job = db_fetch_object(db_query($sql,$job_id));
-
-   // we do not know what the arguments are for and we want to provide a 
-   // meaningful description to the end-user. So we use a callback function
-   // deinfed in the module that created the job to describe in an array
-   // the arguments provided.  If the callback fails then just use the 
-   // arguments as they are
-   $args = preg_split("/::/",$job->arguments);
-   $arg_hook = $job->modulename."_job_describe_args";
-   if(is_callable($arg_hook)){
-      $new_args = call_user_func_array($arg_hook,array($job->callback,$args));
-      if(is_array($new_args) and count($new_args)){
-         $job->arguments = $new_args;
-      } else {
-         $job->arguments = $args;
-      }
-   } else {
+function tripal_core_preprocess_tripal_core_job_view(&$variables) {
+
+  // get the job record
+  $job_id = $variables['job_id'];
+  $sql =
+    "SELECT TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
+            TJ.status as job_status, TJ,submit_date,TJ.start_time,
+            TJ.end_time,TJ.priority,U.name as username,TJ.arguments,
+            TJ.callback,TJ.error_msg,TJ.pid
+     FROM {tripal_jobs} TJ
+       INNER JOIN users U on TJ.uid = U.uid
+     WHERE TJ.job_id = %d";
+  $job = db_fetch_object(db_query($sql, $job_id));
+
+  // we do not know what the arguments are for and we want to provide a
+  // meaningful description to the end-user. So we use a callback function
+  // deinfed in the module that created the job to describe in an array
+  // the arguments provided.  If the callback fails then just use the
+  // arguments as they are
+  $args = preg_split("/::/", $job->arguments);
+  $arg_hook = $job->modulename . "_job_describe_args";
+  if (is_callable($arg_hook)) {
+    $new_args = call_user_func_array($arg_hook, array($job->callback, $args));
+    if (is_array($new_args) and count($new_args)) {
+      $job->arguments = $new_args;
+    }
+    else {
       $job->arguments = $args;
-   }
+    }
+  }
+  else {
+    $job->arguments = $args;
+  }
 
-   // make our start and end times more legible
-   $job->submit_date = tripal_jobs_get_submit_date($job);
-   $job->start_time = tripal_jobs_get_start_time($job);
-   $job->end_time = tripal_jobs_get_end_time($job);
+  // make our start and end times more legible
+  $job->submit_date = tripal_jobs_get_submit_date($job);
+  $job->start_time = tripal_jobs_get_start_time($job);
+  $job->end_time = tripal_jobs_get_end_time($job);
 
-   // add the job to the variables that get exported to the template
-   $variables['job'] = $job;
+  // add the job to the variables that get exported to the template
+  $variables['job'] = $job;
 }
+
 /**
  * Set a job to be re-ran (ie: add it back into the job queue)
- * 
+ *
  * @param $job_id
  *   The job_id of the job to be re-ran
- * 
+ *
  * @ingroup tripal_jobs_api
  */
-function tripal_jobs_rerun ($job_id){
-   global $user;
-
-   $sql = "select * from {tripal_jobs} where job_id = %d";
-   $job = db_fetch_object(db_query($sql,$job_id));
+function tripal_jobs_rerun($job_id) {
+  global $user;
 
-   $args = explode("::",$job->arguments);
-   tripal_add_job ($job->job_name,$job->modulename,$job->callback,$args,$user->uid,
-      $job->priority);
-
-   drupal_goto("admin/tripal/tripal_jobs");
+  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = %d";
+  $job = db_fetch_object(db_query($sql, $job_id));
+  $args = explode("::", $job->arguments);
+  tripal_add_job($job->job_name, $job->modulename, $job->callback, $args, $user->uid,
+    $job->priority);
+  drupal_goto("admin/tripal/tripal_jobs");
 }
 
 /**
@@ -420,21 +430,22 @@ function tripal_jobs_rerun ($job_id){
  *
  * @ingroup tripal_jobs_api
  */
-function tripal_jobs_cancel ($job_id){
-   $sql = "select * from {tripal_jobs} where job_id = %d";
-   $job = db_fetch_object(db_query($sql,$job_id));
+function tripal_jobs_cancel($job_id) {
+  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = %d";
+  $job = db_fetch_object(db_query($sql, $job_id));
 
-   // set the end time for this job
-   if($job->start_time == 0){
-      $record = new stdClass();
-      $record->job_id = $job->job_id;
-	   $record->end_time = time();
-	   $record->status = 'Cancelled';
-	   $record->progress = '0';
-	   drupal_write_record('tripal_jobs',$record,'job_id');
-      drupal_set_message("Job #$job_id cancelled");
-   } else {
-      drupal_set_message("Job #$job_id cannot be cancelled. It is in progress or has finished.");
-   }
-   drupal_goto("admin/tripal/tripal_jobs");
-}
+  // set the end time for this job
+  if ($job->start_time == 0) {
+    $record = new stdClass();
+    $record->job_id = $job->job_id;
+    $record->end_time = time();
+    $record->status = 'Cancelled';
+    $record->progress = '0';
+    drupal_write_record('tripal_jobs', $record, 'job_id');
+    drupal_set_message(t("Job #%job_id cancelled", array('%job_id' => $job_id)));
+  }
+  else {
+    drupal_set_message(t("Job %job_id cannot be cancelled. It is in progress or has finished.", array('%job_id' => $job_id)));
+  }
+  drupal_goto("admin/tripal/tripal_jobs");
+}

+ 673 - 616
tripal_core/mviews.php

@@ -1,35 +1,38 @@
 <?php
 
-/** 
+/**
+ * @file
+ * Contains functions for the Materialized Views API
+
  * @defgroup tripal_mviews_api Core Module Materalized Views API
  * @{
  * Provides an application programming interface (API) to manage materialized views in Chado.
  * The Perl-based chado comes with an interface for managing materialzed views.  This
- * API provides an alternative Drupal-based method.  
+ * API provides an alternative Drupal-based method.
  * @}
  * @ingroup tripal_api
  */
 
 /**
  * Add a materialized view to the chado database to help speed data access. This
- * function supports the older style where postgres column specifications 
+ * function supports the older style where postgres column specifications
  * are provided using the $mv_table, $mv_specs and $indexed variables. It also
  * supports the newer preferred method where the materialized view is described
- * using the Drupal Schema API array.  
+ * using the Drupal Schema API array.
  *
- * @param $name 
+ * @param $name
  *   The name of the materialized view.
- * @param $modulename 
+ * @param $modulename
  *   The name of the module submitting the materialized view (e.g. 'tripal_library')
- * @param $mv_table 
+ * @param $mv_table
  *   The name of the table to add to chado. This is the table that can be queried.
- * @param $mv_specs 
- *   The table definition 
- * @param $indexed 
+ * @param $mv_specs
+ *   The table definition
+ * @param $indexed
  *   The columns that are to be indexed
- * @param $query 
+ * @param $query
  *   The SQL query that loads the materialized view with data
- * @param $special_index  
+ * @param $special_index
  *   currently not used
  * @param $comment
  *   A string containing a description of the materialized view
@@ -39,96 +42,101 @@
  *
  * @ingroup tripal_mviews_api
  */
-function tripal_add_mview ($name, $modulename, $mv_table, $mv_specs, $indexed,
-   $query, $special_index, $comment=NULL, $mv_schema=NULL)
-{
-   // get the table name from the schema array
-   $schema_arr = array();
-   if($mv_schema){
-      // get the schema from the mv_specs and use it to add the custom table
-      eval("\$schema_arr = $mv_schema;");
-      $mv_table = $schema_arr['table'];
-   }
-
-   $record = new stdClass();
-   $record->name = $name;
-   $record->modulename = $modulename;
-   $record->mv_table = $mv_table;
-   $record->mv_specs = $mv_specs;
-   $record->indexed = $indexed;
-   $record->query = $query;
-   $record->special_index = $special_index;
-   $record->comment = $comment;
-   $record->mv_schema = $mv_schema;
-
-   // add the record to the tripal_mviews table and if successful
-   // create the new materialized view in the chado schema
-   if(drupal_write_record('tripal_mviews',$record)){
-
-      // drop the table from chado if it exists
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-      if (db_table_exists($mv_table)) {
-         $sql = "DROP TABLE $mv_table";
-         db_query($sql);
-      }
-      tripal_db_set_active($previous_db);  // now use drupal database
-      
-      // now construct the indexes
+function tripal_add_mview($name, $modulename, $mv_table, $mv_specs, $indexed,
+  $query, $special_index, $comment = NULL, $mv_schema = NULL) {
+
+  // get the table name from the schema array
+  $schema_arr = array();
+  if ($mv_schema) {
+    // get the schema from the mv_specs and use it to add the custom table
+    eval("\$schema_arr = $mv_schema;");
+    $mv_table = $schema_arr['table'];
+  }
+
+  // Create a new record
+  $record = new stdClass();
+  $record->name = $name;
+  $record->modulename = $modulename;
+  $record->mv_table = $mv_table;
+  $record->mv_specs = $mv_specs;
+  $record->indexed = $indexed;
+  $record->query = $query;
+  $record->special_index = $special_index;
+  $record->comment = $comment;
+  $record->mv_schema = $mv_schema;
+
+  // add the record to the tripal_mviews table and if successful
+  // create the new materialized view in the chado schema
+  if (drupal_write_record('tripal_mviews', $record)) {
+
+    // drop the table from chado if it exists
+    $previous_db = tripal_db_set_active('chado');  // use chado database
+    if (db_table_exists($mv_table)) {
+      $sql = "DROP TABLE $mv_table";
+      db_query($sql);
+    }
+    tripal_db_set_active($previous_db);  // now use drupal database
+
+    // now construct the indexes
+    $index = '';
+    if ($indexed) {
+      // add to the array of values
+      $vals = preg_split("/[\n,]+/", $indexed);
       $index = '';
-      if($indexed){
-        // add to the array of values
-        $vals = preg_split("/[\n,]+/",$indexed);
-        $index = '';
-        foreach ($vals as $field){
-           $field = trim($field);
-           $index .= "CREATE INDEX idx_${mv_table}_${field} ON $mv_table ($field);";
-        }
+      foreach ($vals as $field) {
+        $field = trim($field);
+        $index .= "CREATE INDEX idx_${mv_table}_${field} ON $mv_table ($field);";
       }
+    }
 
-      // create the table differently depending on if it the traditional method
-      // or the Drupal Schema API method
-      if($mv_schema){
-         if(!tripal_create_chado_table ($ret,$mv_table,$schema_arr)){
-            drupal_set_message("Could not create the materialized view. Check Drupal error report logs.");
-         } else {
-            drupal_set_message(t("View '$name' created"));
-         }
-      } else {
-         // add the table to the database
-         $sql = "CREATE TABLE {$mv_table} ($mv_specs); $index"; 
-         $previous_db = tripal_db_set_active('chado');  // use chado database
-         $results = db_query($sql);
-         tripal_db_set_active($previous_db);  // now use drupal database
-         if($results){
-            drupal_set_message(t("View '$name' created"));
-         } else {
-            drupal_set_message(t("Failed to create the materialized view table: '$mv_table'"));
-         }
+    // create the table differently depending on if it the traditional method
+    // or the Drupal Schema API method
+    if ($mv_schema) {
+      if (!tripal_create_chado_table ($ret, $mv_table, $schema_arr)) {
+        drupal_set_message(t("Could not create the materialized view. Check Drupal error report logs."), 'error');
+      }
+      else {
+        drupal_set_message(t("View '%name' created", array('%name' => $name)));
+      }
+    }
+    else {
+      // add the table to the database
+      $sql = "CREATE TABLE {$mv_table} ($mv_specs); $index";
+      $previous_db = tripal_db_set_active('chado');  // use chado database
+      $results = db_query($sql);
+      tripal_db_set_active($previous_db);  // now use drupal database
+      if ($results) {
+        drupal_set_message(t("View '%name' created", array('%name' => $name)));
+      }
+      else {
+        drupal_set_message(t("Failed to create the materialized view table: '%mv_table'", array('%mv_table' => $mv_table)), 'error');
       }
-   }
+    }
+  }
 }
+
 /**
  * Edits a materialized view to the chado database to help speed data access.This
- * function supports the older style where postgres column specifications 
+ * function supports the older style where postgres column specifications
  * are provided using the $mv_table, $mv_specs and $indexed variables. It also
  * supports the newer preferred method where the materialized view is described
- * using the Drupal Schema API array.  
+ * using the Drupal Schema API array.
  *
- * @param $mview_id 
+ * @param $mview_id
  *   The mview_id of the materialized view to edit
- * @param $name 
+ * @param $name
  *   The name of the materialized view.
- * @param $modulename 
+ * @param $modulename
  *   The name of the module submitting the materialized view (e.g. 'tripal_library')
- * @param $mv_table 
+ * @param $mv_table
  *   The name of the table to add to chado. This is the table that can be queried.
- * @param $mv_specs 
- *   The table definition 
- * @param $indexed 
+ * @param $mv_specs
+ *   The table definition
+ * @param $indexed
  *   The columns that are to be indexed
- * @param $query 
+ * @param $query
  *   The SQL query that loads the materialized view with data
- * @param $special_index  
+ * @param $special_index
  *   currently not used
  * @param $comment
  *   A string containing a description of the materialized view
@@ -138,86 +146,90 @@ function tripal_add_mview ($name, $modulename, $mv_table, $mv_specs, $indexed,
  *
  * @ingroup tripal_mviews_api
  */
-function tripal_edit_mview ($mview_id,$name,$modulename,$mv_table,$mv_specs,
-   $indexed,$query,$special_index,$comment=NULL,$mv_schema=NULL)
-{
-
-   // get the table name from the schema array
-   $schema_arr = array();
-   if($mv_schema){
-      // get the schema from the mv_specs and use it to add the custom table
-      eval("\$schema_arr = $mv_schema;");
-      $mv_table = $schema_arr['table'];
-   }
-
-   $record = new stdClass();
-   $record->mview_id = $mview_id;
-   $record->name = $name;
-   $record->modulename = $modulename;
-   $record->mv_schema = $mv_schema;
-   $record->mv_table = $mv_table;
-   $record->mv_specs = $mv_specs;
-   $record->indexed = $indexed;
-   $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 ";
-   $mview = db_fetch_object(db_query($sql));
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   if (db_table_exists($mview->mv_table)) {
-      $sql = "DROP TABLE $mview->mv_table";
-      db_query($sql);
-   }
-   tripal_db_set_active($previous_db);  // now use drupal database
+function tripal_edit_mview($mview_id, $name, $modulename, $mv_table, $mv_specs,
+  $indexed, $query, $special_index, $comment = NULL, $mv_schema = NULL) {
 
-   // update the record to the tripal_mviews table and if successful
-   // create the new materialized view in the chado schema
-   if(drupal_write_record('tripal_mviews',$record,'mview_id')){
+  // get the table name from the schema array
+  $schema_arr = array();
+  if ($mv_schema) {
+    // get the schema from the mv_specs and use it to add the custom table
+    eval("\$schema_arr = $mv_schema;");
+    $mv_table = $schema_arr['table'];
+  }
 
-      // drop the table from chado if it exists
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-      if (db_table_exists($mv_table)) {
-         $sql = "DROP TABLE $mv_table";
-         db_query($sql);
+  // Create a new record
+  $record = new stdClass();
+  $record->mview_id = $mview_id;
+  $record->name = $name;
+  $record->modulename = $modulename;
+  $record->mv_schema = $mv_schema;
+  $record->mv_table = $mv_table;
+  $record->mv_specs = $mv_specs;
+  $record->indexed = $indexed;
+  $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 = %d";
+  $mview = db_fetch_object(db_query($sql, $mview_id));
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  if (db_table_exists($mview->mv_table)) {
+    $sql = "DROP TABLE %s";
+    db_query($sql, $mview->mv_table);
+  }
+  tripal_db_set_active($previous_db);  // now use drupal database
+
+  // update the record to the tripal_mviews table and if successful
+  // create the new materialized view in the chado schema
+  if (drupal_write_record('tripal_mviews', $record, 'mview_id')) {
+    // drop the table from chado if it exists
+    $previous_db = tripal_db_set_active('chado');  // use chado database
+    if (db_table_exists($mv_table)) {
+      $sql = "DROP TABLE %s";
+      db_query($sql, $mv_table);
+    }
+    tripal_db_set_active($previous_db);  // now use drupal database
+
+    // now construct the indexes
+    $index = '';
+    if ($indexed) {
+      // add to the array of values
+      $vals = preg_split("/[\n,]+/", $indexed);
+      $index = '';
+      foreach ($vals as $field) {
+        $field = trim($field);
+        $index .= "CREATE INDEX idx_${mv_table}_${field} ON $mv_table ($field);";
       }
+    }
+
+    // re-create the table differently depending on if it the traditional method
+    // or the Drupal Schema API method
+    if ($mv_schema) {
+      if (!tripal_create_chado_table ($ret, $mv_table, $schema_arr)) {
+        drupal_set_message(t("Could not create the materialized view. Check Drupal error report logs."));
+      }
+      else {
+        drupal_set_message(t("View '%name' created", array('%name' => $name)));
+      }
+    }
+    else {
+      $sql = "CREATE TABLE {$mv_table} ($mv_specs); $index";
+      $previous_db = tripal_db_set_active('chado');  // use chado database
+      $results = db_query($sql);
       tripal_db_set_active($previous_db);  // now use drupal database
-      
-      // now construct the indexes
-      $index = '';
-      if($indexed){
-        // add to the array of values
-        $vals = preg_split("/[\n,]+/",$indexed);
-        $index = '';
-        foreach ($vals as $field){
-           $field = trim($field);
-           $index .= "CREATE INDEX idx_${mv_table}_${field} ON $mv_table ($field);";
-        }
+      if ($results) {
+        drupal_set_message(t("View '%name' edited and saved.  All results cleared. Please re-populate the view.", array('%name' => $name)));
       }
-      // re-create the table differently depending on if it the traditional method
-      // or the Drupal Schema API method
-      if($mv_schema){         
-         if(!tripal_create_chado_table ($ret,$mv_table,$schema_arr)){
-            drupal_set_message("Could not create the materialized view. Check Drupal error report logs.");
-         } else {
-            drupal_set_message(t("View '$name' created"));
-         }
-      } else {
-         $sql = "CREATE TABLE {$mv_table} ($mv_specs); $index"; 
-         $previous_db = tripal_db_set_active('chado');  // use chado database
-         $results = db_query($sql);
-         tripal_db_set_active($previous_db);  // now use drupal database
-         if($results){
-            drupal_set_message(t("View '$name' edited and saved.  All results cleared. Please re-populate the view."));
-         } else {
-            drupal_set_message(t("Failed to create the materialized view table: '$mv_table'"));
-         }
+      else {
+        drupal_set_message(t("Failed to create the materialized view table: '%mv_table'", array('%mv_table' => $mv_table)), 'error');
       }
-   }
+    }
+  }
 }
+
 /**
  * Retrieve the materialized view_id given the name
  *
@@ -229,475 +241,520 @@ function tripal_edit_mview ($mview_id,$name,$modulename,$mv_table,$mv_specs,
  *
  * @ingroup tripal_mviews_api
  */
-function tripal_mviews_get_mview_id ($view_name){
-
-   $sql = "SELECT * FROM {tripal_mviews} ".
-          "WHERE name = '%s'";
-   if(db_table_exists('tripal_mviews')){
-      $mview = db_fetch_object(db_query($sql,$view_name));
-	   if($mview){
-	      return $mview->mview_id;
-	   }
-   }
-   return 0;
+function tripal_mviews_get_mview_id($view_name) {
+  $sql = "SELECT * FROM {tripal_mviews} ".
+        "WHERE name = '%s'";
+  if (db_table_exists('tripal_mviews')) {
+    $mview = db_fetch_object(db_query($sql, $view_name));
+    if ($mview) {
+      return $mview->mview_id;
+    }
+  }
+
+  return FALSE;
 }
+
 /**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_mviews_action ($op,$mview_id,$redirect=0){
-   global $user;
-   $args = array("$mview_id");
-   
-   if(!$mview_id){
-      return '';
-   }
-
-   // get this mview details
-   $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = $mview_id ";
-   $mview = db_fetch_object(db_query($sql));
-   
-   // add a job or perform the action based on the given operation
-   if($op == 'update'){
-      tripal_add_job("Populate materialized view '$mview->name'",'tripal_core',
-         'tripal_update_mview',$args,$user->uid);
-	}
-   if($op == 'delete'){
-	   // remove the mview from the tripal_mviews table
-	   $sql = "DELETE FROM {tripal_mviews} ".
-             "WHERE mview_id = $mview_id";
+ * Does the specified action for the specified Materialized View
+ *
+ * @param $op
+ *   The action to be taken. One of update or delete
+ * @param $mview_id
+ *   The unique ID of the materialized view for the action to be performed on
+ * @param $redirect
+ *   TRUE/FALSE depending on whether you want to redirect the user to admin/tripal/mviews
+ *
+ * @ingroup tripal_core
+ */
+function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
+  global $user;
+
+  $args = array("$mview_id");
+  if (!$mview_id) {
+    return '';
+  }
+
+  // get this mview details
+  $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
+  $mview = db_fetch_object(db_query($sql, $mview_id));
+
+  // add a job or perform the action based on the given operation
+  if ($op == 'update') {
+    tripal_add_job("Populate materialized view '$mview->name'", 'tripal_core',
+       'tripal_update_mview', $args, $user->uid);
+  }
+  if ($op == 'delete') {
+    // remove the mview from the tripal_mviews table
+    $sql = "DELETE FROM {tripal_mviews} ".
+           "WHERE mview_id = $mview_id";
+    db_query($sql);
+    // 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)) {
+      $sql = "DROP TABLE $mview->mv_table";
       db_query($sql);
-		
-	   // 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)) {
-         $sql = "DROP TABLE $mview->mv_table";
-         db_query($sql);
-      }
-      tripal_db_set_active($previous_db);  // now use drupal database
-   }
-   if($redirect){
-      drupal_goto("admin/tripal/mviews");
-   }
+    }
+    tripal_db_set_active($previous_db);  // now use drupal database
+  }
+
+  // Redirect the user
+  if ($redirect) {
+    drupal_goto("admin/tripal/mviews");
+  }
 }
+
 /**
-* Update a Materialized View
-*
-* @param $mview_id
-*   The unique identifier for the materialized view to be updated
-*
-* @return
-*   True if successful, false otherwise
-*
-* @ingroup tripal_mviews_api
-*/
-function tripal_update_mview ($mview_id){
-   $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
-   $mview = db_fetch_object(db_query($sql,$mview_id));
-   if($mview){
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-	   $results = db_query("DELETE FROM {$mview->mv_table}");
-      $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 " . number_format($count->cnt) . " rows";
-		   drupal_write_record('tripal_mviews',$record,'mview_id');
-		   return 1;
-      } else {
-         # 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;
-	  }
-   }
+ * Update a Materialized View
+ *
+ * @param $mview_id
+ *   The unique identifier for the materialized view to be updated
+ *
+ * @return
+ *   True if successful, FALSE otherwise
+ *
+ * @ingroup tripal_mviews_api
+ */
+function tripal_update_mview($mview_id) {
+  $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
+  $mview = db_fetch_object(db_query($sql, $mview_id));
+  if ($mview) {
+    $previous_db = tripal_db_set_active('chado');  // use chado database
+    $results = db_query("DELETE FROM {%s}", $mview->mv_table);
+    $results = db_query("INSERT INTO {%s} ($mview->query)", $mview->mv_table);
+    tripal_db_set_active($previous_db);  // now use drupal database
+    if ($results) {
+      $sql = "SELECT count(*) as cnt FROM {%s}";
+      $count = db_fetch_object(db_query($sql, $mview->mv_table));
+      $record = new stdClass();
+      $record->mview_id = $mview_id;
+      $record->last_update = time();
+      $record->status = "Populated with " . number_format($count->cnt) . " rows";
+      drupal_write_record('tripal_mviews', $record, 'mview_id');
+      return TRUE;
+    }
+    else {
+      // 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 FALSE;
+    }
+  }
 }
+
 /**
-*
-*
-* @ingroup tripal_mviews_api
-*/
-function tripal_mview_report ($mview_id) {
-   // get this mview details
-   $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = $mview_id ";
-   $mview = db_fetch_object(db_query($sql));
-
-   // create a table with each row containig stats for
-   // an individual job in the results set.
-
-   $return_url = url("admin/tripal/mviews/");
-
-   $output .= "<p><a href=\"$return_url\">Return to table of materialized views.</a></p>";
-   $output .= "<br />";
-   $output .= "<p>Details for <b>$mview->name</b>:</p>";
-   $output .= "<br />";
-   $output .= "<table class=\"border-table\">";
-   if($mview->name){
-      $output .= "  <tr>".
-      "    <th>View Name</th>".
-      "    <td>$mview->name</td>".
-      "  </tr>";
-   }   
-   if($mview->modulename){
-      $output .= "  <tr>".
-      "    <th>Module Name</th>".
-      "    <td>$mview->modulename</td>".
-      "  </tr>";
-   }
-   if($mview->mv_table){
-      $output .= "  <tr>".
-      "    <th>Table Name</th>".
-      "    <td>$mview->mv_table</td>".
-      "  </tr>";
-   }   
-   if($mview->mv_specs){
-      $output .= "  <tr>".
-      "    <th>Table Field Definitions</th>".
-      "    <td>$mview->mv_specs</td>".
-      "  </tr>";
-   }   
-   if($mview->query){
-      $output .= "  <tr>".
-      "    <th>Query</th>".
-      "    <td><pre>$mview->query</pre></td>".
-      "  </tr>";
-   }   
-   if($mview->indexed){
-      $output .= "  <tr>".
-      "    <th>Indexed Fields</th>".
-      "    <td>$mview->indexed</td>".
-      "  </tr>";
-   }   
-   if($mview->special_index){
-      $output .= "  <tr>".
-      "    <th>Special Indexed Fields</th>".
-      "    <td>$mview->speical_index</td>".
-      "  </tr>";
-   }   
-   if($mview->last_update > 0){
-      $update = format_date($mview->last_update);
-   } else {
-      $update = 'Not yet populated';
-   }
-   $output .= "  <tr>".
-      "    <th>Last Update</th>".
-      "    <td>$update</td>".
-      "  </tr>";
-
-   // build the URLs using the url function so we can handle installations where
-   // clean URLs are or are not used
-   $update_url = url("admin/tripal/mviews/action/update/$mview->mview_id");
-   $delete_url = url("admin/tripal/mviews/action/delete/$mview->mview_id");
-   $edit_url = url("admin/tripal/mviews/edit/$mview->mview_id");
-
-   $output .= "<tr><th>Actions</th>".
-              "<td> <a href='$update_url'>Populate</a>, ".
-              "     <a href='$edit_url'>Edit</a>, ".
-              "     <a href='$delete_url'>Delete</a></td></tr>";
-
-   $output .= "</table>";
-
-   return $output;
+ * A template function which returns markup to display details for the current materialized view
+ *
+ * @param $mview_id
+ *  The unique ID of the materialized view to render
+ *
+ * @ingroup tripal_mviews_api
+ */
+function tripal_mview_report($mview_id) {
+
+  // get this mview details
+  $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
+  $mview = db_fetch_object(db_query($sql, $mview_id));
+
+  // create a table with each row containig stats for
+  // an individual job in the results set.
+  $return_url = url("admin/tripal/mviews/");
+  $output .= "<p><a href=\"$return_url\">Return to table of materialized views.</a></p>";
+  $output .= "<br />";
+  $output .= "<p>Details for <b>$mview->name</b>:</p>";
+  $output .= "<br />";
+  $output .= "<table class=\"border-table\">";
+  if ($mview->name) {
+    $output .= "  <tr>".
+    "    <th>View Name</th>".
+    "    <td>$mview->name</td>".
+    "  </tr>";
+  }
+  if ($mview->modulename) {
+    $output .= "  <tr>".
+    "    <th>Module Name</th>".
+    "    <td>$mview->modulename</td>".
+    "  </tr>";
+  }
+  if ($mview->mv_table) {
+    $output .= "  <tr>".
+    "    <th>Table Name</th>".
+    "    <td>$mview->mv_table</td>".
+    "  </tr>";
+  }
+  if ($mview->mv_specs) {
+    $output .= "  <tr>".
+    "    <th>Table Field Definitions</th>".
+    "    <td>$mview->mv_specs</td>".
+    "  </tr>";
+  }
+  if ($mview->query) {
+    $output .= "  <tr>".
+    "    <th>Query</th>".
+    "    <td><pre>$mview->query</pre></td>".
+    "  </tr>";
+  }
+  if ($mview->indexed) {
+    $output .= "  <tr>".
+    "    <th>Indexed Fields</th>".
+    "    <td>$mview->indexed</td>".
+    "  </tr>";
+  }
+  if ($mview->special_index) {
+    $output .= "  <tr>".
+    "    <th>Special Indexed Fields</th>".
+    "    <td>$mview->speical_index</td>".
+    "  </tr>";
+  }
+  if ($mview->last_update > 0) {
+    $update = format_date($mview->last_update);
+  }
+  else {
+    $update = 'Not yet populated';
+  }
+  $output .= "  <tr>".
+    "    <th>Last Update</th>".
+    "    <td>$update</td>".
+    "  </tr>";
+
+  // build the URLs using the url function so we can handle installations where
+  // clean URLs are or are not used
+  $update_url = url("admin/tripal/mviews/action/update/$mview->mview_id");
+  $delete_url = url("admin/tripal/mviews/action/delete/$mview->mview_id");
+  $edit_url = url("admin/tripal/mviews/edit/$mview->mview_id");
+  $output .= "<tr><th>Actions</th>".
+            "<td> <a href='$update_url'>Populate</a>, ".
+            "     <a href='$edit_url'>Edit</a>, ".
+            "     <a href='$delete_url'>Delete</a></td></tr>";
+  $output .= "</table>";
+
+  return $output;
 }
+
 /**
-*
-*
-* @ingroup tripal_mviews_api
-*/
-function tripal_mviews_report () {
-
-   $header = array('','MView Name','Last Update','Status','Description','');
-   $rows = array();
-
-   $mviews = db_query("SELECT * FROM {tripal_mviews} ORDER BY name");  
-   while($mview = db_fetch_object($mviews)){
-      if($mview->last_update > 0){
-         $update = format_date($mview->last_update);
-      } else {
-         $update = 'Not yet populated';
-      }
-      $rows[] = array(
-         l('View',"admin/tripal/mviews/report/$mview->mview_id") ." | ".
-         l('Edit',"admin/tripal/mviews/edit/$mview->mview_id") ." | ".
-         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' => 6),
-         )
-   );
-   $page = theme('table', $header, $rows);
-
-   return $page;
+ * A template function to render a listing of all Materialized Views
+ *
+ * @ingroup tripal_mviews_api
+ */
+function tripal_mviews_report() {
+  $header = array('', 'MView Name', 'Last Update', 'Status', 'Description', '');
+  $rows = array();
+  $mviews = db_query("SELECT * FROM {tripal_mviews} ORDER BY name");
+
+  while ($mview = db_fetch_object($mviews)) {
+    if ($mview->last_update > 0) {
+      $update = format_date($mview->last_update);
+    }
+    else {
+      $update = 'Not yet populated';
+    }
+
+    $rows[] = array(
+      l(t('View'), "admin/tripal/mviews/report/$mview->mview_id") ." | ".
+      l(t('Edit'), "admin/tripal/mviews/edit/$mview->mview_id") ." | ".
+      l(t('Populate'), "admin/tripal/mviews/action/update/$mview->mview_id"),
+      $mview->name,
+      $update,
+      $mview->status,
+      $mview->comment,
+      l(t('Delete'), "admin/tripal/mviews/action/delete/$mview->mview_id"),
+    );
+  }
+
+  $rows[] = array(
+    'data' => array(
+      array('data' => l(t('Create a new materialized view.'), "admin/tripal/mviews/new"),
+        'colspan' => 6),
+    )
+  );
+
+  $page = theme('table', $header, $rows);
+  return $page;
 }
+
 /**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_mviews_form(&$form_state = NULL,$mview_id = NULL){
-
-   if(!$mview_id){
-      $action = 'Add';
-   } else {
-      $action = 'Edit';
-   }
-
-   // get this requested view
-   if(strcmp($action,'Edit')==0){
-      $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
-      $mview = db_fetch_object(db_query($sql,$mview_id));
-      
-      # set the default values.  If there is a value set in the 
-      # form_state then let's use that, otherwise, we'll pull 
-      # the values from the database 
-      $default_name = $form_state['values']['name'];
-      $default_mv_table = $form_state['values']['mv_table'];
-      $default_mv_specs = $form_state['values']['mv_specs'];
-      $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;
-      }
-      if(!$default_mv_table){
-         $default_mv_table = $mview->mv_table;
-      }
-      if(!$default_mv_specs){
-         $default_mv_specs = $mview->mv_specs;
-      }
-      if(!$default_indexed){
-         $default_indexed = $mview->indexed;
-      }
-      if(!$default_mvquery){
-         $default_mvquery = $mview->query;
-      }
-      if(!$default_special_index){
-         $default_special_index = $mview->special_index;
-      }
-      if(!$default_comment){
-         $default_comment = $mview->comment;
-      }      
-      if(!$default_schema){
-         $default_schema = $mview->mv_schema;
-      }
-      // the mv_table column of the tripal_mviews table always has the table 
-      // name even if it is a custom table. However, for the sake of the form,
-      // we do not want this to show up as the mv_table is needed for the 
-      // traditional style input.  We'll blank it out if we have a custom 
-      // table and it will get reset in the submit function using the 
-      // 'table' value from the schema array
-      if($default_schema){
-         $default_mv_table = '';
-      }
-      
-      // set which fieldset is collapsed 
-      $schema_collapsed = 0;      
-      $traditional_collapsed = 1;
-      if(!$default_schema){
-         $schema_collapsed = 1;      
-         $traditional_collapsed = 0;
-      }
-   }
-   // Build the form
-   $form['action'] = array(
-      '#type' => 'value',
-      '#value' => $action
-   );
-   $form['mview_id'] = array(
-      '#type' => 'value',
-      '#value' => $mview_id
-   );
-   $form['name']= array(
-      '#type'          => 'textfield',
-      '#title'         => t('View Name'),
-      '#description'   => t('Please enter the name for this materialized view.'),
-      '#required'      => TRUE,
-      '#default_value' => $default_name,
-   );
-   $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,
-   );
-
-   // add a fieldset for the Drupal Schema API
-   $form['schema'] = array(
-     '#type' => 'fieldset',
-     '#title' => 'Drupal Schema API Setup',
-     '#description' => t('Use the Drupal Schema API array to describe a table. The benefit is that it '.
-                         'can be fully integrated with Tripal Views.  Tripal supports an extended '.
-                         'array format to allow for descriptoin of foreign key relationships.'),
-     '#collapsible' => 1,
-     '#collapsed' => $schema_collapsed ,
-   );
-   $form['schema']['schema']= array(
-      '#type'          => 'textarea',
-      '#title'         => t('Schema Array'),
-      '#description'   => t('Please enter the Drupal Schema API compatible array that defines the table.'),
-      '#required'      => FALSE,
-      '#default_value' => $default_schema,
-      '#rows'          => 25,
-   ); 
-   // add a fieldset for the Original Table Description fields
-   $form['traditional'] = array(
-     '#type' => 'fieldset',
-     '#title' => 'Traditional MViews Setup',
-     '#description' => t('Traidtionally with Tripal MViews were created by specifying PostgreSQL style '.
-                         'column types.  This method can be used but is deprecated in favor of the '.
-                         'newer Drupal schema API method provided above.'),
-     '#collapsible' => 1,
-     '#collapsed' => $traditional_collapsed,
-   ); 
-   $form['traditional']['mv_table']= array(
-      '#type'          => 'textfield',
-      '#title'         => t('Table Name'),
-      '#description'   => t('Please enter the table name that this view will generate in the database.  You can use the schema and table name for querying the view'),
-      '#required'      => FALSE,
-      '#default_value' => $default_mv_table,
-   );
-   $form['traditional']['mv_specs']= array(
-      '#type'          => 'textarea',
-      '#title'         => t('Table Definition'),
-      '#description'   => t('Please enter the field definitions for this view. Each field should be separated by a comma or enter each field definition on each line.'),
-      '#required'      => FALSE,
-      '#default_value' => $default_mv_specs,
-   );
-   $form['traditional']['indexed']= array(
-      '#type'          => 'textarea',
-      '#title'         => t('Indexed Fields'),
-      '#description'   => t('Please enter the field names (as provided in the table definition above) that will be indexed for this view.  Separate by a comma or enter each field on a new line.'),
-      '#required'      => FALSE,
-      '#default_value' => $default_indexed,
-   );
-/**
-   $form['traditional']['special_index']= array(
-      '#type'          => 'textarea',
-      '#title'         => t('View Name'),
-      '#description'   => t('Please enter the name for this materialized view.'),
-      '#required'      => TRUE,
-      '#default_value' => $default_special_index,
-   );
-*/
-   $form['mvquery']= array(
-      '#type'          => 'textarea',
-      '#title'         => t('Query'),
-      '#description'   => t('Please enter the SQL statement used to populate the table.'),
-      '#required'      => TRUE,
-      '#default_value' => $default_mvquery,
-      '#rows'          => 25,
-   );
-   if($action == 'Edit'){
-      $value = 'Save';
-   }
-   if($action == 'Add'){
-      $value = 'Add';
-   }
-   $form['submit'] = array (
-     '#type'         => 'submit',
-     '#value'        => t($value),
-     '#weight'       => 9,
-     '#executes_submit_callback' => TRUE,
-   );
-
-   $form['#redirect'] = 'admin/tripal/mviews';
-   return $form;
+ * A Form to Create/Edit a Materialized View
+ *
+ * @param $form_state
+ *   The current state of the form (Form API)
+ * @param $mview_id
+ *   The unique ID of the Materialized View to Edit or NULL if creating a new materialized view
+ *
+ * @return
+ *   A form array (Form API)
+ *
+ * @ingroup tripal_core
+ */
+function tripal_mviews_form(&$form_state = NULL, $mview_id = NULL) {
+
+  if (!$mview_id) {
+    $action = 'Add';
+  }
+  else {
+    $action = 'Edit';
+  }
+
+  // get this requested view
+  if (strcmp($action, 'Edit')==0) {
+    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
+    $mview = db_fetch_object(db_query($sql, $mview_id));
+
+    // set the default values.  If there is a value set in the
+    // form_state then let's use that, otherwise, we'll pull
+    // the values from the database
+    $default_name = $form_state['values']['name'];
+    $default_mv_table = $form_state['values']['mv_table'];
+    $default_mv_specs = $form_state['values']['mv_specs'];
+    $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;
+    }
+    if (!$default_mv_table) {
+      $default_mv_table = $mview->mv_table;
+    }
+    if (!$default_mv_specs) {
+      $default_mv_specs = $mview->mv_specs;
+    }
+    if (!$default_indexed) {
+      $default_indexed = $mview->indexed;
+    }
+    if (!$default_mvquery) {
+      $default_mvquery = $mview->query;
+    }
+    if (!$default_special_index) {
+      $default_special_index = $mview->special_index;
+    }
+    if (!$default_comment) {
+      $default_comment = $mview->comment;
+    }
+    if (!$default_schema) {
+      $default_schema = $mview->mv_schema;
+    }
+
+    // the mv_table column of the tripal_mviews table always has the table
+    // name even if it is a custom table. However, for the sake of the form,
+    // we do not want this to show up as the mv_table is needed for the
+    // traditional style input.  We'll blank it out if we have a custom
+    // table and it will get reset in the submit function using the
+    // 'table' value from the schema array
+    if ($default_schema) {
+      $default_mv_table = '';
+    }
+    // set which fieldset is collapsed
+    $schema_collapsed = 0;
+    $traditional_collapsed = 1;
+    if (!$default_schema) {
+      $schema_collapsed = 1;
+      $traditional_collapsed = 0;
+    }
+  }
+
+  // Build the form
+  $form['action'] = array(
+    '#type' => 'value',
+    '#value' => $action
+  );
+
+  $form['mview_id'] = array(
+    '#type' => 'value',
+    '#value' => $mview_id
+  );
+
+  $form['name']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('View Name'),
+    '#description'   => t('Please enter the name for this materialized view.'),
+    '#required'      => TRUE,
+    '#default_value' => $default_name,
+  );
+
+  $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,
+  );
+
+  // add a fieldset for the Drupal Schema API
+  $form['schema'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Drupal Schema API Setup',
+    '#description' => t('Use the Drupal Schema API array to describe a table. The benefit is that it '.
+                       'can be fully integrated with Tripal Views.  Tripal supports an extended '.
+                       'array format to allow for descriptoin of foreign key relationships.'),
+    '#collapsible' => 1,
+    '#collapsed' => $schema_collapsed ,
+  );
+
+  $form['schema']['schema']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Schema Array'),
+    '#description'   => t('Please enter the Drupal Schema API compatible array that defines the table.'),
+    '#required'      => FALSE,
+    '#default_value' => $default_schema,
+    '#rows'          => 25,
+  );
+
+  // add a fieldset for the Original Table Description fields
+  $form['traditional'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Traditional MViews Setup',
+    '#description' => t('Traidtionally with Tripal MViews were created by specifying PostgreSQL style '.
+                       'column types.  This method can be used but is deprecated in favor of the '.
+                       'newer Drupal schema API method provided above.'),
+    '#collapsible' => 1,
+    '#collapsed' => $traditional_collapsed,
+  );
+
+  $form['traditional']['mv_table']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('Table Name'),
+    '#description'   => t('Please enter the table name that this view will generate in the database.  You can use the schema and table name for querying the view'),
+    '#required'      => FALSE,
+    '#default_value' => $default_mv_table,
+  );
+
+  $form['traditional']['mv_specs']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Table Definition'),
+    '#description'   => t('Please enter the field definitions for this view. Each field should be separated by a comma or enter each field definition on each line.'),
+    '#required'      => FALSE,
+    '#default_value' => $default_mv_specs,
+  );
+
+  $form['traditional']['indexed']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Indexed Fields'),
+    '#description'   => t('Please enter the field names (as provided in the table definition above) that will be indexed for this view.  Separate by a comma or enter each field on a new line.'),
+    '#required'      => FALSE,
+    '#default_value' => $default_indexed,
+  );
+
+  /**
+  $form['traditional']['special_index']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('View Name'),
+    '#description'   => t('Please enter the name for this materialized view.'),
+    '#required'      => TRUE,
+    '#default_value' => $default_special_index,
+  );
+  */
+
+  $form['mvquery']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Query'),
+    '#description'   => t('Please enter the SQL statement used to populate the table.'),
+    '#required'      => TRUE,
+    '#default_value' => $default_mvquery,
+    '#rows'          => 25,
+  );
+
+  if ($action == 'Edit') {
+    $value = 'Save';
+  }
+  if ($action == 'Add') {
+    $value = 'Add';
+  }
+  $form['submit'] = array(
+    '#type'         => 'submit',
+    '#value'        => t($value),
+    '#weight'       => 9,
+    '#executes_submit_callback' => TRUE,
+  );
+  $form['#redirect'] = 'admin/tripal/mviews';
+
+  return $form;
 }
+
 /**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_mviews_form_validate($form, &$form_state){
-   $action = $form_state['values']['action'];
-   $mview_id = $form_state['values']['mview_id'];
-   $name = $form_state['values']['name'];
-   $mv_table = $form_state['values']['mv_table'];
-   $mv_specs = $form_state['values']['mv_specs'];
-   $indexed = $form_state['values']['indexed'];
-   $query = $form_state['values']['mvquery'];
-   $special_index = $form_state['values']['special_index'];
-   $comment = $form_state['values']['comment'];
-   $schema = $form_state['values']['schema'];
-   
-   if($schema and ($mv_table or $mv_specs or $indexed or $special_index)){
-       form_set_error($form_state['values']['schema'], 
-          t('You can create an MView using the Drupal Schema API method or the '.
-            'traditional method but not both.'));
-   }
-   if(!$schema){
-      if(!$mv_specs){
-         form_set_error($form_state['values']['mv_specs'], 
-            t('The Table Definition field is required.'));
-      }
-      if(!$mv_table){
-         form_set_error($form_state['values']['mv_table'], 
-            t('The Table Name field is required.'));
-      }
-   }
-   
-   // make sure the array is valid
-   if($schema){
-      $success = eval("\$schema_array = $schema;");
-      if ($success === FALSE){
-         $error = error_get_last();
-         form_set_error($form_state['values']['schema'], 
-            t("The schema array is improperly formatted. Parse Error : " . $error["message"]));
-      }
-      if(!array_key_exists('table',$schema_array)){
-         form_set_error($form_state['values']['schema'], 
-            t("The schema array must have key named 'table'"));
-      } 
-      // TODO: add in more validation checks of the array to help the user
-   }
+ * Validate the Create/Edit Materialized View Form
+ * Implements hook_form_validate().
+ *
+ * @ingroup tripal_core
+ */
+function tripal_mviews_form_validate($form, &$form_state) {
+  $action = $form_state['values']['action'];
+  $mview_id = $form_state['values']['mview_id'];
+  $name = $form_state['values']['name'];
+  $mv_table = $form_state['values']['mv_table'];
+  $mv_specs = $form_state['values']['mv_specs'];
+  $indexed = $form_state['values']['indexed'];
+  $query = $form_state['values']['mvquery'];
+  $special_index = $form_state['values']['special_index'];
+  $comment = $form_state['values']['comment'];
+  $schema = $form_state['values']['schema'];
+
+  if ($schema and ($mv_table or $mv_specs or $indexed or $special_index)) {
+    form_set_error($form_state['values']['schema'],
+      t('You can create an MView using the Drupal Schema API method or the '.
+        'traditional method but not both.'));
+  }
+  if (!$schema) {
+    if (!$mv_specs) {
+      form_set_error($form_state['values']['mv_specs'],
+        t('The Table Definition field is required.'));
+    }
+    if (!$mv_table) {
+      form_set_error($form_state['values']['mv_table'],
+        t('The Table Name field is required.'));
+    }
+  }
+
+  // make sure the array is valid
+  if ($schema) {
+    $success = eval("\$schema_array = $schema;");
+    if ($success === FALSE) {
+      $error = error_get_last();
+      form_set_error($form_state['values']['schema'],
+        t("The schema array is improperly formatted. Parse Error : " . $error["message"]));
+    }
+    if (!array_key_exists('table', $schema_array)) {
+      form_set_error($form_state['values']['schema'],
+        t("The schema array must have key named 'table'"));
+    }
+
+    // TODO: add in more validation checks of the array to help the user
+  }
 }
+
 /**
-*
-*
-* @ingroup tripal_core
-*/
-function tripal_mviews_form_submit($form, &$form_state){
-   $ret = array();
-   
-   $action = $form_state['values']['action'];
-   $mview_id = $form_state['values']['mview_id'];
-   $name = $form_state['values']['name'];
-   $mv_table = $form_state['values']['mv_table'];
-   $mv_specs = $form_state['values']['mv_specs'];
-   $indexed = $form_state['values']['indexed'];
-   $query = $form_state['values']['mvquery'];
-   $special_index = $form_state['values']['special_index'];
-   $comment = $form_state['values']['comment'];
-   $schema = $form_state['values']['schema'];
-
-   if(strcmp($action,'Edit')==0){
-      tripal_edit_mview($mview_id,$name, 'tripal_core',$mv_table, $mv_specs,
-         $indexed,$query,$special_index,$comment,$schema);
-   }
-   else if(strcmp($action,'Add')==0){
-      tripal_add_mview ($name, 'tripal_core',$mv_table, $mv_specs,
-         $indexed,$query,$special_index,$comment,$schema);
-   }
-   else {
-        drupal_set_message("No action performed.");
-   }
-   return '';
-}
+ * Submit the Create/Edit Materialized View Form
+ * Implements hook_form_submit().
+ *
+ * @ingroup tripal_core
+ */
+function tripal_mviews_form_submit($form, &$form_state) {
+
+  $ret = array();
+  $action = $form_state['values']['action'];
+  $mview_id = $form_state['values']['mview_id'];
+  $name = $form_state['values']['name'];
+  $mv_table = $form_state['values']['mv_table'];
+  $mv_specs = $form_state['values']['mv_specs'];
+  $indexed = $form_state['values']['indexed'];
+  $query = $form_state['values']['mvquery'];
+  $special_index = $form_state['values']['special_index'];
+  $comment = $form_state['values']['comment'];
+  $schema = $form_state['values']['schema'];
+
+  if (strcmp($action, 'Edit') == 0) {
+    tripal_edit_mview($mview_id, $name, 'tripal_core', $mv_table, $mv_specs,
+      $indexed, $query, $special_index, $comment, $schema);
+  }
+  elseif (strcmp($action, 'Add') == 0) {
+    tripal_add_mview($name, 'tripal_core', $mv_table, $mv_specs,
+      $indexed, $query, $special_index, $comment, $schema);
+  }
+  else {
+    drupal_set_message(t("No action performed."));
+  }
+
+  return '';
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 671 - 638
tripal_core/tripal_core.api.inc


+ 21 - 0
tripal_core/tripal_core.coder_ignores.txt

@@ -0,0 +1,21 @@
+; The file should be formatted this way :
+; file:line:warning-type
+; where warning-type is one of security, style, sql, i18n, comment, etc.
+
+; This select statement is acting upon the pg_catalog schema rather then the Drupal
+; schema and thus the curly brackets ({}) are not needed.
+tripal_core.schema.api.inc:54:sql
+tripal_core.schema.api.inc:59:sql
+tripal_core.api.inc:1953:sql
+
+; This query selects from a non-drupal schema where the database prefixes are not
+; applied and thus the curcly brackets ({}) are not needed
+tripal_core.api.inc:971:sql
+
+; Only module designers can create the criteria evaluated by drupal_eval since it
+; is designed in a hook. Since module designers can already write php code to act on 
+; the database and the criteria is never subject to user input, this is not a security 
+; risk.
+tripal_core.api.inc:906:security
+tripal_core.api.inc:941:security
+tripal_core.api.inc:992:security

+ 31 - 29
tripal_core/tripal_core.drush.inc

@@ -1,5 +1,10 @@
 <?php
 
+/**
+ * @file
+ * Contains function relating to drush-integration of this module.
+ */
+
 /**
  * Describes each drush command implemented by the module
  *
@@ -71,50 +76,46 @@ 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
  */
-function drush_tripal_core_tripal_launch_jobs () {
-  $parallel = drush_get_option('parallel');   
-  
-  if($parallel){
+function drush_tripal_core_tripal_launch_jobs() {
+  $parallel = drush_get_option('parallel');
+  if ($parallel) {
     print "Tripal Job Launcher (in parallel)\n";
     print "-------------------\n";
     tripal_jobs_launch($parallel);
-  } else {
+  }
+  else {
     print "Tripal Job Launcher\n";
     print "-------------------\n";
-    tripal_jobs_launch();  
+    tripal_jobs_launch();
   }
 }
 
 /**
  * Prints details about the current running job
- * 
+ *
  * NOTE: The following code is executed when 'drush trpjob-curr' or 'drush tripal-current-job' is called
  */
-function drush_tripal_core_tripal_current_job () {
-  
+function drush_tripal_core_tripal_current_job() {
   $sql =  "SELECT * FROM {tripal_jobs} TJ ".
             "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
   $jobs = db_query($sql);
   while ($job = db_fetch_object($jobs)) {
     $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) {
     drush_print('There are currently no running jobs.');
   }
-    
   //log to the command line with an OK status
   drush_log('Running tripal-current-job', 'ok');
 }
@@ -128,11 +129,11 @@ function drush_tripal_core_tripal_current_job () {
  *   The name of the table storing the materialized view (tripal_mview.mv_table)
  *
  * Note: Either $mview_id OR $table_name is required
- */ 
-function drush_tripal_core_tripal_update_mview () {
+ */
+function drush_tripal_core_tripal_update_mview() {
   $mview_id = drush_get_option('mview_id');
   $table_name = drush_get_option('table_name');
-  
+
   // Either table_name or mview is required
   if (!$mview_id) {
     if ($table_name) {
@@ -143,17 +144,18 @@ function drush_tripal_core_tripal_update_mview () {
         drush_set_error('No Materialized View associated with that table_name.');
       }
       $mview_id=$r->mview_id;
-    } else {
+    }
+    else {
       drush_set_error('Either mview_id OR table_name are required.');
     }
   }
-  
-  drush_print('Updating the Materialized View with ID='.$mview_id);  
+
+  drush_print('Updating the Materialized View with ID=' . $mview_id);
   $status = tripal_update_mview($mview_id);
   if ($status) {
     drush_log('Materialized View Updated', 'ok');
-  } else {
+  }
+  else {
     drush_set_error('Update failed.');
   }
-  
-}
+}

+ 189 - 175
tripal_core/tripal_core.install

@@ -1,195 +1,209 @@
 <?php
 
-/************************************************************************
-*  Implementation of hook_install();
-* 
-* @ingroup tripal_core
-*/
-function tripal_core_install(){
-
-   // make the data directory for this module
-   $data_dir = file_directory_path() . "/tripal";
-   if(!file_check_directory($data_dir,FILE_CREATE_DIRECTORY)){
-      $message = "Cannot create directory $data_dir. This module may not ".
-                 "behave correctly without this directory.  Please  create ".
-                 "the directory manually or fix the problem and reinstall.";
-      drupal_set_message($message,'error');      
-      watchdog('tripal_core',$message,array(),WATCHDOG_ERROR);
-   }
+/**
+ * @file
+ * Contains functions used to install/uninstall tripal_core.
+ */
+
+/**
+ * Implementation of hook_install().
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_install() {
+
+  // make the data directory for this module
+  $data_dir = file_directory_path() . "/tripal";
+  if (!file_check_directory($data_dir, FILE_CREATE_DIRECTORY)) {
+    $message = "Cannot create directory $data_dir. This module may not ".
+               "behave correctly without this directory.  Please  create ".
+               "the directory manually or fix the problem and reinstall.";
+    drupal_set_message(check_plain($message), 'error');
+    watchdog('tripal_core', $message, array(), WATCHDOG_ERROR);
+  }
 
   // create the tables that manage materialized views and jobs
   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(){
-   // add additional columsn to the tripal_mviews table
-   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));
-   db_add_field($ret, 'tripal_mviews', 'mv_schema', array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
-   db_change_field($ret, 'tripal_mviews', 'mv_table','mv_table',array('type' => 'varchar','length' => 128, 'not null' => FALSE));
-   db_change_field($ret, 'tripal_mviews', 'mv_specs','mv_specs',array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
-   db_change_field($ret, 'tripal_mviews', 'indexed','indexed',array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
-
-   
-   // create the custom tables table
-   $ret = array();
-   $schema = tripal_core_custom_tables_schema();
-   db_create_table($ret,'tripal_custom_tables',$schema['tripal_custom_tables']);
-   
-   $ret = array(
-      '#finished' => 1,
-   );
-
-   return $ret;
+ *  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() {
+  // add additional columsn to the tripal_mviews table
+  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));
+  db_add_field($ret, 'tripal_mviews', 'mv_schema', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
+  db_change_field($ret, 'tripal_mviews', 'mv_table', 'mv_table', array('type' => 'varchar', 'length' => 128, 'not NULL' => FALSE));
+  db_change_field($ret, 'tripal_mviews', 'mv_specs', 'mv_specs', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
+  db_change_field($ret, 'tripal_mviews', 'indexed', 'indexed', array('type' => 'text', 'size' => 'normal', 'not NULL' => FALSE));
+
+  // create the custom tables table
+  $ret = array();
+  $schema = tripal_core_custom_tables_schema();
+  db_create_table($ret, 'tripal_custom_tables', $schema['tripal_custom_tables']);
+
+  $ret = array(
+    '#finished' => 1,
+  );
+
+  return $ret;
 }
 
-/************************************************************************
-* Implementation of hook_schema().
-*
-* @ingroup tripal_core
-*/
+/**
+ * Implementation of hook_schema().
+ *
+ * @ingroup tripal_core
+ */
 function tripal_core_schema() {
-   $schema = tripal_core_get_schemas();
-   
-   // if this module is already installed and enabled, then we want to provide
-   // the schemas for all of the custom tables.  This will allow Views to 
-   // see the schemas.  We check if the module is installed because during 
-   // installation we don't want to make these custom tables available as we don't
-   // want them created in the Drupal database.  The custom tables go in the 
-   // Chado database.
-   $sql = 'SELECT * FROM {tripal_custom_tables}';
-   $q = db_query($sql);
-   while($custom = db_fetch_object($q)){
-      $schema[$custom->table_name] = unserialize($custom->schema);
-   }
-   return $schema;
+  $schema = tripal_core_get_schemas();
+
+  // if this module is already installed and enabled, then we want to provide
+  // the schemas for all of the custom tables.  This will allow Views to
+  // see the schemas.  We check if the module is installed because during
+  // installation we don't want to make these custom tables available as we don't
+  // want them created in the Drupal database.  The custom tables go in the
+  // Chado database.
+  $sql = 'SELECT * FROM {tripal_custom_tables}';
+  $q = db_query($sql);
+  while ($custom = db_fetch_object($q)) {
+    $schema[$custom->table_name] = unserialize($custom->schema);
+  }
+
+  return $schema;
 }
-/************************************************************************
-* Implementation of hook_uninstall()
-*
-* @ingroup tripal_core
-*/
-function tripal_core_uninstall(){
-   drupal_uninstall_schema('tripal_core');
+
+/**
+ * Implementation of hook_uninstall().
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_uninstall() {
+  drupal_uninstall_schema('tripal_core');
 }
 
-/************************************************************************
-* This function simply defines all tables needed for the module to work
-* correctly.  By putting the table definitions in a separate function we
-* can easily provide the entire list for hook_install or individual
-* tables for an update.
-*
-* @ingroup tripal_core
-*/
-function tripal_core_get_schemas (){  
-   $schema = array();
-
-   // get all the various schema parts and join them together
-   $temp = tripal_core_jobs_schema();
-   foreach ($temp as $table => $arr){ 
-      $schema[$table] = $arr; 
-   }
-   $temp = tripal_core_mviews_schema();
-   foreach ($temp as $table => $arr){ 
-      $schema[$table] = $arr; 
-   }
-   $temp = tripal_core_custom_tables_schema();
-   foreach ($temp as $table => $arr){ 
-      $schema[$table] = $arr; 
-   }
-	return $schema;
+/**
+ * This function simply defines all tables needed for the module to work
+ * correctly.  By putting the table definitions in a separate function we
+ * can easily provide the entire list for hook_install or individual
+ * tables for an update.
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_get_schemas() {
+  $schema = array();
+
+  // get all the various schema parts and join them together
+  $temp = tripal_core_jobs_schema();
+  foreach ($temp as $table => $arr) {
+    $schema[$table] = $arr;
+  }
+  $temp = tripal_core_mviews_schema();
+  foreach ($temp as $table => $arr) {
+    $schema[$table] = $arr;
+  }
+  $temp = tripal_core_custom_tables_schema();
+  foreach ($temp as $table => $arr) {
+    $schema[$table] = $arr;
+  }
+
+  return $schema;
 }
-/************************************************************************
-* 
-*
-* @ingroup tripal_core
-*/
-function tripal_core_mviews_schema(){
-   $schema = array();
-   $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),
-      ),
-      'indexes' => array(
-         'mview_id' => array('mview_id')
-      ),
-      'unique keys' => array(
-         'mv_table' => array('mv_table'),
-         'mv_name' => array('name'),
-      ),
-      'primary key' => array('mview_id'),
+
+/**
+ *
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_mviews_schema() {
+  $schema = array();
+
+  $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),
+    ),
+    'indexes' => array(
+      'mview_id' => array('mview_id')
+    ),
+    'unique keys' => array(
+      'mv_table' => array('mv_table'),
+      'mv_name' => array('name'),
+    ),
+    'primary key' => array('mview_id'),
   );
+
   return $schema;
 }
-/************************************************************************
-* 
-*
-* @ingroup tripal_core
-*/
-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'),
-      ),
-      'indexes' => array(
-         'job_id' => array('job_id'),
-         'job_name' => array('job_name')
-      ),
-      'primary key' => array('job_id'),
-   );
-   return $schema;
+
+/**
+ *
+ *
+ * @ingroup tripal_core
+ */
+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'),
+    ),
+    'indexes' => array(
+      'job_id' => array('job_id'),
+      'job_name' => array('job_name')
+    ),
+    'primary key' => array('job_id'),
+  );
+
+  return $schema;
 }
-/************************************************************************
-* 
-*
-* @ingroup tripal_core
-*/
-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),
-      ),
-      'indexes' => array(
-         'table_id' => array('table_id'),
-      ),
-      'primary key' => array('table_id'),
-   );
-   return $schema;
+
+/**
+ *
+ *
+ * @ingroup tripal_core
+ */
+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),
+    ),
+    'indexes' => array(
+      'table_id' => array('table_id'),
+    ),
+    'primary key' => array('table_id'),
+  );
+
+  return $schema;
 }
-?>

+ 187 - 183
tripal_core/tripal_core.module

@@ -5,178 +5,174 @@ require_once "mviews.php";
 require_once "chado_install.php";
 require_once "tripal_core.api.inc";
 
-
 /**
  * @defgroup tripal_modules Tripal Modules
  * @{
  * All documented functions for the various Tripal Modules
  * @}
- */
-
-/**
+ *
  * @defgroup tripal_core Core Tripal Module
  * @ingroup tripal_modules
  */
- 
+
 /**
  *
  *
  * @ingroup tripal_core
  */
-function tripal_core_init(){
-   // the two lines below are necessary to ensure that the search_path
-   // variable is always set.  In the case where a view needs to query the
-   // chado schema when it is local to the Drupal database.  Otherwise the
-   // search_path isn't set.  When tripal_db_set_active is called it
-   // automatically sets the serach path if chado is local to the
-   // Drupal database
-   $previous = tripal_db_set_active('chado');
-   tripal_db_set_active($previous);
+function tripal_core_init() {
 
-   // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
-   // only if the chado database is present.
-   if(tripal_core_is_chado_installed()){
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-      if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
-         $results = db_query("INSERT INTO {cv} (name,definition) ".
-    	                     "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
-      }
-      if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
-         $results = db_query("INSERT INTO {db} (name,description) ".
-	                        "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
-      }
-      tripal_db_set_active($previous_db);  // now use drupal database
-   }
+  // the two lines below are necessary to ensure that the search_path
+  // variable is always set.  In the case where a view needs to query the
+  // chado schema when it is local to the Drupal database.  Otherwise the
+  // search_path isn't set.  When tripal_db_set_active is called it
+  // automatically sets the serach path if chado is local to the
+  // Drupal database
+  $previous = tripal_db_set_active('chado');
+  tripal_db_set_active($previous);
 
-   // add some variables for all javasript to use for building URLs
-   global $base_url;
-   $theme_dir = drupal_get_path('theme', 'tripal');
-   $clean_urls  = variable_get('clean_url', 0);
-   drupal_add_js("
-      var baseurl = '$base_url';
+  // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
+  // only if the chado database is present.
+  if (tripal_core_is_chado_installed()) {
+    $previous_db = tripal_db_set_active('chado');  // use chado database
+    if (!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))) {
+      $results = db_query("INSERT INTO {cv} (name,definition) ".
+                         "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
+    }
+    if (!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))) {
+      $results = db_query("INSERT INTO {db} (name,description) ".
+                        "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')");
+    }
+    tripal_db_set_active($previous_db);  // now use drupal database
+  }
+
+  // add some variables for all javasript to use for building URLs
+  global $base_url;
+  $theme_dir = drupal_get_path('theme', 'tripal');
+  $clean_urls  = variable_get('clean_url', 0);
+  drupal_add_js(
+    "var baseurl = '$base_url';
       var themedir = '$theme_dir';
-      var isClean = $clean_urls;",'inline');
+      var isClean = $clean_urls;",
+    'inline');
 
-   // make sure the date time settings are the way Tripal will insert them
-   // otherwise PostgreSQL version that may have a different datestyle setting
-   // will fail when inserting or updating a date column in a table.
-   db_query("SET DATESTYLE TO '%s'",'MDY');
+  // make sure the date time settings are the way Tripal will insert them
+  // otherwise PostgreSQL version that may have a different datestyle setting
+  // will fail when inserting or updating a date column in a table.
+  db_query("SET DATESTYLE TO '%s'", 'MDY');
 }
 
-
-
 /**
  *
  *
  * @ingroup tripal_core
  */
 function tripal_core_menu() {
-   $items = array();
-   
-   // Triapl setting groups
-   $items['admin/tripal'] = array(
-      'title' => 'Tripal Management',
-      'description' => "Manage the behavior or Tripal and its various modules.",
-      'position' => 'right',
-      'weight' => -5,
-      'page callback' => 'system_admin_menu_block_page',
-      'access arguments' => array('administer site configuration'),
-      'file' => 'system.admin.inc',
-      'file path' => drupal_get_path('module', 'system'),
-   );
-   $items['tripal_toggle_box_menu/%/%/%'] = array(
-     'title' => t('Toggle Box'),
-     'page callback' => 'tripal_toggle_box_menu',
-     'page arguments' => array(1,2,3),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
-   );
-   $items['admin/tripal/chado_1_11_install'] = array(
-     'title' => 'Install Chado v1.11',
-     'description' => 'Installs Chado version 1.11 inside the current Drupal database',
-     'page callback' => 'drupal_get_form',
-     'page arguments' => array('tripal_core_chado_v1_11_load_form'),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_NORMAL_ITEM,
-   );
+  $items = array();
+
+  // Triapl setting groups
+  $items['admin/tripal'] = array(
+    'title' => 'Tripal Management',
+    'description' => "Manage the behavior or Tripal and its various modules.",
+    'position' => 'right',
+    'weight' => -5,
+    'page callback' => 'system_admin_menu_block_page',
+    'access arguments' => array('administer site configuration'),
+    'file' => 'system.admin.inc',
+    'file path' => drupal_get_path('module', 'system'),
+  );
+  $items['tripal_toggle_box_menu/%/%/%'] = array(
+    'title' => 'Toggle Box',
+    'page callback' => 'tripal_toggle_box_menu',
+    'page arguments' => array(1, 2, 3),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
+  );
+  $items['admin/tripal/chado_1_11_install'] = array(
+    'title' => 'Install Chado v1.11',
+    'description' => 'Installs Chado version 1.11 inside the current Drupal database',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_core_chado_v1_11_load_form'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  // Jobs Management
+  $items['admin/tripal/tripal_jobs'] = array(
+    'title' => 'Jobs',
+    'description' => 'Jobs managed by Tripal',
+    'page callback' => 'tripal_jobs_report',
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/tripal_jobs/cancel/%'] = array(
+    'title' => 'Jobs',
+    'description' => 'Cancel a pending job',
+    'page callback' => 'tripal_jobs_cancel',
+    'page arguments' => array(4),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/tripal_jobs/rerun/%'] = array(
+    'title' => 'Jobs',
+    'description' => 'Re-run an existing job.',
+    'page callback' => 'tripal_jobs_rerun',
+    'page arguments' => array(4),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/tripal_jobs/view/%'] = array(
+    'title' => 'Jobs Details',
+    'description' => 'View job details.',
+    'page callback' => 'tripal_jobs_view',
+    'page arguments' => array(4),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
+
+  // Materialized Views
+  $items['admin/tripal/mviews'] = array(
+    'title' => 'MViews',
+    'description' => 'Materialized views are used to improve speed of large or complex queries.',
+    'page callback' => 'tripal_mviews_report',
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/mviews/report/%'] = array(
+    'title' => 'Materialized View',
+    'description' => 'Materialized views are used to improve speed of large or complex queries.',
+    'page callback' => 'tripal_mview_report',
+    'page arguments' => array(4),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/mviews/new'] = array(
+    'title' => 'Create MView',
+    'description' => 'Materialized views are used to improve speed of large or complex queries.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_mviews_form'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/mviews/edit/%'] = array(
+    'title' => 'Edit MView',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_mviews_form', 4),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/mviews/action/%/%'] = array(
+    'title' => 'Create MView',
+    'description' => 'Materialized views are used to improve speed of large or complex queries.',
+    'page callback' => 'tripal_mviews_action',
+    'page arguments' => array(4, 5, "1"),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
 
-   // Jobs Management
-   $items['admin/tripal/tripal_jobs'] = array(
-     'title' => 'Jobs',
-     'description' => 'Jobs managed by Tripal',
-     'page callback' => 'tripal_jobs_report',
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-   $items['admin/tripal/tripal_jobs/cancel/%'] = array(
-     'title' => 'Jobs',
-     'description' => 'Cancel a pending job',
-     'page callback' => 'tripal_jobs_cancel',
-     'page arguments' => array(4),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK,
-   );
-   $items['admin/tripal/tripal_jobs/rerun/%'] = array(
-     'title' => 'Jobs',
-     'description' => 'Re-run an existing job.',
-     'page callback' => 'tripal_jobs_rerun',
-     'page arguments' => array(4),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK,
-   );
-   $items['admin/tripal/tripal_jobs/view/%'] = array(
-     'title' => 'Jobs Details',
-     'description' => 'View job details.',
-     'page callback' => 'tripal_jobs_view',
-     'page arguments' => array(4),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK,
-   );
- 
-   
-   // Materialized Views 
-   $items['admin/tripal/mviews'] = array(
-     'title' => 'MViews',
-     'description' => 'Materialized views are used to improve speed of large or complex queries.',
-     'page callback' => 'tripal_mviews_report',
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-   $items['admin/tripal/mviews/report/%'] = array(
-     'title' => 'Materialized View',
-     'description' => 'Materialized views are used to improve speed of large or complex queries.',
-     'page callback' => 'tripal_mview_report',
-     'page arguments' => array(4),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-   $items['admin/tripal/mviews/new'] = array(
-     'title' => 'Create MView',
-     'description' => 'Materialized views are used to improve speed of large or complex queries.',
-     'page callback' => 'drupal_get_form',
-     'page arguments' => array('tripal_mviews_form'),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK,
-   );
-   $items['admin/tripal/mviews/edit/%'] = array(
-     'title' => 'Edit MView',
-     'page callback' => 'drupal_get_form',
-     'page arguments' => array('tripal_mviews_form',4),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_NORMAL_ITEM,
-   );
-   $items['admin/tripal/mviews/action/%/%'] = array(
-     'title' => 'Create MView',
-     'description' => 'Materialized views are used to improve speed of large or complex queries.',
-     'page callback' => 'tripal_mviews_action',
-     'page arguments' => array(4,5,"1"),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK,
-   );
   return $items;
 }
 
-
 /**
  *  Set the permission types that the chado module uses.  Essentially we
  *  want permissionis that protect creation, editing and deleting of chado
@@ -184,10 +180,10 @@ function tripal_core_menu() {
  *
  * @ingroup tripal_core
  */
-function tripal_core_perm(){
-   return array(
-   );
+function tripal_core_perm() {
+  return array();
 }
+
 /**
  *
  *
@@ -200,22 +196,19 @@ function tripal_core_perm(){
  *
  * @ingroup tripal_chado_api
  */
-function tripal_core_is_chado_installed(){
-   global $db_url, $db_type;
+function tripal_core_is_chado_installed() {
+  global $db_url, $db_type;
 
-   // first check if chado is in the db_url of the
-   // settings.php file
-   if(is_array($db_url)){
-      if(isset($db_url['chado'])){
-         return true;
-      }
-   }
-   // check to make sure the chado schema exists
-   $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
-   if(db_fetch_object(db_query($sql))){
-      return true;
-   }
-   return false;
+  // first check if chado is in the db_url of the
+  // settings.php file
+  if (is_array($db_url)) {
+    if (isset($db_url['chado'])) {
+      return TRUE;
+    }
+  }
+
+  // check to make sure the chado schema exists
+  return tripal_core_chado_schema_exists();
 }
 
 
@@ -223,36 +216,47 @@ function tripal_core_is_chado_installed(){
  *
  * @ingroup tripal_core
  */
-function tripal_core_theme () {
-   return array(
-      'tripal_core_job_view' => array (
-         'arguments' => array('job_id'=> null),
-         'template' => 'tripal_core_job_view',
-      ),
-   );
+function tripal_core_theme() {
+  return array(
+    'tripal_core_job_view' => array(
+       'arguments' => array('job_id' => NULL),
+       'template' => 'tripal_core_job_view',
+    ),
+  );
 }
+
 /**
  *
  * @ingroup tripal_core
  */
-function tripal_core_job_describe_args($callback,$args){
-   $new_args = array();
-   if($callback == 'tripal_update_mview'){
-      // get this mview details
-      $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
-      $mview = db_fetch_object(db_query($sql,$args[0]));
-      $new_args['View Name'] = $mview->name;
-   }
-   return $new_args;
+function tripal_core_job_describe_args($callback, $args) {
+  $new_args = array();
+  if ($callback == 'tripal_update_mview') {
+    // get this mview details
+    $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
+    $mview = db_fetch_object(db_query($sql, $args[0]));
+    $new_args['View Name'] = $mview->name;
+  }
+
+  return $new_args;
 }
 
 // this is just a wrapper for backwards compatibility with a naming mistake.
 // it can go away in the future as it only is useful for jobs created by v0.3b
-function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0,
-   $update = 0, $refresh = 0, $remove = 0, $job = NULL)
-{
-   tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only,
-      $update, $refresh, $remove, $job);
+function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
+  $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
+
+  tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
+    $update, $refresh, $remove, $job);
 }
- 
 
+/**
+ * Implements hook_coder_ignore().
+ * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
+ */
+function tripal_core_coder_ignore() {
+  return array(
+    'path' => drupal_get_path('module', 'tripal_core'),
+    'line prefix' => drupal_get_path('module', 'tripal_core'),
+  );
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 183 - 185
tripal_core/tripal_core.schema.api.inc


+ 16 - 12
tripal_core/tripal_core_job_view.tpl.php

@@ -1,21 +1,27 @@
 <?php
+
+/**
+ * @file
+ * This is a template file to show how the details of an individual job should be displayed
+ */
+
 $job = $variables['job'];
 
 $cancel_link = '';
 $return_link = url("admin/tripal/tripal_jobs/");
-if($job->start_time == 0 and $job->end_time == 0){
-   $cancel_link = url("admin/tripal/tripal_jobs/cancel/".$job->job_id);
+if ($job->start_time == 0 and $job->end_time == 0) {
+  $cancel_link = url("admin/tripal/tripal_jobs/cancel/" . $job->job_id);
 }
-$rerun_link = url("admin/tripal/tripal_jobs/rerun/".$job->job_id);
- 
+$rerun_link = url("admin/tripal/tripal_jobs/rerun/" . $job->job_id);
+
 ?>
 
 <div id="tripal_core-job_view-box" class="tripal_core-info-box tripal-info-box">
   <div class="tripal_core-info-box-title tripal-info-box-title">Details for Job <?php print $job->job_id?></div>
   <div class="tripal_core-info-box-desc tripal-info-box-desc"></div>
-   <a href="<?php print $return_link?>">Return to jobs list</a> | 
-   <a href="<?php print $rerun_link?>">Re-run this job</a> | 
-   <a href="<?php print $cancel_link?>">Cancel this Job</a><br>
+   <a href="<?php print $return_link?>">Return to jobs list</a> |
+   <a href="<?php print $rerun_link?>">Re-run this job</a> |
+   <a href="<?php print $cancel_link?>">Cancel this Job</a><br />
    <table id="tripal_core-job_view-table" class="tripal_core-table tripal-table tripal-table-vert">
       <tr class="tripal_core-table-odd-row tripal-table-even-row tripal-table-first-row">
          <th>Job Description</th>
@@ -33,9 +39,9 @@ $rerun_link = url("admin/tripal/tripal_jobs/rerun/".$job->job_id);
          <th>Arguments</th>
          <td>
            <table>
-           <?php foreach($job->arguments as $key => $value){
-              print "<tr><td>$key</td><td>$value</td></tr>";
-           } ?>
+          <?php foreach ($job->arguments as $key => $value) {
+            print "<tr><td>$key</td><td>$value</td></tr>";
+          } ?>
            </table>
          </td>
       </tr>
@@ -77,5 +83,3 @@ $rerun_link = url("admin/tripal/tripal_jobs/rerun/".$job->job_id);
       </tr>
    </table>
 </div>
-
-

+ 41 - 44
tripal_core/tripal_launch_jobs.php

@@ -1,57 +1,54 @@
 <?php
-//
-// Copyright 2009 Clemson University
-//
 
-/* 
-
-This script must be run at the base directory level of the drupal installation 
-in order to pick up all necessary dependencies 
-
-*/
+/**
+ * @file
+ * This script will launch any waiting tripal jobs in succession.
+ *
+ * This script must be run at the base directory level of the drupal installation
+ * in order to pick up all necessary dependencies
+ */
 
-  $stdout = fopen('php://stdout', 'w');
+$stdout = fopen('php://stdout', 'w');
 
-  // we require one command-line argument
-  if(sizeof($argv) < 2){
-     print_usage($stdout);
-     exit;
-  }
+// we require one command-line argument
+if (sizeof($argv) < 2) {
+  print_usage($stdout);
+  exit;
+}
 
-  $drupal_base_url = parse_url('http://www.example.com');
-  $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
+$drupal_base_url = parse_url('http://www.example.com');
+$_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
 //  $_SERVER['PHP_SELF'] = $drupal_base_url['path'].'/index.php';
-  $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
-  $_SERVER['REMOTE_ADDR'] = NULL;
-  $_SERVER['REQUEST_METHOD'] = NULL;
-
-  require_once 'includes/bootstrap.inc';
-  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-
-  fwrite($stdout, "Tripal Job Launcher\n");
-  fwrite($stdout, "-------------------\n");
+$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
+$_SERVER['REMOTE_ADDR'] = NULL;
+$_SERVER['REQUEST_METHOD'] = NULL;
+
+require_once 'includes/bootstrap.inc';
+drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+
+fwrite($stdout, "Tripal Job Launcher\n");
+fwrite($stdout, "-------------------\n");
+
+// check to make sure the username is valid
+$username = $argv[1];
+$do_parallel = $argv[2];
+if (!db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '%s'", $username))) {
+  fwrite($stdout, "'$username' is not a valid Drupal username. exiting...\n");
+  exit;
+}
 
-  // check to make sure the username is valid
-  $username = $argv[1];
-  $do_parallel = $argv[2];
-  if(!db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '$username'"))){
-     fwrite($stdout, "'$username' is not a valid Drupal username. exiting...\n");
-     exit;
-  }
-  global $user;
-  $user = user_load(array('name' => $username));
+global $user;
+$user = user_load(array('name' => $username));
 
-  tripal_jobs_launch($do_parallel);
+tripal_jobs_launch($do_parallel);
 
 /**
- *
+ * Print out the usage instructions if they are not followed correctly
  *
  * @ingroup tripal_core
  */
-function print_usage ($stdout){
-  fwrite($stdout,"Usage:\n");
-  fwrite($stdout,"  php ./sites/all/modules/tripal_core/tripal_launch_jobs <username> \n\n");
-  fwrite($stdout,"    where <username> is a Drupal user name\n\n");
-}
-
-?>
+function print_usage($stdout) {
+  fwrite($stdout, "Usage:\n");
+  fwrite($stdout, "  php ./sites/all/modules/tripal_core/tripal_launch_jobs <username> \n\n");
+  fwrite($stdout, "    where <username> is a Drupal user name\n\n");
+}

+ 47 - 42
tripal_core/tripal_launch_jobs_multi.php

@@ -1,22 +1,25 @@
 <?php
 
-/* This script can be used to launch jobs on a multi-site Drupal installation*/
+/**
+ * @file
+ * This script can be used to launch jobs on a multi-site Drupal installation
+ */
 
 include_once './includes/bootstrap.inc';
 
-fwrite(STDOUT,"Running Tripal Job Launcher\n");
+fwrite(STDOUT, "Running Tripal Job Launcher\n");
 
-/***********
-* SETTINGS
-**********/
+/**
+ * SETTINGS
+ */
 
 //the location of the 'sites' directory relative to this script.
-$sitesDir = 'sites';
+$sites_dir = 'sites';
 $debug=0;
-/***********
-* END SETTINGS
-**********/
 
+/**
+ * END SETTINGS
+ */
 
 //error_reporting(E_ALL);
 
@@ -26,25 +29,26 @@ include ("Console/Getopt.php");
 $cg = new Console_Getopt();
 
 /* define list of allowed options - p = h:sitename, u:username  */
-$allowedShortOptions = "h:u:";
+$allowed_short_options = "h:u:";
 
 // read the command line
 $args = $cg->readPHPArgv();
 
 // get the options
-$ret = $cg->getopt($args, $allowedShortOptions);
+$ret = $cg->getopt($args, $allowed_short_options);
 
 // check for errors and die with an error message if there was a problem
 if (PEAR::isError($ret)) {
-    die ("Error in command line: " . $ret->getMessage() . "\n");
+    die("Error in command line: " . $ret->getMessage() . "\n");
 }
 
-ini_set('include_path',ini_get('include_path'). PATH_SEPARATOR . './scripts');
+ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . './scripts');
 
-/* This doesn't work in every case: getopt function is not always available
-$options = getopt("h:r:");
-var_dump($options);
-*/
+/*
+ * This doesn't work in every case: getopt function is not always available
+  $options = getopt("h:r:");
+  var_dump($options);
+ */
 
 $hostname = "";
 $username = "";
@@ -62,18 +66,19 @@ if (sizeof($opts) > 0) {
                 $username = $opt[1];
                 break;
             default:
-                fwrite(STDOUT,'Usage: \n');
-                fwrite(STDOUT,'- h hostname\n');
-                fwrite(STDOUT." -u username\n");
+                fwrite(STDOUT, 'Usage: \n');
+                fwrite(STDOUT, '- h hostname\n');
+                fwrite(STDOUT, " -u username\n");
                 break;
 
         }
     }
-}else{
-  fwrite(STDOUT,"Usage: \n");
-  fwrite(STDOUT," -h hostname\n");
-  fwrite(STDOUT," -u username\n"); 
-  
+}
+else {
+  fwrite(STDOUT, "Usage: \n");
+  fwrite(STDOUT, " -h hostname\n");
+  fwrite(STDOUT, " -u username\n");
+
 }
 
 runjob($hostname, $username);
@@ -84,23 +89,23 @@ runjob($hostname, $username);
  * @ingroup tripal_core
  */
 function runjob($sitename, $username) {
+  global $user;
 
-    $_SERVER['SCRIPT_NAME'] = '/sites/all/modules/tripal_jobs/tripal_launch_jobs_multi.php';
-    $_SERVER['SCRIPT_FILENAME'] = '/sites/all/modules/tripal_jobs/tripal_launch_jobs_multi.php';
-    $_SERVER['HTTP_HOST'] = $sitename;
-    $_SERVER['REMOTE_ADDR'] = 'localhost';
-    $_SERVER['REQUEST_METHOD'] = 'GET';
-
-    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-        
-    if(!db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '$username'"))){
-     fwrite(STDOUT, "'$username' is not a valid Drupal username. exiting...\n");
-     exit;
-    }
-    global $user;
-    $user = $username;
-    $user = user_load(array('name' => $username));
+  $_SERVER['SCRIPT_NAME'] = '/sites/all/modules/tripal_jobs/tripal_launch_jobs_multi.php';
+  $_SERVER['SCRIPT_FILENAME'] = '/sites/all/modules/tripal_jobs/tripal_launch_jobs_multi.php';
+  $_SERVER['HTTP_HOST'] = $sitename;
+  $_SERVER['REMOTE_ADDR'] = 'localhost';
+  $_SERVER['REQUEST_METHOD'] = 'GET';
+
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+
+  if (!db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '%s'", $username))) {
+    fwrite(STDOUT, "'$username' is not a valid Drupal username. exiting...\n");
+    exit;
+  }
+
+  $user = $username;
+  $user = user_load(array('name' => $username));
 
-    tripal_jobs_launch();
+  tripal_jobs_launch();
 }
-?>

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov