/**
  * Validate topic summary
  *
  * @throws InvalidDataException
  */
 protected function validateTopicSummary()
 {
     if (!isset($this->submitted['summary']) || !is_string($this->submitted['summary'])) {
         $this->addError('content', $this->context->msg('flow-error-missing-summary'));
         return;
     }
     if ($this->workflow->isNew()) {
         throw new InvalidDataException('Topic summary can only be added to an existing topic', 'missing-topic-title');
     }
     // Create topic summary
     if (!$this->topicSummary) {
         $topicTitle = $this->findTopicTitle();
         $boardWorkflow = $topicTitle->getCollection()->getBoardWorkflow();
         if (!$this->permissions->isRevisionAllowed(null, 'create-topic-summary') || !$this->permissions->isRootAllowed($topicTitle, 'create-topic-summary') || !$this->permissions->isBoardAllowed($boardWorkflow, 'create-topic-summary')) {
             $this->addError('permissions', $this->context->msg('flow-error-not-allowed'));
             return;
         }
         // new summary should not have a previous revision
         if (!empty($this->submitted['prev_revision'])) {
             $this->addError('prev_revision', $this->context->msg('flow-error-prev-revision-does-not-exist'));
             return;
         }
         $this->nextRevision = PostSummary::create($this->workflow->getArticleTitle(), $this->findTopicTitle(), $this->context->getUser(), $this->submitted['summary'], isset($this->submitted['format']) ? $this->submitted['format'] : 'wikitext', 'create-topic-summary');
         // Edit topic summary
     } else {
         if (!$this->permissions->isAllowed($this->topicSummary, 'edit-topic-summary')) {
             $this->addError('permissions', $this->context->msg('flow-error-not-allowed'));
             return;
         }
         // Check the previous revision to catch possible edit conflict
         if (empty($this->submitted['prev_revision'])) {
             $this->addError('prev_revision', $this->context->msg('flow-error-missing-prev-revision-identifier'));
             return;
         } elseif ($this->topicSummary->getRevisionId()->getAlphadecimal() !== $this->submitted['prev_revision']) {
             $this->addError('prev_revision', $this->context->msg('flow-error-prev-revision-mismatch')->params($this->submitted['prev_revision'], $this->topicSummary->getRevisionId()->getAlphadecimal(), $this->context->getUser()->getName()), array('revision_id' => $this->topicSummary->getRevisionId()->getAlphadecimal()));
             return;
         }
         $this->nextRevision = $this->topicSummary->newNextRevision($this->context->getUser(), $this->submitted['summary'], isset($this->submitted['format']) ? $this->submitted['format'] : 'wikitext', 'edit-topic-summary', $this->workflow->getArticleTitle());
     }
     if (!$this->checkSpamFilters($this->topicSummary, $this->nextRevision)) {
         return;
     }
 }
 /**
  * @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");
 }