Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Bugfix #37

Merged
merged 2 commits into from Apr 17, 2012
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
14 changes: 13 additions & 1 deletion src/morph/PropertySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,27 @@ public function __setRawPropertyValue($name, $value, $state = null)
public function getState()
{
$state = \morph\Enum::STATE_NEW;
$hasCleanProperty = false;
$hasNewProperty = false;

foreach ($this as $n => $property) {
$propertyState = $property->getState();
if ( \morph\Enum::STATE_DIRTY == $propertyState) {
$state = $propertyState;
break;
} elseif ( \morph\Enum::STATE_CLEAN == $propertyState) {
$state = $propertyState;
$hasCleanProperty = true;
} elseif ( \morph\Enum::STATE_NEW == $propertyState) {
$state = $propertyState;
$hasNewProperty = true;
}
}
}

if ($hasCleanProperty && $hasNewProperty) {
return \morph\Enum::STATE_DIRTY;
}

return $state;
}

Expand Down
6 changes: 5 additions & 1 deletion src/morph/property/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __getRawValue()
* @param $value
* @return Morph_Property_Generic
*/
public function __setRawValue($value)
public function __setRawValue($value, $state = null)
{
if ($value instanceof \MongoDate) {
$this->value = (int) $value->sec;
Expand All @@ -72,6 +72,10 @@ public function __setRawValue($value)
$this->value = null;
}
}

if (null != $state) {
$this->state = $state;
}
return $this;
}

Expand Down