浏览代码

- completed the implementaiton o the 'is dirty' flag to prevent reloading an object being modified.
- added a protection against reading an uninitialized field that triggered a PHP 'notice' error.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@201 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 15 年之前
父节点
当前提交
0a11ce88ae
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      core/dbobject.class.php

+ 9 - 3
core/dbobject.class.php

@@ -302,6 +302,7 @@ abstract class DBObject
 			}
 		}
 		$this->m_aCurrValues[$sAttCode] = $oAttDef->MakeRealValue($value);
+		$this->RegisterAsDirty(); // Make sure we do not reload it anymore... before saving it
 	}
 	
 	public function Get($sAttCode)
@@ -310,13 +311,13 @@ abstract class DBObject
 		{
 			throw new CoreException("Unknown attribute code '$sAttCode' for the class ".get_class($this));
 		}
-		if ($this->m_bIsInDB && !$this->m_aLoadedAtt[$sAttCode])
+		if ($this->m_bIsInDB && !$this->m_aLoadedAtt[$sAttCode] && !$this->m_bDirty)
 		{
 			// #@# non-scalar attributes.... handle that differentely
 			$this->Reload();
 		}
 		$this->ComputeFields();
-		return $this->m_aCurrValues[$sAttCode];
+		return isset($this->m_aCurrValues[$sAttCode]) ? $this->m_aCurrValues[$sAttCode] : '';
 	}
 
 	public function GetOriginal($sAttCode)
@@ -696,6 +697,7 @@ abstract class DBObject
 	public function DBInsert()
 	{
 		$this->DBInsertNoReload();
+		$this->m_bDirty = false;
 		$this->Reload();
 		return $this->m_iKey;
 	}
@@ -741,9 +743,13 @@ abstract class DBObject
 		}
 
 		$this->DBWriteLinks();
+		$this->m_bDirty = false;
 
 		// Reload to get the external attributes
-		if ($bHasANewExternalKeyValue) $this->Reload();
+		if ($bHasANewExternalKeyValue)
+		{
+			$this->Reload();
+		}
 
 		return $this->m_iKey;
 	}