Explorar el Código

Merge pull request #753 from tripal/727-tv3-bulk_aliases

Bug Fix for bulk setting of URL Aliases
Lacey-Anne Sanderson hace 6 años
padre
commit
e9f107bf41

+ 14 - 3
tripal/includes/TripalBundleUIController.inc

@@ -447,8 +447,18 @@ function tripal_tripal_bundle_form_validate($form, $form_state) {
 
   // PART 2: URL Alias'
   if ($form_state['values']['url']['url_pattern']) {
+    $url_pattern = trim($form_state['values']['url']['url_pattern']);    
     $tokens_available = unserialize($form_state['values']['url']['tokens']);
-    if (preg_match_all('/(\[\w+\])/', $form_state['values']['url']['url_pattern'], $matches)) {
+    
+    // For backwards compatibility we should warn uses if they use the word 
+    // 'feature' as this conflicts with the feature lookup tool. 
+    if (preg_match('/^feature\//', $url_pattern)) {
+      $msg = t('The word "feature" should not be used first in the pattern as it conflicts with the feature lookup tool provided by Tripal');
+      form_set_error('url][url_pattern', $msg);
+    }
+    
+    // Now make sure the tokens are valid.
+    if (preg_match_all('/(\[\w+\])/', $url_pattern, $matches)) {
 
       // The matches of the first and only pattern will be our tokens.
       $tokens_used = $matches[1];
@@ -501,7 +511,8 @@ function tripal_tripal_bundle_form_submit($form, &$form_state) {
 
     // Save the URL alias pattern if it's set.
     if ($form_state['values']['url']['url_pattern']) {
-      tripal_set_bundle_variable('url_format', $bundle->id, $form_state['values']['url']['url_pattern']);
+      $url_pattern = trim($form_state['values']['url']['url_pattern']);
+      tripal_set_bundle_variable('url_format', $bundle->id, $url_pattern);
     }
 
     // There are two submit buttons for this either updating the paths or the
@@ -521,7 +532,7 @@ function tripal_tripal_bundle_form_submit($form, &$form_state) {
         'tripal_update_all_urls_and_titles', $args, $user->uid, 10, $includes);
     }
     elseif ($trigger == 'Bulk update all aliases'){
-      $update = $form_state['input']['url']['url_pattern'];
+      $update = $url_pattern;
       $type = 'alias';
       $args = array(
         'bundle_id' => $bundle->name,

+ 8 - 3
tripal/includes/tripal.bulk_update.inc

@@ -18,11 +18,11 @@ function tripal_update_all_urls_and_titles($bundle_id, $update, $type) {
   $num_entities = $entities->rowCount();
   
   // Parse the $update variable for tokens and load those tokens.
-  preg_match_all("'/\[.*?\]/'", $update, $bundle_tokens);
+  preg_match_all("/\[.*?\]/", $update, $bundle_tokens);
 
   $fields = array();
   foreach ($bundle_tokens as $bundle_token) {
-    $elements = explode(',', $token);
+    $elements = explode(',', $bundle_token[0]);
     $field_name = array_shift($elements);
     $field_array = field_info_field($field_name);
     $fields[] = $field_array['id'];
@@ -48,7 +48,6 @@ function tripal_update_all_urls_and_titles($bundle_id, $update, $type) {
         if (is_array($arg)) {
           $ent = reset($arg);
         }
-
         $ec = entity_get_controller('TripalEntity');
         $ec->setTitle($ent, $update);
         $ec->resetCache();
@@ -61,6 +60,12 @@ function tripal_update_all_urls_and_titles($bundle_id, $update, $type) {
     }
     $i++;
   }
+  
+  // To speed up bulk alias updating the following function was skipped
+  // over. We'll add it back here to complete the process.
+  if ($type == 'alias') {
+    drupal_path_alias_whitelist_rebuild();
+  }
 
   print "\nDone.";
 }