Skip to content

Commit 42988a6

Browse files
authored
Move orig data to abstract model (like M2) (#1325)
1 parent ca3d916 commit 42988a6

File tree

2 files changed

+52
-51
lines changed

2 files changed

+52
-51
lines changed

app/code/core/Mage/Core/Model/Abstract.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ abstract class Mage_Core_Model_Abstract extends Varien_Object
5858
*/
5959
protected $_eventObject = 'object';
6060

61+
/**
62+
* Original data that was loaded
63+
*
64+
* @var array
65+
*/
66+
protected $_origData;
67+
6168
/**
6269
* Name of the resource model
6370
*
@@ -114,6 +121,51 @@ protected function _init($resourceModel)
114121
$this->_setResourceModel($resourceModel);
115122
}
116123

124+
/**
125+
* Get object loaded data (original data)
126+
*
127+
* @param string $key
128+
* @return mixed
129+
*/
130+
public function getOrigData($key = null)
131+
{
132+
if (is_null($key)) {
133+
return $this->_origData;
134+
}
135+
return isset($this->_origData[$key]) ? $this->_origData[$key] : null;
136+
}
137+
138+
/**
139+
* Initialize object original data
140+
*
141+
* @param string $key
142+
* @param mixed $data
143+
* @return $this
144+
*/
145+
public function setOrigData($key = null, $data = null)
146+
{
147+
if (is_null($key)) {
148+
$this->_origData = $this->_data;
149+
} else {
150+
$this->_origData[$key] = $data;
151+
}
152+
return $this;
153+
}
154+
155+
/**
156+
* Compare object data with original data
157+
*
158+
* @param string $field
159+
* @return boolean
160+
*/
161+
public function dataHasChangedFor($field)
162+
{
163+
$newData = $this->getData($field);
164+
$origData = $this->getOrigData($field);
165+
166+
return $newData != $origData;
167+
}
168+
117169
/**
118170
* Set resource names
119171
*

lib/Varien/Object.php

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ class Varien_Object implements ArrayAccess
4646
*/
4747
protected $_hasDataChanges = false;
4848

49-
/**
50-
* Original data that was loaded
51-
*
52-
* @var array
53-
*/
54-
protected $_origData;
55-
5649
/**
5750
* Name of object id field
5851
*
@@ -749,50 +742,6 @@ public function serialize($attributes = array(), $valueSeparator='=', $fieldSepa
749742
return $res;
750743
}
751744

752-
/**
753-
* Get object loaded data (original data)
754-
*
755-
* @param string $key
756-
* @return mixed
757-
*/
758-
public function getOrigData($key=null)
759-
{
760-
if (is_null($key)) {
761-
return $this->_origData;
762-
}
763-
return isset($this->_origData[$key]) ? $this->_origData[$key] : null;
764-
}
765-
766-
/**
767-
* Initialize object original data
768-
*
769-
* @param string $key
770-
* @param mixed $data
771-
* @return $this
772-
*/
773-
public function setOrigData($key=null, $data=null)
774-
{
775-
if (is_null($key)) {
776-
$this->_origData = $this->_data;
777-
} else {
778-
$this->_origData[$key] = $data;
779-
}
780-
return $this;
781-
}
782-
783-
/**
784-
* Compare object data with original data
785-
*
786-
* @param string $field
787-
* @return boolean
788-
*/
789-
public function dataHasChangedFor($field)
790-
{
791-
$newData = $this->getData($field);
792-
$origData = $this->getOrigData($field);
793-
return $newData!=$origData;
794-
}
795-
796745
/**
797746
* Clears data changes status
798747
*

0 commit comments

Comments
 (0)