partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit c13c1124884af0c68813b58d52031f8c94752987
parent aa65808961caa4410f8658c60d4f5d46ce1e9291
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 31 Oct 2015 16:44:35 +0100

Ensure that all footprints have a category assigned

Diffstat:
Asrc/PartKeepr/CoreBundle/DoctrineMigrations/Version20151031163951.php | 42++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+), 0 deletions(-)

diff --git a/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20151031163951.php b/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20151031163951.php @@ -0,0 +1,42 @@ +<?php + +namespace PartKeepr\CoreBundle\DoctrineMigrations; + +use Doctrine\DBAL\Migrations\AbstractMigration; +use Doctrine\DBAL\Schema\Schema; + +/** + * Ensures that each footprint has a category assigned + */ +class Version20151031163951 extends BaseMigration +{ + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + $footprintRepository = $this->getEM()->getRepository( + 'PartKeeprFootprintBundle:Footprint' + ); + + $rootNode = $this->getContainer()->get("partkeepr.footprint.category_service")->getRootNode(); + + $footprints = $footprintRepository->findAll(); + + foreach ($footprints as $footprint) { + if ($footprint->getCategory() === null) { + $footprint->setCategory($rootNode); + } + } + + $this->getEM()->flush(); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + } +}