Hi,

I had an issue with pathauto, some SQL syntax. When doing bulk updates if there is no category (taxonomy) present the bulk update failed (for categories). I created a patch, please review to make sure it's alright.

Thanks,
JG

Comments

greggles’s picture

@joseguevara - yes, I've thought about this before. What is the error message you get?

Do you really have no taxonomies present or just none with a pattern and no default pattern?

jose.guevara’s picture

None present, the taxonomy module is enabled but for that site I didn't need any taxonomy, I just used different content types and views.

The error message was:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 0, 50' at line 1 query: SELECT tid, vid, name, src, dst FROM hy_term_data LEFT JOIN hy_url_alias ON CONCAT('taxonomy/term/', CAST(tid AS CHAR)) = src WHERE src IS NULL AND vid <> 0 ) LIMIT 0, 50 in /website/includes/database.mysql.inc on line 172.
NaX’s picture

This patch fixed my problem. Still to be tested once I have some categories and terms.
My original post: http://drupal.org/node/289417

greggles’s picture

Title: Bulk Update of Category Path with no existing categories » Bulk Update of Category Path with no existing categories AND/OR remove bulk generate checkbox?
StatusFileSize
new6.14 KB

Another idea I had is that if there are no objects to do a bulk generate then we shouldn't even show this box. But...we should still protect against taxonomy_pathauto_bulkupdate being called outside of our form.

So, here is a patch which combines your work with a new check to see if there are objects to bulk update prior to showing the checkbox.

greggles’s picture

Version: 5.x-2.3 » 7.x-1.x-dev

This is actually against 6.x-2.x but we should fix it in 5.x-2 and 6.x-1.

arhak’s picture

subscribing

greggles’s picture

@arhak can you test the code? It needs reviews.

Thanks.

arhak’s picture

The first patch obviously does the trick.
The second patch looks fine (just read it) but right now I have no time to play around all the details it covers

A comment regarding the fragment below: the addition of an initialization for $vid_where improve readability, OTH the first assigment to it when empty($vid_where) unnecessarily begins with " AND (vid = '%s' "; and from there everything gets more obscure.
Consider the following fixes (I didn't run a diff rather I wrote an imitation by hand):

 function taxonomy_pathauto_bulkupdate() {
   // From all node types, only attempt to update those with patterns
   $pattern_vids = array();
   $vid_where = '';
   foreach (taxonomy_get_vocabularies() as $vid => $info) {
     $pattern = trim(variable_get('pathauto_taxonomy_'. $vid .'_pattern', ''));
    }
    if (!empty($pattern)) {
      $pattern_vids[] = $vid;
      if (empty($vid_where)) {
-        $vid_where = " AND (vid = '%s' ";
+        $vid_where = "vid = '%s' ";
      }
      else {
        $vid_where .= " OR vid = '%s'";
      }
    }
  }
-  $vid_where .= !empty($vid_where) ? ')' : '';

  // Exclude the forums and join all the args into one array so they can be passed to db_query
  $forum_vid[] = variable_get('forum_nav_vocabulary', '');
  $query_args = array_merge($forum_vid, $pattern_vids);
- $query = "SELECT tid, vid, name, src, dst FROM {term_data} LEFT JOIN {url_alias} ON CONCAT('taxonomy/term/', CAST(tid AS CHAR)) = src WHERE src IS NULL AND vid <> %d ". $vid_where;
+ $query = "SELECT tid, vid, name, src, dst FROM {term_data} LEFT JOIN {url_alias} ON CONCAT('taxonomy/term/', CAST(tid AS CHAR)) = src WHERE src IS NULL AND vid <> %d " . (!empty($vid_where) ? " AND (" . $vid_where . ")" : "");

This is a little bit cleaner, don't you think?
Also, it could be done with less casuistic, but with a tweaked initialization:

 function taxonomy_pathauto_bulkupdate() {
   // From all node types, only attempt to update those with patterns
   $pattern_vids = array();
-  $vid_where = '';
+  $vid_where = 'TRUE'; // This is for avoiding considering empty($vid_where) in a different branch
   foreach (taxonomy_get_vocabularies() as $vid => $info) {
     $pattern = trim(variable_get('pathauto_taxonomy_'. $vid .'_pattern', ''));
    }
    if (!empty($pattern)) {
      $pattern_vids[] = $vid;
-     if (empty($vid_where)) {
-        $vid_where = " AND (vid = '%s' ";
-     }
-     else {
-       $vid_where .= " OR vid = '%s'";
-     }
+     $vid_where .= " OR vid = '%s'";
    }
  }
-  $vid_where .= !empty($vid_where) ? ')' : '';

  // Exclude the forums and join all the args into one array so they can be passed to db_query
  $forum_vid[] = variable_get('forum_nav_vocabulary', '');
  $query_args = array_merge($forum_vid, $pattern_vids);
- $query = "SELECT tid, vid, name, src, dst FROM {term_data} LEFT JOIN {url_alias} ON CONCAT('taxonomy/term/', CAST(tid AS CHAR)) = src WHERE src IS NULL AND vid <> %d ". $vid_where;
+ $query = "SELECT tid, vid, name, src, dst FROM {term_data} LEFT JOIN {url_alias} ON CONCAT('taxonomy/term/', CAST(tid AS CHAR)) = src WHERE src IS NULL AND vid <> %d AND (" . $vid_where . ")"; // Now $vid_where is never empty (at least holds a 'TRUE')

What do you think about it?

greggles’s picture

It may be cleaner but it changes the logic of the where clause. So...no.

The only patch worth testing is the one in #4.

greggles’s picture

Assigned: Unassigned » greggles
StatusFileSize
new5.67 KB
new5.3 KB

Updated patches for 6x and 5x.

Any testers/reviewers?

munrageek’s picture

Hey every one.

the patch 286845_bulk_generate_no_objects_6x2.patch and 286845_bulk_generate_no_objects.patch don't work for me , this is the error in both:

patching file pathauto.admin.inc
Hunk #1 succeeded at 246 (offset -10 lines).
patching file pathauto_node.inc
patching file pathauto_taxonomy.inc
patching file pathauto_user.inc
Hunk #4 FAILED at 109.
1 out of 4 hunks FAILED -- saving rejects to file pathauto_user.inc.rej

used in pathauto 6.x-1.1 with Date 2008-Jun-26 and in Drupal 6.6.

The first one (pathauto_taxonomy.patch) works good.

Thanks for the patchs.

anoopjohn’s picture

The patch 286845_bulk_generate_no_objects_6x2.patch ran fine. I tried the patch on the latest 6.x.2.x-dev version. However I cannot access any of the Fieldsets inside the Automated Alias Settings page after I ran the patch. Is that by design? ie no access to any settings when there are no categories? Shouldn't the settings be available without the bulk update options?

greggles’s picture

Hmmm - the settings should be available, but not the "bulk generate" box. Perhaps this needs work.

coltrane’s picture

6x2 patch from #10 applied cleanly to latest 6.x-2.x-dev. All fieldsets visible and functional and "bulk generate" box not visible when I had no vocabs or terms. Submitting form gave no errors.

Created vocab, submitted pathauto form again without errors. Created a term then went back to pathauto form and "bulk generate" option was there. Submitted with it checked and received no errors.

Not sure what wasn't working correctly for you @anoopjohn. What theme are you using?

Maybe get another set of eyes on this but I'm tempted to RTBC it for 6.x-2.x. Patch looks fine.

coltrane’s picture

Error confirmed with pathauto 5.x-2.x-dev. Patch for 5.x applies cleanly and bulk option not available without vocabs or terms.

ShutterFreak’s picture

Subscribing to this issue as it is still relevant for the latest official 6.x release: 6.x-1.1.

Witch’s picture

I always get timeouts when trying to bulk update categorys. i choosed 20 items per run :\

dave reid’s picture

Issue tags: +bulk

Tagging all the bulk alias issues for #713238: RFC: Pathauto Bulk module.

durum’s picture

subscribing

Status: Needs review » Needs work

The last submitted patch, 286845_bulk_generate_no_objects_6x2.patch, failed testing.

dave reid’s picture

Status: Needs work » Closed (won't fix)

This issue is a 'won't fix' because of the upcoming change in #201151: Use batch API to perform path alias bulk updates.