/** * Saves a PostRevision to storage. * Be sure to add the required tables to $tablesUsed and add @group Database * to the class' phpDoc. * * @param PostRevision $revision */ protected function store(PostRevision $revision) { if ($revision->isTopicTitle()) { $root = $revision; } else { /** @var PostCollection $parentCollection */ $parentCollection = PostCollection::newFromId($revision->getReplyToId()); $root = $parentCollection->getRoot()->getLastRevision(); } $topicWorkflow = $this->workflows[$root->getCollectionId()->getAlphadecimal()]; $boardWorkflow = Container::get('factory.loader.workflow')->createWorkflowLoader($topicWorkflow->getOwnerTitle())->getWorkflow(); $metadata = array('workflow' => $topicWorkflow, 'board-workflow' => $boardWorkflow); // check if this topic (+ workflow + board workflow + board page) have // already been inserted or do so now $found = $this->getStorage()->find('TopicListEntry', array('topic_id' => $topicWorkflow->getId())); if (!$found) { $title = $boardWorkflow->getOwnerTitle(); $user = User::newFromName('127.0.0.1', false); /** @var OccupationController $occupationController */ $occupationController = Container::get('occupation_controller'); // make sure user has rights to create board $user->mRights = array_merge($user->getRights(), array('flow-create-board')); $occupationController->allowCreation($title, $user); $occupationController->ensureFlowRevision(new \Article($title), $boardWorkflow); $topicListEntry = TopicListEntry::create($boardWorkflow, $topicWorkflow); $this->getStorage()->put($boardWorkflow, $metadata); $this->getStorage()->put($topicWorkflow, $metadata); $this->getStorage()->put($topicListEntry, $metadata); } $this->getStorage()->put($revision, $metadata); /** @var SplQueue $deferredQueue */ $deferredQueue = Container::get('deferred_queue'); while (!$deferredQueue->isEmpty()) { try { DeferredUpdates::addCallableUpdate($deferredQueue->dequeue()); // doing updates 1 by 1 so an exception doesn't break others in // the queue DeferredUpdates::doUpdates(); } catch (\MWException $e) { // ignoring exceptions for now, not all are phpunit-proof yet } } // save for removal at end of tests $this->revisions[] = $revision; }
protected function isLastReply(PostRevision $revision) { if ($revision->isTopicTitle()) { return false; } $reply = $revision->getReplyToId()->getAlphadecimal(); if (!isset($this->identityMap[$reply])) { wfDebugLog('Flow', __METHOD__ . ": Missing {$reply} in identity map"); return false; } $parent = $this->identityMap[$revision->getReplyToId()->getAlphadecimal()]; $keys = array_keys($parent['children']); return end($keys) === $revision->getPostId()->getAlphadecimal(); }