コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     if ($oppositeRecord->getValue($this->field) !== null || $this->setNullIfEmpty) {
         $recordToHandle->setValue($this->field, $oppositeRecord->getValue($this->field));
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $value = $recordToHandle->getValue('value');
     if (!$value) {
         return;
     }
     $this->validate($recordToHandle);
     $parts = explode(':', $value, 4);
     $partsCount = count($parts);
     if ($partsCount == 4) {
         $initVector = $parts[2];
         $encryptedValue = $parts[3];
         $mode = MCRYPT_MODE_CBC;
         $cypher = MCRYPT_RIJNDAEL_128;
     } else {
         $initVector = false;
         $encryptedValue = $value;
         $mode = MCRYPT_MODE_ECB;
         $cypher = MCRYPT_BLOWFISH;
     }
     $crypt = $this->cryptFactory->create(['key' => $this->cryptKey, 'cipher' => $cypher, 'mode' => $mode, 'initVector' => $initVector]);
     $decryptedValue = trim($crypt->decrypt(base64_decode((string) $encryptedValue)));
     $encodedValue = $this->encryptor->encrypt($decryptedValue);
     $recordToHandle->setValue('value', $encodedValue);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $oppositeValue = $oppositeRecord->getValue($this->baseField);
     $hashMethod = $this->hash;
     $resultValue = $hashMethod($oppositeValue);
     $recordToHandle->setValue($this->field, $resultValue);
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $value = $recordToHandle->getValue($this->field);
     $valueOpposite = $oppositeRecord->getValue($this->field);
     if (!is_numeric($value) && $valueOpposite) {
         $value = $valueOpposite;
     }
     $recordToHandle->setValue($this->field, $value);
 }
コード例 #5
0
 /**
  * Add Record to collection
  *
  * @param \Migration\ResourceModel\Record $record
  * @return $this
  * @throws Exception
  */
 public function addRecord($record)
 {
     if (!$record->getStructure()) {
         $record->setStructure($this->structure);
     }
     if (!$record->validateStructure($this->structure)) {
         throw new Exception("Record structure does not equal Collection structure");
     }
     $this->data[] = $record;
     return $this;
 }
 /**
  * @param Record $recordToHandle
  * @param Record $oppositeRecord
  * @return void
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $sourceModel = $recordToHandle->getValue($this->field);
     $oppositeRecordValue = $oppositeRecord->getValue($this->field);
     if (empty($sourceModel) && !empty($oppositeRecordValue)) {
         $recordToHandle->setValue($this->field, $oppositeRecord->getValue($this->field));
     } elseif (empty($sourceModel) || $recordToHandle->getValue('is_configurable')) {
         $recordToHandle->setValue($this->field, null);
     }
 }
コード例 #7
0
 /**
  * @param Record $recordToHandle
  * @param Record $oppositeRecord
  * @return mixed
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $sourceModel = $recordToHandle->getValue($this->field);
     $oppositeRecordValue = $oppositeRecord->getValue($this->field);
     if (empty($sourceModel) && !empty($oppositeRecordValue)) {
         $recordToHandle->setValue($this->field, $oppositeRecord->getValue($this->field));
     } elseif (empty($sourceModel)) {
         $recordToHandle->setValue($this->field, null);
     } else {
         $recordToHandle->setValue($this->field, $this->classMap->convertClassName($sourceModel));
     }
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function validate(Record $record)
 {
     $offsetInt = $this->offset;
     $sign = substr($this->offset, 0, 1);
     if (in_array($sign, [self::SIGN_PLUS, self::SIGN_MINUS])) {
         $offsetInt = substr($this->offset, 1, strlen($this->offset) - 1);
     } else {
         $sign = self::SIGN_PLUS;
     }
     if (self::SIGN_PLUS === $sign && $offsetInt > self::MAX_OFFSET || self::SIGN_MINUS === $sign && $offsetInt < self::MIN_OFFSET) {
         throw new Exception('Offset can have value between ' . '"' . self::MIN_OFFSET . '" and "' . self::SIGN_PLUS . self::MAX_OFFSET . '""');
     }
     $fieldType = $record->getStructure()->getFields()[$this->field]['DATA_TYPE'];
     if (!in_array($fieldType, $this->supportedDatatypes)) {
         throw new Exception('Provided datatype for field "' . $this->field . '" is not supported');
     }
     parent::validate($record);
 }
コード例 #9
0
 /**
  * @dataProvider stateProvider
  * @param string $state
  * @return void
  */
 public function testHandleVisibleState($state)
 {
     $fieldName = 'visible_on_front';
     $this->recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
     $this->recordToHandle->expects($this->any())->method('getValue')->will($this->returnCallback(function ($value) use($state) {
         switch ($value) {
             case 'status':
                 return 'some_my_status';
                 break;
             case 'state':
                 return $state;
                 break;
         }
         return '';
     }));
     $this->recordToHandle->expects($this->once())->method('setValue')->with($fieldName, 1);
     $handler = new SetVisibleOnFront();
     $handler->setField($fieldName);
     $handler->handle($this->recordToHandle, $this->oppositeRecord);
 }
コード例 #10
0
 /**
  * @param Record $record
  * @return mixed
  */
 public function getRecordEntityType(Record $record)
 {
     $isCategory = $record->getValue('category_id') ? 'category' : null;
     $isProduct = $record->getValue('product_id') ? 'product' : null;
     return $isProduct ?: $isCategory;
 }
コード例 #11
0
 /**
  * @param ResourceModel\Record $destinationRecord
  * @param array $recordData
  * @return ResourceModel\Record
  */
 protected function transformRecord($destinationRecord, $recordData)
 {
     foreach ($destinationRecord->getFields() as $recordField) {
         $destinationRecord->setValue($recordField, $recordData[$recordField]);
     }
     return $destinationRecord;
 }
コード例 #12
0
 /**
  * {@inheritdoc}
  */
 public function validate(Record $record)
 {
     if (!in_array($this->field, $record->getFields())) {
         throw new Exception("{$this->field} field not found in the record.");
     }
 }
コード例 #13
0
 /**
  * @param Record $from
  * @param Record $to
  * @return void
  */
 protected function copy(Record $from, Record $to)
 {
     $sourceDocumentName = $this->sourceDocument->getName();
     $data = $from->getData();
     $sourceFields = $from->getFields();
     $destinationFields = $to->getFields();
     $diff = array_diff($sourceFields, $destinationFields);
     foreach ($diff as $field) {
         if (!$this->mapReader->isFieldIgnored($sourceDocumentName, $field, MapInterface::TYPE_SOURCE)) {
             $fieldMap = $this->mapReader->getFieldMap($sourceDocumentName, $field, MapInterface::TYPE_SOURCE);
             $data[$fieldMap] = $from->getValue($field);
         }
         unset($data[$field]);
     }
     foreach ($data as $key => $value) {
         $to->setValue($key, $value);
     }
 }
コード例 #14
0
 /**
  * @param Record $sourceRecord
  * @param array $keyFields
  * @return string
  */
 protected function getMappingValue(Record $sourceRecord, $keyFields)
 {
     $value = [];
     foreach ($keyFields as $field) {
         switch ($field) {
             case 'attribute_id':
                 $value[] = $this->getDestinationAttributeId($sourceRecord->getValue($field));
                 break;
             default:
                 $value[] = $sourceRecord->getValue($field);
                 break;
         }
     }
     return implode('-', $value);
 }
コード例 #15
0
 /**
  * @throws \Migration\Exception
  * @return void
  */
 public function testGetFieldsInvalid()
 {
     $this->record->setStructure(null);
     $this->setExpectedException('Exception', 'Structure not set');
     $this->record->getFields();
 }