PHPCRPurger.php 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Doctrine\Common\DataFixtures\Purger;
  3. use Doctrine\ODM\PHPCR\DocumentManager;
  4. use Doctrine\ODM\PHPCR\DocumentManagerInterface;
  5. use PHPCR\Util\NodeHelper;
  6. /**
  7. * Class responsible for purging databases of data before reloading data fixtures.
  8. *
  9. * @author Daniel Barsotti <daniel.barsotti@liip.ch>
  10. */
  11. class PHPCRPurger implements PurgerInterface
  12. {
  13. /**
  14. * @var DocumentManagerInterface
  15. */
  16. private $dm;
  17. public function __construct(DocumentManagerInterface $dm = null)
  18. {
  19. $this->dm = $dm;
  20. }
  21. public function setDocumentManager(DocumentManager $dm)
  22. {
  23. $this->dm = $dm;
  24. }
  25. public function getObjectManager()
  26. {
  27. return $this->dm;
  28. }
  29. /**
  30. * @inheritDoc
  31. */
  32. public function purge()
  33. {
  34. $session = $this->dm->getPhpcrSession();
  35. NodeHelper::purgeWorkspace($session);
  36. $session->save();
  37. }
  38. }