Exemplo n.º 1
0
 /**
  * do the thing here.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new DoctrineAdapter();
     $driver->init();
     $em = $driver->getManager();
     $classes = loadAppModels();
     $schema = new SchemaTool($em);
     $models = [];
     try {
         $schemaManager = $em->getConnection()->getSchemaManager();
         foreach ($classes as $class) {
             $metadata = $em->getClassMetadata($class);
             $table_name = $metadata->getTableName();
             if ($schemaManager->tablesExist([$table_name]) == true) {
                 array_push($models, $metadata);
             }
         }
         if (count($models) > 0) {
             $schema->dropSchema($models);
         } else {
             $output->writeln('Nao ha models exportados para o banco de dados');
         }
     } catch (\Doctrine\ORM\Mapping\MappingException $e) {
         $output->writeln('Erro encontrado:');
         $output->writeln($e->getMessage());
         return;
     }
     $output->writeln('Tabelas removidas com sucesso.');
 }
Exemplo n.º 2
0
 /**
  * do the thing here.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new DoctrineAdapter();
     $driver->init();
     $em = $driver->getManager();
     $schema = new SchemaTool($em);
     $models = [];
     $model_name = $input->getArgument('model_name');
     $full_name = Config::getInstance()->get('root-namespace') . '\\Models' . '\\' . $model_name . 'Model';
     $schemaManager = $em->getConnection()->getSchemaManager();
     try {
         $metadata = $em->getClassMetadata($full_name);
         $table_name = $metadata->getTableName();
         if ($schemaManager->tablesExist([$table_name]) == true) {
             $models[] = $metadata;
         }
         if (count($models) > 0) {
             $schema->dropSchema($models);
         } else {
             $output->writeln('O model ' . $full_name . ' nao esta registrado no banco de dados.');
         }
     } catch (\Doctrine\ORM\Mapping\MappingException $e) {
         $output->writeln('Erro encontrado:');
         $output->writeln($e->getMessage());
         return;
     }
     $output->writeln('Tabela ' . $table_name . ' removida com sucesso.');
 }
Exemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new DoctrineAdapter();
     $driver->init();
     $manager = $driver->getManager();
     $cacheDriver = $manager->getConfiguration()->getResultCacheImpl();
     try {
         if (is_object($cacheDriver)) {
             $deleted = $cacheDriver->deleteAll();
         }
     } catch (\Exception $e) {
         $output->writeln('Falha na conexao com o servidor de cache:');
         $output->writeln($e->getMessage());
     }
     if (isset($deleted)) {
         $output->writeln('Cache limpo com sucesso.');
     }
 }
Exemplo n.º 4
0
 /**
  * do the thing here.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new DoctrineAdapter();
     $driver->init();
     $em = $driver->getManager();
     $classes = loadAppModels();
     $schema = new SchemaTool($em);
     $models = [];
     try {
         $schemaManager = $em->getConnection()->getSchemaManager();
         foreach ($classes as $class) {
             $metadata = $em->getClassMetadata($class);
             $table_name = $metadata->getTableName();
             if ($schemaManager->tablesExist([$table_name]) != true) {
                 $models[] = $metadata;
             }
         }
         if (count($models) > 0) {
             $schema->createSchema($models);
         } else {
             $output->writeln('Sem Models para exportar');
         }
         if ($input->getOption('update')) {
             $models = [];
             foreach ($classes as $class) {
                 $metadata = $em->getClassMetadata($class);
                 $table_name = $metadata->getTableName();
                 if ($schemaManager->tablesExist([$table_name]) == true) {
                     $models[] = $metadata;
                 }
             }
             if (count($models) > 0) {
                 $schema->updateSchema($models);
             } else {
                 $output->writeln('Sem models para atualizar');
             }
         }
     } catch (\Doctrine\ORM\Mapping\MappingException $e) {
         $output->writeln('Erro encontrado:');
         $output->writeln($e->getMessage());
     }
     $output->writeln('Banco de dados sincronizado com sucesso.');
 }