public function commit() { if ($this->action !== 'new-topic') { throw new FailCommitException('Unknown commit action', 'fail-commit'); } $metadata = array('workflow' => $this->topicWorkflow, 'board-workflow' => $this->workflow, 'topic-title' => $this->topicTitle, 'first-post' => $this->firstPost); /* * Order of storage is important! We've been changing when we stored * workflow a couple of times. For now, it needs to be stored first: * * OccupationListener.php (workflow listener) must first create the * board before NotificationListener.php (topic/post listeners) * creates notifications (& mails) that link to the board * * ReferenceExtractor.php (run from ReferenceRecorder.php, a post * listener) needs to parse content with Parsoid & for that it needs * the board title. AbstractRevision::getContent() will figure out * the title from the workflow: $this->getCollection()->getTitle() * If you even feel the need to change the order, make sure you come * up with a fix for the above things ;) */ $this->storage->put($this->workflow, array()); // 'discussion' workflow $this->storage->put($this->topicWorkflow, $metadata); // 'topic' workflow $this->storage->put($this->topicListEntry, $metadata); $this->storage->put($this->topicTitle, $metadata); if ($this->firstPost !== null) { $this->storage->put($this->firstPost, $metadata + array('reply-to' => $this->topicTitle)); } $output = array('topic-page' => $this->topicWorkflow->getArticleTitle()->getPrefixedText(), 'topic-id' => $this->topicTitle->getPostId(), 'topic-revision-id' => $this->topicTitle->getRevisionId(), 'post-id' => $this->firstPost ? $this->firstPost->getPostId() : null, 'post-revision-id' => $this->firstPost ? $this->firstPost->getRevisionId() : null); return $output; }
public function commit() { switch ($this->action) { case 'edit-topic-summary': // pseudo-action does not do anything, only includes data in api response return array(); case 'reply': case 'moderate-topic': case 'lock-topic': case 'restore-post': case 'moderate-post': case 'edit-title': case 'undo-edit-post': case 'edit-post': if ($this->newRevision === null) { throw new FailCommitException('Attempt to save null revision', 'fail-commit'); } $metadata = $this->extraCommitMetadata + array('workflow' => $this->workflow, 'topic-title' => $this->loadTopicTitle()); if (!$metadata['topic-title'] instanceof PostRevision) { // permissions failure, should never have gotten this far throw new PermissionException('Not Allowed', 'insufficient-permission'); } if ($this->newRevision->getPostId()->equals($metadata['topic-title']->getPostId())) { // When performing actions against the topic-title self::loadTopicTitle // returns the previous revision. $metadata['topic-title'] = $this->newRevision; } $this->storage->put($this->newRevision, $metadata); $this->workflow->updateLastModified($this->newRevision->getRevisionId()); $this->storage->put($this->workflow, $metadata); $newRevision = $this->newRevision; // If no context was loaded render the post in isolation // @todo make more explicit try { $newRevision->getChildren(); } catch (\MWException $e) { $newRevision->setChildren(array()); } $returnMetadata = array('post-id' => $this->newRevision->getPostId(), 'post-revision-id' => $this->newRevision->getRevisionId()); return $returnMetadata; default: throw new InvalidActionException("Unknown commit action: {$this->action}", 'invalid-action'); } }