/**
  * Do something before dumping data
  */
 protected function preDump()
 {
     $this->rdfBuilder->startDocument();
     $this->rdfBuilder->addDumpHeader($this->timestamp);
     $header = $this->rdfBuilder->getRDF();
     $this->writeToDump($header);
 }
 /**
  * @param int $produce One of the RdfProducer::PRODUCE_... constants.
  * @param DedupeBag|null $dedup
  *
  * @return RdfBuilder
  */
 private function newRdfBuilder($produce, DedupeBag $dedup = null)
 {
     if ($dedup === null) {
         $dedup = new HashDedupeBag();
     }
     // Note: using the actual factory here makes this an integration test!
     $valueBuilderFactory = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory();
     $emitter = new NTriplesRdfWriter();
     $builder = new RdfBuilder($this->getTestData()->getSiteList(), $this->getTestData()->getVocabulary(), $valueBuilderFactory, $this->getTestData()->getMockRepository(), $produce, $emitter, $dedup);
     $builder->startDocument();
     return $builder;
 }
 /**
  * @param EntityRevision $entityRevision
  * @param RedirectRevision|null $followedRedirect a redirect leading to the entity for use in the output
  * @param EntityId[] $incomingRedirects Incoming redirects to include in the output
  * @param RdfBuilder $rdfBuilder
  * @param string|null $flavor The type of the output provided by serializer
  *
  * @return string RDF
  */
 private function rdfSerialize(EntityRevision $entityRevision, RedirectRevision $followedRedirect = null, array $incomingRedirects, RdfBuilder $rdfBuilder, $flavor = null)
 {
     $rdfBuilder->startDocument();
     $redir = null;
     if ($followedRedirect) {
         $redir = $followedRedirect->getRedirect();
         $rdfBuilder->addEntityRedirect($redir->getEntityId(), $redir->getTargetId());
         if ($followedRedirect->getRevisionId() > 0) {
             $rdfBuilder->addEntityRevisionInfo($redir->getEntityId(), $followedRedirect->getRevisionId(), $followedRedirect->getTimestamp());
         }
     }
     if ($followedRedirect && $flavor === 'dump') {
         // For redirects, don't output the target entity data if the "dump" flavor is requested.
         // @todo: In this case, avoid loading the Entity all together.
         // However we want to output the revisions for redirects
     } else {
         $rdfBuilder->addEntityRevisionInfo($entityRevision->getEntity()->getId(), $entityRevision->getRevisionId(), $entityRevision->getTimestamp());
         $rdfBuilder->addEntity($entityRevision->getEntity());
         $rdfBuilder->resolveMentionedEntities($this->entityLookup);
     }
     if ($flavor !== 'dump') {
         // For $flavor === 'dump' we don't need to output incoming redirects.
         $targetId = $entityRevision->getEntity()->getId();
         $this->addIncomingRedirects($targetId, $redir, $incomingRedirects, $rdfBuilder);
     }
     $rdfBuilder->finishDocument();
     return $rdfBuilder->getRDF();
 }