diff --git a/core/inlineimage.class.inc.php b/core/inlineimage.class.inc.php index 7b6297410..05b75ddc8 100644 --- a/core/inlineimage.class.inc.php +++ b/core/inlineimage.class.inc.php @@ -176,26 +176,32 @@ class InlineImage extends DBObject $sOQL = 'SELECT InlineImage WHERE temp_id = :temp_id'; $oSearch = DBObjectSearch::FromOQL($sOQL); $oSet = new DBObjectSet($oSearch, array(), array('temp_id' => $sTempId)); + $aInlineImagesId = array(); while($oInlineImage = $oSet->Fetch()) { + $aInlineImagesId[] = $oInlineImage->GetKey(); $oInlineImage->SetItem($oObject); $oInlineImage->Set('temp_id', ''); $oInlineImage->DBUpdate(); } + IssueLog::Trace('FinalizeInlineImages (see $aInlineImagesId for the id list)', 'InlineImage', array( + '$sObjectClass' => get_class($oObject), + '$sTransactionId' => $iTransactionId, + '$sTempId' => $sTempId, + '$aInlineImagesId' => $aInlineImagesId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + )); } -// For tracing issues with Inline Images... but beware not all updates are interactive, so this trace happens when creating objects non-interactively (REST, Synchro...) -// else -// { -// IssueLog::Error('InlineImage: Error during FinalizeInlineImages(), no transaction ID for object '.get_class($oObject).'#'.$oObject->GetKey().'.'); -// -// IssueLog::Error('|- Call stack:'); -// $oException = new Exception(); -// $sStackTrace = $oException->getTraceAsString(); -// IssueLog::Error($sStackTrace); -// -// IssueLog::Error('|- POST vars:'); -// IssueLog::Error(print_r($_POST, true)); -// } + else + { + IssueLog::Trace('FinalizeInlineImages "error" $iTransactionId is null', 'InlineImage', array( + '$sObjectClass' => get_class($oObject), + '$sTransactionId' => $iTransactionId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + )); + } } /** @@ -208,10 +214,18 @@ class InlineImage extends DBObject $sOQL = 'SELECT InlineImage WHERE temp_id = :temp_id'; $oSearch = DBObjectSearch::FromOQL($sOQL); $oSet = new DBObjectSet($oSearch, array(), array('temp_id' => $sTempId)); + $aInlineImagesId = array(); while($oInlineImage = $oSet->Fetch()) { + $aInlineImagesId[] = $oInlineImage->GetKey(); $oInlineImage->DBDelete(); } + IssueLog::Trace('OnFormCancel', 'InlineImage', array( + '$sTempId' => $sTempId, + '$aInlineImagesId' => $aInlineImagesId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + )); } /** @@ -548,6 +562,61 @@ EOF JS ; } + + protected function AfterInsert() + { + IssueLog::Trace(__METHOD__, 'InlineImage', array( + 'id' => $this->GetKey(), + 'expire' => $this->Get('expire'), + 'temp_id' => $this->Get('temp_id'), + 'item_class' => $this->Get('item_class'), + 'item_id' => $this->Get('item_id'), + 'item_org_id' => $this->Get('item_org_id'), + 'secret' => $this->Get('secret'), + 'user' => $sUser = UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + + parent::AfterInsert(); + } + + protected function AfterUpdate() + { + IssueLog::Trace(__METHOD__, 'InlineImage', array( + 'id' => $this->GetKey(), + 'expire' => $this->Get('expire'), + 'temp_id' => $this->Get('temp_id'), + 'item_class' => $this->Get('item_class'), + 'item_id' => $this->Get('item_id'), + 'item_org_id' => $this->Get('item_org_id'), + 'secret' => $this->Get('secret'), + 'user' => $sUser = UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + + parent::AfterUpdate(); + } + + protected function AfterDelete() + { + IssueLog::Trace(__METHOD__, 'InlineImage', array( + 'id' => $this->GetKey(), + 'expire' => $this->Get('expire'), + 'temp_id' => $this->Get('temp_id'), + 'item_class' => $this->Get('item_class'), + 'item_id' => $this->Get('item_id'), + 'item_org_id' => $this->Get('item_org_id'), + 'secret' => $this->Get('secret'), + 'user' => $sUser = UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + + parent::AfterDelete(); + } + } diff --git a/pages/UI.php b/pages/UI.php index a67630b50..0c9dc110e 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -912,7 +912,16 @@ HTML $sTransactionId = utils::ReadPostedParam('transaction_id', '', 'transaction_id'); if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid ! { - throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id')); + IssueLog::Trace('Object not updated (empty class or id)', $sClass, array( + '$operation' => $operation, + '$id' => $id, + '$sTransactionId' => $sTransactionId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + + throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id')); } $bDisplayDetails = true; $oObj = MetaModel::GetObject($sClass, $id, false); @@ -921,16 +930,34 @@ HTML $bDisplayDetails = false; $oP->set_title(Dict::S('UI:ErrorPageTitle')); $oP->P(Dict::S('UI:ObjectDoesNotExist')); + + IssueLog::Trace('Object not updated (id not found)', $sClass, array( + '$operation' => $operation, + '$id' => $id, + '$sTransactionId' => $sTransactionId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); } elseif (!utils::IsTransactionValid($sTransactionId, false)) { - //TODO: since $bDisplayDetails= true, there will be an redirection, thus, the content generated here is ignored, only the $sMessage and $sSeverity are used afeter the redirection + //TODO: since $bDisplayDetails= true, there will be an redirection, thus, the content generated here is ignored, only the $sMessage and $sSeverity are used afeter the redirection $sUser = UserRights::GetUser(); IssueLog::Error("UI.php '$operation' : invalid transaction_id ! data: user='$sUser', class='$sClass'"); $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding $oP->p("".Dict::S('UI:Error:ObjectAlreadyUpdated')."\n"); $sMessage = Dict::Format('UI:Error:ObjectAlreadyUpdated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()); $sSeverity = 'error'; + + IssueLog::Trace('Object not updated (invalid transaction_id)', $sClass, array( + '$operation' => $operation, + '$id' => $id, + '$sTransactionId' => $sTransactionId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); } else { @@ -943,9 +970,31 @@ HTML $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding $sMessage = Dict::Format('UI:Class_Object_NotUpdated', MetaModel::GetName(get_class($oObj)), $oObj->GetName()); $sSeverity = 'info'; + + IssueLog::Trace('Object not updated (see either $aErrors or IsModified)', $sClass, array( + '$operation' => $operation, + '$id' => $id, + '$sTransactionId' => $sTransactionId, + '$aErrors' => $aErrors, + 'IsModified' => $oObj->IsModified(), + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); } else { + IssueLog::Trace('Object updated', $sClass, array( + '$operation' => $operation, + '$id' => $id, + '$sTransactionId' => $sTransactionId, + '$aErrors' => $aErrors, + 'IsModified' => $oObj->IsModified(), + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + try { if (!empty($aErrors)) @@ -1118,6 +1167,14 @@ HTML $aWarnings = array(); if ( empty($sClass) ) // TO DO: check that the class name is valid ! { + IssueLog::Trace('Object not created (empty class)', $sClass, array( + '$operation' => $operation, + '$sTransactionId' => $sTransactionId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class')); } if (!utils::IsTransactionValid($sTransactionId, false)) @@ -1125,6 +1182,14 @@ HTML $sUser = UserRights::GetUser(); IssueLog::Error("UI.php '$operation' : invalid transaction_id ! data: user='$sUser', class='$sClass'"); $oP->p("".Dict::S('UI:Error:ObjectAlreadyCreated')."\n"); + + IssueLog::Trace('Object not created (invalid transaction_id)', $sClass, array( + '$operation' => $operation, + '$sTransactionId' => $sTransactionId, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); } else { @@ -1155,11 +1220,30 @@ HTML { if (!empty($aErrors) || !empty($aWarnings)) { + IssueLog::Trace('Object not created (see $aErrors)', $sClass, array( + '$operation' => $operation, + '$sTransactionId' => $sTransactionId, + '$aErrors' => $aErrors, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + throw new CoreCannotSaveObjectException(array('id' => $oObj->GetKey(), 'class' => $sClass, 'issues' => $aErrors)); } $oObj->DBInsertNoReload();// No need to reload + IssueLog::Trace('Object created', $sClass, array( + '$operation' => $operation, + '$id' => $oObj->GetKey(), + '$sTransactionId' => $sTransactionId, + '$aErrors' => $aErrors, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + utils::RemoveTransaction($sTransactionId); $oP->set_title(Dict::S('UI:PageTitle:ObjectCreated')); diff --git a/pages/ajax.render.php b/pages/ajax.render.php index f10099aa1..25910adde 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -1020,7 +1020,18 @@ try { $bReleaseLock = iTopOwnershipLock::ReleaseLock($sObjClass, $iObjKey, $sToken); } - break; + + IssueLog::Trace('on_form_cancel', $sObjClass, array( + '$iObjKey' => $iObjKey, + '$sTransactionId' => $iTransactionId, + '$sTempId' => $sTempId, + '$sToken' => $sToken, + '$sUser' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); + + break; case 'dashboard': $oPage->SetContentType('text/html'); @@ -2649,6 +2660,17 @@ EOF $aResult['width'] = $aDimensions['width']; $aResult['height'] = $aDimensions['height']; } + + IssueLog::Trace('InlineImage created', 'InlineImage', array( + '$operation' => $operation, + '$aResult' => $aResult, + 'secret' => $oAttachment->Get('secret'), + 'temp_id' => $sTempId, + 'item_class' => $sObjClass, + 'user' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); } else { @@ -2689,6 +2711,16 @@ EOF $oAttachment->Set('contents', $oDoc); $oAttachment->Set('secret', sprintf('%06x', mt_rand(0, 0xFFFFFF))); // something not easy to guess $iAttId = $oAttachment->DBInsert(); + + IssueLog::Trace('InlineImage created', 'InlineImage', array( + '$operation' => $operation, + 'secret' => $oAttachment->Get('secret'), + 'temp_id' => $sTempId, + 'item_class' => $sObjClass, + 'user' => UserRights::GetUser(), + 'HTTP_REFERER' => @$_SERVER['HTTP_REFERER'], + 'REQUEST_URI' => @$_SERVER['REQUEST_URI'], + )); } } catch (FileUploadException $e)