main.itop-tickets.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. class ProcessSLAResponseTicket implements iBackgroundProcess
  19. {
  20. public function GetPeriodicity()
  21. {
  22. return 2; // seconds
  23. }
  24. public function Process($iTimeLimit)
  25. {
  26. $oMyChange = new CMDBChange();
  27. $oMyChange->Set("date", time());
  28. $oMyChange->Set("userinfo", "Automatic updates");
  29. $iChangeId = $oMyChange->DBInsertNoReload();
  30. $aReport = array();
  31. $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'new\' AND tto_escalation_deadline <= NOW()'));
  32. while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch())
  33. {
  34. $oToEscalate->ApplyStimulus('ev_timeout');
  35. //$oToEscalate->Set('tto_escalation_deadline', null);
  36. $oToEscalate->DBUpdateTracked($oMyChange, true);
  37. $aReport['reached TTO ESCALATION deadline'][] = $oToEscalate->Get('ref');
  38. }
  39. $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'assigned\' AND ttr_escalation_deadline <= NOW()'));
  40. while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch())
  41. {
  42. $oToEscalate->ApplyStimulus('ev_timeout');
  43. //$oToEscalate->Set('ttr_escalation_deadline', null);
  44. $oToEscalate->DBUpdateTracked($oMyChange, true);
  45. $aReport['reached TTR ESCALATION deadline'][] = $oToEscalate->Get('ref');
  46. }
  47. $oSet = new DBObjectSet(DBObjectSearch::FromOQL('SELECT ResponseTicket WHERE status = \'resolved\' AND closure_deadline <= NOW()'));
  48. while ((time() < $iTimeLimit) && $oToEscalate = $oSet->Fetch())
  49. {
  50. $oToEscalate->ApplyStimulus('ev_close');
  51. //$oToEscalate->Set('closure_deadline', null);
  52. $oToEscalate->DBUpdateTracked($oMyChange, true);
  53. $aReport['reached closure deadline'][] = $oToEscalate->Get('ref');
  54. }
  55. $aStringReport = array();
  56. foreach ($aReport as $sOperation => $aTicketRefs)
  57. {
  58. if (count($aTicketRefs) > 0)
  59. {
  60. $aStringReport[] = $sOperation.': '.count($aTicketRefs).' {'.implode(', ', $aTicketRefs).'}';
  61. }
  62. }
  63. if (count($aStringReport) == 0)
  64. {
  65. return "No ticket to process";
  66. }
  67. else
  68. {
  69. return "Some tickets reached the limit - ".implode('; ', $aStringReport);
  70. }
  71. }
  72. }
  73. ?>