瀏覽代碼

No time limit for long operations like: Bulk delete, CSV import (interactive) and Bulk modify

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2946 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 年之前
父節點
當前提交
8a3f7b2104
共有 4 個文件被更改,包括 34 次插入6 次删除
  1. 4 1
      application/cmdbabstract.class.inc.php
  2. 5 1
      core/bulkchange.class.inc.php
  3. 17 1
      core/dbobject.class.php
  4. 8 3
      core/deletionplan.class.inc.php

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

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2012 Combodo SARL
+// Copyright (C) 2010-2013 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -3212,8 +3212,10 @@ EOF
 			}
 			utils::RemoveTransaction($sTransactionId);
 		}
+		$iPreviousTimeLimit = ini_get('max_execution_time');
 		foreach($aSelectedObj as $iId)
 		{
+			set_time_limit(5);
 			$oObj = MetaModel::GetObject($sClass, $iId);
 			$aErrors = $oObj->UpdateObjectFromPostedForm('');
 			$bResult = (count($aErrors) == 0);
@@ -3244,6 +3246,7 @@ EOF
 				$oObj->DBUpdate();
 			}
 		}
+		set_time_limit($iPreviousTimeLimit);
 		$oP->Table($aHeaders, $aRows);
 		if ($bPreview)
 		{

+ 5 - 1
core/bulkchange.class.inc.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2012 Combodo SARL
+// Copyright (C) 2010-2013 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -788,8 +788,10 @@ class BulkChange
 		{
 			$aVisited = array();
 		}
+		$iPreviousTimeLimit = ini_get('max_execution_time');
 		foreach($this->m_aData as $iRow => $aRowData)
 		{
+			set_time_limit(5);
 			if (isset($aResult[$iRow]["__STATUS__"]))
 			{
 				// An issue at the earlier steps - skip the rest
@@ -908,11 +910,13 @@ class BulkChange
 				$iObj = $oObj->GetKey();
 				if (!in_array($iObj, $aVisited))
 				{
+					set_time_limit(5);
 					$iRow++;
 					$this->UpdateMissingObject($aResult, $iRow, $oObj, $oChange);
 				}
 			}
 		}
+		set_time_limit($iPreviousTimeLimit);
 
 		// Fill in the blanks - the result matrix is expected to be 100% complete
 		//

+ 17 - 1
core/dbobject.class.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2012 Combodo SARL
+// Copyright (C) 2010-2013 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -1742,6 +1742,10 @@ abstract class DBObject
 		}
 		else
 		{
+			// 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');
+
 			foreach ($oDeletionPlan->ListDeletes() as $sClass => $aToDelete)
 			{
 				foreach ($aToDelete as $iId => $aData)
@@ -1753,6 +1757,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);
 						$oToDelete->DBDeleteSingleObject();
 					}
 				}
@@ -1766,10 +1771,13 @@ abstract class DBObject
 					foreach ($aData['attributes'] as $sRemoteExtKey => $aRemoteAttDef)
 					{
 						$oToUpdate->Set($sRemoteExtKey, $aData['values'][$sRemoteExtKey]);
+						set_time_limit(5);
 						$oToUpdate->DBUpdate();
 					}
 				}
 			}
+
+			set_time_limit($iPreviousTimeLimit);
 		}
 
 		return $oDeletionPlan;
@@ -2236,10 +2244,17 @@ abstract class DBObject
 		$oDeletionPlan->SetDeletionIssues($this, $this->m_aDeleteIssues, $this->m_bSecurityIssue);
 	
 		$aDependentObjects = $this->GetReferencingObjects(true /* allow all data */);
+
+		// 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');
+
 		foreach ($aDependentObjects as $sRemoteClass => $aPotentialDeletes)
 		{
 			foreach ($aPotentialDeletes as $sRemoteExtKey => $aData)
 			{
+				set_time_limit(5);
+
 				$oAttDef = $aData['attribute'];
 				$iDeletePropagationOption = $oAttDef->GetDeletionPropagationOption();
 				$oDepSet = $aData['objects'];
@@ -2269,6 +2284,7 @@ abstract class DBObject
 				}
 			}
 		}
+		set_time_limit($iPreviousTimeLimit);
 	}
 
 	/**

+ 8 - 3
core/deletionplan.class.inc.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2012 Combodo SARL
+// Copyright (C) 2010-2013 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -20,7 +20,7 @@
 /**
  * Algorithm to delete object(s) and maintain data integrity
  *
- * @copyright   Copyright (C) 2010-2012 Combodo SARL
+ * @copyright   Copyright (C) 2010-2013 Combodo SARL
  * @license     http://opensource.org/licenses/AGPL-3.0
  */
 
@@ -107,10 +107,15 @@ 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');
+
 		foreach($this->m_aToUpdate as $sClass => $aToUpdate)
 		{
 			foreach($aToUpdate as $iId => $aData)
 			{
+				set_time_limit(5);
 				$this->m_iToUpdate++;
 
 				$oObject = $aData['to_reset'];
@@ -134,9 +139,9 @@ class DeletionPlan
 						$this->m_bFoundSecurityIssue = true;
 					}
 				}
-
 			}
 		}
+		set_time_limit($iPreviousTimeLimit);
 	}
 
 	public function GetIssues()