Procházet zdrojové kódy

#867 (and #907 as a dup') De-harcode set_time_limit (per loop) in lengthy operations. Default value is 30 seconds (per loop), configurable via the new parameter "max_execution_time_per_loop", instead of 5 seconds previously.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3144 a333f486-631f-4898-b8df-5754b55c2be0
dflaven před 11 roky
rodič
revize
f060c7d25d

+ 2 - 1
application/cmdbabstract.class.inc.php

@@ -3223,9 +3223,10 @@ EOF
 			utils::RemoveTransaction($sTransactionId);
 		}
 		$iPreviousTimeLimit = ini_get('max_execution_time');
+		$iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
 		foreach($aSelectedObj as $iId)
 		{
-			set_time_limit(5);
+			set_time_limit($iLoopTimeLimit);
 			$oObj = MetaModel::GetObject($sClass, $iId);
 			$aErrors = $oObj->UpdateObjectFromPostedForm('');
 			$bResult = (count($aErrors) == 0);

+ 3 - 2
core/bulkchange.class.inc.php

@@ -789,9 +789,10 @@ class BulkChange
 			$aVisited = array();
 		}
 		$iPreviousTimeLimit = ini_get('max_execution_time');
+		$iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
 		foreach($this->m_aData as $iRow => $aRowData)
 		{
-			set_time_limit(5);
+			set_time_limit($iLoopTimeLimit);
 			if (isset($aResult[$iRow]["__STATUS__"]))
 			{
 				// An issue at the earlier steps - skip the rest
@@ -910,7 +911,7 @@ class BulkChange
 				$iObj = $oObj->GetKey();
 				if (!in_array($iObj, $aVisited))
 				{
-					set_time_limit(5);
+					set_time_limit($iLoopTimeLimit);
 					$iRow++;
 					$this->UpdateMissingObject($aResult, $iRow, $oObj, $oChange);
 				}

+ 9 - 0
core/config.class.inc.php

@@ -700,6 +700,15 @@ class Config
 			'source_of_value' => '',
 			'show_in_conf_sample' => true,
 		),
+		'max_execution_time_per_loop' => array(
+			'type' => 'integer',
+			'description' => 'Maximum execution time requested, per loop, during bulk operations. Zero means no limit.',
+			// examples... not used
+			'default' => 30,
+			'value' => 30,
+			'source_of_value' => '',
+			'show_in_conf_sample' => false,
+		),
 	);
 
 	public function IsProperty($sPropCode)

+ 14 - 4
core/dbobject.class.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2013 Combodo SARL
+// Copyright (C) 2010-2014 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -1828,6 +1828,11 @@ abstract class DBObject
 	//
 	public function DBDelete(&$oDeletionPlan = null)
 	{
+		static $iLoopTimeLimit = null;
+		if ($iLoopTimeLimit == null)
+		{
+			$iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
+		}
 		if (is_null($oDeletionPlan))
 		{
 			$oDeletionPlan = new DeletionPlan();
@@ -1857,7 +1862,7 @@ abstract class DBObject
 					// As a temporary fix: delete only the objects that are still to be deleted...
 					if ($oToDelete->m_bIsInDB)
 					{
-						set_time_limit(5);
+						set_time_limit($iLoopTimeLimit);
 						$oToDelete->DBDeleteSingleObject();
 					}
 				}
@@ -1871,7 +1876,7 @@ abstract class DBObject
 					foreach ($aData['attributes'] as $sRemoteExtKey => $aRemoteAttDef)
 					{
 						$oToUpdate->Set($sRemoteExtKey, $aData['values'][$sRemoteExtKey]);
-						set_time_limit(5);
+						set_time_limit($iLoopTimeLimit);
 						$oToUpdate->DBUpdate();
 					}
 				}
@@ -2326,6 +2331,11 @@ abstract class DBObject
 
 	private function MakeDeletionPlan(&$oDeletionPlan, $aVisited = array(), $iDeleteOption = null)
 	{
+		static $iLoopTimeLimit = null;
+		if ($iLoopTimeLimit == null)
+		{
+			$iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
+		}
 		$sClass = get_class($this);
 		$iThisId = $this->GetKey();
 
@@ -2359,7 +2369,7 @@ abstract class DBObject
 		{
 			foreach ($aPotentialDeletes as $sRemoteExtKey => $aData)
 			{
-				set_time_limit(5);
+				set_time_limit($iLoopTimeLimit);
 
 				$oAttDef = $aData['attribute'];
 				$iDeletePropagationOption = $oAttDef->GetDeletionPropagationOption();

+ 2 - 2
core/deletionplan.class.inc.php

@@ -110,12 +110,12 @@ class DeletionPlan
 		// Getting and setting time limit are not symetric:
 		// www.php.net/manual/fr/function.set-time-limit.php#72305
 		$iPreviousTimeLimit = ini_get('max_execution_time');
-
+		$iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop');
 		foreach($this->m_aToUpdate as $sClass => $aToUpdate)
 		{
 			foreach($aToUpdate as $iId => $aData)
 			{
-				set_time_limit(5);
+				set_time_limit($iLoopTimeLimit);
 				$this->m_iToUpdate++;
 
 				$oObject = $aData['to_reset'];