/** * @param PostRevision|PostSummary $object * @param array $metadata * @return string alphadecimal uuid * @throws InvalidInputException When $object is not PostRevision or PostSummary */ protected function findTopicRootId($object, array $metadata) { if (isset($metadata['workflow']) && $metadata['workflow'] instanceof Workflow) { return $metadata['workflow']->getId(); } elseif ($object instanceof PostRevision) { return $object->getRootPost()->getPostId()->getAlphadecimal(); } elseif ($object instanceof PostSummary) { return $object->getCollection()->getWorkflowId()->getAlphadecimal(); } else { throw new InvalidInputException('Unexpected revision type: ' . get_class($object)); } }
/** * Save topic summary * * @throws FailCommitException */ protected function saveTopicSummary() { if (!$this->nextRevision) { throw new FailCommitException('Attempt to save summary on null revision', 'fail-commit'); } $this->storage->put($this->nextRevision, array('workflow' => $this->workflow)); // Reload the $this->formatterRow for renderApi() after save $this->formatterRow = new FormatterRow(); $this->formatterRow->revision = $this->nextRevision; $this->formatterRow->previousRevision = $this->topicSummary; $this->formatterRow->currentRevision = $this->nextRevision; $this->formatterRow->workflow = $this->workflow; $this->topicSummary = $this->nextRevision; return array('summary-revision-id' => $this->nextRevision->getRevisionId()); }
/** * @param TopicImportState $state * @param IImportSummary $importSummary */ public function importSummary(TopicImportState $state, IImportSummary $importSummary) { $state->parent->logger->info("Importing summary"); $existingId = $state->parent->getImportedId($importSummary); if ($existingId) { $summary = $state->parent->getTopRevision('PostSummary', $existingId); if ($summary) { $state->recordModificationTime($summary->getRevisionId()); $state->parent->logger->info("Summary previously imported"); return; } } $revisions = $this->importObjectWithHistory($importSummary, function (IObjectRevision $rev) use($state) { return PostSummary::create($state->topicWorkflow->getArticleTitle(), $state->topicTitle, $state->parent->createUser($rev->getAuthor()), $rev->getText(), 'wikitext', 'create-topic-summary'); }, 'edit-topic-summary', $state->parent, $state->topicWorkflow->getArticleTitle()); $metadata = array('workflow' => $state->topicWorkflow); $state->parent->put($revisions, $metadata); $state->parent->recordAssociation(reset($revisions)->getCollectionId(), $importSummary); $state->recordModificationTime(end($revisions)->getRevisionId()); $state->parent->logger->info("Finished importing summary with " . count($revisions) . " revisions"); }
/** * Recursively get the data for all children. This will add the revision's * content to the results array, with the post ID as key. * * @param PostRevision|PostSummary $revision * @return array */ public function getRevisionsData($revision) { // make sure we don't parse text that isn't meant to be parsed (e.g. // topic titles are never meant to be parsed from wikitext to html) $format = $revision->isFormatted() ? 'html' : 'wikitext'; // store type of revision so we can also search for very specific types // (e.g. titles only) // possible values will be: // * title // * post // * post-summary $type = $revision->getRevisionType(); if (method_exists($revision, 'isTopicTitle') && $revision->isTopicTitle()) { $type = 'title'; } $data = array(); if ($this->permissions->isAllowed($revision, 'view')) { $data[] = array('id' => $revision->getCollectionId()->getAlphadecimal(), 'text' => trim(Sanitizer::stripAllTags($revision->getContent($format))), 'source_text' => $revision->getContent('wikitext'), 'moderation_state' => $revision->getModerationState(), 'timestamp' => $revision->getCollectionId()->getTimestamp(TS_ISO_8601), 'update_timestamp' => $revision->getRevisionId()->getTimestamp(TS_ISO_8601), 'type' => $type); } if ($revision instanceof PostRevision) { // get data from all child posts too foreach ($revision->getChildren() as $child) { $data = array_merge($data, $this->getRevisionsData($child)); } } return $data; }