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

SVN:trunk[901]
This commit is contained in:
Denis Flaven
2010-10-19 13:42:54 +00:00
parent e9304bbcfa
commit ff80b06ea2
3 changed files with 40 additions and 9 deletions

View File

@@ -46,15 +46,41 @@ 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
* will return false
* @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
*/
public static function IsTransactionValid($id)
public static function IsTransactionValid($id, $bRemoveTransaction = true)
{
$bResult = false;
if (isset($_SESSION['transactions']))
{
// Strictly speaking, the eight lines below should be grouped together
// inside the same critical section as above
// sem_acquire($rSemIdentified);
if (isset($_SESSION['transactions'][$id]))
{
$bResult = true;
if ($bRemoveTransaction)
{
unset($_SESSION['transactions'][$id]);
}
}
// sem_release($rSemIdentified);
}
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
@@ -62,12 +88,10 @@ class privUITransaction
// sem_acquire($rSemIdentified);
if (isset($_SESSION['transactions'][$id]))
{
$bResult = true;
unset($_SESSION['transactions'][$id]);
}
// sem_release($rSemIdentified);
}
return $bResult;
}
}
}
?>

View File

@@ -157,9 +157,14 @@ class utils
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)

View File

@@ -881,7 +881,7 @@ try
$oP->set_title(Dict::S('UI:ErrorPageTitle'));
$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->p("<strong>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</strong>\n");
@@ -916,6 +916,7 @@ try
$oMyChange->Set("userinfo", $sUserString);
$iChangeId = $oMyChange->DBInsert();
$oObj->DBUpdateTracked($oMyChange);
utils::RemoveTransaction($sTransactionId);
$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'));
}
if (!utils::IsTransactionValid($sTransactionId))
if (!utils::IsTransactionValid($sTransactionId, false))
{
$oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyCreated')."</strong>\n");
}
@@ -1051,6 +1052,7 @@ try
$oMyChange->Set("userinfo", $sUserString);
$iChangeId = $oMyChange->DBInsert();
$oObj->DBInsertTracked($oMyChange);
utils::RemoveTransaction($sTransactionId);
$oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
$oP->add("<h1>".Dict::Format('UI:Title:Object_Of_Class_Created', $oObj->GetName(), $sClassLabel)."</h1>\n");
$oObj->DisplayDetails($oP);