searchsubtrackoffcommand.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. defined('GNUSOCIAL') || die();
  17. class SearchSubTrackoffCommand extends Command
  18. {
  19. public function handle($channel)
  20. {
  21. $cur = $this->user;
  22. $all = new SearchSub();
  23. $all->profile_id = $cur->id;
  24. $all->find();
  25. if ($all->N == 0) {
  26. // TRANS: Error text shown a user tries to disable all a search subscriptions with track off command, but has none.
  27. $channel->error($cur, _m('You are not tracking any searches.'));
  28. return;
  29. }
  30. $profile = $cur->getProfile();
  31. while ($all->fetch()) {
  32. try {
  33. SearchSub::cancel($profile, $all->search);
  34. } catch (Exception $e) {
  35. // TRANS: Message given having failed to cancel one of the search subs with 'track off' command.
  36. // TRANS: %s is the search for which the subscription removal failed.
  37. $channel->error($cur, sprintf(
  38. _m('Error disabling search subscription for query "%s".'),
  39. $all->search
  40. ));
  41. return;
  42. }
  43. }
  44. // TRANS: Message given having disabled all search subscriptions with 'track off'.
  45. $channel->output($cur, _m('Disabled all your search subscriptions.'));
  46. }
  47. }