Skip to content

Commit e4a7e6b

Browse files
author
Maksym Savich
committed
MAGETWO-35461: Refactor \Magento\Framework\Model\AbstractModel
- Implemented storedData
1 parent 5108e72 commit e4a7e6b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lib/internal/Magento/Framework/Model/AbstractModel.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ abstract class AbstractModel extends \Magento\Framework\Object
127127
*/
128128
protected $_actionValidator;
129129

130+
/**
131+
* Array to store object's original data
132+
*
133+
* @var array
134+
*/
135+
private $storedData = [];
136+
130137
/**
131138
* @param \Magento\Framework\Model\Context $context
132139
* @param \Magento\Framework\Registry $registry
@@ -155,7 +162,7 @@ public function __construct(
155162
) {
156163
$this->_idFieldName = $this->_getResource()->getIdFieldName();
157164
}
158-
165+
$this->updateStoredData();
159166
parent::__construct($data);
160167
$this->_construct();
161168
}
@@ -354,6 +361,7 @@ public function afterLoad()
354361
{
355362
$this->getResource()->afterLoad($this);
356363
$this->_afterLoad();
364+
$this->updateStoredData();
357365
return $this;
358366
}
359367

@@ -566,6 +574,7 @@ public function afterSave()
566574
$this->_eventManager->dispatch('model_save_after', ['object' => $this]);
567575
$this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
568576
$this->_eventManager->dispatch($this->_eventPrefix . '_save_after', $this->_getEventData());
577+
$this->updateStoredData();
569578
return $this;
570579
}
571580

@@ -611,6 +620,7 @@ public function afterDelete()
611620
$this->_eventManager->dispatch('model_delete_after', ['object' => $this]);
612621
$this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
613622
$this->_eventManager->dispatch($this->_eventPrefix . '_delete_after', $this->_getEventData());
623+
$this->updateStoredData();
614624
return $this;
615625
}
616626

@@ -689,4 +699,19 @@ protected function _clearData()
689699
{
690700
return $this;
691701
}
702+
703+
/**
704+
* Synchronize object's stored data with the actual data
705+
*
706+
* @return $this
707+
*/
708+
protected function updateStoredData()
709+
{
710+
if (isset($this->_data)) {
711+
$this->storedData = $this->_data;
712+
} else {
713+
$this->storedData = [];
714+
}
715+
return $this;
716+
}
692717
}

0 commit comments

Comments
 (0)