public function execute() { if (!$this->safeToRun('address')) { $this->printDebug('script already running'); die; } if (!$this->_addresses) { $this->setAddresses(); } if (!count($this->_addresses)) { echo 'no more addresses'; die; } foreach ($this->_addresses as $address) { try { $this->db->beginTransaction(); $this->printDebug('standardizing ' . $address->getOneLiner() . ' entity: ' . $address->entity_id); $address = AddressTable::standardize($address); if ($address) { $address->save(); $this->printDebug('address saved'); $this->printDebug('saved as ' . $address->getOneLiner()); } $this->saveMeta('standardization', 'last_processed', $address->id); $this->db->commit(); } catch (Exception $e) { $this->db->rollback(); throw $e; } } }
public function addAddress($address) { if (!($address = AddressTable::standardize($address))) { return false; } if ($this->exists()) { if ($address->latitude && $address->longitude && AddressTable::getByCoordsQuery($address->longitude, $address->latitude, $this)->count()) { return false; } else { if (!$address->latitude && AddressTable::retrieveByAddress($address, false, $this)) { return false; } } } $this->Address[] = $address; return $address; }
public function executeEditAddress($request) { $this->address = Doctrine::getTable('Address')->find($request->getParameter('id')); $this->forward404Unless($this->address); $this->entity = $this->address->Entity; $this->forward404Unless($this->entity); $this->address_form = new AddressForm($this->address); $this->reference_form = new ReferenceForm(); $this->reference_form->setSelectObject($this->entity, false, true); if ($request->isMethod('post')) { $params = $request->getParameter('address'); $refParams = $request->getParameter('reference'); $this->address_form->bind($params); $this->reference_form->bind($refParams); if ($this->address_form->isValid() && $this->reference_form->isValid()) { $this->address_form->updateObject(); $address = $this->address_form->getObject(); //standardize $address = AddressTable::standardize($address); //make sure edited address isn't a duplicate if ($address->latitude && $address->longitude) { $q = AddressTable::getByCoordsQuery($address->longitude, $address->latitude, $this->entity); $q->addWhere('a.entity_id <> ?', $this->entity->id); if (!$q->count()) { //save address and reference $address->saveWithRequiredReference($refParams); $this->clearCache($this->entity); $this->redirect('entity/address?id=' . $address->id); } else { $validator = new sfValidatorString(array(), array('invalid' => 'This ' . strtolower($this->entity->getPrimaryExtension()) . ' already has an address with the same coordinates')); $this->address_form->getErrorSchema()->addError(new sfValidatorError($validator, 'invalid')); } } else { $address->save(); $this->clearCache($this->entity); $this->redirect('entity/address?id=' . $address->id); } } } }