/** * Remove the invalid emails from records to be imported */ protected function beforeImport($params, &$model, &$attributes, $record) { if (isset($attributes['email']) && !\GO\Base\Util\String::validate_email($attributes['email'])) { unset($attributes['email']); } return parent::beforeImport($params, $model, $attributes, $record); }
/** * Before importing a contact in the database first check if the company name of this contact * Is a company that excists in the database. If not create a company. After this set the id * of the create company to the contact we insert. * * If the email addres set to a contact does not validate. Remove it so import wont fail */ protected function beforeImport($params, &$model, &$attributes, $record) { $impBasParams = json_decode($params['importBaseParams'], true); $addressbookId = $impBasParams['addressbook_id']; if (!empty($attributes['Company'])) { $companyName = $attributes['Company']; } else { if (!empty($attributes['company'])) { $companyName = $attributes['company']; } else { if (!empty($attributes['company_name'])) { $companyName = $attributes['company_name']; } else { if (!empty($attributes['companyName'])) { $companyName = $attributes['companyName']; } else { if (!empty($attributes['name'])) { $companyName = $attributes['name']; } } } } } if (!empty($companyName)) { $companyModel = \GO\Addressbook\Model\Company::model()->find(\GO\Base\Db\FindParams::newInstance()->single()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('name', $companyName)->addCondition('addressbook_id', $addressbookId))); if (empty($companyModel)) { $companyModel = new \GO\Addressbook\Model\Company(); $companyModel->setAttributes(array('name' => $companyName, 'addressbook_id' => $addressbookId)); $companyModel->save(); } $model->company_id = $companyModel->id; } if (isset($attributes['email']) && !\GO\Base\Util\String::validate_email($attributes['email'])) { unset($attributes['email']); } if (isset($attributes['email2']) && !\GO\Base\Util\String::validate_email($attributes['email2'])) { unset($attributes['email2']); } if (isset($attributes['email3']) && !\GO\Base\Util\String::validate_email($attributes['email3'])) { unset($attributes['email3']); } return parent::beforeImport($params, $model, $attributes, $record); }