SchemaSetupController.php (1521B)
1 <?php 2 3 namespace PartKeepr\SetupBundle\Controller; 4 5 use Doctrine\ORM\Tools\SchemaTool; 6 use Symfony\Component\HttpFoundation\JsonResponse; 7 use Symfony\Component\HttpFoundation\Request; 8 use Symfony\Component\HttpFoundation\Response; 9 use Symfony\Component\Routing\Annotation\Route; 10 11 class SchemaSetupController extends SetupBaseController 12 { 13 /** 14 * @Route("/setup/_int_setup_schema") 15 */ 16 public function intSetupSchemaAction(Request $request) 17 { 18 if (!$this->ensureAuthKey($request)) { 19 return $this->getAuthKeyErrorResponse(); 20 } 21 22 $response = [ 23 'success' => true, 24 'errors' => [], 25 'message' => 'Database successfully installed/updated', 26 ]; 27 28 $entityManager = $this->get('doctrine.orm.default_entity_manager'); 29 $schemaTool = new SchemaTool($entityManager); 30 $metadatas = $entityManager->getMetadataFactory()->getAllMetadata(); 31 32 try { 33 $schemaTool->updateSchema($metadatas, true); 34 } catch (\Exception $e) { 35 $response['success'] = false; 36 $response['message'] = 'Database setup error'; 37 $response['errors'] = [$e->getMessage()]; 38 } 39 40 return new JsonResponse($response); 41 } 42 43 /** 44 * @Route("/setup/schemaSetup") 45 */ 46 public function setupSchemaAction(Request $request) 47 { 48 $response = $this->handleRequest($request, '/setup/_int_setup_schema'); 49 50 return new Response($response->getContent()); 51 } 52 }