hi, pathauto is good, but it doesnt seem to remove paths when content/terms are deleted.

Comments

greggles’s picture

Title: create path... delete? » provide an admin feature to delete aliases for nodes/users/taxonomy that no longer exist
Category: bug » feature

There are definitely situations of paths getting created which don't get deleted but these are mostly core issues. It shouldn't be pathauto's job to do this, but instead it should be done in user.module or node.module or taxonomy.module. The reason is that aliases can be built manually so there is a chance that an alias should be deleted and pathauto won't be around to do the deletes.

If you find situations where the aliases are not being deleted please file those against their respective core modules. Also, please be very specific about each separate instance so that people can understand what you are describing.

As I was thinking about this I realized that a handy feature to add to pathauto would be to delete old (non-existent) aliases. The feature would go through the aliases table and looking for node/nid% patterns for nids that no longer exist and then deleting them (and then do it again for users, and taxonomy).

niklp’s picture

Further to that Greg, would it not also be a simple task to have a checkbox next to each alias that could be used to delete multiple aliases at once? Renaming a category (vocab) renders all old aliases useless, and deleting these manually is a pain. It's understood that this could probably be accomplished directly in the DB, but this is outside of a lot of normal users' skill-sets.

greggles’s picture

NikLP - I think you are confusing the pathauto pages and the drupal core url aliases page. Adding a checkbox next to each alias is something that should be added to drupal core and not just an add-on from an external module. If you want to see that (which it seems like a nice idea, so I suggest you do) then please submit an issue for drupal core related to that.

greggles’s picture

Version: 5.x-1.0 » 5.x-2.x-dev

Changing version. I also kind of like this idea and have done some work on it. I think it's possible and potentially beneficial, even if it's only a matter of adding documentation to show people how to do this instead of actually including the delete statements in code.

senpai’s picture

Title: provide an admin feature to delete aliases for nodes/users/taxonomy that no longer exist » Provide an admin feature to delete aliases that no longer exist

[Changing the title to make it more readable and direct.]
I have been thinking for some time that Pathauto should have an admin interface to allow deletion of all aliases that match a certain pattern. In the Starting Over: docs page, it states that:

For example, a query like the following will delete all node objects:

DELETE FROM url_alias WHERE src LIKE 'node/%';

Using more advanced query syntax you can selectively delete nodes of a certain type, or by a certain user, etc. This system can be helpful to regenerate all of the aliases after a user's name has changed or some other pattern has changed rendering their aliases no longer valid. While it could be useful to provide this feature in the admin page, the number of possible delete queries that might be useful would quickly grow to being arbitrarily large and irreducibly complex (i.e. too hard).

Well, what if the Pathauto admin page offered a fieldset that had a place for "Delete all aliases that begin with the pattern ___"? Users who had accidentally created a bunch of aliases for one of their content types, and who didn't want to re-generate ALL their aliases due to some behind-the-scenes customizations or something, could use that box to nuke the 200 offending aliases without harming all their other carefully crafted ones. The SQL would be simple, since you don't have to offer GUI options for 'begins with', 'contains', 'ends with', or any other fluff.

I'm thinking that users who want to bulk-delete aliases selectively are most probably going to know the initial path of those aliases. Something like "pathauto/tutorials/[nid]/" or somesuch. After all, if you really need the functionality to delete aliases that only have a "3" in the seventeenth position, you're most likely going to want to do that in the database itself because you actually knew that it was possible to do that, so therefore you know how to write the SQL to do it anyway!

Thoughts?

senpai’s picture

[Followup to my own followup. Classy!]
After an IRC discussion about the subject, it seems to make sense that allowing a user the ability to delete all aliases that *begin* with a certain pattern can't be too terribly dastardly, provided there's some sort of flag or confirmation before nuking commences. A user who mistakenly creates a pattern of "example/path/" that was then auto-generated using bulk update is gonna know that if they type that same string into the Delete field it will get rid of all the aliases they just made.

Before the Delete is processed against the db, Pathauto should count how many aliases will be nuked, and confirm that to the user with a "You are about to delete all 201 aliases beginning with 'example/path/'. Are you sure?"

greggles’s picture

Status: Active » Needs review
StatusFileSize
new7.17 KB

This is actually for a slightly separate issue than the initial one...but here's a fun related patch that does what senpai hijacked this thread into...

greggles’s picture

Title: Provide an admin feature to delete aliases that no longer exist » Provide an admin feature to delete aliases for certain kinds of objects or all aliases

Fwiw, I'm changing the focus - thanks for the hijack!

The original problem is a real pain.

Here are two queries that I worked out that achieve some of this:

DELETE url_alias FROM url_alias LEFT JOIN users u ON src = CONCAT('user/', u.uid,'/track') WHERE src LIKE 'user/%/track' AND u.uid IS NULL
DELETE url_alias FROM url_alias LEFT JOIN users u ON src = CONCAT('user/', u.uid) WHERE src LIKE 'user/%' AND src NOT LIKE '%/track' AND u.uid IS NULL;

These may be mysql only and they may not work well if you have /feed aliases as well. I'm providing this as a start, but really creating these things is just too much of a pain for me right now.

greggles’s picture

StatusFileSize
new7 KB

cleaner patch - this is probably what I'll actually commit

senpai’s picture

It appears this patch has been committed to the latest pathauto .dev, cause applying this against pathauto.module v1.44.4.21 results in a:
"Hunk #4 failed at 298"

Has this baby been committed already, or am I doing something wrong here?

senpai’s picture

Ummm, I D 10 T error. I was just informed by Update Status that there is indeed a newer dev version of Pathauto available. I shall commence downloading just as soon as I can relocate the mother ship.

Senpai out.

senpai’s picture

I applied the granular_0.patch to pathauto 5.x-2.x-dev (aug 26th version) successfully. I was then greeted with a

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'pathauto_admin_delete_confirm' was given in /Websites/drupal5/includes/form.inc on line 217.

message on the 'delete all aliases' tab of the Pathauto Settings. This was not there before the patch, because I tried all those tabs just before patching the module.

greggles’s picture

@senpai - clear the menu cache :/

One hunk fails if you use the latest 5.x-2.x code - but it's not important...

greggles’s picture

Status: Needs review » Fixed

I committed this to the 5.x-2.x branch. Thanks everyone for your ideas, input, and reviews.

Anonymous’s picture

Status: Fixed » Closed (fixed)