Permalink
Browse files

fixed missing clear() method

also changed all private method to protected to allow extension.
  • Loading branch information...
1 parent 8678165 commit 39156a8c681be1ff75f89fad6d1ca9a4fca1c885 @WanWizard WanWizard committed Apr 17, 2012
Showing with 38 additions and 18 deletions.
  1. +38 −18 classes/model.php
View
@@ -887,7 +887,7 @@ public function tree_delete_tree($all = false)
$query->execute(call_user_func(__CLASS__.'::connection'));
// reset the current object, it's no longer valid
- $this->clear();
+ $this->tree_clear();
return true;
}
@@ -924,7 +924,7 @@ public function tree_delete()
}
// reset the current object, it's no longer valid
- $this->clear();
+ $this->tree_clear();
return true;
}
@@ -1076,18 +1076,6 @@ public function tree_dump_as_tab(Array $attributes = array(), $skip_root = true)
return $this->_tree_dump_as('tab', $attributes, $skip_root);
}
- /* -------------------------------------------------------------------------
- * private class functions
- * ---------------------------------------------------------------------- */
-
- private function tree_validate_model($object, $method)
- {
- if (get_class($object) !== get_class($this))
- {
- throw new \Exception('Model object passed to '.$method.'() is not an instance of '.get_class($this).'.');
- }
- }
-
// -----------------------------------------------------------------
/**
@@ -1109,6 +1097,18 @@ public function tree_get_tree_id()
}
}
+ /* -------------------------------------------------------------------------
+ * protected class functions
+ * ---------------------------------------------------------------------- */
+
+ protected function tree_validate_model($object, $method)
+ {
+ if (get_class($object) !== get_class($this))
+ {
+ throw new \Exception('Model object passed to '.$method.'() is not an instance of '.get_class($this).'.');
+ }
+ }
+
// -----------------------------------------------------------------
/**
@@ -1119,7 +1119,7 @@ public function tree_get_tree_id()
* @param boolean if true, the object itself (root of the dump) will not be included
* @return mixed
*/
- private function _tree_dump_as($type, $attributes, $skip_root)
+ protected function _tree_dump_as($type, $attributes, $skip_root)
{
if ($this->tree_is_valid($this))
{
@@ -1304,7 +1304,7 @@ private function _tree_dump_as($type, $attributes, $skip_root)
// -----------------------------------------------------------------
- private function _tree_shift_rlvalues($first, $delta)
+ protected function _tree_shift_rlvalues($first, $delta)
{
$query = \DB::update(static::table());
@@ -1359,7 +1359,7 @@ private function _tree_shift_rlvalues($first, $delta)
// -----------------------------------------------------------------
- private function _tree_shift_rlrange($first, $last, $delta)
+ protected function _tree_shift_rlrange($first, $last, $delta)
{
$query = \DB::update(static::table());
@@ -1394,7 +1394,7 @@ private function _tree_shift_rlrange($first, $last, $delta)
// -----------------------------------------------------------------
- private function _tree_move_subtree($destination_id)
+ protected function _tree_move_subtree($destination_id)
{
// catch a recursive move
if ( $destination_id >= $this->{$this->configuration['left_field']} and $destination_id <= $this->{$this->configuration['right_field']} )
@@ -1429,6 +1429,26 @@ private function _tree_move_subtree($destination_id)
// return the moved object
return $this;
}
+
+ // -----------------------------------------------------------------
+
+ protected function tree_clear()
+ {
+ // Perform cleanup:
+ // remove from internal object cache, remove PK's, set to non saved object, remove db original values
+ if (array_key_exists(get_called_class(), static::$_cached_objects)
+ and array_key_exists(static::implode_pk($this), static::$_cached_objects[get_called_class()]))
+ {
+ unset(static::$_cached_objects[get_called_class()][static::implode_pk($this)]);
+ }
+ foreach ($this->primary_key() as $pk)
+ {
+ unset($this->_data[$pk]);
+ }
+ $this->_is_new = true;
+ $this->_original = array();
+ }
+
}
/* End of file model.php */

0 comments on commit 39156a8

Please sign in to comment.