diff --git a/app/models/History.php b/app/models/History.php index 68c1e77..af5dad7 100755 --- a/app/models/History.php +++ b/app/models/History.php @@ -104,12 +104,12 @@ class History extends Rails\ActiveRecord\Base foreach (array_reverse($stack) as $node) { $object = $node['o']; - /** - * MI: Only Pool model sets the undo (:after) callback. - * Calling it manually at the end because runCallbacks doesn't behave like in Rails. - * TODO: fix callbacks in the framework and update this. - */ - // $object->runCallbacks('undo', function() { + // /** + // * MI: Only Pool model sets the undo (:after) callback. + // * Calling it manually at the end because runCallbacks doesn't behave like in Rails. + // * TODO: fix callbacks in the framework and update this. + // */ + $object->runCallbacks('undo', function() { $changes = !empty($node['changes']) ? $node['changes'] : []; if ($changes) { @@ -137,8 +137,8 @@ class History extends Rails\ActiveRecord\Base } } } - $object->runCallbacks('after_undo'); - // }); + // $object->runCallbacks('after_undo'); + }); $object->save(); } diff --git a/app/models/Post.php b/app/models/Post.php index 5f989eb..529af6c 100755 --- a/app/models/Post.php +++ b/app/models/Post.php @@ -195,8 +195,9 @@ class Post extends Rails\ActiveRecord\Base public function first_delete() { - $this->updateAttributes(array('status' => 'deleted')); - $this->runCallbacks('after_delete'); + $this->runCallbacks('delete', function() { + $this->updateAttributes(array('status' => 'deleted')); + }); } public function delete_from_database() @@ -211,14 +212,14 @@ class Post extends Rails\ActiveRecord\Base $this->runCallbacks('after_destroy'); } - # This method is in status_methods public function undelete() { - $this->status = 'active'; - $this->save(); - if ($this->parent_id) { - Post::update_has_children($this->parent_id); + if ($this->status == 'active') { + return; } + $this->runCallbacks('undelete', function() { + $this->updateAttributes(['status' => 'active']); + }); } public function service_icon() @@ -229,18 +230,26 @@ class Post extends Rails\ActiveRecord\Base protected function callbacks() { return [ - 'before_save' => ['commit_tags', 'filter_parent_id'], 'before_create' => ['set_index_timestamp'], 'after_create' => ['after_creation'], - 'after_delete' => ['clear_avatars', 'give_favorites_to_parent'], + + 'before_delete' => ['clear_avatars'], + 'after_delete' => ['give_favorites_to_parent', 'decrement_count'], + + 'after_undelete'=> ['increment_count'], + + 'before_save' => ['commit_tags', 'filter_parent_id'], 'after_save' => ['update_parent', 'save_post_history', 'expire_cache'], + 'after_destroy' => ['expire_cache'], - 'after_validation_on_create' => ['before_creation'], + 'before_validation_on_create' => [ 'download_source', 'ensure_tempfile_exists', 'determine_content_type', 'validate_content_type', 'generate_hash', 'set_image_dimensions', 'set_image_status', 'check_pending_count', 'generate_sample', - 'generate_jpeg', 'generate_preview', 'move_file'] + 'generate_jpeg', 'generate_preview', 'move_file' + ], + 'after_validation_on_create' => ['before_creation'] ]; } diff --git a/app/models/Post/FileMethods.php b/app/models/Post/FileMethods.php index 1eee9aa..ecc4c47 100755 --- a/app/models/Post/FileMethods.php +++ b/app/models/Post/FileMethods.php @@ -648,12 +648,12 @@ trait PostFileMethods public function get_sample_width($user = null) { - $this->get_file_sample($user)['width']; + return $this->get_file_sample($user)['width']; } public function get_sample_height($user = null) { - $this->get_file_sample($user)['height']; + return $this->get_file_sample($user)['height']; } public function has_jpeg() diff --git a/app/models/Post/StatusMethods.php b/app/models/Post/StatusMethods.php index 3abd30f..6370740 100755 --- a/app/models/Post/StatusMethods.php +++ b/app/models/Post/StatusMethods.php @@ -114,11 +114,13 @@ trait PostStatusMethods return $hold; } - public function undelete() - { - if ($this->status == 'active') - return; - $this->updateAttribute('status', 'active'); - $this->runCallbacks('after_undelete'); - } + # MI: Can't have a method with bang! + // public function undelete!() + // { + // $this->status = 'active'; + // $this->save(); + // if ($this->parent_id) { + // Post::update_has_children($this->parent_id); + // } + // } } \ No newline at end of file