Commit 2c37cd9a2181eb1075c7f8ba89f0a0572d340675
1 parent
e51667b5
Exists in
master
Evita coleta de classe repetida e conserta versão do software
Showing
4 changed files
with
80 additions
and
11 deletions
Show diff stats
src/Cacic/CommonBundle/DoctrineMigrations/Version20141030153634.php
0 → 100644
| @@ -0,0 +1,68 @@ | @@ -0,0 +1,68 @@ | ||
| 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 | + * Auto-generated Migration: Please modify to your needs! | ||
| 12 | + */ | ||
| 13 | +class Version20141030153634 extends AbstractMigration implements ContainerAwareInterface | ||
| 14 | +{ | ||
| 15 | + private $container; | ||
| 16 | + | ||
| 17 | + public function setContainer(ContainerInterface $container = null) | ||
| 18 | + { | ||
| 19 | + $this->container = $container; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public function up(Schema $schema) | ||
| 23 | + { | ||
| 24 | + // this up() migration is auto-generated, please modify it to your needs | ||
| 25 | + $this->abortIf($this->connection->getDatabasePlatform()->getName() != "postgresql", "Migration can only be executed safely on 'postgresql'."); | ||
| 26 | + $logger = $this->container->get('logger'); | ||
| 27 | + | ||
| 28 | + $this->addSql(" | ||
| 29 | + CREATE OR REPLACE FUNCTION conserta_propriedade() RETURNS VOID AS $$ | ||
| 30 | + DECLARE | ||
| 31 | + impr record; | ||
| 32 | + v_id integer; | ||
| 33 | + BEGIN | ||
| 34 | + FOR impr IN select id_class_property | ||
| 35 | + from class_property | ||
| 36 | + where id_class IS NULL LOOP | ||
| 37 | + | ||
| 38 | + RAISE NOTICE 'Removing property_id = %',impr.id_class_property; | ||
| 39 | + | ||
| 40 | + DELETE FROM computador_coleta_historico | ||
| 41 | + WHERE id_class_property = impr.id_class_property; | ||
| 42 | + | ||
| 43 | + DELETE FROM computador_coleta | ||
| 44 | + WHERE id_class_property = impr.id_class_property; | ||
| 45 | + | ||
| 46 | + DELETE FROM class_property | ||
| 47 | + WHERE id_class_property = impr.id_class_property; | ||
| 48 | + | ||
| 49 | + END LOOP; | ||
| 50 | + RETURN; | ||
| 51 | + END; | ||
| 52 | + $$ LANGUAGE 'plpgsql'; | ||
| 53 | + "); | ||
| 54 | + $logger->info("Função de atualização das impressoras criada"); | ||
| 55 | + $this->addSql("SELECT conserta_propriedade();"); | ||
| 56 | + $logger->info("Propriedades nulas removaidas"); | ||
| 57 | + $this->addSql("ALTER TABLE class_property ALTER id_class SET NOT NULL;"); | ||
| 58 | + $logger->info("Índice único criado"); | ||
| 59 | + | ||
| 60 | + | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public function down(Schema $schema) | ||
| 64 | + { | ||
| 65 | + // this down() migration is auto-generated, please modify it to your needs | ||
| 66 | + | ||
| 67 | + } | ||
| 68 | +} |
src/Cacic/CommonBundle/Entity/ClassProperty.php
src/Cacic/CommonBundle/Resources/config/doctrine/ClassProperty.orm.yml
| @@ -39,5 +39,6 @@ Cacic\CommonBundle\Entity\ClassProperty: | @@ -39,5 +39,6 @@ Cacic\CommonBundle\Entity\ClassProperty: | ||
| 39 | joinColumns: | 39 | joinColumns: |
| 40 | id_class: | 40 | id_class: |
| 41 | referencedColumnName: id_class | 41 | referencedColumnName: id_class |
| 42 | + nullable: false | ||
| 42 | orphanRemoval: false | 43 | orphanRemoval: false |
| 43 | lifecycleCallbacks: { } | 44 | lifecycleCallbacks: { } |
src/Cacic/WSBundle/Controller/NeoController.php
| @@ -267,7 +267,7 @@ class NeoController extends Controller { | @@ -267,7 +267,7 @@ class NeoController extends Controller { | ||
| 267 | 267 | ||
| 268 | // 2 - Adiciona módulos da subrede | 268 | // 2 - Adiciona módulos da subrede |
| 269 | $modulos = $em->getRepository('CacicCommonBundle:RedeVersaoModulo')->findBy(array('idRede' => $computador->getIdRede())); | 269 | $modulos = $em->getRepository('CacicCommonBundle:RedeVersaoModulo')->findBy(array('idRede' => $computador->getIdRede())); |
| 270 | - $logger->debug("Módulos encontrados \n". print_r($modulos, true)); | 270 | + //$logger->debug("Módulos encontrados \n". print_r($modulos, true)); |
| 271 | $mods = array(); | 271 | $mods = array(); |
| 272 | foreach($modulos as $elm) { | 272 | foreach($modulos as $elm) { |
| 273 | $tipo = $elm->getTipo(); | 273 | $tipo = $elm->getTipo(); |
| @@ -667,19 +667,19 @@ class NeoController extends Controller { | @@ -667,19 +667,19 @@ class NeoController extends Controller { | ||
| 667 | $logger = $this->get('logger'); | 667 | $logger = $this->get('logger'); |
| 668 | $em = $this->getDoctrine()->getManager(); | 668 | $em = $this->getDoctrine()->getManager(); |
| 669 | 669 | ||
| 670 | - try { | ||
| 671 | - $classObject = $em->getRepository('CacicCommonBundle:Classe')->findOneBy( array( | ||
| 672 | - 'nmClassName'=> $classe | ||
| 673 | - )); | ||
| 674 | - } | ||
| 675 | - catch(\Doctrine\ORM\NoResultException $e) { | ||
| 676 | - $logger->error("COLETA: Classe não cadastrada: $classe \n$e"); | 670 | + $classObject = $em->getRepository('CacicCommonBundle:Classe')->findOneBy( array( |
| 671 | + 'nmClassName'=> $classe | ||
| 672 | + )); | ||
| 673 | + | ||
| 674 | + if (empty($classObject)) { | ||
| 675 | + $logger->error("COLETA: Classe não cadastrada: $classe"); | ||
| 677 | return; | 676 | return; |
| 678 | } | 677 | } |
| 679 | 678 | ||
| 680 | foreach (array_keys($valor) as $propriedade) { | 679 | foreach (array_keys($valor) as $propriedade) { |
| 681 | if (is_array($valor[$propriedade])) { | 680 | if (is_array($valor[$propriedade])) { |
| 682 | $logger->error("COLETA: Atributo $propriedade multivalorado não implementado na coleta"); | 681 | $logger->error("COLETA: Atributo $propriedade multivalorado não implementado na coleta"); |
| 682 | + $valor[$propriedade] = $valor[$propriedade][0]; | ||
| 683 | continue; | 683 | continue; |
| 684 | } | 684 | } |
| 685 | $logger->debug("COLETA: Gravando dados da propriedade $propriedade com o valor ".$valor[$propriedade]); | 685 | $logger->debug("COLETA: Gravando dados da propriedade $propriedade com o valor ".$valor[$propriedade]); |
| @@ -835,7 +835,7 @@ class NeoController extends Controller { | @@ -835,7 +835,7 @@ class NeoController extends Controller { | ||
| 835 | $propSoftware->setUrlInfoAbout($valor['url']); | 835 | $propSoftware->setUrlInfoAbout($valor['url']); |
| 836 | } | 836 | } |
| 837 | if (array_key_exists('version', $valor)) { | 837 | if (array_key_exists('version', $valor)) { |
| 838 | - $propSoftware->setDisplayVersion($valor['url']); | 838 | + $propSoftware->setDisplayVersion($valor['version']); |
| 839 | } | 839 | } |
| 840 | 840 | ||
| 841 | $em->persist($classProperty); | 841 | $em->persist($classProperty); |
| @@ -871,4 +871,4 @@ class NeoController extends Controller { | @@ -871,4 +871,4 @@ class NeoController extends Controller { | ||
| 871 | 871 | ||
| 872 | } | 872 | } |
| 873 | 873 | ||
| 874 | -} | ||
| 875 | \ No newline at end of file | 874 | \ No newline at end of file |
| 875 | +} |