From 6f7822b07d3647a1d9dafbb5bdc76fe71df1f217 Mon Sep 17 00:00:00 2001
From: Ninassi Benjamin <benjamin.ninassi@inria.fr>
Date: Tue, 9 Apr 2019 10:07:41 +0200
Subject: [PATCH] adding some controle

---
 .../ImportStructuresFromJsonCommand.php       | 46 ++++++++++++++-----
 1 file changed, 35 insertions(+), 11 deletions(-)

diff --git a/src/ClassCodeBundle/Command/ImportStructuresFromJsonCommand.php b/src/ClassCodeBundle/Command/ImportStructuresFromJsonCommand.php
index 67eebd2..99c47c2 100644
--- a/src/ClassCodeBundle/Command/ImportStructuresFromJsonCommand.php
+++ b/src/ClassCodeBundle/Command/ImportStructuresFromJsonCommand.php
@@ -73,22 +73,46 @@ class ImportStructuresFromJsonCommand extends ContainerAwareCommand
           $type = ltrim(rtrim($data_structure['type']));      
           $name = ltrim(rtrim($data_structure['name']));
           if($type && $name){
-            
-            $logo = ltrim(rtrim($data_structure['logo']));   
-            $url = ltrim(rtrim($data_structure['url']));   
-            $who = ltrim(rtrim($data_structure['who']));
-            $address = ltrim(rtrim($data_structure['address']));
-            $location = $data_structure['location'];
-            if($location && is_array($location)){
-              $lat = ltrim(rtrim($location['lat']));
-              $long = ltrim(rtrim($location['lng']));
+            if($data_structure['logo']){
+              $logo = ltrim(rtrim($data_structure['logo']));  
+            }else{
+              $logo ="";
+            }
+            if($data_structure['url']){
+              $url = ltrim(rtrim($data_structure['url']));  
+            }else{
+              $url="";
+            }
+            if($data_structure['who']){
+              $who = ltrim(rtrim($data_structure['who']));  
+            }else{
+              $who = "";
+            }
+            if($data_structure['address']){
+              $address = ltrim(rtrim($data_structure['address']));  
+            }else{
+              $address="";
+            }
+            if($data_structure['location']){
+              $location = $data_structure['location'];
+              if($location && is_array($location) && $location['lat'] && $location['lng']){
+                $lat = ltrim(rtrim($location['lat']));
+                $long = ltrim(rtrim($location['lng']));
+              }else{
+                $lat = 0;
+                $long = 0;
+              }  
             }else{
               $lat = 0;
               $long = 0;
             }
-            $email = ltrim(rtrim($data_structure['email']));
+            if($data_structure['email']){
+              $email = ltrim(rtrim($data_structure['email']));  
+            }else{
+              $email="";
+            }            
       
-            $structure =  $em->getRepository('ClassCodeBundle:Structure')->findOneBy(array('name' => $name,'type' => $type) );
+            $structure =  $em->getRepository('ClassCodeBundle:Structure')->findOneBy(array('name' => $name,'mainType' => $type) );
             
             if(!$structure){
               $structure = new Structure();   
-- 
GitLab