/**
  * @dataProvider provideGetReferencesFromRevisionContent
  */
 public function testGetReferencesAfterRevisionInsert($content, $expectedReferences)
 {
     $content = Utils::convert('wikitext', 'html', $content, $this->workflow->getOwnerTitle());
     $revision = $this->generatePost(array('rev_content' => $content));
     // Save to storage to test if ReferenceRecorder listener picks this up
     $this->store($this->revision);
     $this->store($revision);
     $expectedReferences = $this->expandReferences($this->workflow, $revision, $expectedReferences);
     // References will be stored as linked from Topic:<id>
     $title = Title::newFromText($this->workflow->getId()->getAlphadecimal(), NS_TOPIC);
     // Retrieve references from storage
     $foundReferences = $this->updater->getReferencesForTitle($title);
     $this->assertReferenceListsEqual($expectedReferences, $foundReferences);
 }
 /**
  * @param Workflow $workflow
  * @param string $action
  * @return \Title
  */
 public function getRcTitle(Workflow $workflow, $action)
 {
     if ($this->actions->getValue($action, 'rc_title') === 'owner') {
         return $workflow->getOwnerTitle();
     } else {
         return $workflow->getArticleTitle();
     }
 }
 /**
  * @param Workflow $obj
  * @return array
  * @throws FailCommitException
  */
 public static function toStorageRow(Workflow $obj)
 {
     if ($obj->pageId === 0) {
         /*
          * We try to defer creating a new page as long as possible, which
          * means that a new board page won't have been created by the time
          * Workflow object was created: new workflows will have a 0 pageId.
          * This method is called when the workflow is about to be inserted.
          * By now, the page has been inserted & we should store the real
          * page_id this workflow is associated with.
          */
         // store ID of newly created page
         $title = $obj->getOwnerTitle();
         $obj->pageId = $title->getArticleID(Title::GAID_FOR_UPDATE);
         if ($obj->pageId === 0) {
             throw new FailCommitException('No page for workflow: ' . serialize($obj));
         }
     }
     return array('workflow_id' => $obj->id->getAlphadecimal(), 'workflow_type' => $obj->type, 'workflow_wiki' => $obj->wiki, 'workflow_page_id' => $obj->pageId, 'workflow_namespace' => $obj->namespace, 'workflow_title_text' => $obj->titleText, 'workflow_lock_state' => 0, 'workflow_last_update_timestamp' => $obj->lastModified, 'workflow_name' => '');
 }
 /**
  * @param Workflow $workflow
  * @param AbstractBlock[] $blocks
  * @return array Map from committed block name to an array of metadata returned
  *  about inserted objects.
  * @throws \Exception
  */
 public function commit(Workflow $workflow, array $blocks)
 {
     $cache = $this->bufferedCache;
     $dbw = $this->dbFactory->getDB(DB_MASTER);
     /**
      * Ideally, I'd create the page in Workflow::toStorageRow, but
      * WikiPage::doEditContent uses transactions & our DB wrapper
      * doesn't allow nested transactions, so that part has moved.
      *
      * Don't allowCreation() here: a board has to be explicitly created,
      * or allowed via the occupyNamespace & occupyPages globals, in
      * which case allowCreation() won't be needed.
      *
      * @var OccupationController $occupationController
      */
     $occupationController = Container::get('occupation_controller');
     $title = $workflow->getOwnerTitle();
     $occupationController->ensureFlowRevision(new \Article($title), $workflow);
     try {
         $dbw->begin();
         $cache->begin();
         $results = array();
         foreach ($blocks as $block) {
             $results[$block->getName()] = $block->commit();
         }
         $dbw->commit();
         // Now commit to cache. If this fails, cache keys should have been
         // invalidated, but still log the failure.
         if (!$cache->commit()) {
             wfDebugLog('Flow', __METHOD__ . ': Committed to database but failed applying to cache');
         }
     } catch (\Exception $e) {
         while (!$this->deferredQueue->isEmpty()) {
             $this->deferredQueue->dequeue();
         }
         $dbw->rollback();
         $cache->rollback();
         throw $e;
     }
     while (!$this->deferredQueue->isEmpty()) {
         DeferredUpdates::addCallableUpdate($this->deferredQueue->dequeue());
     }
     $workflow->getArticleTitle()->purgeSquid();
     return $results;
 }