/** * Find a topic list id related to an abstract revision * * @param AbstractRevision $object * @param string[] $row * @param array $metadata * @return string Alphadecimal uid of the related board * @throws InvalidInputException When $object is not a Header, PostRevision or * PostSummary instance. * @throws DataModelException When the related id cannot be located */ protected function findTopicListId(AbstractRevision $object, array $row, array $metadata) { if ($object instanceof Header) { return $row['rev_type_id']; } if (isset($metadata['workflow']) && $metadata['workflow'] instanceof Workflow) { $topicId = $metadata['workflow']->getId(); } else { if ($object instanceof PostRevision) { $post = $object; } elseif ($object instanceof PostSummary) { $post = $object->getCollection()->getPost()->getLastRevision(); } else { throw new InvalidInputException('Unexpected object type: ' . get_class($object)); } $topicId = $post->getRootPost()->getPostId(); } $found = $this->om->find(array('topic_id' => $topicId)); if (!$found) { throw new DataModelException("No topic list contains topic " . $topicId->getAlphadecimal() . ", called for revision " . $object->getRevisionId()->getAlphadecimal()); } /** @var TopicListEntry $topicListEntry */ $topicListEntry = reset($found); return $topicListEntry->getListId()->getAlphadecimal(); }
/** * @param AbstractRevision $revision * @return string */ public function getContent(AbstractRevision $revision) { return $this->apply($revision->getContent('html'), $revision->getCollection()->getTitle()); }
/** * @param AbstractRevision $revision * @return AbstractRevision */ protected function getRoot(AbstractRevision $revision) { if ($revision instanceof PostSummary) { $topicId = $revision->getSummaryTargetId(); } elseif ($revision instanceof PostRevision && !$revision->isTopicTitle()) { try { $topicId = $revision->getCollection()->getWorkflowId(); } catch (DataModelException $e) { // failed to locate root post (most likely in unit tests, where // we didn't store the tree) return $revision; } } else { // if we can't the revision it back to a root, this revision is root return $revision; } $collection = PostCollection::newFromId($topicId); return $collection->getLastRevision(); }
/** * Retrieves the current revision for a given AbstractRevision * @param AbstractRevision $revision The revision to retrieve the current revision for. * @return AbstractRevision|null AbstractRevision of the current revision. */ protected function getCurrentRevision(AbstractRevision $revision) { $collectionId = $revision->getCollectionId(); if (!isset($this->currentRevisionsCache[$collectionId->getAlphadecimal()])) { $currentRevision = $revision->getCollection()->getLastRevision(); $this->currentRevisionsCache[$collectionId->getAlphadecimal()] = $currentRevision->getRevisionId(); $this->revisionCache[$currentRevision->getRevisionId()->getAlphadecimal()] = $currentRevision; } $currentRevisionId = $this->currentRevisionsCache[$collectionId->getAlphadecimal()]; return $this->revisionCache[$currentRevisionId->getAlphaDecimal()]; }