true, * 'entries' => [ * '' => [ * html_rendering => '', * ], * '' => [ * html_rendering => '', * ], * ... * ], * 'renewed_transaction_id' => '', * ] * * @throws \ArchivedObjectException * @throws \CoreCannotSaveObjectException * @throws \CoreException * @throws \CoreUnexpectedValue * @throws \OQLException * @throws \ReflectionException * @throws \Twig\Error\LoaderError * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ public static function AddCaseLogsEntries(): array { $sObjectClass = utils::ReadPostedParam('object_class', null, utils::ENUM_SANITIZATION_FILTER_CLASS); $sObjectId = utils::ReadPostedParam('object_id', 0); $sTransactionId = utils::ReadPostedParam('transaction_id', null, utils::ENUM_SANITIZATION_FILTER_TRANSACTION_ID); $aEntries = utils::ReadPostedParam('entries', [], utils::ENUM_SANITIZATION_FILTER_RAW_DATA); // Consistency checks // - Mandatory parameters if (empty($sObjectClass) || empty($sObjectId) || empty($sTransactionId) || empty($aEntries)) { throw new Exception('Missing mandatory parameters object_class / object_id / transaction_id / entries'); } // - Transaction ID // Note: We keep the transaction ID for several reasons: // - We might send several messages, so renewing it would not make such a difference except making the follwoing line harder // - We need the transaction ID to passed in the JS snippet that allows images to be uploaded (see InlineImage::EnableCKEditorImageUpload()), renewing it would only make things more complicated // => For all those reasons, we let the GC clean the transactions IDs, just like when a transaction ID is not deleted when cancelling a regular object edition. if (!utils::IsTransactionValid($sTransactionId, false)) { throw new Exception(Dict::S('iTopUpdate:Error:InvalidToken')); } $aResults = [ 'success' => true, 'entries' => [], ]; // Note: Will trigger an exception if object does not exists or not accessible to the user $oObject = MetaModel::GetObject($sObjectClass, $sObjectId); foreach ($aEntries as $sAttCode => $aData) { // Add entry to object $oObject->Set($sAttCode, $aData['value']); // Make entry rendering to send back to the front $aEntryAsArray = $oObject->Get($sAttCode)->GetAsArray()[0]; $oEntryBlock = ActivityEntryFactory::MakeFromCaseLogEntryArray($sAttCode, $aEntryAsArray); $oEntryBlock->SetCaseLogRank((int)$aData['rank']); $sEntryAsHtml = BlockRenderer::RenderBlockTemplates($oEntryBlock); $aResults['entries'][$sAttCode] = [ 'html_rendering' => $sEntryAsHtml, ]; } $oObject->DBWrite(); // Finalize inline images InlineImage::FinalizeInlineImages($oObject); return $aResults; } }