callbacks, set_avatar fix
This commit is contained in:
parent
6fc7d4c02b
commit
3dd3c8c81f
@ -104,12 +104,12 @@ class History extends Rails\ActiveRecord\Base
|
|||||||
|
|
||||||
foreach (array_reverse($stack) as $node) {
|
foreach (array_reverse($stack) as $node) {
|
||||||
$object = $node['o'];
|
$object = $node['o'];
|
||||||
/**
|
// /**
|
||||||
* MI: Only Pool model sets the undo (:after) callback.
|
// * MI: Only Pool model sets the undo (:after) callback.
|
||||||
* Calling it manually at the end because runCallbacks doesn't behave like in Rails.
|
// * Calling it manually at the end because runCallbacks doesn't behave like in Rails.
|
||||||
* TODO: fix callbacks in the framework and update this.
|
// * TODO: fix callbacks in the framework and update this.
|
||||||
*/
|
// */
|
||||||
// $object->runCallbacks('undo', function() {
|
$object->runCallbacks('undo', function() {
|
||||||
$changes = !empty($node['changes']) ? $node['changes'] : [];
|
$changes = !empty($node['changes']) ? $node['changes'] : [];
|
||||||
|
|
||||||
if ($changes) {
|
if ($changes) {
|
||||||
@ -137,8 +137,8 @@ class History extends Rails\ActiveRecord\Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$object->runCallbacks('after_undo');
|
// $object->runCallbacks('after_undo');
|
||||||
// });
|
});
|
||||||
|
|
||||||
$object->save();
|
$object->save();
|
||||||
}
|
}
|
||||||
|
@ -195,8 +195,9 @@ class Post extends Rails\ActiveRecord\Base
|
|||||||
|
|
||||||
public function first_delete()
|
public function first_delete()
|
||||||
{
|
{
|
||||||
$this->updateAttributes(array('status' => 'deleted'));
|
$this->runCallbacks('delete', function() {
|
||||||
$this->runCallbacks('after_delete');
|
$this->updateAttributes(array('status' => 'deleted'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete_from_database()
|
public function delete_from_database()
|
||||||
@ -211,14 +212,14 @@ class Post extends Rails\ActiveRecord\Base
|
|||||||
$this->runCallbacks('after_destroy');
|
$this->runCallbacks('after_destroy');
|
||||||
}
|
}
|
||||||
|
|
||||||
# This method is in status_methods
|
|
||||||
public function undelete()
|
public function undelete()
|
||||||
{
|
{
|
||||||
$this->status = 'active';
|
if ($this->status == 'active') {
|
||||||
$this->save();
|
return;
|
||||||
if ($this->parent_id) {
|
|
||||||
Post::update_has_children($this->parent_id);
|
|
||||||
}
|
}
|
||||||
|
$this->runCallbacks('undelete', function() {
|
||||||
|
$this->updateAttributes(['status' => 'active']);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function service_icon()
|
public function service_icon()
|
||||||
@ -229,18 +230,26 @@ class Post extends Rails\ActiveRecord\Base
|
|||||||
protected function callbacks()
|
protected function callbacks()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'before_save' => ['commit_tags', 'filter_parent_id'],
|
|
||||||
'before_create' => ['set_index_timestamp'],
|
'before_create' => ['set_index_timestamp'],
|
||||||
'after_create' => ['after_creation'],
|
'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_save' => ['update_parent', 'save_post_history', 'expire_cache'],
|
||||||
|
|
||||||
'after_destroy' => ['expire_cache'],
|
'after_destroy' => ['expire_cache'],
|
||||||
'after_validation_on_create' => ['before_creation'],
|
|
||||||
'before_validation_on_create' => [
|
'before_validation_on_create' => [
|
||||||
'download_source', 'ensure_tempfile_exists', 'determine_content_type',
|
'download_source', 'ensure_tempfile_exists', 'determine_content_type',
|
||||||
'validate_content_type', 'generate_hash', 'set_image_dimensions',
|
'validate_content_type', 'generate_hash', 'set_image_dimensions',
|
||||||
'set_image_status', 'check_pending_count', 'generate_sample',
|
'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']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,12 +648,12 @@ trait PostFileMethods
|
|||||||
|
|
||||||
public function get_sample_width($user = null)
|
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)
|
public function get_sample_height($user = null)
|
||||||
{
|
{
|
||||||
$this->get_file_sample($user)['height'];
|
return $this->get_file_sample($user)['height'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function has_jpeg()
|
public function has_jpeg()
|
||||||
|
@ -114,11 +114,13 @@ trait PostStatusMethods
|
|||||||
return $hold;
|
return $hold;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function undelete()
|
# MI: Can't have a method with bang!
|
||||||
{
|
// public function undelete!()
|
||||||
if ($this->status == 'active')
|
// {
|
||||||
return;
|
// $this->status = 'active';
|
||||||
$this->updateAttribute('status', 'active');
|
// $this->save();
|
||||||
$this->runCallbacks('after_undelete');
|
// if ($this->parent_id) {
|
||||||
}
|
// Post::update_has_children($this->parent_id);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user