delete_notice.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * StatusNet - a distributed open-source microblogging tool
  5. * Copyright (C) 2008, 2009, 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', dirname(__DIR__));
  21. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  22. $shortoptions = 'i::u::y';
  23. $longoptions = array('id=', 'uri=', 'yes');
  24. $helptext = <<<END_OF_HELP
  25. delete_notice.php [options]
  26. deletes a notice (but not related File objects) from the database
  27. -i --id Local ID of the notice
  28. -u --uri Notice URI
  29. -y --yes do not wait for confirmation
  30. END_OF_HELP;
  31. require_once INSTALLDIR.'/scripts/commandline.inc';
  32. try {
  33. if (have_option('i', 'id')) {
  34. $id = get_option_value('i', 'id');
  35. $notice = Notice::getByID($id);
  36. } else if (have_option('u', 'uri')) {
  37. $uri = get_option_value('u', 'uri');
  38. $notice = Notice::getByUri($uri);
  39. } else {
  40. print $helptext;
  41. throw new ClientException('You must provide either an ID or a URI.');
  42. }
  43. } catch (Exception $e) {
  44. print "ERROR: {$e->getMessage()}\n";
  45. exit(1);
  46. }
  47. if (!have_option('y', 'yes')) {
  48. print "About to PERMANENTLY delete notice ".$notice->getID()." by '".$notice->getProfile()->getNickname()."'. Are you sure? [y/N] ";
  49. $response = fgets(STDIN);
  50. if (strtolower(trim($response)) != 'y') {
  51. print "Aborting.\n";
  52. exit(0);
  53. }
  54. }
  55. print "Deleting...";
  56. $notice->delete();
  57. print "DONE.\n";