/** * {@inheritdoc} * * Prepare items for PersistentBatchWriter, filters for duplicates and takes only latest versions */ public function write(array $items) { $uniqueItems = []; $uniqueKeys = []; foreach ($items as $item) { if ($item instanceof Customer || $item instanceof Cart) { $this->handleIdentifier($uniqueItems, $item, $item->getOriginId()); } elseif ($item instanceof Order) { $this->handleIdentifier($uniqueItems, $item, $item->getIncrementId()); } elseif ($item instanceof NewsletterSubscriber) { $identifier = $item->getCustomer() ? $item->getCustomer()->getId() : 0; if ($identifier !== 0 && in_array($identifier, $uniqueKeys)) { $this->logSkipped($item->getOriginId()); } else { $uniqueKeys[] = $identifier; $uniqueItems[] = $item; } } else { $uniqueItems[] = $item; } } $this->writer->write($uniqueItems); // force entity cache clear if clear is skipped $this->databaseHelper->onClear(); }
/** * {@inheritdoc} */ public function denormalize($data, $class, $format = null, array $context = []) { /** @var MemberExtendedMergeVar $entity */ $entity = parent::denormalize($data, $class, $format, $context); /** @var StaticSegment $staticSegment */ $staticSegment = $this->databaseHelper->getEntityReference($entity->getStaticSegment()); if (!$staticSegment) { return $entity; } $extendedMergeVars = $staticSegment->getSyncedExtendedMergeVars(); if ($extendedMergeVars->isEmpty()) { return $entity; } $columns = $this->getColumns($staticSegment->getMarketingList()); $columnAliases = $this->getColumnAliases($staticSegment->getMarketingList()); $mergeVarValues = []; foreach ($extendedMergeVars as $extendedMergeVar) { $value = $this->getValue($extendedMergeVar, $data, $columns, $columnAliases); if ($value) { $mergeVarValues[$extendedMergeVar->getTag()] = $value; } } $this->fieldHelper->setObjectValue($entity, 'merge_var_values', $mergeVarValues); return $entity; }
/** * {@inheritdoc} * * Prepare items for PersistentBatchWriter, filters for duplicates and takes only latest versions */ public function write(array $items) { $uniqueItems = []; foreach ($items as $item) { if ($item instanceof Customer || $item instanceof Cart) { $identifier = $item->getOriginId(); if (array_key_exists($identifier, $uniqueItems)) { $this->logSkipped($identifier); } if ($item instanceof Customer) { $item->setIsSynced(true); } $uniqueItems[$identifier] = $item; } elseif ($item instanceof Order) { $identifier = $item->getIncrementId(); if (array_key_exists($identifier, $uniqueItems)) { $this->logSkipped($item->getIncrementId()); } $uniqueItems[$identifier] = $item; } else { $uniqueItems[] = $item; } } $this->writer->write($uniqueItems); // force entity cache clear if clear is skipped $this->databaseHelper->onClear(); }
/** * @dataProvider itemsProvider * * @param array $items * @param array $expectedItems */ public function testWrite(array $items, array $expectedItems) { $this->wrapped->expects($this->once())->method('write')->with($this->equalTo($expectedItems)); $stepExecution = $this->getMockBuilder('Akeneo\\Bundle\\BatchBundle\\Entity\\StepExecution')->disableOriginalConstructor()->getMock(); $this->databaseHelper->expects($this->once())->method('onClear'); $this->writer->setStepExecution($stepExecution); $this->writer->write($items); }
/** * Try to find entity by identity fields if at least one is specified * * @param string $entityName * @param array $identityValues * @return null|object */ protected function findEntityByIdentityValues($entityName, array $identityValues) { foreach ($identityValues as $value) { if (null !== $value && '' !== $value) { return $this->databaseHelper->findOneBy($entityName, $identityValues); } } return null; }
public function testGetEntityReference() { $entity = new \stdClass(); $reference = new \stdClass(); $entityName = get_class($entity); $identifier = 1; $this->doctrineHelper->expects($this->once())->method('getSingleEntityIdentifier')->with($entity)->will($this->returnValue($identifier)); $this->doctrineHelper->expects($this->once())->method('getEntityReference')->with($entityName, $identifier)->will($this->returnValue($reference)); $this->assertEquals($reference, $this->helper->getEntityReference($entity)); }
/** * @param FieldConfigModel $field * @param bool $isExist * @param FieldConfigModel|null $expected * * @dataProvider processProvider */ public function testProcess($field, $isExist, $expected) { $this->databaseHelper->expects(static::any())->method('findOneBy')->willReturn($isExist ? $field : null); static::assertEquals($expected, $this->strategy->process($field)); }
/** * @param string $type * @param bool $expected * @dataProvider isSingleInversedRelationDataProvider */ public function testIsSingleInversedRelation($type, $expected) { $fieldName = 'relation'; $this->metadata->expects($this->once())->method('getAssociationMapping')->with($fieldName)->will($this->returnValue(array('type' => $type))); $this->assertEquals($expected, $this->helper->isSingleInversedRelation(self::TEST_CLASS, $fieldName)); }