Browse Source

Removed creation of module directory during module install

Stephen Ficklin 10 years ago
parent
commit
b6a0a8061a

+ 1 - 4
tripal_analysis/tripal_analysis.install

@@ -50,9 +50,6 @@ function tripal_analysis_requirements($phase) {
  */
 function tripal_analysis_install() {
 
-  // create the module's data directory
-  tripal_create_files_dir('tripal_analysis');
-
   // we may need the analysisfeatureprop table if it doesn't already exist
   tripal_analysis_create_analysisfeatureprop();
 
@@ -125,7 +122,7 @@ function tripal_analysis_add_cvs() {
 function tripal_analysis_add_cvterms() {
 
   tripal_insert_cv(
-    'tripal_analysis', 
+    'tripal_analysis',
     'Terms used for managing analyses in Tripal'
   );
 

+ 1 - 4
tripal_contact/tripal_contact.install

@@ -51,9 +51,6 @@ function tripal_contact_requirements($phase) {
  */
 function tripal_contact_install() {
 
-  // Create the module's data directory.
-  tripal_create_files_dir('tripal_contact');
-
   // Add the contactprop table to Chado.
   tripal_contact_add_custom_tables();
 
@@ -406,7 +403,7 @@ function tripal_contact_update_7202() {
     db_delete('tripal_cv_obo')
       ->condition('name', 'Tripal Contacts')
       ->execute();
-    
+
     // Add in the updated path.
     $obo_path = '{tripal_contact}/files/tcontact.obo';
     $obo_id = tripal_insert_obo('Tripal Contacts', $obo_path);

+ 25 - 7
tripal_core/api/tripal_core.files.api.inc

@@ -16,10 +16,16 @@
  */
 
 /**
- * This function is typically used in the '.install' file for a Tripal module
- * Each module should call this function during installation to create
- * the module data directory which is sites/default/files/tripal/[module_name].
- * This directory can then be used by the module for storing files.
+ * Creates a directory for a module in the Drupal's public files directory.
+ *
+ * Previously it was recommended that this function be called during
+ * installation of the module in the .install file.  However this causes
+ * permission problems if the module is installed via drush with a
+ * user account that is not the same as the web user.  Therefore, this
+ * function should not be called in a location accessiblve via a drush
+ * command.  The tripal_get_files_dir() and tripal_get_files_stream()
+ * will automatically create the directory if it doesn't exist so there is
+ * little need to call this function directly.
  *
  * @param $module_name
  *   the name of the module being installed
@@ -61,7 +67,7 @@ function tripal_create_files_dir($module_name, $path = FALSE) {
 
 /**
  * Retreives the Drupal relative directory for a Tripal module.
- * 
+ *
  * Each Tripal module has a unique data directory which was created using the
  * tripal_create_files_dir function during installation.  This function
  * retrieves the directory path.
@@ -76,10 +82,16 @@ function tripal_create_files_dir($module_name, $path = FALSE) {
  */
 function tripal_get_files_dir($module_name = FALSE) {
 
+  // Build the directory path.
   $data_dir = variable_get('file_public_path', conf_path() . '/files/tripal');
 
+  // If a module name is provided then append the module directory.
   if ($module_name) {
     $data_dir .= "/$module_name";
+
+    // Make sure the directory exists.
+    tripal_create_files_dir($module_name, "/$module_name");
+
   }
 
   return $data_dir;
@@ -87,7 +99,7 @@ function tripal_get_files_dir($module_name = FALSE) {
 
 /**
  * Retreives the Drupal stream (e.g. public://...) for a Tripal module.
- * 
+ *
  * Each Tripal module has a unique data directory which was created using the
  * tripal_create_files_dir function during installation.  This function
  * retrieves the directory path.
@@ -101,10 +113,16 @@ function tripal_get_files_dir($module_name = FALSE) {
  * @ingroup tripal_files_api
  */
 function tripal_get_files_stream($module_name = FALSE) {
+  // Build the directory path.
   $stream =  'public://tripal';
+
+  // If a module name is provided then append the module directory.
   if ($module_name) {
     $stream .= "/$module_name";
+
+    // Make sure the directory exists.
+    tripal_create_files_dir($module_name, "/$module_name");
   }
-  
+
   return $stream;
 }

+ 0 - 3
tripal_cv/tripal_cv.install

@@ -49,9 +49,6 @@ function tripal_cv_requirements($phase) {
  */
 function tripal_cv_install() {
 
-  // create the module's data directory
-  tripal_create_files_dir('tripal_cv');
-
   // add the cv_root_mview
   tripal_cv_add_cv_root_mview();
 

+ 0 - 3
tripal_db/tripal_db.install

@@ -48,9 +48,6 @@ function tripal_db_requirements($phase) {
  */
 function tripal_db_install() {
 
-  // create the module's data directory
-  tripal_create_files_dir('tripal_db');
-
 }
 
 /**

+ 0 - 9
tripal_example/tripal_example.install

@@ -69,15 +69,6 @@ function tripal_example_requirements($phase) {
  */
 function tripal_example_install() {
 
-  // EXPLANATION: If your module will making data publicly available for
-  // download or use by the site you can create the directory using the
-  // tripal_create_files_dir() function. This will create a directory in the
-  // public access directory which will typically be in
-  // sites/default/files/tripal/[module name]/
-
-  // create the module's data directory
-  tripal_create_files_dir('tripal_example');
-
   // EXPLANATION: Here is a good place to add any materialized views, controlled
   // vocabularies CV, databases or CV terms needed by your module.
   // To keep this module code short, create functions to do each of those tasks

+ 62 - 65
tripal_feature/includes/tripal_feature.fasta_loader.inc

@@ -400,21 +400,16 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type, $re_name, $re_un
         LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
       WHERE cv.name = :cvname and (CVT.name = :name or CVTS.synonym = :synonym)
     ";
-    $cvterm = chado_query($cvtermsql, array(':cvname' => 'sequence',':name' => $type,
-      ':synonym' => $type
-    ))->fetchObject();
+    $cvterm = chado_query($cvtermsql, array(':cvname' => 'sequence',':name' => $type,':synonym' => $type))->fetchObject();
     if (!$cvterm) {
-      tripal_report_error("T_fasta_loader", TRIPAL_ERROR, "Cannot find the term type: '%type'", array(
-        '%type' => $type
-      ));
+      tripal_report_error("T_fasta_loader", TRIPAL_ERROR,
+        "Cannot find the term type: '%type'", array('%type' => $type));
       return 0;
     }
 
     // Second, if there is a parent type then get that.
     if ($parent_type) {
-      $parentcvterm = chado_query($cvtermsql, array(':cvname' => 'sequence',
-        ':name' => $parent_type,':synonym' => $parent_type
-      ))->fetchObject();
+      $parentcvterm = chado_query($cvtermsql, array(':cvname' => 'sequence', ':name' => $parent_type,':synonym' => $parent_type))->fetchObject();
       if (!$parentcvterm) {
         tripal_report_error("T_fasta_loader", TRIPAL_ERROR, "Cannot find the paretne term type: '%type'", array(
           '%type' => $parentcvterm
@@ -425,9 +420,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type, $re_name, $re_un
 
     // Third, if there is a relationship type then get that.
     if ($rel_type) {
-      $relcvterm = chado_query($cvtermsql, array(':cvname' => 'sequence',':name' => $rel_type,
-        ':synonym' => $rel_type
-      ))->fetchObject();
+      $relcvterm = chado_query($cvtermsql, array(':cvname' => 'sequence',':name' => $rel_type,':synonym' => $rel_type))->fetchObject();
       if (!$relcvterm) {
         tripal_report_error("T_fasta_loader", TRIPAL_ERROR, "Cannot find the relationship term type: '%type'", array(
           '%type' => $relcvterm
@@ -498,8 +491,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type, $re_name, $re_un
           if (preg_match("/^\s*(.*?)[\s\|].*$/", $defline, $matches)) {
             if (strlen($matches[1]) > $feature_tbl['fields']['name']['length']) {
               tripal_report_error('trp-fasta', "WARNING: Regular expression retrieves a feature name too long for the feature name. Line %line.", array(
-                '%line' => $i
-              ), 'error');
+                '%line' => $i), 'error');
             }
             else {
               $name = trim($matches[1]);
@@ -507,8 +499,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type, $re_name, $re_un
           }
           else {
             tripal_report_error('trp-fasta', "ERROR: Cannot find a feature name. Line %line.", array(
-              '%line' => $i
-            ), 'error');
+              '%line' => $i), 'error');
           }
         }
 
@@ -516,8 +507,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type, $re_name, $re_un
         if ($re_uname) {
           if (!preg_match("/$re_uname/", $defline, $matches)) {
             tripal_report_error('trp-fasta', "ERROR: Regular expression for the feature unique name finds nothing. Line %line.", array(
-              '%line' => $i
-            ), 'error');
+              '%line' => $i), 'error');
           }
           $uname = trim($matches[1]);
         }
@@ -530,8 +520,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type, $re_name, $re_un
           }
           else {
             tripal_report_error('trp-fasta', "ERROR: Cannot find a feature unique name. Line %line.", array(
-              '%line' => $i
-            ), 'error');
+              '%line' => $i), 'error');
           }
         }
 
@@ -551,8 +540,12 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type, $re_name, $re_un
         $subject = trim($matches[1]);
 
         // Add the details to the sequence.
-        $seqs[$num_seqs] = array('name' => $name,'uname' => $uname,'accession' => $accession,
-          'subject' => $subject,'seq_start' => ftell($fh)
+        $seqs[$num_seqs] = array(
+          'name' => $name,
+          'uname' => $uname,
+          'accession' => $accession,
+          'subject' => $subject,
+          'seq_start' => ftell($fh)
         );
         $set_start = TRUE;
         // If this isn't the first sequence, then we want to specify where
@@ -634,9 +627,7 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
     ), $values);
     if (count($results) > 1) {
       tripal_report_error('T_fasta_loader', "Multiple features exist with the name '%name' of type
-               '%type' for the organism.  skipping", array(
-        '%name' => $name,'%type' => $type
-      ));
+               '%type' for the organism.  skipping", array('%name' => $name,'%type' => $type));
       return 0;
     }
     if (count($results) == 1) {
@@ -646,16 +637,16 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
 
   // Check if this feature already exists if the match_type is 'Unique Name'.
   if (strcmp($match_type, 'Unique name') == 0) {
-    $values = array('organism_id' => $organism_id,'uniquename' => $uname,
+    $values = array(
+      'organism_id' => $organism_id,
+      'uniquename' => $uname,
       'type_id' => $cvterm->cvterm_id
     );
 
-    $results = chado_select_record('feature', array('feature_id'
-    ), $values);
+    $results = chado_select_record('feature', array('feature_id'), $values);
     if (count($results) > 1) {
       tripal_report_error('T_fasta_loader', TRIPAL_WARNING, "Multiple features exist with the name '%name' of type '%type' for the organism.  skipping", array(
-        '%name' => $name,'%type' => $type
-      ));
+        '%name' => $name,'%type' => $type));
       return 0;
     }
     if (count($results) == 1) {
@@ -683,31 +674,33 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
     }
 
     // Insert the feature record.
-    $values = array('organism_id' => $organism_id,'name' => $name,'uniquename' => $uname,
+    $values = array(
+      'organism_id' => $organism_id,
+      'name' => $name,
+      'uniquename' => $uname,
       'type_id' => $cvterm->cvterm_id
     );
     $success = chado_insert_record('feature', $values);
     if (!$success) {
       tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to insert feature '%name (%uname)'", array(
-        '%name' => $name,'%uname' => $numane
-      ));
+        '%name' => $name,'%uname' => $numane));
       return 0;
     }
 
     // now get the feature we just inserted
-    $values = array('organism_id' => $organism_id,'uniquename' => $uname,
+    $values = array(
+      'organism_id' => $organism_id,
+      'uniquename' => $uname,
       'type_id' => $cvterm->cvterm_id
     );
-    $results = chado_select_record('feature', array('feature_id'
-    ), $values);
+    $results = chado_select_record('feature', array('feature_id'), $values);
     if (count($results) == 1) {
       $inserted = 1;
       $feature = $results[0];
     }
     else {
       tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to retreive newly inserted feature '%name (%uname)'", array(
-        '%name' => $name,'%uname' => $numane
-      ));
+        '%name' => $name,'%uname' => $numane));
       return 0;
     }
 
@@ -719,8 +712,7 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
   if (!$feature and (strcmp($method, 'Update only') == 0 or
      drupal_strcmp($method, 'Insert and update') == 0)) {
     tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to find feature '%name' ('%uname') while matching on " .
-     drupal_strtolower($match_type), array('%name' => $name,'%uname' => $uname
-    ));
+      drupal_strtolower($match_type), array('%name' => $name,'%uname' => $uname));
     return 0;
   }
 
@@ -739,7 +731,9 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
         // First check to make sure that by changing the unique name of this
         // feature that we won't conflict with another existing feature of
         // the same name
-        $values = array('organism_id' => $organism_id,'uniquename' => $uname,
+        $values = array(
+          'organism_id' => $organism_id,
+          'uniquename' => $uname,
           'type_id' => $cvterm->cvterm_id
         );
         $results = chado_select_record('feature', array('feature_id'
@@ -753,9 +747,10 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
         }
 
         // the changes to the uniquename don't conflict so proceed with the update
-        $values = array('uniquename' => $uname
-        );
-        $match = array('name' => $name,'organism_id' => $organism_id,
+        $values = array('uniquename' => $uname);
+        $match = array(
+          'name' => $name,
+          'organism_id' => $organism_id,
           'type_id' => $cvterm->cvterm_id
         );
 
@@ -776,9 +771,10 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
       // we want to update the name.
       $values = array();
       if ($name) {
-        $values = array('name' => $name
-        );
-        $match = array('uniquename' => $uname,'organism_id' => $organism_id,
+        $values = array('name' => $name);
+        $match = array(
+          'uniquename' => $uname,
+          'organism_id' => $organism_id,
           'type_id' => $cvterm->cvterm_id
         );
         $success = chado_update_record('feature', $match, $values);
@@ -798,10 +794,11 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
   // add in the analysis link
   if ($analysis_id) {
     // if the association doens't alredy exist then add one
-    $values = array('analysis_id' => $analysis_id,'feature_id' => $feature->feature_id
+    $values = array(
+      'analysis_id' => $analysis_id,
+      'feature_id' => $feature->feature_id
     );
-    $results = chado_select_record('analysisfeature', array('analysisfeature_id'
-    ), $values);
+    $results = chado_select_record('analysisfeature', array('analysisfeature_id'), $values);
     if (count($results) == 0) {
       $success = chado_insert_record('analysisfeature', $values);
       if (!$success) {
@@ -816,28 +813,26 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
   // now add the database cross reference
   if ($db_id) {
     // check to see if this accession reference exists, if not add it
-    $values = array('db_id' => $db_id,'accession' => $accession
+    $values = array(
+      'db_id' => $db_id,
+      'accession' => $accession
     );
-    $results = chado_select_record('dbxref', array('dbxref_id'
-    ), $values);
+    $results = chado_select_record('dbxref', array('dbxref_id'), $values);
     // if the accession doesn't exist then add it
     if (count($results) == 0) {
       $results = chado_insert_record('dbxref', $values);
       if (!$results) {
         tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to add database accession '%accession'", array(
-          '%accession' => $accession
-        ));
+          '%accession' => $accession));
         return 0;
       }
-      $results = chado_select_record('dbxref', array('dbxref_id'
-      ), $values);
+      $results = chado_select_record('dbxref', array('dbxref_id'), $values);
       if (count($results) == 1) {
         $dbxref = $results[0];
       }
       else {
         tripal_report_error('T_fasta_loader', TRIPAL_ERROR, "Failed to retreive newly inserted dbxref '%name (%uname)'", array(
-          '%name' => $name,'%uname' => $numane
-        ));
+          '%name' => $name,'%uname' => $numane));
         return 0;
       }
     }
@@ -846,10 +841,11 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
     }
 
     // check to see if the feature dbxref record exists if not, then add it
-    $values = array('feature_id' => $feature->feature_id,'dbxref_id' => $dbxref->dbxref_id
+    $values = array(
+      'feature_id' => $feature->feature_id,
+      'dbxref_id' => $dbxref->dbxref_id
     );
-    $results = chado_select_record('feature_dbxref', array('feature_dbxref_id'
-    ), $values);
+    $results = chado_select_record('feature_dbxref', array('feature_dbxref_id'), $values);
     if (count($results) == 0) {
       $success = chado_insert_record('feature_dbxref', $values);
       if (!$success) {
@@ -878,11 +874,12 @@ function tripal_feature_load_fasta_feature($fh, $name, $uname, $db_id, $accessio
     $parent_feature = $results[0];
 
     // check to see if the relationship already exists if not then add it
-    $values = array('subject_id' => $feature->feature_id,'object_id' => $parent_feature->feature_id,
+    $values = array(
+      'subject_id' => $feature->feature_id,
+      'object_id' => $parent_feature->feature_id,
       'type_id' => $relcvterm->cvterm_id
     );
-    $results = chado_select_record('feature_relationship', array('feature_relationship_id'
-    ), $values);
+    $results = chado_select_record('feature_relationship', array('feature_relationship_id'), $values);
     if (count($results) == 0) {
       $success = chado_insert_record('feature_relationship', $values);
       if (!$success) {

+ 0 - 3
tripal_feature/tripal_feature.install

@@ -48,9 +48,6 @@ function tripal_feature_requirements($phase) {
  * @ingroup tripal_feature
  */
 function tripal_feature_install() {
-  // Create the module's data directory.
-  tripal_create_files_dir('tripal_feature');
-
   // Add the materialized view.
   tripal_feature_add_organism_count_mview();
 

+ 0 - 2
tripal_featuremap/tripal_featuremap.install

@@ -47,8 +47,6 @@ function tripal_featuremap_requirements($phase) {
  * @ingroup tripal_featuremap
  */
 function tripal_featuremap_install() {
-  // create the module's data directory
-  tripal_create_files_dir('tripal_featuremap');
 
   // add the featuremapprop table to Chado
   tripal_featuremap_add_custom_tables();

+ 0 - 3
tripal_library/tripal_library.install

@@ -48,9 +48,6 @@ function tripal_library_requirements($phase) {
  */
 function tripal_library_install() {
 
-  // create the module's data directory
-  tripal_create_files_dir('tripal_library');
-
   // add the materialized view
   tripal_library_add_mview_library_feature_count();
 

+ 0 - 3
tripal_natural_diversity/tripal_natural_diversity.install

@@ -48,9 +48,6 @@ function tripal_natural_diversity_requirements($phase) {
  */
 function tripal_natural_diversity_install() {
 
-  // create the module's data directory
-  tripal_create_files_dir('tripal_natural_diversity');
-
   // add cvterms
   tripal_natural_diversity_add_cvterms();
 

+ 0 - 7
tripal_organism/tripal_organism.install

@@ -27,13 +27,6 @@ function tripal_organism_disable() {
  * @ingroup tripal_organism
  */
 function tripal_organism_install() {
-
-  // create the module's data directory
-  tripal_create_files_dir('tripal_organism');
-
-  // create the directory where image files will be stored.  We create this
-  tripal_create_files_dir('tripal_organism', '/images');
-
   // cvs & cvterms
   tripal_organism_add_cvs();
   tripal_organism_add_cvterms();

+ 0 - 3
tripal_project/tripal_project.install

@@ -48,9 +48,6 @@ function tripal_project_requirements($phase) {
  */
 function tripal_project_install() {
 
-  // create the module's data directory
-  tripal_create_files_dir('tripal_project');
-
   tripal_project_add_cvs();
   tripal_project_add_cvterms();
 

+ 0 - 3
tripal_pub/tripal_pub.install

@@ -49,9 +49,6 @@ function tripal_pub_requirements($phase) {
 function tripal_pub_install() {
   global $base_path;
 
-  // create the module's data directory
-  tripal_create_files_dir('tripal_pub');
-
   // add loading of the the tripal pub ontology to the job queue
   $obo_path = '{tripal_pub}/files/tpub.obo';
   $obo_id = tripal_insert_obo('Tripal Publication', $obo_path);

+ 0 - 3
tripal_stock/tripal_stock.install

@@ -47,9 +47,6 @@ function tripal_stock_requirements($phase) {
  * @ingroup tripal_stock
  */
 function tripal_stock_install() {
-  // create the module's data directory
-  tripal_create_files_dir('tripal_stock');
-
   // add some controlled vocabularies
   tripal_stock_add_cvs();
 

+ 0 - 3
tripal_views/tripal_views.install

@@ -31,9 +31,6 @@ function tripal_views_requirements($phase) {
  */
 function tripal_views_install() {
 
-  // create the module's data directory
-  tripal_create_files_dir('tripal_views');
-
   // we want views to pick up our changes
   views_invalidate_cache();