/** * Updates the given LexEntry in $projectId * @param string $projectId * @param array $params * @param string $userId * @param string $mergeQueuePath * @param string $pidFilePath * @param string $command * @return bool|array<encoded LexEntryModel> if the project is syncing (or on hold) return false (no save)FixSe */ public static function updateEntry($projectId, $params, $userId, $mergeQueuePath = null, $pidFilePath = null, $command = null) { CodeGuard::checkTypeAndThrow($params, 'array'); $project = new LexProjectModel($projectId); ProjectCommands::checkIfArchivedAndThrow($project); $now = UniversalTimestamp::now(); if (array_key_exists('id', $params) && $params['id'] != '') { $entry = new LexEntryModel($project, $params['id']); $action = 'update'; } else { $entry = new LexEntryModel($project); $entry->authorInfo->createdByUserRef->id = $userId; $entry->authorInfo->createdDate = $now; $entry->guid = Guid::create(); $action = 'create'; // TODO: Consider adding more specific activity entry: which fields were modified? 2014-09-03 RM // E.g., "User _____ updated entry _____ by adding a new sense with definition ______" } $entry->authorInfo->modifiedDate = $now; $entry->authorInfo->modifiedByUserRef->id = $userId; if ($project->hasSendReceive()) { // $entry->dirtySR++; $entry->dirtySR = 0; $status = SendReceiveCommands::getProjectStatus($projectId); if ($status && $status['SRState'] != 'IDLE') { return false; } } LexEntryDecoder::decode($entry, $params); $entry->write(); ActivityCommands::writeEntry($project, $userId, $entry, $action); // SendReceiveCommands::queueProjectForUpdate($project, $mergeQueuePath); // SendReceiveCommands::startLFMergeIfRequired($projectId, 'merge', $pidFilePath, $command); return JsonEncoder::encode($entry); }
public function testDecode_ExistingModelAndMapOf_DecodeOk() { $multiParagraph = new LexMultiParagraph(); $multiParagraph->inputSystem = 'en'; $paragraph1 = new LexParagraph(); $paragraph1->styleName = 'styleA'; $paragraph1->content = 'This is the first paragraph in <span lang="de">die Deutsche Sprache</span>'; $multiParagraph->paragraphs->append($paragraph1); $paragraph2 = new LexParagraph(); $paragraph2->content = 'This is the second paragraph in <span lang="es">la lingua Espanol</span>'; $multiParagraph->paragraphs->append($paragraph2); $paragraph3 = new LexParagraph(); $paragraph3->styleName = 'styleC'; $multiParagraph->paragraphs->append($paragraph3); $params = json_decode(json_encode(LexDbeDtoEntriesEncoder::encode($multiParagraph)), true); $newMultiParagraph = new LexMultiParagraph($multiParagraph->guid); $key = 'customField_entry_Cust_MultiPara'; $newTestMapOf = new MultiParagraphInMap(); $newTestMapOf->data[$key] = clone $newMultiParagraph; LexEntryDecoder::decode($newMultiParagraph, $params); $this->assertEquals($multiParagraph, $newMultiParagraph); $testMapOf = new MultiParagraphInMap(); $testMapOf->data[$key] = $multiParagraph; $params = json_decode(json_encode(LexDbeDtoEntriesEncoder::encode($testMapOf)), true); LexEntryDecoder::decode($newTestMapOf, $params); $this->assertEquals($testMapOf->data[$key]->guid, $newTestMapOf->data[$key]->guid); $this->assertEquals($testMapOf, $newTestMapOf); }
/** * Sets the public properties of $model to values from $values[propertyName] * @param object $model * @param array $values A mixed array of JSON (like) data. * @param string $id */ public static function decode($model, $values, $id = '') { $decoder = new LexEntryDecoder(); $decoder->_decode($model, $values, $id); }