diff options
Diffstat (limited to 'modules/gallery/libraries')
-rw-r--r-- | modules/gallery/libraries/IdentityProvider.php | 4 | ||||
-rw-r--r-- | modules/gallery/libraries/MY_Forge.php | 14 | ||||
-rw-r--r-- | modules/gallery/libraries/MY_ORM.php | 31 | ||||
-rw-r--r-- | modules/gallery/libraries/ORM_MPTT.php | 114 | ||||
-rw-r--r-- | modules/gallery/libraries/drivers/IdentityProvider.php | 3 |
5 files changed, 58 insertions, 108 deletions
diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index e07838d1..79151154 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -164,8 +164,8 @@ class IdentityProvider_Core { /** * @see IdentityProvider_Driver::create_user. */ - public function create_user($name, $full_name, $password) { - return $this->driver->create_user($name, $full_name, $password); + public function create_user($name, $full_name, $password, $email) { + return $this->driver->create_user($name, $full_name, $password, $email); } /** diff --git a/modules/gallery/libraries/MY_Forge.php b/modules/gallery/libraries/MY_Forge.php index 9564f941..ee2a0bef 100644 --- a/modules/gallery/libraries/MY_Forge.php +++ b/modules/gallery/libraries/MY_Forge.php @@ -35,20 +35,6 @@ class Forge extends Forge_Core { } /** - * Associate validation rules defined in the model with this form. - */ - public function add_rules_from($model) { - foreach ($this->inputs as $name => $input) { - if (isset($input->inputs)) { - $input->add_rules_from($model); - } - if (isset($model->form_rules[$name])) { - $input->rules($model->form_rules[$name]); - } - } - } - - /** * Validate our CSRF value as a mandatory part of all form validation. */ public function validate() { diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index 56c776aa..a158d853 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -18,38 +18,9 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class ORM extends ORM_Core { - // Track the original value of this ORM so that we can look it up in ORM::original() - protected $original = null; - public function save() { model_cache::clear(); - $result = parent::save(); - $this->original = clone $this; - return $result; - } - - public function __set($column, $value) { - if (!isset($this->original)) { - $this->original = clone $this; - } - - if ($value instanceof SafeString) { - $value = $value->unescaped(); - } - - return parent::__set($column, $value); - } - - public function __unset($column) { - if (!isset($this->original)) { - $this->original = clone $this; - } - - return parent::__unset($column); - } - - public function original() { - return $this->original; + return parent::save(); } } diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 0ea519c9..a7bb24ea 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -40,43 +40,45 @@ class ORM_MPTT_Core extends ORM { } /** - * Add this node as a child of the parent provided. + * Overload ORM::save() to update the MPTT tree when we add new items to the hierarchy. * * @chainable - * @param integer $parent_id the id of the parent node - * @return ORM + * @return ORM */ - function add_to_parent($parent) { - $this->lock(); - $parent->reload(); // Assume that the prior lock holder may have changed the parent - - try { - // Make a hole in the parent for this new item - $this->db_builder - ->update($this->table_name) - ->set("left_ptr", new Database_Expression("`left_ptr` + 2")) - ->where("left_ptr", ">=", $parent->right_ptr) - ->execute(); - $this->db_builder - ->update($this->table_name) - ->set("right_ptr", new Database_Expression("`right_ptr` + 2")) - ->where("right_ptr", ">=", $parent->right_ptr) - ->execute(); - $parent->right_ptr += 2; - - // Insert this item into the hole - $this->left_ptr = $parent->right_ptr - 2; - $this->right_ptr = $parent->right_ptr - 1; - $this->parent_id = $parent->id; - $this->level = $parent->level + 1; - $this->save(); - $parent->reload(); - } catch (Exception $e) { + function save() { + if (!$this->loaded()) { + $this->lock(); + $parent = ORM::factory("item")->where("id", "=", $this->parent_id)->find(); + + try { + // Make a hole in the parent for this new item + db::build() + ->update($this->table_name) + ->set("left_ptr", new Database_Expression("`left_ptr` + 2")) + ->where("left_ptr", ">=", $parent->right_ptr) + ->execute(); + db::build() + ->update($this->table_name) + ->set("right_ptr", new Database_Expression("`right_ptr` + 2")) + ->where("right_ptr", ">=", $parent->right_ptr) + ->execute(); + $parent->right_ptr += 2; + + // Insert this item into the hole + $this->left_ptr = $parent->right_ptr - 2; + $this->right_ptr = $parent->right_ptr - 1; + $this->parent_id = $parent->id; + $this->level = $parent->level + 1; + } catch (Exception $e) { + $this->unlock(); + throw $e; + } + parent::save(); $this->unlock(); - throw $e; + } else { + parent::save(); } - $this->unlock(); return $this; } @@ -100,12 +102,12 @@ class ORM_MPTT_Core extends ORM { $this->lock(); $this->reload(); // Assume that the prior lock holder may have changed this entry try { - $this->db_builder + db::build() ->update($this->table_name) ->set("left_ptr", new Database_Expression("`left_ptr` - 2")) ->where("left_ptr", ">", $this->right_ptr) ->execute(); - $this->db_builder + db::build() ->update($this->table_name) ->set("right_ptr", new Database_Expression("`right_ptr` - 2")) ->where("right_ptr", ">", $this->right_ptr) @@ -165,11 +167,8 @@ class ORM_MPTT_Core extends ORM { * @return array ORM */ function children($limit=null, $offset=null, $where=null, $order_by=array("id" => "ASC")) { - if ($where) { - $this->merge_where($where); - } - return $this + ->merge_where($where) ->where("parent_id", "=", $this->id) ->order_by($order_by) ->find_all($limit, $offset); @@ -183,11 +182,8 @@ class ORM_MPTT_Core extends ORM { * @return array ORM */ function children_count($where=null) { - if ($where) { - $this->merge_where($where); - } - return $this + ->merge_where($where) ->where("parent_id", "=", $this->id) ->count_all(); } @@ -202,11 +198,8 @@ class ORM_MPTT_Core extends ORM { * @return object ORM_Iterator */ function descendants($limit=null, $offset=null, $where=null, $order_by=array("id" => "ASC")) { - if ($where) { - $this->merge_where($where); - } - return $this + ->merge_where($where) ->where("left_ptr", ">", $this->left_ptr) ->where("right_ptr", "<=", $this->right_ptr) ->order_by($order_by) @@ -220,11 +213,8 @@ class ORM_MPTT_Core extends ORM { * @return integer child count */ function descendants_count($where=null) { - if ($where) { - $this->merge_where($where); - } - return $this + ->merge_where($where) ->where("left_ptr", ">", $this->left_ptr) ->where("right_ptr", "<=", $this->right_ptr) ->count_all(); @@ -237,11 +227,15 @@ class ORM_MPTT_Core extends ORM { * @param Item_Model $target Target node * @return ORM_MTPP */ - function move_to($target) { + protected function move_to($target) { if ($this->contains($target)) { throw new Exception("@todo INVALID_TARGET can't move item inside itself"); } + $this->lock(); + $this->reload(); // Assume that the prior lock holder may have changed this entry + $target->reload(); + $number_to_move = (int)(($this->right_ptr - $this->left_ptr) / 2 + 1); $size_of_hole = $number_to_move * 2; $original_left_ptr = $this->left_ptr; @@ -249,13 +243,10 @@ class ORM_MPTT_Core extends ORM { $target_right_ptr = $target->right_ptr; $level_delta = ($target->level + 1) - $this->level; - $this->lock(); - $this->reload(); // Assume that the prior lock holder may have changed this entry - $target->reload(); try { if ($level_delta) { // Update the levels for the to-be-moved items - $this->db_builder + db::build() ->update($this->table_name) ->set("level", new Database_Expression("`level` + $level_delta")) ->where("left_ptr", ">=", $original_left_ptr) @@ -264,25 +255,26 @@ class ORM_MPTT_Core extends ORM { } // Make a hole in the target for the move - $target->db_builder + db::build() ->update($this->table_name) ->set("left_ptr", new Database_Expression("`left_ptr` + $size_of_hole")) ->where("left_ptr", ">=", $target_right_ptr) ->execute(); - $target->db_builder + db::build() ->update($this->table_name) ->set("right_ptr", new Database_Expression("`right_ptr` + $size_of_hole")) ->where("right_ptr", ">=", $target_right_ptr) ->execute(); // Change the parent. - $this->db_builder + db::build() ->update($this->table_name) ->set("parent_id", $target->id) ->where("id", "=", $this->id) ->execute(); - // If the source is to the right of the target then we just adjusted its left_ptr and right_ptr above. + // If the source is to the right of the target then we just adjusted its left_ptr and + // right_ptr above. $left_ptr = $original_left_ptr; $right_ptr = $original_right_ptr; if ($original_left_ptr > $target_right_ptr) { @@ -291,7 +283,7 @@ class ORM_MPTT_Core extends ORM { } $new_offset = $target->right_ptr - $left_ptr; - $this->db_builder + db::build() ->update($this->table_name) ->set("left_ptr", new Database_Expression("`left_ptr` + $new_offset")) ->set("right_ptr", new Database_Expression("`right_ptr` + $new_offset")) @@ -300,12 +292,12 @@ class ORM_MPTT_Core extends ORM { ->execute(); // Close the hole in the source's parent after the move - $this->db_builder + db::build() ->update($this->table_name) ->set("left_ptr", new Database_Expression("`left_ptr` - $size_of_hole")) ->where("left_ptr", ">", $right_ptr) ->execute(); - $this->db_builder + db::build() ->update($this->table_name) ->set("right_ptr", new Database_Expression("`right_ptr` - $size_of_hole")) ->where("right_ptr", ">", $right_ptr) diff --git a/modules/gallery/libraries/drivers/IdentityProvider.php b/modules/gallery/libraries/drivers/IdentityProvider.php index a808c7e8..b7b1fbe8 100644 --- a/modules/gallery/libraries/drivers/IdentityProvider.php +++ b/modules/gallery/libraries/drivers/IdentityProvider.php @@ -38,9 +38,10 @@ interface IdentityProvider_Driver { * @param string $name * @param string $full_name * @param string $password + * @param string $email * @return User_Definition the user object */ - public function create_user($name, $full_name, $password); + public function create_user($name, $full_name, $password, $email); /** * Is the password provided correct? |