コード例 #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
ファイル: Template.php プロジェクト: okite11/frames21
 /**
  * {@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);
 }
コード例 #3
0
 /**
  * @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);
     }
 }
コード例 #4
0
ファイル: Collection.php プロジェクト: okite11/frames21
 /**
  * Add Record to collection
  *
  * @param \Migration\Resource\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;
 }
コード例 #5
0
ファイル: ConvertModel.php プロジェクト: okite11/frames21
 /**
  * @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));
     }
 }
コード例 #6
0
 /**
  * @dataProvider stateProvider
  * @param string $state
  */
 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);
 }
コード例 #7
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);
 }
コード例 #8
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]);
     }
     $to->setData($data);
 }
コード例 #9
0
 /**
  * @param Resource\Record $destinationRecord
  * @param array $recordData
  * @return Resource\Record
  */
 protected function transformRecord($destinationRecord, $recordData)
 {
     foreach ($destinationRecord->getFields() as $recordField) {
         $destinationRecord->setValue($recordField, $recordData[$recordField]);
     }
     return $destinationRecord;
 }
コード例 #10
0
ファイル: Version191to2000.php プロジェクト: okite11/frames21
 /**
  * @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
 public function testGetFieldsInvalid()
 {
     $this->record->setStructure(null);
     $this->setExpectedException('Exception', 'Structure not set');
     $this->record->getFields();
 }
コード例 #12
0
 /**
  * @param Record $from
  * @param Record $to
  * @return void
  */
 protected function copy(Record $from, Record $to)
 {
     foreach ($from->getFields() as $field) {
         if (!$this->mapReader->isFieldIgnored($this->sourceDocument->getName(), $field, MapInterface::TYPE_SOURCE)) {
             $fieldMap = $this->mapReader->getFieldMap($this->sourceDocument->getName(), $field, MapInterface::TYPE_SOURCE);
             $to->setValue($fieldMap, $from->getValue($field));
         }
     }
 }
コード例 #13
0
ファイル: AbstractHandler.php プロジェクト: okite11/frames21
 /**
  * {@inheritdoc}
  */
 public function validate(Record $record)
 {
     if (!in_array($this->field, $record->getFields())) {
         throw new Exception("{$this->field} field not found in the record.");
     }
 }