fixup_files.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * StatusNet - a distributed open-source microblogging tool
  5. * Copyright (C) 2010 StatusNet, Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  21. $longoptions = array('dry-run');
  22. $helptext = <<<END_OF_USERROLE_HELP
  23. fixup_files.php [options]
  24. Patches up file entries with corrupted types and titles (the "h bug").
  25. --dry-run look but don't touch
  26. END_OF_USERROLE_HELP;
  27. require_once INSTALLDIR.'/scripts/commandline.inc';
  28. $dry = have_option('dry-run');
  29. $f = new File();
  30. $f->title = 'h';
  31. $f->mimetype = 'h';
  32. $f->size = 0;
  33. $f->protected = 0;
  34. $f->find();
  35. echo "Found $f->N bad items:\n";
  36. while ($f->fetch()) {
  37. echo "$f->id $f->url";
  38. $data = File_redirection::lookupWhere($f->url);
  39. if ($dry) {
  40. if (is_array($data)) {
  41. echo " (unchanged)\n";
  42. } else {
  43. echo " (unchanged, but embedding lookup failed)\n";
  44. }
  45. } else {
  46. // NULL out the mime/title/size/protected fields
  47. $sql = sprintf("UPDATE file " .
  48. "SET mimetype=null,title=null,size=null,protected=null " .
  49. "WHERE id=%d",
  50. $f->id);
  51. $f->query($sql);
  52. $f->decache();
  53. if (is_array($data)) {
  54. Event::handle('EndFileSaveNew', array($f, $data, $f->url));
  55. echo " (ok)\n";
  56. } else {
  57. echo " (ok, but embedding lookup failed)\n";
  58. }
  59. }
  60. }
  61. echo "done.\n";