Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 305ea826 authored by NINASSI Benjamin's avatar NINASSI Benjamin
Browse files

json import correction

parent 4e4fcc20
Branches
No related tags found
No related merge requests found
...@@ -68,56 +68,60 @@ class ImportStructuresFromJsonCommand extends ContainerAwareCommand ...@@ -68,56 +68,60 @@ class ImportStructuresFromJsonCommand extends ContainerAwareCommand
$json_array = json_decode($json_source,true); $json_array = json_decode($json_source,true);
} }
if($json_array['structures']){ if($json_array['structures']){
foreach ($json_array as $data_structure) { foreach ($json_array['structures'] as $data_structure) {
$type = ltrim(rtrim($data_structure['type'])); if($data_structure['type'] && $data_structure['name']){
$name = ltrim(rtrim($data_structure['name'])); $type = ltrim(rtrim($data_structure['type']));
if($type && $name){ $name = ltrim(rtrim($data_structure['name']));
if($type && $name){
$logo = ltrim(rtrim($data_structure['logo']));
$url = ltrim(rtrim($data_structure['url'])); $logo = ltrim(rtrim($data_structure['logo']));
$who = ltrim(rtrim($data_structure['who'])); $url = ltrim(rtrim($data_structure['url']));
$address = ltrim(rtrim($data_structure['address'])); $who = ltrim(rtrim($data_structure['who']));
$location = $data_structure['location']; $address = ltrim(rtrim($data_structure['address']));
if($location && is_array($location)){ $location = $data_structure['location'];
$lat = ltrim(rtrim($location['lat'])); if($location && is_array($location)){
$long = ltrim(rtrim($location['lng'])); $lat = ltrim(rtrim($location['lat']));
}else{ $long = ltrim(rtrim($location['lng']));
$lat = 0; }else{
$long = 0; $lat = 0;
} $long = 0;
$email = ltrim(rtrim($data_structure['email'])); }
$email = ltrim(rtrim($data_structure['email']));
$structure = $em->getRepository('ClassCodeBundle:Structure')->findOneBy(array('name' => $name,'type' => $type) );
$structure = $em->getRepository('ClassCodeBundle:Structure')->findOneBy(array('name' => $name,'type' => $type) );
if(!$structure){
$structure = new Structure();
$structure->setName($name);
$structure->setMainType($type);
}
if(($structure->getLogo() != $logo)||
($structure->getUrl() != $url)||
($structure->getWho()!=$who)||
($structure->getAddress() != $address)||
($structure->getLatitude() != $lat)||
($structure->getLongitude() != $long)||
($structure->getDataSource() != $dataSource)||
($structure->getEmail() != $email)){
$structure->setLogo($logo);
$structure->setUrl($url);
$structure->setWho($who);
$structure->setEmail($email);
$structure->setAddress($address);
$structure->setLatitude($lat);
$structure->setLongitude($long);
$structure->setDataSource($dataSource);
$structure->setUpdatedAt(new \DateTime());
$structure->setUpdatedBy($userName);
$em->persist($structure); if(!$structure){
$em->flush(); $structure = new Structure();
} $structure->setName($name);
} $structure->setMainType($type);
}
if(($structure->getLogo() != $logo)||
($structure->getUrl() != $url)||
($structure->getWho()!=$who)||
($structure->getAddress() != $address)||
($structure->getLatitude() != $lat)||
($structure->getLongitude() != $long)||
($structure->getDataSource() != $dataSource)||
($structure->getEmail() != $email)){
$structure->setLogo($logo);
$structure->setUrl($url);
$structure->setWho($who);
$structure->setEmail($email);
$structure->setAddress($address);
$structure->setLatitude($lat);
$structure->setLongitude($long);
$structure->setDataSource($dataSource);
$structure->setUpdatedAt(new \DateTime());
$structure->setUpdatedBy($userName);
$em->persist($structure);
$em->flush();
}
}
}else{
$log_msg_error .= "No type or no name defined, structure passed !\n";
}
} }
}else{ }else{
$log_msg_error .= "No structures found, aborting import !\n"; $log_msg_error .= "No structures found, aborting import !\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment