Browse Source

- Fixed Trac #284: do not "consume" a transaction until it really worked.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@901 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 14 years ago
parent
commit
fdfde39a8b
3 changed files with 39 additions and 8 deletions
  1. 28 4
      application/transaction.class.inc.php
  2. 7 2
      application/utils.inc.php
  3. 4 2
      pages/UI.php

+ 28 - 4
application/transaction.class.inc.php

@@ -46,28 +46,52 @@ class privUITransaction
 	}
 	}
 
 
 	/**
 	/**
-	 * Check whether a transaction is valid or not and remove the valid transaction from
+	 * Check whether a transaction is valid or not and (optionally) remove the valid transaction from
 	 * the session so that another call to IsTransactionValid for the same transaction id
 	 * the session so that another call to IsTransactionValid for the same transaction id
 	 * will return false
 	 * will return false
 	 * @param int $id Identifier of the transaction, as returned by GetNewTransactionId
 	 * @param int $id Identifier of the transaction, as returned by GetNewTransactionId
+	 * @param bool $bRemoveTransaction True if the transaction must be removed
 	 * @return bool True if the transaction is valid, false otherwise
 	 * @return bool True if the transaction is valid, false otherwise
 	 */	
 	 */	
-	public static function IsTransactionValid($id)
+	public static function IsTransactionValid($id, $bRemoveTransaction = true)
 	{
 	{
 		$bResult = false;
 		$bResult = false;
 		if (isset($_SESSION['transactions']))
 		if (isset($_SESSION['transactions']))
 		{
 		{
-			// Strictly speaking, the three lines below should be grouped together
+			// Strictly speaking, the eight lines below should be grouped together
 			// inside the same critical section as above
 			// inside the same critical section as above
 			// sem_acquire($rSemIdentified);
 			// sem_acquire($rSemIdentified);
 			if (isset($_SESSION['transactions'][$id]))
 			if (isset($_SESSION['transactions'][$id]))
 			{
 			{
 				$bResult = true;
 				$bResult = true;
-				unset($_SESSION['transactions'][$id]);
+				if ($bRemoveTransaction)
+				{
+					unset($_SESSION['transactions'][$id]);
+				}
 			}
 			}
 			// sem_release($rSemIdentified);
 			// sem_release($rSemIdentified);
 		}
 		}
 		return $bResult;
 		return $bResult;
 	}
 	}
+	
+	/**
+	 * Removes the transaction specified by its id
+	 * @param int $id The Identifier (as returned by GetNewTranscationId) of the transaction to be removed.
+	 * @return void
+	 */
+	public static function RemoveTransaction($id)
+	{
+		if (isset($_SESSION['transactions']))
+		{
+			// Strictly speaking, the three lines below should be grouped together
+			// inside the same critical section as above
+			// sem_acquire($rSemIdentified);
+			if (isset($_SESSION['transactions'][$id]))
+			{
+				unset($_SESSION['transactions'][$id]);
+			}
+			// sem_release($rSemIdentified);
+		}		
+	}
 }
 }
 ?>
 ?>

+ 7 - 2
application/utils.inc.php

@@ -157,9 +157,14 @@ class utils
 		return privUITransaction::GetNewTransactionId();
 		return privUITransaction::GetNewTransactionId();
 	}
 	}
 	
 	
-	public static function IsTransactionValid($sId)
+	public static function IsTransactionValid($sId, $bRemoveTransaction = true)
 	{
 	{
-		return privUITransaction::IsTransactionValid($sId);
+		return privUITransaction::IsTransactionValid($sId, $bRemoveTransaction);
+	}
+	
+	public static function RemoveTransaction($sId)
+	{
+		return privUITransaction::RemoveTransaction($sId);
 	}
 	}
 	
 	
 	public static function ReadFromFile($sFileName)
 	public static function ReadFromFile($sFileName)

+ 4 - 2
pages/UI.php

@@ -881,7 +881,7 @@ try
 				$oP->set_title(Dict::S('UI:ErrorPageTitle'));
 				$oP->set_title(Dict::S('UI:ErrorPageTitle'));
 				$oP->P(Dict::S('UI:ObjectDoesNotExist'));
 				$oP->P(Dict::S('UI:ObjectDoesNotExist'));
 			}
 			}
-			elseif (!utils::IsTransactionValid($sTransactionId))
+			elseif (!utils::IsTransactionValid($sTransactionId, false))
 			{
 			{
 				$oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
 				$oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetName(), $sClassLabel));
 				$oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</strong>\n");
 				$oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</strong>\n");
@@ -916,6 +916,7 @@ try
 						$oMyChange->Set("userinfo", $sUserString);
 						$oMyChange->Set("userinfo", $sUserString);
 						$iChangeId = $oMyChange->DBInsert();
 						$iChangeId = $oMyChange->DBInsert();
 						$oObj->DBUpdateTracked($oMyChange);
 						$oObj->DBUpdateTracked($oMyChange);
+						utils::RemoveTransaction($sTransactionId);
 			
 			
 						$oP->p(Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
 						$oP->p(Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()));
 					}
 					}
@@ -1021,7 +1022,7 @@ try
 		{
 		{
 			throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
 			throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
 		}
 		}
-		if (!utils::IsTransactionValid($sTransactionId))
+		if (!utils::IsTransactionValid($sTransactionId, false))
 		{
 		{
 			$oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyCreated')."</strong>\n");
 			$oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyCreated')."</strong>\n");
 		}
 		}
@@ -1051,6 +1052,7 @@ try
 				$oMyChange->Set("userinfo", $sUserString);
 				$oMyChange->Set("userinfo", $sUserString);
 				$iChangeId = $oMyChange->DBInsert();
 				$iChangeId = $oMyChange->DBInsert();
 				$oObj->DBInsertTracked($oMyChange);
 				$oObj->DBInsertTracked($oMyChange);
+				utils::RemoveTransaction($sTransactionId);
 				$oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
 				$oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
 				$oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oObj->GetName(), $sClassLabel)."</h1>\n");
 				$oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oObj->GetName(), $sClassLabel)."</h1>\n");
 				$oObj->DisplayDetails($oP);
 				$oObj->DisplayDetails($oP);