Make WordPress Core

Opened 17 years ago

Closed 16 years ago

#5364 closed defect (bug) (fixed)

Cron not updated correctly when deleting a future post

Reported by: develish's profile develish Owned by:
Milestone: 2.8 Priority: low
Severity: minor Version: 2.3.1
Component: Optimization Keywords: has-patch commit
Focuses: Cc:

Description

Hi,

my name is Mariano and this is my first bug report so please bear with me :D

When I delete a future post using
wp_delete_post($post->ID)
it does not update the cron correctly.

I use this code to actually manually delete and unschedule the future posts

$posts = $wpdb->get_results( "SELECT ID FROM $wpdb->posts where post_status = 'future';" );
foreach ($posts as $post)
  {
    wp_clear_scheduled_hook( 'publish_future_post', $post->ID );
    wp_delete_post($post->ID)<
  }

Maybe a check if the post is of post_status future and then unscheduling it in the post deletion process would fix it.

I was not able to find the unschedule in post.php -> wp_delete_post

Thanks for consideration

Mariano

Attachments (1)

5364.diff (352 bytes) - added by Denis-de-Bernardy 16 years ago.

Download all attachments as: .zip

Change History (14)

#1 @tellyworth
17 years ago

I've confirmed this in a unit test:

There was 1 failure:

1) test_delete_future_post_cron(WPTestIncludesPost)
Failed asserting that <integer:1195415622> is false.
/home/zem/projects/wordpress/wordpress-tests/wp-testcase/test_includes_post.php:146
/home/zem/projects/wordpress/wordpress-tests/wp-testlib/base.php:348
/home/zem/projects/wordpress/wordpress-tests/wp-test.php:92

See test_delete_future_post_cron() in http://svn.automattic.com/wordpress-tests/wp-testcase/test_includes_post.php.

#2 @lloydbudd
17 years ago

  • Milestone changed from 2.5 to 2.4

#3 @hailin
17 years ago

After we delete a post, the post ID becomes invalid.
Therefore, even the entry was still in cron, when cron fires up, it tries to retrieve
an invalid post, it will return right away. logic is in wp_publish_post:

$post = get_post($post_id);

if ( empty($post) )

return;

So while a fix is good, I don't think there is real harm.

#4 @lloydbudd
17 years ago

  • Milestone changed from 2.5 to 2.6

#5 @Denis-de-Bernardy
16 years ago

  • Component changed from General to Optimization
  • Keywords needs-patch added; cron delete post wp_delete_post removed

wontfix? or optimization?

#6 @Denis-de-Bernardy
16 years ago

  • Keywords has-patch commit added; needs-patch removed
  • Milestone changed from 2.9 to 2.8

#7 @westi
16 years ago

While this patch looks fine, it doesn't pass the unit test :-( the cron array still has the scheduled post in it afterwards.

#8 @Denis-de-Bernardy
16 years ago

I *think* I might know why... will find the ticket and report back

#9 @Denis-de-Bernardy
16 years ago

see: #8808 for the likely reason

#10 @Denis-de-Bernardy
16 years ago

so, if #8808 gets applied, and we use array( (string)$post_id ) instead, it should work.

#11 @Denis-de-Bernardy
16 years ago

on a separate note, it may be worth tweaking the cron a little bit so as to check for something like:

if args is numeric, and floatval() = intval() then cast to int.

that way, the stuff can be passed (string) $post_id etc, and it'll still work.

#12 @westi
16 years ago

Turns out this is due to hapazard sanitisation. [11282] makes it more regular.

#13 @westi
16 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11284]) Clear future publishing hook on post deletion. Fixes #5364 props develish and Denis-de-Bernardy.

Note: See TracTickets for help on using tickets.