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;
 }
 /**
  * @todo Any failed action performed against a single revisions ends up here.
  * To generate forms with validation errors in the non-javascript renders we
  * need to add something to this output, but not sure what yet
  */
 protected function renderPostApi(array $options, $postId = '')
 {
     if ($this->workflow->isNew()) {
         throw new FlowException('No posts can exist for non-existent topic');
     }
     $format = isset($options['format']) ? $options['format'] : 'fixed-html';
     $serializer = $this->getRevisionFormatter($format);
     if (!$postId) {
         if (isset($options['postId'])) {
             $postId = $options['postId'];
         } elseif ($this->newRevision) {
             // API results after a reply will have no $postId (ID is not yet
             // known when the reply is submitted) so we'll grab it from the
             // newly added revision
             $postId = $this->newRevision->getPostId();
         }
     } else {
         // $postId is only set for lock-topic, which should default to
         // wikitext instead of html
         $format = isset($options['format']) ? $options['format'] : 'wikitext';
         $serializer->setContentFormat($format, UUID::create($postId));
     }
     $row = Container::get('query.singlepost')->getResult(UUID::create($postId));
     $serialized = $serializer->formatApi($row, $this->context);
     if (!$serialized) {
         return null;
     }
     return array('roots' => array($serialized['postId']), 'posts' => array($serialized['postId'] => array($serialized['revisionId'])), 'revisions' => array($serialized['revisionId'] => $serialized));
 }
 /**
  * @param Title $title
  * @param PostRevision $post
  * @param User $user
  * @param string $content
  * @param string $format wikitext|html
  * @param string $changeType
  * @return PostSummary
  */
 public static function create(Title $title, PostRevision $post, User $user, $content, $format, $changeType)
 {
     $obj = new self();
     $obj->revId = UUID::create();
     $obj->user = UserTuple::newFromUser($user);
     $obj->prevRevision = null;
     $obj->changeType = $changeType;
     $obj->summaryTargetId = $post->getPostId();
     $obj->setContent($content, $format, $title);
     return $obj;
 }
 /**
  * Generate a reply to $this->revision (which is a topic title)
  *
  * @param array $overrides
  * @return PostRevision
  * @throws \Flow\Exception\FlowException
  */
 protected function generatePost($overrides)
 {
     $uuid = UUID::create();
     return $this->generateObject($overrides + array('rev_change_type' => 'reply', 'tree_rev_descendant_id' => $uuid->getBinary(), 'rev_type_id' => $uuid->getBinary(), 'tree_parent_id' => $this->revision->getPostId()));
 }
 /**
  * Gets the root post ID for a given PostRevision
  * @param  PostRevision $revision The revision to get the root post ID for.
  * @return UUID                   The UUID for the root post.
  * @throws \MWException
  */
 protected function getRootPostId(PostRevision $revision)
 {
     $postId = $revision->getPostId();
     if ($revision->isTopicTitle()) {
         return $postId;
     } elseif (isset($this->rootPostIdCache[$postId->getAlphadecimal()])) {
         return $this->rootPostIdCache[$postId->getAlphadecimal()];
     } else {
         throw new \MWException("Unable to find root post ID for post " . $postId->getAlphadecimal());
     }
 }