diff --git a/composer.lock b/composer.lock index 7666dec2..bfae9cb5 100644 --- a/composer.lock +++ b/composer.lock @@ -367,12 +367,12 @@ "source": { "type": "git", "url": "https://github.com/as3io/symfony-data-importer.git", - "reference": "ef74374c5ba8144486a64f541b8b4b2c6e537e54" + "reference": "cc8bfdc84860baadda97b3f82a2f8defbb71038f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/as3io/symfony-data-importer/zipball/ef74374c5ba8144486a64f541b8b4b2c6e537e54", - "reference": "ef74374c5ba8144486a64f541b8b4b2c6e537e54", + "url": "https://api.github.com/repos/as3io/symfony-data-importer/zipball/cc8bfdc84860baadda97b3f82a2f8defbb71038f", + "reference": "cc8bfdc84860baadda97b3f82a2f8defbb71038f", "shasum": "" }, "require": { @@ -396,7 +396,7 @@ } ], "description": "Symfony console application to handle data importing.", - "time": "2016-09-21 17:19:01" + "time": "2016-11-07 16:06:37" }, { "name": "doctrine/annotations", diff --git a/src/AppBundle/Import/Importer/Merrick/Identity.php b/src/AppBundle/Import/Importer/Merrick/Identity.php new file mode 100644 index 00000000..473a0d79 --- /dev/null +++ b/src/AppBundle/Import/Importer/Merrick/Identity.php @@ -0,0 +1,40 @@ + + */ +class Identity extends Merrick +{ + /** + * {@inheritdoc} + */ + public function __construct(AccountManager $accountManager, PersisterInterface $persister, SourceInterface $source) + { + parent::__construct($accountManager, $persister, $source); + $source->setDatabase('merrick'); + + // Identity data + $this->segments[] = new Segment\Account($this, $source); + $this->segments[] = new Segment\External($this, $source); + $this->segments[] = new Segment\Internal($this, $source); + $this->segments[] = new Segment\AccountEmail($this, $source); + } + + /** + * {@inheritdoc} + */ + public function getKey() + { + return 'merrick_identity'; + } +} diff --git a/src/AppBundle/Import/Importer/Merrick/Customer.php b/src/AppBundle/Import/Importer/Merrick/IdentityData.php similarity index 55% rename from src/AppBundle/Import/Importer/Merrick/Customer.php rename to src/AppBundle/Import/Importer/Merrick/IdentityData.php index cf0a1909..73be021c 100644 --- a/src/AppBundle/Import/Importer/Merrick/Customer.php +++ b/src/AppBundle/Import/Importer/Merrick/IdentityData.php @@ -4,7 +4,7 @@ use AppBundle\Core\AccountManager; use AppBundle\Import\Importer\Merrick; -use AppBundle\Import\Segment\Merrick\Customer as Segment; +use AppBundle\Import\Segment\Merrick\IdentityData as Segment; use As3\SymfonyData\Import\PersisterInterface; use As3\SymfonyData\Import\SourceInterface; @@ -13,7 +13,7 @@ * * @author Josh Worden */ -class Customer extends Merrick +class IdentityData extends Merrick { /** * {@inheritdoc} @@ -23,14 +23,14 @@ public function __construct(AccountManager $accountManager, PersisterInterface $ parent::__construct($accountManager, $persister, $source); $source->setDatabase('merrick'); - // Customer data - $this->segments[] = new Segment\Model\CustomerAccount($this, $source); - $this->segments[] = new Segment\Model\CustomerIdentity($this, $source); - $this->segments[] = new Segment\Model\CustomerAddress($this, $source); - $this->segments[] = new Segment\Model\CustomerEmail($this, $source); + // Input submissions + $this->segments[] = new Segment\InquiryRmi($this, $source); - // Demographics - $this->segments[] = new Segment\Model\CustomerAnswer($this, $source); + // Input Answers + $this->segments[] = new Segment\Answer($this, $source); + $this->segments[] = new Segment\InputAnswerOmeda($this, $source); + $this->segments[] = new Segment\InputAnswerComments($this, $source); + $this->segments[] = new Segment\InputAnswerPurchaseIntent($this, $source); } /** @@ -38,6 +38,6 @@ public function __construct(AccountManager $accountManager, PersisterInterface $ */ public function getKey() { - return 'merrick_customer'; + return 'merrick_identity_data'; } } diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAddress.php b/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAddress.php deleted file mode 100644 index f9ea8386..00000000 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAddress.php +++ /dev/null @@ -1,70 +0,0 @@ -getCollectionForModel($this->getCollection())->count($this->getCriteria()); - } - - /** - * {@inheritdoc} - */ - public function getKey() - { - return 'merrick_customer_model_customer_address'; - } - - /** - * Returns formatted key-values for the passed legacy document - * - * @param array $doc The legacy key values - * @return mixed array of key values or null - */ - protected function formatModel(array $doc) - { - $transformer = new Transformer\CustomerAddress(); - $transformer->defineStatic('legacy.id', (string) $doc['_id']); - $transformer->defineStatic('customer', ['id' => $doc['_id'], 'type' => $doc['_type']]); - return $transformer->toApp($doc['legacy']['address']); - } - - /** - * {@inheritdoc} - */ - protected function getCollection() - { - return 'customer'; - } - - /** - * {@inheritdoc} - */ - protected function getDocuments($limit = 200, $skip = 0) - { - return $this->getCollectionForModel($this->getCollection())->find($this->getCriteria(), $this->getFields())->sort($this->getSort())->limit($limit)->skip($skip); - } - - /** - * {@inheritdoc} - */ - protected function getCriteria() - { - return ['legacy.address' => ['$exists' => true]]; - } - - /** - * {@inheritdoc} - */ - protected function getModelType() - { - return 'customer-address'; - } -} diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerIdentity.php b/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerIdentity.php deleted file mode 100644 index 11dfe4a2..00000000 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerIdentity.php +++ /dev/null @@ -1,51 +0,0 @@ -define('primaryEmail', 'email', 'strtolower'); - $transformer->define('legacy.external', 'origin', function($value) { - return 'link_tracking' === $value; - }); - return $transformer->toApp($doc); - } - - /** - * {@inheritdoc} - */ - protected function getCriteria() - { - $criteria = [ - '$or' => [ - ['pwd' => ['$exists' => false]], - ['pwd' => ['$eq' => '']] - ] - ]; - return array_merge(parent::getCriteria(), $criteria); - } - - /** - * {@inheritdoc} - */ - protected function getModelType() - { - return 'customer-identity'; - } -} diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/CustomerAddress.php b/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/CustomerAddress.php deleted file mode 100644 index 2b948b25..00000000 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/CustomerAddress.php +++ /dev/null @@ -1,25 +0,0 @@ -defineStatic('legacy.source', 'customer'); - $this->define('street', 'street'); - $this->define('extra', 'extra'); - $this->define('city', 'city'); - $this->define('postalCode', 'postalCode'); - $this->define('country', 'country'); - $this->define('countryCode', 'countryCode'); - $this->define('region', 'region'); - $this->define('regionCode', 'regionCode'); - } -} diff --git a/src/AppBundle/Import/Segment/Merrick/Customer.php b/src/AppBundle/Import/Segment/Merrick/Identity.php similarity index 92% rename from src/AppBundle/Import/Segment/Merrick/Customer.php rename to src/AppBundle/Import/Segment/Merrick/Identity.php index 7cf425d0..d5d8693a 100644 --- a/src/AppBundle/Import/Segment/Merrick/Customer.php +++ b/src/AppBundle/Import/Segment/Merrick/Identity.php @@ -4,7 +4,7 @@ use AppBundle\Import\Segment\Merrick; -abstract class Customer extends Merrick +abstract class Identity extends Merrick { /** * {@inheritdoc} diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAccount.php b/src/AppBundle/Import/Segment/Merrick/Identity/Account.php similarity index 77% rename from src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAccount.php rename to src/AppBundle/Import/Segment/Merrick/Identity/Account.php index e292510e..f4addff0 100644 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAccount.php +++ b/src/AppBundle/Import/Segment/Merrick/Identity/Account.php @@ -1,17 +1,17 @@ define('legacy.email', 'email', 'strtolower'); + $transformer = new Transformer\Account(); return $transformer->toApp($doc); } @@ -46,7 +45,7 @@ protected function getCriteria() */ protected function getModelType() { - return 'customer-account'; + return 'identity-account'; } /** diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerEmail.php b/src/AppBundle/Import/Segment/Merrick/Identity/AccountEmail.php similarity index 77% rename from src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerEmail.php rename to src/AppBundle/Import/Segment/Merrick/Identity/AccountEmail.php index bcb0b2ca..690606a4 100644 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerEmail.php +++ b/src/AppBundle/Import/Segment/Merrick/Identity/AccountEmail.php @@ -1,10 +1,10 @@ $doc['legacy']['email'], 'account' => $doc['_id'] ]; - $transformer = new Transformer\CustomerEmail(); + $transformer = new Transformer\AccountEmail(); return $transformer->toApp($email); } @@ -44,7 +44,7 @@ protected function formatModel(array $doc) */ protected function getCollection() { - return 'customer'; + return 'identity'; } /** @@ -60,7 +60,7 @@ protected function getDocuments($limit = 200, $skip = 0) */ protected function getCriteria() { - return ['legacy.email' => ['$exists' => true]]; + return ['_type' => 'identity-account']; } /** @@ -68,6 +68,6 @@ protected function getCriteria() */ protected function getModelType() { - return 'customer-email'; + return 'identity-account-email'; } } diff --git a/src/AppBundle/Import/Segment/Merrick/Identity/External.php b/src/AppBundle/Import/Segment/Merrick/Identity/External.php new file mode 100644 index 00000000..0cfcabc2 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/Identity/External.php @@ -0,0 +1,58 @@ +getOmedaBrandKey()); + return $transformer->toApp($doc); + } + + /** + * {@inheritdoc} + */ + protected function getCriteria() + { + $criteria = [ + '$or' => [ + ['pwd' => ['$exists' => false]], + ['pwd' => ['$eq' => '']] + ], + 'origin' => 'link_tracking' + ]; + return array_merge(parent::getCriteria(), $criteria); + } + + /** + * {@inheritdoc} + */ + protected function getModelType() + { + return 'identity-external'; + } + + private function getOmedaBrandKey() + { + $store = $this->getPersister()->getStorageEngine(); + $integration = $store->findQuery('integration-service', ['_type' => 'integration-service-omeda'])->getSingleResult(); + if (null !== $integration) { + return $integration->get('brandKey'); + } + throw new \RuntimeException('Unable to find an omeda integration service!'); + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/Identity/Internal.php b/src/AppBundle/Import/Segment/Merrick/Identity/Internal.php new file mode 100644 index 00000000..bb540c20 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/Identity/Internal.php @@ -0,0 +1,57 @@ +toApp($doc); + } + + /** + * {@inheritdoc} + */ + protected function getCriteria() + { + $criteria = [ + '$and' => [ + [ + '$or' => [ + ['pwd' => ['$exists' => false]], + ['pwd' => ['$eq' => '']] + ] + ], + [ + '$or' => [ + ['origin' => ['$exists' => false]], + ['origin' => ['$ne' => 'link_tracking']] + ] + ] + ] + ]; + return array_merge(parent::getCriteria(), $criteria); + } + + /** + * {@inheritdoc} + */ + protected function getModelType() + { + return 'identity-internal'; + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Account.php b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Account.php new file mode 100644 index 00000000..86e14c0f --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Account.php @@ -0,0 +1,31 @@ +define('legacy.email', 'email', 'strtolower'); + $this->defineGlobal('credentials', 'credentials'); + + } + + public function credentials($data) + { + $credentials = []; + if (isset($data['pwd'])) { + $credentials['password'] = [ + 'value' => $data['pwd'], + 'salt' => isset($data['salt']) ? $data['salt'] : null, + 'mechanism' => 'merrick' + ]; + } + return $credentials; + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/CustomerEmail.php b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/AccountEmail.php similarity index 65% rename from src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/CustomerEmail.php rename to src/AppBundle/Import/Segment/Merrick/Identity/Transformer/AccountEmail.php index f9e8758a..391a2874 100644 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/CustomerEmail.php +++ b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/AccountEmail.php @@ -1,10 +1,10 @@ defineStatic('legacy.source', 'customer'); $this->define('value', 'value', 'strtolower'); $this->define('account', 'account', function($value) { - return ['id' => $value, 'type' => 'customer-account']; + return ['id' => $value, 'type' => 'identity-account']; }); $this->defineStatic('isPrimary', true); $this->defineStatic('verification.verified', true); diff --git a/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Address.php b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Address.php new file mode 100644 index 00000000..247385f5 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Address.php @@ -0,0 +1,54 @@ +defineStatic('identifier', (string) new \MongoId()); + $this->defineStatic('isPrimary', true); + $this->define('street', 'address1'); + $this->define('extra', 'address2'); + $this->define('city', 'city'); + $this->define('postalCode', 'postal_code'); + $this->defineCallable('country', 'country', 'country'); + $this->defineCallable('countryCode', 'country', 'countryCode'); + $this->defineCallable('region', 'region', 'region'); + $this->defineCallable('regionCode', 'region', 'regionCode'); + } + + public function country($value) + { + if (strlen($value) > 3) { + return $value; + } + } + + public function countryCode($value) + { + if (strlen($value) === 3) { + return $value; + } + } + + public function region($value) + { + if (strlen($value) > 3) { + return $value; + } + } + + public function regionCode($value) + { + if (strlen($value) <= 3) { + return $value; + } + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/External.php b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/External.php new file mode 100644 index 00000000..bb924100 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/External.php @@ -0,0 +1,17 @@ +define('identifier', 'omeda_id'); + $this->defineStatic('source', sprintf('identify:%s:%s', $serviceKey, $brandKey)); + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/Customer.php b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Identity.php similarity index 52% rename from src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/Customer.php rename to src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Identity.php index 9a7bdacf..a3d55cb2 100644 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer/Customer.php +++ b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Identity.php @@ -1,10 +1,10 @@ define('legacy.address.street', 'address1'); - $this->define('legacy.address.extra', 'address2'); - $this->define('legacy.address.city', 'city'); - $this->define('legacy.address.postalCode', 'postal_code'); - $this->defineCallable('legacy.address.country', 'country', 'country'); - $this->defineCallable('legacy.address.countryCode', 'country', 'countryCode'); - $this->defineCallable('legacy.address.region', 'region', 'region'); - $this->defineCallable('legacy.address.regionCode', 'region', 'regionCode'); + $this->define('legacy.omeda_id', 'omeda_id', 'strval'); + $this->define('legacy.omeda_encrypted_id', 'omeda_encrypted_id', 'strval'); // Global passes for multi fields - $this->defineGlobal('credentials', 'credentials'); + $this->defineGlobal('addresses', 'addresses'); $this->defineGlobal('phones', 'phones'); - $this->defineGlobal('externalIds', 'externalIds'); $this->defineGlobal('legacy.questions', 'questions'); } - public function country($value) + public function addresses($data) { - if (strlen($value) > 3) { - return $value; + $transformer = new Address(); + $address = $transformer->toApp($data); + if (count($address) > 2) { + return [$address]; } } - public function countryCode($value) - { - if (strlen($value) === 3) { - return $value; - } - } - - public function region($value) - { - if (strlen($value) > 3) { - return $value; - } - } - - public function regionCode($value) - { - if (strlen($value) <= 3) { - return $value; - } - } - - public function externalIds($data) - { - $externalIds = []; - - if (isset($data['omeda_id']) && !empty($data['omeda_id'])) { - $externalIds[] = [ - 'identifier' => (string) $data['omeda_id'], - 'source' => 'omeda', - ]; - } - - if (isset($data['omeda_encrypted_id']) && !empty($data['omeda_encrypted_id'])) { - $externalIds[] = [ - 'identifier' => (string) $data['omeda_encrypted_id'], - 'source' => 'omeda', - 'extra' => ['encrypted' => true] - ]; - } - return $externalIds; - } - - public function credentials($data) - { - $credentials = []; - if (isset($data['pwd'])) { - $credentials['password'] = [ - 'value' => $data['pwd'], - 'salt' => isset($data['salt']) ? $data['salt'] : null, - 'mechanism' => 'merrick' - ]; - } - return $credentials; - } - public function phones($data) { $phones = []; diff --git a/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Internal.php b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Internal.php new file mode 100644 index 00000000..e248a0a8 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/Identity/Transformer/Internal.php @@ -0,0 +1,27 @@ +defineCallable('emails', 'email', 'identityEmail'); + } + + public function identityEmail($value) + { + return [ + [ + 'identifier' => (string) new \MongoId(), + 'isPrimary' => true, + 'value' => strtolower($value), + ] + ]; + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/IdentityData.php b/src/AppBundle/Import/Segment/Merrick/IdentityData.php new file mode 100644 index 00000000..9a32a921 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData.php @@ -0,0 +1,32 @@ +source->count($this->getCollection(), $this->getCriteria()); + } + + /** + * {@inheritdoc} + */ + protected function getCollection() + { + return 'content_user_rel'; + } + + /** + * {@inheritdoc} + */ + protected function getCriteria() + { + return ['site' => $this->importer->getDomain()]; + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAnswer.php b/src/AppBundle/Import/Segment/Merrick/IdentityData/Answer.php similarity index 81% rename from src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAnswer.php rename to src/AppBundle/Import/Segment/Merrick/IdentityData/Answer.php index 560a6663..b9b59f55 100644 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/CustomerAnswer.php +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData/Answer.php @@ -1,10 +1,10 @@ (string) $doc['_id'], 'type' => $doc['_type']]; + $question['identity'] = ['id' => (string) $doc['_id'], 'type' => $doc['_type']]; $kv = $this->formatModel($question); if (null !== $kv) { $kvs[] = $kv; @@ -75,10 +75,10 @@ protected function formatModel(array $doc) return [ 'legacy' => [ - 'id' => (string) $doc['customer']['id'], - 'source' => sprintf('customer-omeda_%s', $doc['question']) + 'id' => (string) $doc['identity']['id'], + 'source' => sprintf('identity-omeda_%s', $doc['question']) ], - 'customer' => $doc['customer'], + 'identity' => $doc['identity'], 'question' => ['id' => $question['_id'], 'type' => 'question'], 'value' => ['id' => $answer['_id'], 'type' => 'question-choice'] ]; @@ -89,7 +89,7 @@ protected function formatModel(array $doc) */ protected function getCollection() { - return 'customer'; + return 'identity'; } /** @@ -113,13 +113,13 @@ protected function getCriteria() */ protected function getModelType() { - return 'customer-answer-choice'; + return 'identity-answer-choice'; } private function retrieveQuestion($legacyId) { if (!array_key_exists($legacyId, $this->questions)) { - $this->questions[$legacyId] = $this->getCollectionForModel('question')->findOne(['key' => sprintf('omeda-%s', $legacyId)]); + $this->questions[$legacyId] = $this->getCollectionForModel('question')->findOne(['key' => sprintf('integration-omeda-%s', $legacyId)]); } return $this->questions[$legacyId]; } @@ -128,7 +128,7 @@ private function retrieveAnswer($legacyId) { $legacyId = (string) $legacyId; if (!array_key_exists($legacyId, $this->answers)) { - $this->answers[$legacyId] = $this->getCollectionForModel('question-choice')->findOne(['integration.clientKey' => 'omeda', 'integration.identifier' => $legacyId]); + $this->answers[$legacyId] = $this->getCollectionForModel('question-choice')->findOne(['integration.pull.identifier' => $legacyId]); } return $this->answers[$legacyId]; } diff --git a/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswer.php b/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswer.php new file mode 100644 index 00000000..7d93af82 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswer.php @@ -0,0 +1,153 @@ + null, + 'ooh_primary_business' => null, + ]; + + /** + * @var array + */ + protected $answers = []; + + /** + * {@inheritdoc} + */ + public function count() + { + return $this->getCollectionForModel($this->getCollection())->count($this->getCriteria()); + } + + /** + * {@inheritdoc} + */ + public function getKey() + { + return 'merrick_customer_identity_data_input_answer'; + } + + /** + * {@inheritdoc} + */ + public function modify($limit = 200, $skip = 0) + { + $kvs = []; + $docs = $this->getDocuments($limit, $skip); + + foreach ($docs as $doc) { + foreach ($doc['legacy']['answers'] as $question) { + $question['identity'] = ['id' => (string) $doc['_id'], 'type' => $doc['_type']]; + $kv = $this->formatModel($question); + if (null !== $kv) { + $kvs[] = $kv; + } + } + } + return $kvs; + } + + /** + * Returns formatted key-values for the passed legacy document + * + * @param array $doc The legacy key values + * @return mixed array of key values or null + */ + protected function formatModel(array $doc) + { + try { + $question = $this->retrieveQuestionId($doc['question']); + if (null === $question) { + return; + } + $answer = $this->retrieveAnswerId($doc['answer']); + if (null === $answer) { + return; + } + return [ + 'legacy' => [ + 'id' => (string) $doc['identity']['id'], + 'source' => sprintf('identity-omeda_%s', $doc['question']) + ], + 'identity' => $doc['identity'], + 'question' => ['id' => $question, 'type' => 'question'], + 'value' => ['id' => $answer, 'type' => 'question-choice'] + ]; + } catch (\Exception $e) { + } + } + + /** + * {@inheritdoc} + */ + protected function getCollection() + { + return 'input-submission'; + } + + /** + * {@inheritdoc} + */ + protected function getDocuments($limit = 200, $skip = 0) + { + return $this->getCollectionForModel($this->getCollection())->find($this->getCriteria(), $this->getFields())->sort($this->getSort())->limit($limit)->skip($skip); + } + + /** + * {@inheritdoc} + */ + protected function getCriteria() + { + return ['legacy.questions' => ['$exists' => true]]; + } + + /** + * {@inheritdoc} + */ + protected function getModelType() + { + return 'identity-answer-choice'; + } + + protected function retrieveQuestionId($legacyId) + { + if (array_key_exists($legacyId, $this->mappedQuestions)) { + return $this->mappedQuestions[$legacyId]; + } + $legacyId = (string) $legacyId; + if (!array_key_exists($legacyId, $this->questions)) { + $question = $this->getCollectionForModel('question')->findOne(['key' => sprintf('integration-omeda-%s', $legacyId)]); + if (null === $question) { + throw new \Exception(sprintf('Could not find question using "%s"', $legacyId)); + } + $this->questions[$legacyId] = $question; + } + return $this->questions[$legacyId]['_id']; + } + + protected function retrieveAnswerId($legacyId) + { + $legacyId = (string) $legacyId; + if (!array_key_exists($legacyId, $this->answers)) { + $answer = $this->getCollectionForModel('question-choice')->findOne(['integration.pull.identifier' => $legacyId]); + if (null === $answer) { + $answer = $this->getCollectionForModel('question-choice')->findOne(['alternateId' => $legacyId]); + } + if (null === $answer) { + throw new \Exception(sprintf('Could not find answer using "%s"', $legacyId)); + } + $this->answers[$legacyId] = $answer; + } + return $this->answers[$legacyId]['_id']; + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerComments.php b/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerComments.php new file mode 100644 index 00000000..133600b9 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerComments.php @@ -0,0 +1,83 @@ +getDocuments($limit, $skip); + + foreach ($docs as $doc) { + $kv = $this->formatModel($doc); + if (null !== $kv) { + $kvs[] = $kv; + } + } + return $kvs; + } + + /** + * Returns formatted key-values for the passed legacy document + * + * @param array $doc The legacy key values + * @return mixed array of key values or null + */ + protected function formatModel(array $doc) + { + $question = $this->retrieveQuestionId('comments'); + + return [ + 'legacy' => [ + 'id' => (string) $doc['_id'], + 'source' => 'input-submission_comments' + ], + 'createdDate' => $doc['createdDate'], + 'touchedDate' => $doc['createdDate'], + 'updatedDate' => $doc['createdDate'], + 'question' => ['id' => $question, 'type' => 'question'], + 'submission' => ['id' => (string) $doc['_id'], 'type' => 'input-submission'], + 'value' => $doc['legacy']['answers']['comments'], + ]; + } + + /** + * {@inheritdoc} + */ + protected function retrieveQuestionId($legacyId) + { + $question = $this->getCollectionForModel('question')->findOne(['key' => 'comments']); + if (null === $question) { + throw new \InvalidArgumentException('Could not find question with key `comments`. Was it created?'); + } + return $question['_id']; + } + + /** + * {@inheritdoc} + */ + protected function getCriteria() + { + return ['legacy.answers.comments' => ['$exists' => true]]; + } + + /** + * {@inheritdoc} + */ + protected function getModelType() + { + return 'input-answer-string'; + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerOmeda.php b/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerOmeda.php new file mode 100644 index 00000000..f3d84e36 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerOmeda.php @@ -0,0 +1,85 @@ +getDocuments($limit, $skip); + + foreach ($docs as $doc) { + foreach ($doc['legacy']['answers']['omeda'] as $question) { + $question['submission'] = $doc['_id']; + $question['date'] = $doc['createdDate']; + $kv = $this->formatModel($question); + if (null !== $kv) { + $kvs[] = $kv; + } + } + } + return $kvs; + } + + /** + * Returns formatted key-values for the passed legacy document + * + * @param array $doc The legacy key values + * @return mixed array of key values or null + */ + protected function formatModel(array $doc) + { + try { + $question = $this->retrieveQuestionId($doc['question']); + if (null === $question) { + return; + } + $answer = $this->retrieveAnswerId($doc['answer']); + if (null === $answer) { + return; + } + return [ + 'legacy' => [ + 'id' => (string) $doc['submission'], + 'source' => sprintf('input-submission_%s', $doc['question']) + ], + 'createdDate' => $doc['date'], + 'touchedDate' => $doc['date'], + 'updatedDate' => $doc['date'], + 'question' => ['id' => $question, 'type' => 'question'], + 'submission' => ['id' => $doc['submission'], 'type' => 'input-submission'], + 'value' => ['id' => $answer, 'type' => 'question-choice'] + ]; + } catch (\Exception $e) { + var_dump(__METHOD__, $e->getMessage(), __METHOD__); + } + } + + /** + * {@inheritdoc} + */ + protected function getCriteria() + { + return ['legacy.answers.omeda' => ['$exists' => true]]; + } + + /** + * {@inheritdoc} + */ + protected function getModelType() + { + return 'input-answer-choice'; + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerPurchaseIntent.php b/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerPurchaseIntent.php new file mode 100644 index 00000000..caa7e3e9 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData/InputAnswerPurchaseIntent.php @@ -0,0 +1,132 @@ +getDocuments($limit, $skip); + + foreach ($docs as $doc) { + $kv = $this->formatModel($doc); + if (null !== $kv) { + $kvs[] = $kv; + } + } + return $kvs; + } + + /** + * Returns formatted key-values for the passed legacy document + * + * @param array $doc The legacy key values + * @return mixed array of key values or null + */ + protected function formatModel(array $doc) + { + $question = $this->retrieveQuestionId($this->questionKey); + $answer = $this->retrieveAnswerId($doc['legacy']['answers']['purchaseIntent']); + + return [ + 'legacy' => [ + 'id' => (string) $doc['_id'], + 'source' => 'input-submission_purchaseIntent' + ], + 'createdDate' => $doc['createdDate'], + 'touchedDate' => $doc['createdDate'], + 'updatedDate' => $doc['createdDate'], + 'question' => ['id' => $question, 'type' => 'question'], + 'submission' => ['id' => (string) $doc['_id'], 'type' => 'input-submission'], + 'value' => ['id' => $answer, 'type' => 'question-choice'], + ]; + } + + /** + * {@inheritdoc} + */ + protected function retrieveAnswerId($legacyId) + { + $legacyId = (string) $legacyId; + switch ($legacyId) { + case 'immediately': + $legacyId = 'Immediately'; + break; + case '_1to3': + $legacyId = '1 - 3 Months'; + break; + case '_4to6': + $legacyId = '4 - 6 Months'; + break; + case '_7to9': + $legacyId = '7 - 9 Months'; + break; + case '_12': + $legacyId = '10 - 12 Months'; + break; + case '': + case 'none': + $legacyId = 'No plans. Just researching.'; + break; + } + + if (isset($this->answers[$legacyId])) { + return $this->answers[$legacyId]['_id']; + } + + throw new \InvalidArgumentException(sprintf('Could not find an answer by key `%s`!', $legacyId)); + } + + /** + * {@inheritdoc} + */ + protected function retrieveQuestionId($legacyId) + { + $question = $this->getCollectionForModel('question')->findOne(['key' => $legacyId]); + if (null === $question) { + throw new \InvalidArgumentException(sprintf('Could not find question with key `%s`. Was it created?', $legacyId)); + } + $this->loadAnswers($question['_id']); + return $question['_id']; + } + + /** + * {@inheritdoc} + */ + protected function getCriteria() + { + return ['legacy.answers.purchaseIntent' => ['$exists' => true]]; + } + + /** + * {@inheritdoc} + */ + protected function getModelType() + { + return 'input-answer-choice'; + } + + private function loadAnswers($questionId) + { + if (empty($this->answers)) { + $choices = $this->getCollectionForModel('question-choice')->find(['question' => $questionId]); + foreach ($choices as $choice) { + $this->answers[$choice['name']] = $choice; + } + } + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/IdentityData/Inquiry.php b/src/AppBundle/Import/Segment/Merrick/IdentityData/Inquiry.php new file mode 100644 index 00000000..ce0b37ec --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData/Inquiry.php @@ -0,0 +1,19 @@ +toApp($doc); + } + + /** + * {@inheritdoc} + */ + protected function getCriteria() + { + $criteria = [ + 'action' => 'rmi' + ]; + return array_merge(parent::getCriteria(), $criteria); + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/IdentityData/Transformer/Inquiry.php b/src/AppBundle/Import/Segment/Merrick/IdentityData/Transformer/Inquiry.php new file mode 100644 index 00000000..569cec11 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData/Transformer/Inquiry.php @@ -0,0 +1,76 @@ +defineId('_id'); + $this->define('legacy.id', '_id', 'strval'); + $this->defineStatic('legacy.source', 'content_user_rel'); + $this->define('legacy.email', 'email', 'strtolower'); + + $this->defineStatic('sourceKey', 'inquiry'); + $this->define('createdDate', 'timestamp', function($timestamp) { + $date = new \DateTime(); + return $date->setTimestamp($timestamp); + }); + + $this->define('payload.identity.givenName', 'first_name'); + $this->define('payload.identity.familyName', 'last_name'); + // $this->define('payload.identity.primaryEmail', 'email'); + $this->define('payload.identity.primaryPhone', 'phone'); + $this->define('payload.identity.companyName', 'company_name'); + $this->defineGlobal('payload.identity.primaryAddress', 'primaryAddress'); + $this->define('legacy.identity._id', 'user_id', function($value) { + if (is_string($value) && !empty($value)) { + return new \MongoId((string) $value); + } + }); + + $this->defineGlobal('legacy.answers.omeda', 'omedaAnswers'); + $this->define('legacy.answers.comments', 'comments'); + $this->define('legacy.answers.purchaseIntent', 'purchase_intent'); + } + + public function primaryAddress($data) + { + $transformer = new Address(); + $address = $transformer->toApp($data); + if (count($address) > 2) { + return $address; + } + } + + public function omedaAnswers($data) + { + $questions = []; + foreach ($data as $key => $value) { + if (false === stripos($key, 'omeda')) { + continue; + } + $oKey = str_replace('omeda_', '', $key); + // if (!is_numeric($oKey)) { + // continue; + // } + $questions[] = ['question' => $oKey, 'answer' => (string) $value]; + } + return $questions; + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/IdentityData/Transformer/InquiryRmi.php b/src/AppBundle/Import/Segment/Merrick/IdentityData/Transformer/InquiryRmi.php new file mode 100644 index 00000000..d1e80c80 --- /dev/null +++ b/src/AppBundle/Import/Segment/Merrick/IdentityData/Transformer/InquiryRmi.php @@ -0,0 +1,17 @@ +defineStatic('payload.meta.model.type', 'content'); + $this->define('payload.meta.model.identifier', 'content_id', 'intval'); + } +} diff --git a/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer.php b/src/AppBundle/Import/Segment/Transformer.php similarity index 97% rename from src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer.php rename to src/AppBundle/Import/Segment/Transformer.php index 249500ea..e5f25d03 100644 --- a/src/AppBundle/Import/Segment/Merrick/Customer/Model/Transformer.php +++ b/src/AppBundle/Import/Segment/Transformer.php @@ -1,6 +1,6 @@ $v) { + if (null === $v || [] === $v) { + unset($data[$k]); + continue; + } if (false !== stripos($k, '.')) { $keys = explode('.', $k); $c = &$data[array_shift($keys)]; diff --git a/src/AppBundle/Resources/config/services/import.yml b/src/AppBundle/Resources/config/services/import.yml index 7c5ce222..79a91ce2 100644 --- a/src/AppBundle/Resources/config/services/import.yml +++ b/src/AppBundle/Resources/config/services/import.yml @@ -3,23 +3,24 @@ services: app_bundle.import.manager: class: As3\SymfonyData\Import\Manager calls: - - ['addImporter', [ "@app_bundle.import.importer.merrick.customer" ]] - # - ['addImporter', [ "@app_bundle.import.importer.merrick.customer_data" ]] + - ['addImporter', [ "@app_bundle.import.importer.merrick.identity" ]] + - ['addImporter', [ "@app_bundle.import.importer.merrick.identity_data" ]] app_bundle.import.importer.merrick: abstract: true arguments: - "@app_bundle.core.account_manager" - app_bundle.import.importer.merrick.customer: - class: AppBundle\Import\Importer\Merrick\Customer + app_bundle.import.importer.merrick.identity: + class: AppBundle\Import\Importer\Merrick\Identity parent: app_bundle.import.importer.merrick arguments: - "@app_bundle.import.persister.as3_modlr" - "@app_bundle.import.source.mongo.legacy" - app_bundle.import.importer.merrick.customer_data: - class: AppBundle\Import\Importer\Merrick\CustomerData + app_bundle.import.importer.merrick.identity_data: + class: AppBundle\Import\Importer\Merrick\IdentityData + parent: app_bundle.import.importer.merrick arguments: - "@app_bundle.import.persister.as3_modlr" - "@app_bundle.import.source.mongo.legacy"