Ticket #146 (closed defect: fixed)

Opened 10 months ago

Last modified 10 months ago

Reassign posts when deleting user reassigns only most recent 5

Reported by: benmillett Owned by:
Priority: minor Milestone: 0.4
Component: -none- Version: SVN
Keywords: Cc:

Description

When deleting a user, selecting "reassign posts to user x", only the 5 most recent posts are reassigned. The next post on the content page in admin has this error:

Error: Trying to get property of non-object /Applications/MAMP/htdocs/habari/system/classes/rawphpengine.php : Line 89

As a result, all the other posts appear to be lost.

Attachments

146.diff (2.2 kB) - added by skippy 10 months ago.

Change History

Changed 10 months ago by skippy

This problem is due to a subtle logic flaw in adminhandler: it invokes Posts::get() to get an array of all the posts belonging to the to-be-deleted user, but it does not pass 'nolimit' to the query. As such, whatever you've selected for pagination in your options will be used to limit the number of posts returned.

On line 267, change this:

$posts= Posts::get( array( 'user_id' => $user_id ) );

to this:

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

However, it's still possible that this process will fail if you're operating on a large number of posts: adminhandler sequentially invokes $post->update() on each post, making a discrete write operation to the database.

Attached is a patch which introduces a new method, Posts::reassign(). It accepts a username or user ID, and an array of post IDs. Then it invokes a single UPDATE query to update all the posts to use the new user as their author.

Changed 10 months ago by skippy

Changed 10 months ago by ringmaster

  • status changed from new to closed
  • resolution set to fixed

Fixed in r1330.

Note: See TracTickets for help on using tickets.