searchsubuntrackcommand.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. class SearchSubUntrackCommand extends Command
  3. {
  4. var $keyword = null;
  5. function __construct($user, $keyword)
  6. {
  7. parent::__construct($user);
  8. $this->keyword = $keyword;
  9. }
  10. function handle($channel)
  11. {
  12. $cur = $this->user;
  13. $searchsub = SearchSub::pkeyGet(array('search' => $this->keyword,
  14. 'profile_id' => $cur->id));
  15. if (!$searchsub) {
  16. // TRANS: Error text shown a user tries to untrack a search query they're not subscribed to.
  17. // TRANS: %s is the keyword for the search.
  18. $channel->error($cur, sprintf(_m('You are not tracking the search "%s".'), $this->keyword));
  19. return;
  20. }
  21. try {
  22. SearchSub::cancel($cur->getProfile(), $this->keyword);
  23. } catch (Exception $e) {
  24. // TRANS: Message given having failed to cancel a search subscription by untrack command.
  25. // TRANS: %s is the keyword for the query.
  26. $channel->error($cur, sprintf(_m('Could not end a search subscription for query "%s".'),
  27. $this->keyword));
  28. return;
  29. }
  30. // TRANS: Message given having removed a search subscription by untrack command.
  31. // TRANS: %s is the keyword for the search.
  32. $channel->output($cur, sprintf(_m('You are no longer subscribed to the search "%s".'),
  33. $this->keyword));
  34. }
  35. }