Commit 88edaeafe84d9dc7b17861ee8df8c7201e446dba
Committed by
Eduardo Santos
1 parent
d2df0718
Exists in
master
and in
1 other branch
Desabilita por padrão a coleta de patrimônio em todos os módulos
Showing
2 changed files
with
64 additions
and
12 deletions
Show diff stats
src/Cacic/CommonBundle/DoctrineMigrations/Version20140527164952.php
0 → 100644
| ... | ... | @@ -0,0 +1,48 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Cacic\CommonBundle\Migrations; | |
| 4 | + | |
| 5 | +use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
| 6 | +use Symfony\Component\DependencyInjection\ContainerInterface; | |
| 7 | +use Doctrine\DBAL\Migrations\AbstractMigration; | |
| 8 | +use Doctrine\DBAL\Schema\Schema; | |
| 9 | + | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Auto-generated Migration: Please modify to your needs! | |
| 13 | + */ | |
| 14 | +class Version20140527164952 extends AbstractMigration implements ContainerAwareInterface | |
| 15 | +{ | |
| 16 | + private $container; | |
| 17 | + | |
| 18 | + public function setContainer(ContainerInterface $container = null) | |
| 19 | + { | |
| 20 | + $this->container = $container; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public function up(Schema $schema) | |
| 24 | + { | |
| 25 | + // this up() migration is auto-generated, please modify it to your needs | |
| 26 | + $em = $this->container->get('doctrine.orm.entity_manager'); | |
| 27 | + $logger = $this->container->get('logger'); | |
| 28 | + $modulos = $em->getRepository('CacicCommonBundle:Acao')->findBy( array('csOpcional' => 'N') ); | |
| 29 | + | |
| 30 | + foreach ($modulos as $elm) { | |
| 31 | + // PEga todos os módulos que são opcionais e remove da tabela acao_rede | |
| 32 | + $acoes = $em->getRepository('CacicCommonBundle:AcaoRede')->findBy( array('acao' => $elm->getIdAcao() ) ); | |
| 33 | + | |
| 34 | + foreach ($acoes as $acao) { | |
| 35 | + $em->remove($acao); | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + $em->flush(); | |
| 40 | + | |
| 41 | + } | |
| 42 | + | |
| 43 | + public function down(Schema $schema) | |
| 44 | + { | |
| 45 | + // this down() migration is auto-generated, please modify it to your needs | |
| 46 | + | |
| 47 | + } | |
| 48 | +} | ... | ... |
src/Cacic/CommonBundle/Entity/AcaoRedeRepository.php
| ... | ... | @@ -84,24 +84,28 @@ class AcaoRedeRepository extends EntityRepository |
| 84 | 84 | |
| 85 | 85 | foreach ($redes as $novaRede) { |
| 86 | 86 | |
| 87 | + // Primeiro apaga todas as ações | |
| 88 | + $acaoRede = $this->findBy( array( 'rede' => $novaRede ) ); | |
| 89 | + | |
| 90 | + foreach ($acaoRede as $acao) { | |
| 91 | + $em->remove($acao); | |
| 92 | + } | |
| 93 | + $em->flush(); | |
| 94 | + | |
| 87 | 95 | // Para cada rede, habilita as ações |
| 88 | 96 | foreach ($acoes as $novaAcao){ |
| 89 | 97 | // com excessão do módulo patrimonio, que inicialmente é desabilitado |
| 90 | - if ($novaAcao->getIdAcao() != "col_patr"){ | |
| 91 | - $new = $this->find( array( 'acao' => $novaAcao->getIdAcao(), 'rede' => $novaRede->getIdRede() )); | |
| 98 | + if ( $novaAcao->getCsOpcional() == 'S' ){ | |
| 92 | 99 | |
| 93 | - // Se não existir, cria a ação para a rede | |
| 94 | - if ( empty($new) ) { | |
| 95 | - $new = new AcaoRede(); | |
| 96 | - } | |
| 100 | + $new = new AcaoRede(); | |
| 97 | 101 | |
| 98 | - // Agora cria a ação | |
| 99 | - $new->setAcao($novaAcao); | |
| 100 | - $new->setRede($novaRede); | |
| 101 | - $em->persist($new); | |
| 102 | + // Agora cria a ação | |
| 103 | + $new->setAcao($novaAcao); | |
| 104 | + $new->setRede($novaRede); | |
| 105 | + $em->persist($new); | |
| 102 | 106 | |
| 103 | - // Grava as mudanças | |
| 104 | - $em->flush(); | |
| 107 | + // Grava as mudanças | |
| 108 | + $em->flush(); | |
| 105 | 109 | } |
| 106 | 110 | } |
| 107 | 111 | ... | ... |