Mentions légales du service

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

correcting json import

parent 37d64be8
No related branches found
No related tags found
No related merge requests found
......@@ -67,57 +67,60 @@ class ImportStructuresFromJsonCommand extends ContainerAwareCommand
$json_source = file_get_contents($structureFile);
$json_array = json_decode($json_source,true);
}
foreach ($json_array as $data_structure) {
$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']));
}else{
$lat = 0;
$long = 0;
}
$email = ltrim(rtrim($data_structure['email']));
$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);
if($json_array['structures']){
foreach ($json_array as $data_structure) {
$type = ltrim(rtrim($data_structure['type']));
$name = ltrim(rtrim($data_structure['name']));
if($type && $name){
$em->persist($structure);
$em->flush();
}
}
$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']));
}else{
$lat = 0;
$long = 0;
}
$email = ltrim(rtrim($data_structure['email']));
$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);
$em->flush();
}
}
}
}else{
$log_msg_error .= "No structures found, aborting import !\n";
}
$em->clear();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment