浏览代码

#727: prevent a crash in cron.php

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2743 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 年之前
父节点
当前提交
0767f53ebf
共有 2 个文件被更改,包括 28 次插入17 次删除
  1. 5 0
      core/dbobject.class.php
  2. 23 17
      webservices/cron.php

+ 5 - 0
core/dbobject.class.php

@@ -1785,6 +1785,11 @@ abstract class DBObject
 		MyHelpers::CheckKeyInArray('object lifecycle stimulus', $sStimulusCode, MetaModel::EnumStimuli(get_class($this)));
 		MyHelpers::CheckKeyInArray('object lifecycle stimulus', $sStimulusCode, MetaModel::EnumStimuli(get_class($this)));
 
 
 		$aStateTransitions = $this->EnumTransitions();
 		$aStateTransitions = $this->EnumTransitions();
+		if (!array_key_exists($sStimulusCode, $aStateTransitions))
+		{
+			// This simulus has no effect in the current state... do nothing
+			return;
+		}
 		$aTransitionDef = $aStateTransitions[$sStimulusCode];
 		$aTransitionDef = $aStateTransitions[$sStimulusCode];
 
 
 		// Change the state before proceeding to the actions, this is necessary because an action might
 		// Change the state before proceeding to the actions, this is necessary because an action might

+ 23 - 17
webservices/cron.php

@@ -63,25 +63,31 @@ function UsageAndExit($oP)
 
 
 function RunTask($oBackgroundProcess, BackgroundTask $oTask, $oStartDate, $iTimeLimit)
 function RunTask($oBackgroundProcess, BackgroundTask $oTask, $oStartDate, $iTimeLimit)
 {
 {
-	$oNow = new DateTime();
-	$fStart = microtime(true);
-	$sMessage = $oBackgroundProcess->Process($iTimeLimit);
-	$fDuration = microtime(true) - $fStart;
-	$oTask->ComputeDurations($fDuration);
-	$oTask->Set('latest_run_date', $oNow->format('Y-m-d H:i:s'));
-	$oPlannedStart = new DateTime($oTask->Get('latest_run_date'));
-	// Let's assume that the task was started exactly when planned so that the schedule does no shift each time
-	// this allows to schedule a task everyday "around" 11:30PM for example
-	$oPlannedStart->modify('+'.$oBackgroundProcess->GetPeriodicity().' seconds');
-	$oEnd = new DateTime();
-	if ($oPlannedStart->format('U') < $oEnd->format('U'))
+	try
 	{
 	{
-		// Huh, next planned start is already in the past, shift it of the periodicity !
-		$oPlannedStart = $oEnd->modify('+'.$oBackgroundProcess->GetPeriodicity().' seconds');
+		$oNow = new DateTime();
+		$fStart = microtime(true);
+		$sMessage = $oBackgroundProcess->Process($iTimeLimit);
+		$fDuration = microtime(true) - $fStart;
+		$oTask->ComputeDurations($fDuration);
+		$oTask->Set('latest_run_date', $oNow->format('Y-m-d H:i:s'));
+		$oPlannedStart = new DateTime($oTask->Get('latest_run_date'));
+		// Let's assume that the task was started exactly when planned so that the schedule does no shift each time
+		// this allows to schedule a task everyday "around" 11:30PM for example
+		$oPlannedStart->modify('+'.$oBackgroundProcess->GetPeriodicity().' seconds');
+		$oEnd = new DateTime();
+		if ($oPlannedStart->format('U') < $oEnd->format('U'))
+		{
+			// Huh, next planned start is already in the past, shift it of the periodicity !
+			$oPlannedStart = $oEnd->modify('+'.$oBackgroundProcess->GetPeriodicity().' seconds');
+		}
+		$oTask->Set('next_run_date', $oPlannedStart->format('Y-m-d H:i:s'));
+		$oTask->DBUpdate();
+	}
+	catch(Exception $e)
+	{
+		$sMessage = 'Processing failed, the following exception occured: '.$e->getMessage();
 	}
 	}
-	$oTask->Set('next_run_date', $oPlannedStart->format('Y-m-d H:i:s'));
-	$oTask->DBUpdate();
-	
 	return $sMessage;	
 	return $sMessage;	
 }
 }