private function doInstitution(Institution $institution, $em) { //$this->output->write("Institution #{$institution->getId()}"); $oldState = \trim($institution->getStateBak()); if ($oldState == '') { //$this->output->writeln('[No old state]'); return; } $country = $institution->getCountry(); // find a state with the same name for this country in chromedia_global $connection = $this->doctrine->getConnection(); $sql = "SELECT gs.* FROM `chromedia_global`.`geo_states` gs WHERE `name` LIKE :state AND `geo_country_id` = :geoCountryId"; $statement = $connection->prepare($sql); $statement->bindValue('state', $oldState); $statement->bindValue('geoCountryId', $country->getId()); $statement->execute(); if (!($rowCount = $statement->rowCount())) { //$this->output->writeln('[No matching state]'); $this->nonMatchingInstitutions[] = $institution; return; } else { if ($rowCount == 1) { $globalStateData = $statement->fetch(); $hcaState = $this->getHcaState($globalStateData, $country); $institution->setState($hcaState); $em->persist($institution); //$this->output->writeln("[Set to {$hcaState->getName()} ]"); } else { if (strtolower($oldState) == 'singapore') { // manual for singapore while ($globalStateData = $statement->fetch()) { if ($globalStateData['id'] == 2732) { $hcaState = $this->getHcaState($globalStateData, $country); $institution->setState($hcaState); $em->persist($institution); //$this->output->writeln("[Set to {$hcaState->getName()} ]"); break; } } } else { $this->nonUniqueStates[] = array('country_id' => $country->getId(), 'state' => $oldState); //$this->output->writeln("[Non unique state {$oldState}]"); $this->nonMatchingInstitutions[] = $institution; } } } }