partkeepr

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

BaseMigration.php (1212B)


      1 <?php
      2 
      3 namespace PartKeepr\CoreBundle\DoctrineMigrations;
      4 
      5 use Doctrine\DBAL\Migrations\AbstractMigration;
      6 use Doctrine\ORM\EntityManager;
      7 use Doctrine\ORM\Tools\SchemaTool;
      8 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
      9 use Symfony\Component\DependencyInjection\ContainerInterface;
     10 
     11 abstract class BaseMigration extends AbstractMigration implements ContainerAwareInterface
     12 {
     13     /**
     14      * @var ContainerInterface
     15      */
     16     private $container;
     17 
     18     public function setContainer(ContainerInterface $container = null)
     19     {
     20         $this->container = $container;
     21     }
     22 
     23     public function getContainer()
     24     {
     25         return $this->container;
     26     }
     27 
     28     protected function performDatabaseUpgrade()
     29     {
     30         /**
     31          * @var EntityManager
     32          */
     33         $entityManager = $this->container->get('doctrine')->getManager();
     34         $tool = new SchemaTool($entityManager);
     35 
     36         $meta = $this->container->get('doctrine')->getManager()->getMetadataFactory()->getAllMetadata();
     37 
     38         $tool->updateSchema($meta, true);
     39     }
     40 
     41     /**
     42      * @return EntityManager
     43      */
     44     protected function getEM()
     45     {
     46         return $this->container->get('doctrine')->getManager();
     47     }
     48 }