partkeepr

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

SchemaMigrationSetupController.php (1644B)


      1 <?php
      2 
      3 namespace PartKeepr\SetupBundle\Controller;
      4 
      5 use Doctrine\Bundle\MigrationsBundle\Command\DoctrineCommand;
      6 use Doctrine\DBAL\Migrations\Configuration\Configuration;
      7 use Doctrine\DBAL\Migrations\Migration;
      8 use Symfony\Component\HttpFoundation\JsonResponse;
      9 use Symfony\Component\HttpFoundation\Request;
     10 use Symfony\Component\HttpFoundation\Response;
     11 use Symfony\Component\Routing\Annotation\Route;
     12 
     13 class SchemaMigrationSetupController extends SetupBaseController
     14 {
     15     /**
     16      * @Route("/setup/_int_migrate_schema")
     17      */
     18     public function intMigrateSchemaAction(Request $request)
     19     {
     20         if (!$this->ensureAuthKey($request)) {
     21             return $this->getAuthKeyErrorResponse();
     22         }
     23 
     24         $response = [
     25             'success' => true,
     26             'errors'  => [],
     27             'message' => 'Database schema successfully migrated',
     28         ];
     29 
     30         $configuration = $this->getMigrationConfiguration();
     31         $migration = new Migration($configuration);
     32 
     33         $version = $configuration->getLatestVersion();
     34 
     35         $migration->migrate($version);
     36 
     37         return new JsonResponse($response);
     38     }
     39 
     40     protected function getMigrationConfiguration()
     41     {
     42         $config = new Configuration($this->get('doctrine.dbal.default_connection'));
     43 
     44         DoctrineCommand::configureMigrations($this->container, $config);
     45 
     46         return $config;
     47     }
     48 
     49     /**
     50      * @Route("/setup/schemaMigration")
     51      */
     52     public function migrateSchemaAction(Request $request)
     53     {
     54         $response = $this->handleRequest($request, '/setup/_int_migrate_schema');
     55 
     56         return new Response($response->getContent());
     57     }
     58 }