callbacks, set_avatar fix

This commit is contained in:
Parziphal 2013-11-13 12:53:33 -05:00
parent 6fc7d4c02b
commit 3dd3c8c81f
4 changed files with 39 additions and 28 deletions

View File

@ -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();
}

View File

@ -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']
];
}

View File

@ -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()

View File

@ -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);
// }
// }
}