/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $factory = $this->container->get('mautic.factory'); $leadRepo = $factory->getModel('lead.lead')->getRepository(); $today = new \DateTime(); $leads = CsvHelper::csv_to_array(__DIR__ . '/fakeleaddata.csv'); foreach ($leads as $count => $l) { $key = $count + 1; $lead = new Lead(); $lead->setDateAdded($today); $ipAddress = new IpAddress(); $ipAddress->setIpAddress($l['ip'], $factory->getSystemParameters()); $this->setReference('ipAddress-' . $key, $ipAddress); unset($l['ip']); $lead->addIpAddress($ipAddress); $lead->setOwner($this->getReference('sales-user')); foreach ($l as $col => $val) { $lead->addUpdatedField($col, $val); } $leadRepo->saveEntity($lead); $this->setReference('lead-' . $count, $lead); } }
/** * {@inheritDoc} */ public function addUpdatedField($alias, $value, $oldValue = '') { $this->__initializer__ && $this->__initializer__->__invoke($this, 'addUpdatedField', array($alias, $value, $oldValue)); return parent::addUpdatedField($alias, $value, $oldValue); }
/** * {@inheritdoc} * * @param Lead $entity * @param bool $unlock */ public function saveEntity($entity, $unlock = true) { //check to see if we can glean information from ip address if (!$entity->imported && count($ips = $entity->getIpAddresses())) { $fields = $entity->getFields(); $details = $ips->first()->getIpDetails(); if (!empty($details['city']) && empty($fields['core']['city']['value'])) { $entity->addUpdatedField('city', $details['city']); } if (!empty($details['region']) && empty($fields['core']['state']['value'])) { $entity->addUpdatedField('state', $details['region']); } if (!empty($details['country']) && empty($fields['core']['country']['value'])) { $entity->addUpdatedField('country', $details['country']); } if (!empty($details['zipcode']) && empty($fields['core']['zipcode']['value'])) { $entity->addUpdatedField('zipcode', $details['zipcode']); } } parent::saveEntity($entity, $unlock); }
/** * {@inheritdoc} * * @param Lead $entity * @param bool $unlock */ public function saveEntity($entity, $unlock = true) { $companyFieldMatches = []; $fields = $entity->getFields(); $updatedFields = $entity->getUpdatedFields(); $company = null; if (isset($updatedFields['company'])) { $companyFieldMatches['company'] = $updatedFields['company']; } //check to see if we can glean information from ip address if (!$entity->imported && count($ips = $entity->getIpAddresses())) { $details = $ips->first()->getIpDetails(); if (!empty($details['city']) && empty($fields['core']['city']['value'])) { $entity->addUpdatedField('city', $details['city']); $companyFieldMatches['city'] = $details['city']; } if (!empty($details['region']) && empty($fields['core']['state']['value'])) { $entity->addUpdatedField('state', $details['region']); $companyFieldMatches['state'] = $details['region']; } if (!empty($details['country']) && empty($fields['core']['country']['value'])) { $entity->addUpdatedField('country', $details['country']); $companyFieldMatches['country'] = $details['country']; } if (!empty($details['zipcode']) && empty($fields['core']['zipcode']['value'])) { $entity->addUpdatedField('zipcode', $details['zipcode']); } } if (!empty($companyFieldMatches)) { list($company, $leadAdded) = IdentifyCompanyHelper::identifyLeadsCompany($companyFieldMatches, $entity, $this->companyModel); if ($leadAdded) { $entity->addCompanyChangeLogEntry('form', 'Identify Company', 'Lead added to the company, ' . $company['companyname'], $company['id']); } unset($updatedFields['company']); } parent::saveEntity($entity, $unlock); if (!empty($company)) { // Save after the lead in for new leads created through the API and maybe other places $this->companyModel->addLeadToCompany($company['id'], $entity, true); } }