Permalinks - Script to Clean-up Old Entries

By Perchpole - August 24, 2016

Hello, All -

Would it be possible to have a plugin (run as a cron job) that cleans up the Permalink database? It would be great to have something that went through the list every night and removed all of the "old" entries.

Just a thought.

:0)

Perch

By Daryl - August 24, 2016

Hi Perch,

Yes, that's doable.

But why would you want to delete the old entries?

We use the old permalinks to redirect the users to the current ones.
This is useful if a user bookmarked an old URL, or search engines haven't indexed the new URL yet and referred the user to the old one.

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By Perchpole - August 24, 2016

Hi, Daryl -

I'm coming up against a client who wants perfect control over the Permalinks. It involves a lot of experimentation on their part and almost always ends-up in a conflict. They choose a Permalink, then another, then want to go back to the original, etc, etc....

With the current set-up there is no way to go back to an old Permalink because it's "reserved". I can't see any other way of freeing-up an old Permalink other than by deleting it.

Happy to hear suggestions!

:0)

Perch

By Daryl - August 24, 2016

If that's the case, you can modify the permalinks plugin (create a backup first) to delete the old permalink as you add a new one.

You can do that by changing the code that updates the old permalink to mark it as "old" to have it delete the old record instead.

You can find that code in the permalink_add() function.

I'd comment out the code that updates the record instead of deleting it so I can restore it back easily when I need to.

Daryl Maximo
PHP Programmer - interactivetools.com

By Perchpole - August 24, 2016

Hi, Daryl -

Thanks for this - but could you be a bit more specific, please! I can't seem to find the code in the plugin.

:0/

Perch

By Daryl - August 24, 2016

In Permalinks v1.05, the code that updates the old permalinks are on line 219-221 and looks like this:

    // mark all other matching permalinks for this record as old
    $where = mysql_escapef("`tableName` = ? AND `recordNum` = ? AND permalink != ?", $tableName, $recordNum, $permalinkText);
    mysql_update('_permalinks', null, $where, array('old' => '1'));

I didn't mention the exact lines/code as I'm not sure what version you're using.

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By Perchpole - August 24, 2016

Got it. Thanks.

:0)