/** * Exclude object from result * * @param ChildCustomerTemp $customerTemp Object to remove from the list of results * * @return ChildCustomerTempQuery The current query, for fluid interface */ public function prune($customerTemp = null) { if ($customerTemp) { $this->addUsingAlias(CustomerTempTableMap::ID, $customerTemp->getId(), Criteria::NOT_EQUAL); } return $this; }
public function import($startRecord = 0) { $count = 0; $errors = 0; $hdl = $this->t1db->query(sprintf("select * from client order by id asc limit %d, %d", intval($startRecord), $this->getChunkSize())); while ($hdl && ($client = $this->t1db->fetch_object($hdl))) { $count++; try { $this->cust_corresp->getT2($client->id); Tlog::getInstance()->warning("Customer ID={$client->id} ref={$client->ref} already imported."); continue; } catch (ImportException $ex) { // Okay, the order was not imported. } try { $title = $this->getT2CustomerTitle($client->raison); $lang = $this->getT2Lang($client->lang); $country = $this->getT2Country($client->pays); try { $sponsor = $this->cust_corresp->getT2($client->parrain); } catch (ImportException $ex) { $sponsor = ''; } $event = new CustomerCreateOrUpdateEvent($title->getId(), $client->prenom, $client->nom, $client->adresse1, $client->adresse2, $client->adresse3, $client->telfixe, $client->telport, $client->cpostal, $client->ville, $country->getId(), $client->email, $client->email, $lang->getId(), $client->type == 1 ? true : false, $sponsor, $client->pourcentage, $client->entreprise, $client->ref); $this->dispatcher->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $event); Tlog::getInstance()->info("Created customer " . $event->getCustomer()->getId() . " from {$client->ref} ({$client->id})"); if (empty($client->email)) { $client->email = 'empty-mail' . $event->getCustomer()->getId() . '@fake-email.com'; } $customerTemp = new CustomerTemp(); $customerTemp->setEmail($client->email)->setPassword($client->motdepasse)->save(); // Import customer addresses $a_hdl = $this->t1db->query("select * from adresse where client=?", array($client->id)); while ($a_hdl && ($adresse = $this->t1db->fetch_object($a_hdl))) { try { $title = $this->getT2CustomerTitle($adresse->raison); $country = $this->getT2Country($adresse->pays); $adr_event = new AddressCreateOrUpdateEvent($adresse->libelle, $title->getId(), $adresse->prenom, $adresse->nom, $adresse->adresse1, $adresse->adresse2, $adresse->adresse3, $adresse->cpostal, $adresse->ville, $country->getId(), '', $adresse->tel, isset($adresse->entreprise) ? $adresse->entreprise : ''); $adr_event->setCustomer($event->getCustomer()); $this->dispatcher->dispatch(TheliaEvents::ADDRESS_CREATE, $adr_event); Tlog::getInstance()->info("Created address " . $adr_event->getAddress()->getId() . " for customer {$client->ref} ({$client->id})"); } catch (ImportException $ex) { Tlog::getInstance()->addError("Failed to create address ID {$adresse->id} for customer ref {$client->ref}:", $ex->getMessage()); } } $this->cust_corresp->addEntry($client->id, $event->getCustomer()->getId()); } catch (\Exception $ex) { Tlog::getInstance()->addError("Failed to import customer ref {$client->ref} :", $ex->getMessage()); $errors++; } } return new ImportChunkResult($count, $errors); }