Skip to content

Instantly share code, notes, and snippets.

@fiver-watson
Last active November 15, 2016 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fiver-watson/929e6c3380bedd32f3a77d21403c80de to your computer and use it in GitHub Desktop.
Save fiver-watson/929e6c3380bedd32f3a77d21403c80de to your computer and use it in GitHub Desktop.
This script can be used by Access to Memory (AtoM) users who have encountered bug #10276 (https://projects.artefactual.com/issues/10276), and have accidentally created slugs (permalinks) for users or other entities with periods in them - these slugs will fail, rendering the record inaccessible. This script can be run from AtoM's root directory u…
<?php
print "Fixing invalid slugs...\n";
// add separator characters you want to convert FROM (DO NOT ADD A BACKSLASH HERE)
$separators = array('.', '/');
// change all instances of 'separator' to dash '-'.
foreach ($separators as $separator)
{
print 'Updating where slug contains: ' . $separator . "\n";
$r = QubitPdo::prepareAndExecute('UPDATE slug SET slug = REPLACE(slug, "' . $separator . '", "-") WHERE slug LIKE "%' . $separator . '%"');
$counter += $r->rowCount();
}
print 'Done. Fixed '.$counter." slugs.\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment