Skip to content

Fix default 'before' date in WP-CLI clean command #1343#1346

Open
MagicGeny wants to merge 1 commit into
woocommerce:trunkfrom
MagicGeny:fix/cli-clean-default-before-date-1343
Open

Fix default 'before' date in WP-CLI clean command #1343#1346
MagicGeny wants to merge 1 commit into
woocommerce:trunkfrom
MagicGeny:fix/cli-clean-default-before-date-1343

Conversation

@MagicGeny

Copy link
Copy Markdown

Description

Closes #1343

This PR fixes an issue where running the wp action-scheduler clean command without specifying the --before flag incorrectly deletes all completed/failed/cancelled actions instead of keeping the last 31 days of data as stated in the documentation.

Cause of the bug

In ActionScheduler_WPCLI_Clean_Command::clean(), the default value for the before argument was set to an empty string ''. When passed further down into strtotime(), this empty string evaluates to "now", causing the cleaner to wipe out even newly created/completed actions.

Solution

Changed the default value from '' to '31 days ago' to align the default CLI behavior with the plugin's default retention period and documentation.

How to test

  1. Create some fresh completed actions:
    wp eval 'for($i=0; $i<5; $i++) { $id = as_schedule_single_action(time(), "test", [], "test"); ActionScheduler::store()->mark_complete($id); }'
  2. Run the clean command without flags: wp action-scheduler clean
  3. Before this fix: All 5 fresh actions are deleted (5 actions deleted.).
  4. After this fix: The fresh actions are safely preserved (0 batches processed.).

@MagicGeny

Copy link
Copy Markdown
Author

Hi @barryhughes!

I wanted to provide some context for this PR. This change resolves the default 'before' value issue for the cleanup process.

It is also a crucial dependency for another bugfix I just submitted in #13480 (which addresses the incorrect 'before' filtering in the WP-CLI clean command, #1107).

I have tested this locally, and all tests pass. Please let me know if you would like me to adjust anything here so we can move this forward. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WP-CLI clean command ignores its documented 31-day default and deletes ALL completed/canceled actions when --before is omitted

1 participant