main.itop-tickets.php 2.8 KB

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