/** * 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 static function updateReply($projectId, $userId, $website, $commentId, $params) { CodeGuard::checkTypeAndThrow($params, 'array'); CodeGuard::checkEmptyAndThrow($commentId, 'commentId in updateReply()'); $project = new LexProjectModel($projectId); ProjectCommands::checkIfArchivedAndThrow($project); $comment = new LexCommentModel($project, $commentId); $rightsHelper = new RightsHelper($userId, $project, $website); $replyId = $params['id']; if (array_key_exists('id', $params) && $replyId != '') { $reply = $comment->getReply($replyId); if ($reply->authorInfo->createdByUserRef->asString() != $userId && !$rightsHelper->userHasProjectRight(Domain::COMMENTS + Operation::EDIT)) { throw new \Exception("No permission to update other people's lex comment replies!"); } if ($reply->content != $params['content']) { $reply->authorInfo->modifiedDate = UniversalTimestamp::now(); } $reply->content = $params['content']; $comment->setReply($replyId, $reply); } else { $reply = new LexCommentReply(); $reply->content = $params['content']; $reply->authorInfo->createdByUserRef->id = $userId; $reply->authorInfo->modifiedByUserRef->id = $userId; $now = UniversalTimestamp::now(); $reply->authorInfo->createdDate = $now; $reply->authorInfo->modifiedDate = $now; $comment->replies->append($reply); $replyId = $reply->id; } $comment->write(); return $replyId; }
/** * Writes the model to the mongo collection * @return string The unique id of the object written * @see MongoMapper::write() */ public function write() { CodeGuard::checkTypeAndThrow($this->id, 'Api\\Model\\Shared\\Mapper\\Id'); $now = UniversalTimestamp::now(); $this->dateModified = $now; if (Id::isEmpty($this->id)) { $this->dateCreated = $now; } $this->id->id = $this->_mapper->write($this, $this->id->id); return $this->id->id; }
public function __construct() { $this->createdByUserRef = new IdReference(); $this->modifiedByUserRef = new IdReference(); $now = UniversalTimestamp::now(); $this->createdDate = $now; $this->modifiedDate = $now; $this->setReadOnlyProp('createdByUserRef'); $this->setReadOnlyProp('modifiedByUserRef'); $this->setReadOnlyProp('createdDate'); $this->setReadOnlyProp('modifiedDate'); }
public function __construct() { $this->dateTime = new DateTime(); $this->universalTimestamp = UniversalTimestamp::now(); }