Skip to content

Commit

Permalink
Rearrange the order of operations for deleting a user, such that the …
Browse files Browse the repository at this point in the history
…user's posts are retrieved, the user is deleted, and then the posts will be deleted. Add a check to the undelete plugin to make sure user_id exists; posts will be deleted as usual if user_id doesn't (as it wouldn't now that users are deleted before posts). This probably isn't ideal, but it should close habari/habari#253.
  • Loading branch information
mikelietz committed Dec 29, 2011
1 parent d1193ec commit 39443b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion handlers/adminusershandler.php
Expand Up @@ -335,6 +335,8 @@ public function update_users( $handler_vars )

$posts = Posts::get( array( 'user_id' => $user->id, 'nolimit' => 1) );

$user->delete();

if ( isset( $posts[0] ) ) {
if ( 0 == $assign ) {
foreach ( $posts as $post ) {
Expand All @@ -345,7 +347,6 @@ public function update_users( $handler_vars )
Posts::reassign( $assign, $posts );
}
}
$user->delete();
}
else {
$msg_status = _t( 'You cannot delete yourself.' );
Expand Down
2 changes: 1 addition & 1 deletion plugins/undelete/undelete.plugin.php
Expand Up @@ -40,7 +40,7 @@ function filter_post_delete_allow( $result, $post )
// and then return false. The Post::delete() method will
// see the false return value, and simply return, leaving
// the post in the database.
if ( $post->status != Post::status( 'deleted' ) && ACL::access_check( $post->get_access(), 'delete' ) ) {
if ( $post->status != Post::status( 'deleted' ) && ACL::access_check( $post->get_access(), 'delete' ) && User::get_by_id( $post->user_id ) ) {
$post->info->prior_status = $post->status;
$post->status = Post::status( 'deleted' );
$post->update();
Expand Down

0 comments on commit 39443b7

Please sign in to comment.