コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function purge(array $options = [])
 {
     $versionsToPurge = [];
     $versionsPurgedCount = 0;
     $optionResolver = new OptionsResolver();
     $this->configureOptions($optionResolver);
     $options = $optionResolver->resolve($options);
     $versionsCursor = $this->versionRepository->findPotentiallyPurgeableBy($options);
     foreach ($versionsCursor as $version) {
         $this->eventDispatcher->dispatch(PurgeVersionEvents::PRE_ADVISEMENT, new PreAdvisementVersionEvent($version));
         if ($this->isVersionPurgeable($version, $options)) {
             $this->eventDispatcher->dispatch(PurgeVersionEvents::PRE_PURGE, new PrePurgeVersionEvent($version));
             $versionsPurgedCount++;
             $versionsToPurge[] = $version;
             if (count($versionsToPurge) >= self::BULK_THRESHOLD) {
                 $this->versionRemover->removeAll($versionsToPurge);
                 $this->objectDetacher->detachAll($versionsToPurge);
                 $versionsToPurge = [];
             }
         } else {
             $this->objectDetacher->detach($version);
         }
     }
     $this->versionRemover->removeAll($versionsToPurge);
     $this->objectDetacher->detachAll($versionsToPurge);
     return $versionsPurgedCount;
 }
コード例 #2
0
 function it_purges_the_versions_according_to_an_advisor_and_returns_the_number_of_purged_versions(VersionRepositoryInterface $versionRepository, BulkRemoverInterface $versionRemover, BulkObjectDetacherInterface $objectDetacher, VersionPurgerAdvisorInterface $advisor, VersionInterface $versionToBePurged, VersionInterface $versionNotSupported, VersionInterface $versionToNotPurge)
 {
     $versionToBePurged->getResourceName()->willReturn('products');
     $versionToBePurged->getId()->willReturn(1);
     $versionNotSupported->getResourceName()->willReturn('products');
     $versionNotSupported->getId()->willReturn(2);
     $versionToNotPurge->getResourceName()->willReturn('products');
     $versionToNotPurge->getId()->willReturn(3);
     $versionRepository->findPotentiallyPurgeableBy(Argument::type('array'))->willReturn([$versionToBePurged, $versionNotSupported, $versionToNotPurge]);
     $advisor->supports($versionToBePurged)->shouldBeCalled()->willReturn(true);
     $advisor->isPurgeable($versionToBePurged, Argument::type('array'))->shouldBeCalled()->willReturn(true);
     $advisor->supports($versionNotSupported)->shouldBeCalled()->willReturn(false);
     $advisor->isPurgeable($versionNotSupported, Argument::type('array'))->shouldNotBeCalled();
     $advisor->supports($versionToNotPurge)->shouldBeCalled()->willReturn(true);
     $advisor->isPurgeable($versionToNotPurge, Argument::type('array'))->shouldBeCalled()->willReturn(false);
     $this->addVersionPurgerAdvisor($advisor);
     $versionRemover->removeAll([$versionToBePurged, $versionNotSupported])->shouldBeCalled();
     $objectDetacher->detachAll([$versionToBePurged, $versionNotSupported])->shouldBeCalled();
     $objectDetacher->detach($versionToNotPurge)->shouldBeCalled();
     $this->purge([])->shouldReturn(2);
 }