Sfoglia il codice sorgente

#935 Better support of CheckToWrite() in object's transitions, improved by checking the data sooner for a consistent workflow.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3183 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 11 anni fa
parent
commit
87eb366519
1 ha cambiato i file con 25 aggiunte e 10 eliminazioni
  1. 25 10
      pages/UI.php

+ 25 - 10
pages/UI.php

@@ -1445,24 +1445,39 @@ EOF
 					}
 				}
 				
-				$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);
+				$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);				
 				
 				if (count($aErrors) == 0)
 				{
 					$sIssues = '';
-					try
+					$bApplyStimulus = true;
+					list($bRes, $aIssues) = $oObj->CheckToWrite(); // Check before trying to write the object
+					if ($bRes)
+					{
+						try
+						{
+							$bApplyStimulus = $oObj->ApplyStimulus($sStimulus); // will write the object in the DB
+						}
+						catch(CoreException $e)
+						{
+							// Rollback to the previous state... by reloading the object from the database and applying the modifications again
+							$oObj = MetaModel::GetObject(get_class($oObj), $oObj->GetKey());
+							$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);
+							$aData = $e->getContextData();
+							$sIssues = (array_key_exists('issues', $aData)) ? $aData['issues'] : 'Unknown error...';
+						}
+					}
+					else
 					{
-						$sPreviousState = $oObj->GetState();
-						$bApplyStimulus = $oObj->ApplyStimulus($sStimulus); // will write the object in the DB
+						$sIssues = implode(' ', $aIssues);
 					}
-					catch(CoreException $e)
+					
+					if (!$bApplyStimulus)
 					{
-						// Rollback to the previous state...
-						$oObj->Set(MetaModel::GetStateAttributeCode(get_class($oObj)), $sPreviousState);
-						$aData = $e->getContextData();
-						$sIssues = (array_key_exists('issues', $aData)) ? $aData['issues'] : 'Unknown error...';
+						$sMessage = Dict::S('UI:FailedToApplyStimuli');
+						$sSeverity = 'error';								
 					}
-					if ($sIssues != '')
+					else if ($sIssues != '')
 					{
 						$bDisplayDetails = false;
 						// Found issues, explain and give the user a second chance