Version20151031163951.php (982B)
1 <?php 2 3 namespace PartKeepr\CoreBundle\DoctrineMigrations; 4 5 use Doctrine\DBAL\Schema\Schema; 6 7 /** 8 * Ensures that each footprint has a category assigned. 9 */ 10 class Version20151031163951 extends BaseMigration 11 { 12 /** 13 * @param Schema $schema 14 */ 15 public function up(Schema $schema) 16 { 17 $footprintRepository = $this->getEM()->getRepository( 18 'PartKeeprFootprintBundle:Footprint' 19 ); 20 21 $rootNode = $this->getContainer()->get('partkeepr.footprint.category_service')->getRootNode(); 22 23 $footprints = $footprintRepository->findAll(); 24 25 foreach ($footprints as $footprint) { 26 if ($footprint->getCategory() === null) { 27 $footprint->setCategory($rootNode); 28 } 29 } 30 31 $this->getEM()->flush(); 32 } 33 34 /** 35 * @param Schema $schema 36 */ 37 public function down(Schema $schema) 38 { 39 // this down() migration is auto-generated, please modify it to your needs 40 } 41 }