本文整理汇总了PHP中utils::IsTransactionValid方法的典型用法代码示例。如果您正苦于以下问题:PHP utils::IsTransactionValid方法的具体用法?PHP utils::IsTransactionValid怎么用?PHP utils::IsTransactionValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils
的用法示例。
在下文中一共展示了utils::IsTransactionValid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DoUpdateObjectFromPostedForm
/**
* Updates the object form POSTED arguments, and writes it into the DB (applies a stimuli if requested)
* @param DBObject $oObj The object to update
* $param array $aAttList If set, this will limit the list of updated attributes
* @return void
*/
public function DoUpdateObjectFromPostedForm(DBObject $oObj, $aAttList = null)
{
$sTransactionId = utils::ReadPostedParam('transaction_id', '');
if (!utils::IsTransactionValid($sTransactionId)) {
throw new TransactionException();
}
$sClass = get_class($oObj);
$sStimulus = trim(utils::ReadPostedParam('apply_stimulus', ''));
$sTargetState = '';
if (!empty($sStimulus)) {
// Compute the target state
$aTransitions = $oObj->EnumTransitions();
if (!isset($aTransitions[$sStimulus])) {
throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
}
$sTargetState = $aTransitions[$sStimulus]['target_state'];
}
$oObj->UpdateObjectFromPostedForm('', $aAttList, $sTargetState);
// Optional: apply a stimulus
//
if (!empty($sStimulus)) {
if (!$oObj->ApplyStimulus($sStimulus)) {
throw new Exception("Cannot apply stimulus '{$sStimulus}' to {$oObj->GetName()}");
}
}
if ($oObj->IsModified()) {
// Record the change
//
$oObj->DBUpdate();
// Trigger ?
//
$aClasses = MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL);
$sClassList = implode(", ", CMDBSource::Quote($aClasses));
$oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnPortalUpdate AS t WHERE t.target_class IN ({$sClassList})"));
while ($oTrigger = $oSet->Fetch()) {
$oTrigger->DoActivate($oObj->ToArgs('this'));
}
$this->p("<h1>" . Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()) . "</h1>\n");
}
$bLockEnabled = MetaModel::GetConfig()->Get('concurrent_lock_enabled');
if ($bLockEnabled) {
// Release the concurrent lock, if any
$sOwnershipToken = utils::ReadPostedParam('ownership_token', null, false, 'raw_data');
if ($sOwnershipToken !== null) {
// We're done, let's release the lock
iTopOwnershipLock::ReleaseLock(get_class($oObj), $oObj->GetKey(), $sOwnershipToken);
}
}
}
示例2: DoCreateRequest
/**
* Validate the parameters and create the ticket object (based on the page's POSTed parameters)
* @param WebPage $oP The current web page for the output
* @param Organization $oUserOrg The organization of the current user
* @return void
*/
function DoCreateRequest($oP, $oUserOrg)
{
$aParameters = $oP->ReadAllParams(PORTAL_ALL_PARAMS . ',template_id');
$sTransactionId = utils::ReadPostedParam('transaction_id', '');
if (!utils::IsTransactionValid($sTransactionId)) {
$oP->add("<h1>" . Dict::S('UI:Error:ObjectAlreadyCreated') . "</h1>\n");
//ShowOngoingTickets($oP);
return;
}
// Validate the parameters
// 1) ServiceCategory
$oSearch = DBObjectSearch::FromOQL(PORTAL_VALIDATE_SERVICECATEGORY_QUERY);
$oSearch->AllowAllData();
// In case the user has the rights on his org only
$oSet = new CMDBObjectSet($oSearch, array(), array('id' => $aParameters['service_id'], 'org_id' => $oUserOrg->GetKey()));
if ($oSet->Count() != 1) {
// Invalid service for the current user !
throw new Exception("Invalid Service Category: id={$aParameters['service_id']} - count: " . $oSet->Count());
}
$oServiceCategory = $oSet->Fetch();
// 2) Service Subcategory
$oSearch = DBObjectSearch::FromOQL(PORTAL_VALIDATE_SERVICESUBCATEGORY_QUERY);
RestrictSubcategories($oSearch);
$oSearch->AllowAllData();
// In case the user has the rights on his org only
$oSet = new CMDBObjectSet($oSearch, array(), array('service_id' => $aParameters['service_id'], 'id' => $aParameters['servicesubcategory_id'], 'org_id' => $oUserOrg->GetKey()));
if ($oSet->Count() != 1) {
// Invalid subcategory
throw new Exception("Invalid ServiceSubcategory: id={$aParameters['servicesubcategory_id']} for service category " . $oServiceCategory->GetName() . "({$aParameters['service_id']}) - count: " . $oSet->Count());
}
$oServiceSubCategory = $oSet->Fetch();
$sClass = ComputeClass($oServiceSubCategory->GetKey());
$oRequest = MetaModel::NewObject($sClass);
$aAttList = array_merge(explode(',', GetConstant($sClass, 'FORM_ATTRIBUTES')), array('service_id', 'servicesubcategory_id'));
$oRequest->UpdateObjectFromPostedForm('', $aAttList);
$oRequest->Set('org_id', $oUserOrg->GetKey());
$oRequest->Set('caller_id', UserRights::GetContactId());
if (isset($aParameters['moreinfo'])) {
// There is a template, insert it into the description
$sLogAttCode = GetConstant($sClass, 'PUBLIC_LOG');
$oRequest->Set($sLogAttCode, $aParameters['moreinfo']);
}
$sTypeAttCode = GetConstant($sClass, 'TYPE');
if ($sTypeAttCode != '' && PORTAL_SET_TYPE_FROM != '') {
$oRequest->Set($sTypeAttCode, $oServiceSubCategory->Get(PORTAL_SET_TYPE_FROM));
}
if (MetaModel::IsValidAttCode($sClass, 'origin')) {
$oRequest->Set('origin', 'portal');
}
$oAttPlugin = new AttachmentPlugIn();
$oAttPlugin->OnFormSubmit($oRequest);
list($bRes, $aIssues) = $oRequest->CheckToWrite();
if ($bRes) {
if (isset($aParameters['template_id'])) {
$oTemplate = MetaModel::GetObject('Template', $aParameters['template_id']);
$sLogAttCode = GetConstant($sClass, 'PUBLIC_LOG');
$oRequest->Set($sLogAttCode, $oTemplate->GetPostedValuesAsText($oRequest) . "\n");
$oRequest->DBInsertNoReload();
$oTemplate->RecordExtraDataFromPostedForm($oRequest);
} else {
$oRequest->DBInsertNoReload();
}
$oP->add("<h1>" . Dict::Format('UI:Title:Object_Of_Class_Created', $oRequest->GetName(), MetaModel::GetName($sClass)) . "</h1>\n");
//DisplayObject($oP, $oRequest, $oUserOrg);
ShowOngoingTickets($oP);
} else {
RequestCreationForm($oP, $oUserOrg);
$sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
$oP->add_ready_script("alert('" . addslashes($sIssueDesc) . "');");
}
}
示例3: DoBulkModify
/**
* Process the reply made from a form built with DisplayBulkModifyForm
*/
public static function DoBulkModify($oP, $sClass, $aSelectedObj, $sCustomOperation, $bPreview, $sCancelUrl, $aContextData = array())
{
$aHeaders = array('form::select' => array('label' => "<input type=\"checkbox\" onClick=\"CheckAll('.selectList:not(:disabled)', this.checked);\"></input>", 'description' => Dict::S('UI:SelectAllToggle+')), 'object' => array('label' => MetaModel::GetName($sClass), 'description' => Dict::S('UI:ModifiedObject')), 'status' => array('label' => Dict::S('UI:BulkModifyStatus'), 'description' => Dict::S('UI:BulkModifyStatus+')), 'errors' => array('label' => Dict::S('UI:BulkModifyErrors'), 'description' => Dict::S('UI:BulkModifyErrors+')));
$aRows = array();
$oP->add("<div class=\"page_header\">\n");
$oP->add("<h1>" . MetaModel::GetClassIcon($sClass) . " " . Dict::Format('UI:Modify_N_ObjectsOf_Class', count($aSelectedObj), MetaModel::GetName($sClass)) . "</h1>\n");
$oP->add("</div>\n");
$oP->set_title(Dict::Format('UI:Modify_N_ObjectsOf_Class', count($aSelectedObj), $sClass));
if (!$bPreview) {
// Not in preview mode, do the update for real
$sTransactionId = utils::ReadPostedParam('transaction_id', '');
if (!utils::IsTransactionValid($sTransactionId, false)) {
throw new Exception(Dict::S('UI:Error:ObjectAlreadyUpdated'));
}
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($iLoopTimeLimit);
$oObj = MetaModel::GetObject($sClass, $iId);
$aErrors = $oObj->UpdateObjectFromPostedForm('');
$bResult = count($aErrors) == 0;
if ($bResult) {
list($bResult, $aErrors) = $oObj->CheckToWrite(true);
}
if ($bPreview) {
$sStatus = $bResult ? Dict::S('UI:BulkModifyStatusOk') : Dict::S('UI:BulkModifyStatusError');
} else {
$sStatus = $bResult ? Dict::S('UI:BulkModifyStatusModified') : Dict::S('UI:BulkModifyStatusSkipped');
}
$sCSSClass = $bResult ? HILIGHT_CLASS_NONE : HILIGHT_CLASS_CRITICAL;
$sChecked = $bResult ? 'checked' : '';
$sDisabled = $bResult ? '' : 'disabled';
$aRows[] = array('form::select' => "<input type=\"checkbox\" class=\"selectList\" {$sChecked} {$sDisabled}\"></input>", 'object' => $oObj->GetHyperlink(), 'status' => $sStatus, 'errors' => '<p>' . ($bResult ? '' : implode('</p><p>', $aErrors)) . '</p>', '@class' => $sCSSClass);
if ($bResult && !$bPreview) {
$oObj->DBUpdate();
}
}
set_time_limit($iPreviousTimeLimit);
$oP->Table($aHeaders, $aRows);
if ($bPreview) {
$sFormAction = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php';
// No parameter in the URL, the only parameter will be the ones passed through the form
// Form to submit:
$oP->add("<form method=\"post\" action=\"{$sFormAction}\" enctype=\"multipart/form-data\">\n");
$aDefaults = utils::ReadParam('default', array());
$oAppContext = new ApplicationContext();
$oP->add($oAppContext->GetForForm());
foreach ($aContextData as $sKey => $value) {
$oP->add("<input type=\"hidden\" name=\"{$sKey}\" value=\"{$value}\">\n");
}
$oP->add("<input type=\"hidden\" name=\"operation\" value=\"{$sCustomOperation}\">\n");
$oP->add("<input type=\"hidden\" name=\"class\" value=\"{$sClass}\">\n");
$oP->add("<input type=\"hidden\" name=\"preview_mode\" value=\"0\">\n");
$oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"" . utils::GetNewTransactionId() . "\">\n");
$oP->add("<button type=\"button\" class=\"action cancel\" onClick=\"window.location.href='{$sCancelUrl}'\">" . Dict::S('UI:Button:Cancel') . "</button> \n");
$oP->add("<button type=\"submit\" class=\"action\"><span>" . Dict::S('UI:Button:ModifyAll') . "</span></button>\n");
foreach ($_POST as $sKey => $value) {
if (preg_match('/attr_(.+)/', $sKey, $aMatches)) {
// Beware: some values (like durations) are passed as arrays
if (is_array($value)) {
foreach ($value as $vKey => $vValue) {
$oP->add("<input type=\"hidden\" name=\"{$sKey}[{$vKey}]\" value=\"" . htmlentities($vValue, ENT_QUOTES, 'UTF-8') . "\">\n");
}
} else {
$oP->add("<input type=\"hidden\" name=\"{$sKey}\" value=\"" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "\">\n");
}
}
}
$oP->add("</form>\n");
} else {
$oP->add("<button type=\"button\" onClick=\"window.location.href='{$sCancelUrl}'\" class=\"action\"><span>" . Dict::S('UI:Button:Done') . "</span></button>\n");
}
}
示例4: ApplicationException
$sTransactionId = utils::ReadPostedParam('transaction_id', '');
$sStimulus = utils::ReadPostedParam('stimulus', '');
if (empty($sClass) || empty($id) || empty($sStimulus)) {
throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus'));
}
$oObj = MetaModel::GetObject($sClass, $id, false);
if ($oObj != null) {
$aTransitions = $oObj->EnumTransitions();
$aStimuli = MetaModel::EnumStimuli($sClass);
$sMessage = '';
$sSeverity = 'ok';
$bDisplayDetails = true;
if (!isset($aTransitions[$sStimulus])) {
throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
}
if (!utils::IsTransactionValid($sTransactionId)) {
$sMessage = Dict::S('UI:Error:ObjectAlreadyUpdated');
$sSeverity = 'info';
} else {
$sActionLabel = $aStimuli[$sStimulus]->GetLabel();
$sActionDetails = $aStimuli[$sStimulus]->GetDescription();
$aTransition = $aTransitions[$sStimulus];
$sTargetState = $aTransition['target_state'];
$aTargetStates = MetaModel::EnumStates($sClass);
$aTargetState = $aTargetStates[$sTargetState];
$aExpectedAttributes = $aTargetState['attribute_list'];
$aDetails = array();
$aErrors = array();
foreach ($aExpectedAttributes as $sAttCode => $iExpectCode) {
$iFlags = $oObj->GetAttributeFlags($sAttCode);
if ($iExpectCode & (OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT) || $oObj->Get($sAttCode) == '') {