Skip to content

Commit

Permalink
Move orig data to abstract model (like M2) (#1325)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekiphp authored Mar 27, 2021
1 parent ca3d916 commit 42988a6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 51 deletions.
52 changes: 52 additions & 0 deletions app/code/core/Mage/Core/Model/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ abstract class Mage_Core_Model_Abstract extends Varien_Object
*/
protected $_eventObject = 'object';

/**
* Original data that was loaded
*
* @var array
*/
protected $_origData;

/**
* Name of the resource model
*
Expand Down Expand Up @@ -114,6 +121,51 @@ protected function _init($resourceModel)
$this->_setResourceModel($resourceModel);
}

/**
* Get object loaded data (original data)
*
* @param string $key
* @return mixed
*/
public function getOrigData($key = null)
{
if (is_null($key)) {
return $this->_origData;
}
return isset($this->_origData[$key]) ? $this->_origData[$key] : null;
}

/**
* Initialize object original data
*
* @param string $key
* @param mixed $data
* @return $this
*/
public function setOrigData($key = null, $data = null)
{
if (is_null($key)) {
$this->_origData = $this->_data;
} else {
$this->_origData[$key] = $data;
}
return $this;
}

/**
* Compare object data with original data
*
* @param string $field
* @return boolean
*/
public function dataHasChangedFor($field)
{
$newData = $this->getData($field);
$origData = $this->getOrigData($field);

return $newData != $origData;
}

/**
* Set resource names
*
Expand Down
51 changes: 0 additions & 51 deletions lib/Varien/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ class Varien_Object implements ArrayAccess
*/
protected $_hasDataChanges = false;

/**
* Original data that was loaded
*
* @var array
*/
protected $_origData;

/**
* Name of object id field
*
Expand Down Expand Up @@ -749,50 +742,6 @@ public function serialize($attributes = array(), $valueSeparator='=', $fieldSepa
return $res;
}

/**
* Get object loaded data (original data)
*
* @param string $key
* @return mixed
*/
public function getOrigData($key=null)
{
if (is_null($key)) {
return $this->_origData;
}
return isset($this->_origData[$key]) ? $this->_origData[$key] : null;
}

/**
* Initialize object original data
*
* @param string $key
* @param mixed $data
* @return $this
*/
public function setOrigData($key=null, $data=null)
{
if (is_null($key)) {
$this->_origData = $this->_data;
} else {
$this->_origData[$key] = $data;
}
return $this;
}

/**
* Compare object data with original data
*
* @param string $field
* @return boolean
*/
public function dataHasChangedFor($field)
{
$newData = $this->getData($field);
$origData = $this->getOrigData($field);
return $newData!=$origData;
}

/**
* Clears data changes status
*
Expand Down

0 comments on commit 42988a6

Please sign in to comment.