Permalink
Browse files

Merge branch 'master' of git://github.com/doctrine/data-fixtures into…

… nosubmodules
  • Loading branch information...
2 parents 98020cb + b913182 commit 2359be43a148c7916fb33e615ab0f1f46a4dcd4d @ornicar committed Jun 10, 2011
View
3 README.md
@@ -134,6 +134,5 @@ To setup and run tests follow these steps:
- go to the root directory of data-fixtures
- run: **git submodule init**
- run: **git submodule update**
-- go to tests directory: **cd tests**
-- copy the phpunit config **cp phpunit.dist.xml phpunit.xml**
+- copy the phpunit config **cp phpunit.xml.dist phpunit.xml**
- run: **phpunit**
View
59 lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php
@@ -0,0 +1,59 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\Common\DataFixtures\Executor;
+
+use Doctrine\ODM\PHPCR\DocumentManager;
+use Doctrine\Common\DataFixtures\Purger\PHPCRPurger;
+
+/**
+ * Class responsible for executing data fixtures.
+ *
+ * @author Jonathan H. Wage <jonwage@gmail.com>
+ * @author Daniel Barsotti <daniel.barsotti@liip.ch>
+ */
+class PHPCRExecutor extends AbstractExecutor
+{
+ /**
+ * Construct new fixtures loader instance.
+ *
+ * @param DocumentManager $dm DocumentManager instance used for persistence.
+ */
+ public function __construct(DocumentManager $dm, PHPCRPurger $purger = null)
+ {
+ $this->dm = $dm;
+ if ($purger !== null) {
+ $this->purger = $purger;
+ $this->purger->setDocumentManager($dm);
+ }
+ parent::__construct($dm);
+ }
+
+ /** @inheritDoc */
+ public function execute(array $fixtures, $append = false)
+ {
+ if ($append === false) {
+ $this->purge();
+ }
+ foreach ($fixtures as $fixture) {
+ $this->load($this->dm, $fixture);
+ }
+ }
+}
+
View
3 lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php
@@ -82,8 +82,9 @@ public function purge()
$orderedTables[] = $class->getTableName();
}
+ $platform = $this->em->getConnection()->getDatabasePlatform();
foreach($orderedTables as $tbl) {
- $this->em->getConnection()->executeUpdate("DELETE FROM $tbl");
+ $this->em->getConnection()->executeUpdate($platform->getTruncateTableSQL($tbl));
}
}
View
68 lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php
@@ -0,0 +1,68 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\Common\DataFixtures\Purger;
+
+use Doctrine\ODM\PHPCR\DocumentManager;
+
+/**
+ * Class responsible for purging databases of data before reloading data fixtures.
+ *
+ * @author Daniel Barsotti <daniel.barsotti@liip.ch>
+ */
+class PHPCRPurger implements PurgerInterface
+{
+ /** DocumentManager instance used for persistence. */
+ private $dm;
+
+ /**
+ * Construct new purger instance.
+ *
+ * @param DocumentManager $dm DocumentManager instance used for persistence.
+ */
+ public function __construct(DocumentManager $dm = null)
+ {
+ $this->dm = $dm;
+ }
+
+ /**
+ * Set the DocumentManager instance this purger instance should use.
+ *
+ * @param DocumentManager $dm
+ */
+ public function setDocumentManager(DocumentManager $dm)
+ {
+ $this->dm = $dm;
+ }
+
+ /**
+ * Delete all the nodes in the repository which are not prefixed with jcr:
+ */
+ public function purge()
+ {
+ $session = $this->dm->getPhpcrSession();
+ foreach($session->getRootNode()->getNodes() as $node) {
+ if (substr($node->getName(), 0, 4) !== 'jcr:') {
+ $node->remove();
+ }
+ }
+ $session->save();
+ }
+
+}

0 comments on commit 2359be4

Please sign in to comment.