PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/root/usr/share/nethesis/NethServer/Module/Mail/Queue/Flush.php

https://github.com/nethesis/nethserver-mail-common
PHP | 69 lines | 34 code | 7 blank | 28 comment | 5 complexity | 7967d02ee6215b673756f0662b0014aa MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. namespace NethServer\Module\Mail\Queue;
  3. /*
  4. * Copyright (C) 2012 Nethesis S.r.l.
  5. *
  6. * This script is part of NethServer.
  7. *
  8. * NethServer is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * NethServer is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with NethServer. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * Flush mail queue, trying to deliver all queued messages
  23. *
  24. * @author Davide Principi <davide.principi@nethesis.it>
  25. * @since 1.0
  26. */
  27. class Flush extends \Nethgui\Controller\Table\AbstractAction
  28. {
  29. /**
  30. *
  31. * @var integer
  32. */
  33. private $messageCount = 0;
  34. public function process()
  35. {
  36. if ($this->getRequest()->isMutation()) {
  37. $process = $this->getPlatform()->exec('/usr/bin/sudo /usr/sbin/postqueue -f');
  38. if ($process->getExitCode() != 0) {
  39. $this->getLog()->error(sprintf("%s: postqueue -f command failed - %s", __CLASS__, $process->getOutput()));
  40. }
  41. }
  42. }
  43. public function bind(\Nethgui\Controller\RequestInterface $request)
  44. {
  45. parent::bind($request);
  46. if ( ! $this->getRequest()->isMutation()) {
  47. $this->messageCount = count($this->getAdapter());
  48. }
  49. }
  50. public function prepareView(\Nethgui\View\ViewInterface $view)
  51. {
  52. parent::prepareView($view);
  53. $view['messageCount'] = $this->messageCount;
  54. }
  55. public function nextPath()
  56. {
  57. if ($this->getRequest()->isMutation()) {
  58. return '/Mail/Queue/read';
  59. }
  60. return parent::nextPath();
  61. }
  62. }