From 5f1e9e80c299c05fb7b2106cfa966efaaf233eba Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 15 Apr 2015 23:26:24 +0200 Subject: [PATCH] remove duplicate file URLs script --- scripts/remove_duplicate_file_urls.php | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 scripts/remove_duplicate_file_urls.php diff --git a/scripts/remove_duplicate_file_urls.php b/scripts/remove_duplicate_file_urls.php new file mode 100755 index 0000000000..dd965991f0 --- /dev/null +++ b/scripts/remove_duplicate_file_urls.php @@ -0,0 +1,59 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'y'; +$longoptions = array('yes'); + +$helptext = <<query('SELECT id, url, COUNT(*) AS c FROM file GROUP BY url HAVING c > 1'); +while ($file->fetch()) { + // We've got a URL that is duplicated in the file table + $dupfile = new File(); + $dupfile->url = $file->url; + if ($dupfile->find(true)) { + // Leave one of the URLs in the database by using ->find(true) + // and only deleting starting with this fetch. + while($dupfile->fetch()) { + $dupfile->delete(); + } + } +} +print "\nDONE.\n";