partkeepr

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

commit 2204f58acf867c22813accb49ab3ad0febac17d0
parent 88eda40453e03929b3d0748fdc8d60398e869360
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri,  2 Oct 2015 14:23:37 +0200

Auto-migrate users to use the builtin provider

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

diff --git a/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20151001180120.php b/src/PartKeepr/CoreBundle/DoctrineMigrations/Version20151001180120.php @@ -0,0 +1,54 @@ +<?php +namespace PartKeepr\CoreBundle\DoctrineMigrations; + +use Doctrine\DBAL\Schema\Schema; +use PartKeepr\AuthBundle\Entity\UserProvider; + +/** + * Auto-generated Migration: Please modify to your needs! + */ +class Version20151001180120 extends BaseMigration +{ + /** + * @param Schema $schema + */ + public function up(Schema $schema) + { + $this->performDatabaseUpgrade(); + + $userProviderRepository = $this->getEM()->getRepository( + 'PartKeeprAuthBundle:UserProvider' + ); + + $builtinProvider = $userProviderRepository->findOneBy(array("type" => "Builtin")); + + if ($builtinProvider === null) { + $builtinProvider = new UserProvider(); + $builtinProvider->setType("Builtin"); + + $this->getEM()->persist($builtinProvider); + } + + $repository = $this->getEM()->getRepository( + 'PartKeeprAuthBundle:User' + ); + + $users = $repository->findAll(); + + foreach ($users as $user) { + $user->setProvider($builtinProvider); + } + + $this->getEM()->flush(); + + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + + } +}