Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move orig data to abstract model (according to Magento 2.x) #1325

Merged
merged 1 commit into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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