Exemplo n.º 1
0
 /**
  * @inheritDoc
  */
 public function save(AbstractModel $object)
 {
     if ($object->isDeleted()) {
         return $this->delete($object);
     }
     $this->beginTransaction();
     try {
         if (!$this->isModified($object)) {
             $this->processNotModifiedSave($object);
             $this->commit();
             $object->setHasDataChanges(false);
             return $this;
         }
         $object->validateBeforeSave();
         $object->beforeSave();
         if ($object->isSaveAllowed()) {
             $this->_serializeFields($object);
             $this->_beforeSave($object);
             $this->_checkUnique($object);
             $this->objectRelationProcessor->validateDataIntegrity($this->getMainTable(), $object->getData());
             $this->entityManager->save(PageInterface::class, $object);
             $this->unserializeFields($object);
             $this->processAfterSaves($object);
         }
         $this->addCommitCallback([$object, 'afterCommitCallback'])->commit();
         $object->setHasDataChanges(false);
     } catch (\Exception $e) {
         $this->rollBack();
         $object->setHasDataChanges(true);
         throw $e;
     }
     return $this;
 }
 public function testSaveCreate()
 {
     $this->hydrator->expects($this->once())->method('extract')->with($this->abstractEntity)->willReturn(['test_field_1' => 'test_value_1', 'test_filed_2' => 'test_field_2']);
     $this->metadata->expects($this->never())->method('checkIsEntityExists');
     $this->orchestratorPool->expects($this->once())->method('getWriteOperation')->with('Test\\Entity\\Type', 'create')->willReturn($this->writeOperation);
     $this->writeOperation->expects($this->once())->method('execute')->with('Test\\Entity\\Type', $this->abstractEntity)->willReturn($this->abstractEntity);
     $result = $this->subject->save('Test\\Entity\\Type', $this->abstractEntity);
     $this->assertEquals($this->abstractEntity, $result);
 }
 /**
  * Save object collected data
  *
  * @param   array $saveData array('newObject', 'entityRow', 'insert', 'update', 'delete')
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _processSaveData($saveData)
 {
     extract($saveData, EXTR_SKIP);
     /**
      * Import variables into the current symbol table from save data array
      *
      * @see \Magento\Eav\Model\Entity\AbstractEntity::_collectSaveData()
      *
      * @var array $entityRow
      * @var \Magento\Framework\Model\AbstractModel $newObject
      * @var array $insert
      * @var array $update
      * @var array $delete
      */
     /**
      * Process base row
      */
     $this->entityManager->save(CategoryInterface::class, $newObject);
     /**
      * insert attribute values
      */
     if (!empty($insert)) {
         foreach ($insert as $attributeId => $value) {
             $attribute = $this->getAttribute($attributeId);
             $this->_insertAttribute($newObject, $attribute, $value);
         }
     }
     /**
      * update attribute values
      */
     if (!empty($update)) {
         foreach ($update as $attributeId => $v) {
             $attribute = $this->getAttribute($attributeId);
             $this->_updateAttribute($newObject, $attribute, $v['value_id'], $v['value']);
         }
     }
     /**
      * delete empty attribute values
      */
     if (!empty($delete)) {
         foreach ($delete as $table => $values) {
             $this->_deleteAttributes($newObject, $table, $values);
         }
     }
     $this->_processAttributeValues();
     $newObject->isObjectNew(false);
     return $this;
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 protected function processSave($object)
 {
     $this->entityManager->save(\Magento\Catalog\Api\Data\ProductInterface::class, $object);
 }