/** * Importing Legacy Records. * */ public function legacyUpdateRecordsAction($records) { global $refOrganisationUnit, $refFieldOptions, $refField; $em = $this->getDoctrine()->getManager(); $records = json_decode($records, True); foreach ($records as $keys => $record) { $value = $record[0]['value']; foreach ($value as $key => $valueInstance) { //checking if the Key Exists and substitute with the DB reference Key if (isset($refField[$key])) { unset($value[$key]); //checking if the field is Select field for reference checking $field = $em->getRepository('HrisFormBundle:Field')->findOneby(array('uid' => $refField[$key])); if ($field->getInputType()->getName() == 'Select') { if (isset($refFieldOptions[$valueInstance])) { $valueInstance = $refFieldOptions[$valueInstance]; } } $value[$refField[$key]] = $valueInstance; } } //getting the Object if Exist from the Database $form = $em->getRepository('HrisFormBundle:Form')->findOneby(array('name' => $record['form_name'])); $orgunitParent = $em->getRepository('HrisOrganisationunitBundle:Organisationunit')->findOneby(array('longname' => $record['orgunit_parent'])); $orgunit = $em->getRepository('HrisOrganisationunitBundle:Organisationunit')->findOneby(array('longname' => $record['orgunit_name'], 'parent' => $orgunitParent)); $recordObjectCheck = $em->getRepository('HrisRecordsBundle:Record')->findOneby(array('instance' => $record[0]['instance'])); $createdDate = new \DateTime($record[0]['inputDate']['date']); if (empty($recordObjectCheck)) { $recordObject = new Record(); $recordObject->setForm($form); $recordObject->setOrganisationunit($orgunit); $recordObject->setInstance($record[0]['instance']); $recordObject->setUid(uniqid()); $recordObject->setValue($value); $recordObject->setDatecreated($createdDate); $recordObject->setUsername($record[0]['username']); $em->persist($recordObject); } } $em->flush(); return new Response('success'); }