Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
16d921e
When deleting expired transients, also delete site transients.
ocean90 Nov 14, 2018
7cc076f
When deleting transients, also delete site transients.
ocean90 Nov 14, 2018
686c2d3
Use proper grammar in success messages
ocean90 Nov 14, 2018
8b6c187
Don't check for timeout when deleting all transients
ocean90 Nov 14, 2018
3a82089
Replace `$wpdb->esc_like(()` as it's only avaiable in WP 4.0+.
ocean90 Nov 15, 2018
219d045
Use consistent escaping
ocean90 Nov 15, 2018
2206b8d
Use polyfill for esc_like() to support older WP core versions.
ocean90 Nov 16, 2018
b0aa797
Import WP_CLI\Utils namespace
ocean90 Nov 16, 2018
43aede3
Use Utils\pluralize() helper
ocean90 Nov 16, 2018
de85f5a
Always remove site transients from the the site meta table if multisite
ocean90 Nov 16, 2018
9f6c300
Improve comment about deleting transients only from the database
ocean90 Nov 16, 2018
cfebf3a
Fix delete query for site transients in multisite
ocean90 Nov 16, 2018
ab5d73b
Add more tests for deleting (expired) transients
ocean90 Nov 16, 2018
90af941
Check of exact STDOUT messages
ocean90 Nov 17, 2018
6a9d783
Update wp-cli/wp-cli-tests to 2.0.11 to disable WP Cron during tests
ocean90 Nov 17, 2018
f457e4d
Add tests to check counts for delete all are correct
ocean90 Nov 17, 2018
97ee7dc
Split delete_all() queries to make it consistent with delete_expired()
ocean90 Nov 17, 2018
1c61b98
Merge branch 'master' into fix/delete-all-transients
ocean90 Nov 20, 2018
d46dada
Honor the --network flag when deleting all/expired transients
ocean90 Nov 21, 2018
75c036d
Make tests more consistent to show expectations
schlessera Nov 22, 2018
62420f3
Use `wp site option` for transients on multisite
schlessera Nov 22, 2018
814750b
When checking for expired transients, use the option as get_transient…
ocean90 Nov 22, 2018
b41d4e7
Split setup and tests to make clear what's actually tested
ocean90 Nov 22, 2018
965cc7d
Add example to delete all transients in a multisite
ocean90 Nov 22, 2018
8fcbde7
Add two more examples for deleting all/expired site transients
ocean90 Nov 22, 2018
b22de3c
Update package readme
ocean90 Nov 22, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,21 @@ network|site cache, please see docs for `wp transient`.
$ wp transient delete --expired
Success: 12 expired transients deleted from the database.

# Delete expired site transients.
$ wp transient delete --expired --network
Success: 1 expired transient deleted from the database.

# Delete all transients.
$ wp transient delete --all
Success: 14 transients deleted from the database.

# Delete all site transients.
$ wp transient delete --all --network
Success: 2 transients deleted from the database.

# Delete all transients in a multsite.
$ wp transient delete --all --network && wp site list --field=url | xargs -n1 -I % wp --url=% transient delete --all



### wp transient get
Expand Down Expand Up @@ -496,15 +507,15 @@ wp transient type
~~~

Indicates whether the transients API is using an object cache or the
options table.
database.

For a more complete explanation of the transient cache, including the
network|site cache, please see docs for `wp transient`.

**EXAMPLES**

$ wp transient type
Transients are saved to the wp_options table.
Transients are saved to the database.

## Installing

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"require-dev": {
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/wp-cli-tests": "^2.0.7"
"wp-cli/wp-cli-tests": "^2.0.11"
},
"config": {
"process-timeout": 7200,
Expand Down
299 changes: 295 additions & 4 deletions features/transient.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Feature: Manage WordPress transient cache
Success: Transient deleted.
"""

Scenario: Transient delete and other flags
Scenario: Deleting all transients on single site
Given a WP install

When I try `wp transient delete`
Expand All @@ -65,11 +65,13 @@ Feature: Manage WordPress transient cache
"""

When I run `wp transient set foo bar`
And I run `wp transient set foo2 bar2`
And I run `wp transient set foo2 bar2 600`
And I run `wp transient set foo3 bar3 --network`
And I run `wp transient set foo4 bar4 600 --network`
And I run `wp transient delete --all`
Then STDOUT should contain:
Then STDOUT should be:
"""
transients deleted from the database.
Success: 2 transients deleted from the database.
"""

When I try `wp transient get foo`
Expand All @@ -83,3 +85,292 @@ Feature: Manage WordPress transient cache
"""
Warning: Transient with key "foo2" is not set.
"""

When I run `wp transient get foo3 --network`
Then STDOUT should be:
"""
bar3
"""

When I run `wp transient get foo4 --network`
Then STDOUT should be:
"""
bar4
"""

When I run `wp transient delete --all --network`
Then STDOUT should be:
"""
Success: 2 transients deleted from the database.
"""

When I try `wp transient get foo3 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo3" is not set.
"""

When I try `wp transient get foo4 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo4" is not set.
"""

Scenario: Deleting expired transients on single site
Given a WP install
And I run `wp transient set foo bar 60`
And I run `wp transient set foo2 bar2 60`
And I run `wp transient set foo3 bar3 60 --network`
And I run `wp transient set foo4 bar4 60 --network`
# Change timeout to be in the past.
And I run `wp option update _transient_timeout_foo 1321009871`
And I run `wp option update _site_transient_timeout_foo3 1321009871`

When I run `wp transient delete --expired`
Then STDOUT should be:
"""
Success: 1 expired transient deleted from the database.
"""

When I try `wp transient get foo`
Then STDERR should be:
"""
Warning: Transient with key "foo" is not set.
"""

When I run `wp transient get foo2`
Then STDOUT should be:
"""
bar2
"""

# Check if option still exists as a get transient call will remove it.
When I run `wp option get _site_transient_foo3`
Then STDOUT should be:
"""
bar3
"""

When I run `wp transient get foo4 --network`
Then STDOUT should be:
"""
bar4
"""

When I run `wp transient delete --expired --network`
Then STDOUT should be:
"""
Success: 1 expired transient deleted from the database.
"""

When I try `wp transient get foo`
Then STDERR should be:
"""
Warning: Transient with key "foo" is not set.
"""

When I run `wp transient get foo2`
Then STDOUT should be:
"""
bar2
"""

When I try `wp transient get foo3 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo3" is not set.
"""

When I run `wp transient get foo4 --network`
Then STDOUT should be:
"""
bar4
"""

Scenario: Deleting all transients on multisite
Given a WP multisite install
And I run `wp site create --slug=foo`

When I try `wp transient delete`
Then STDERR should be:
"""
Error: Please specify transient key, or use --all or --expired.
"""

When I run `wp transient set foo bar`
And I run `wp transient set foo2 bar2 600`
And I run `wp transient set foo3 bar3 --network`
And I run `wp transient set foo4 bar4 600 --network`
And I run `wp --url=example.com/foo transient set foo5 bar5 --network`
And I run `wp --url=example.com/foo transient set foo6 bar6 600 --network`
And I run `wp transient delete --all`
Then STDOUT should be:
"""
Success: 2 transients deleted from the database.
"""

When I try `wp transient get foo`
Then STDERR should be:
"""
Warning: Transient with key "foo" is not set.
"""

When I try `wp transient get foo2`
Then STDERR should be:
"""
Warning: Transient with key "foo2" is not set.
"""

When I run `wp transient get foo3 --network`
Then STDOUT should be:
"""
bar3
"""

When I run `wp transient get foo4 --network`
Then STDOUT should be:
"""
bar4
"""

When I run `wp --url=example.com/foo transient get foo5 --network`
Then STDOUT should be:
"""
bar5
"""

When I run `wp --url=example.com/foo transient get foo6 --network`
Then STDOUT should be:
"""
bar6
"""

When I run `wp transient delete --all --network`
Then STDOUT should be:
"""
Success: 4 transients deleted from the database.
"""

When I try `wp transient get foo3 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo3" is not set.
"""

When I try `wp transient get foo4 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo4" is not set.
"""

When I try `wp --url=example.com/foo transient get foo5 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo5" is not set.
"""

When I try `wp --url=example.com/foo transient get foo6 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo6" is not set.
"""

Scenario: Deleting expired transients on multisite
Given a WP multisite install
And I run `wp site create --slug=foo`
And I run `wp transient set foo bar 60`
And I run `wp transient set foo2 bar2 60`
And I run `wp transient set foo3 bar3 60 --network`
And I run `wp transient set foo4 bar4 60 --network`
And I run `wp --url=example.com/foo transient set foo5 bar5 60 --network`
And I run `wp --url=example.com/foo transient set foo6 bar6 60 --network`
# Change timeout to be in the past.
And I run `wp option update _transient_timeout_foo 1321009871`
And I run `wp site option update _site_transient_timeout_foo3 1321009871`
And I run `wp --url=example.com/foo site option update _site_transient_timeout_foo5 1321009871`

When I run `wp transient delete --expired`
Then STDOUT should be:
"""
Success: 1 expired transient deleted from the database.
"""

When I try `wp transient get foo`
Then STDERR should be:
"""
Warning: Transient with key "foo" is not set.
"""

When I run `wp transient get foo2`
Then STDOUT should be:
"""
bar2
"""

# Check if option still exists as a get transient call will remove it.
When I run `wp site option get _site_transient_foo3`
Then STDOUT should be:
"""
bar3
"""

When I run `wp transient get foo4 --network`
Then STDOUT should be:
"""
bar4
"""

# Check if option still exists as a get transient call will remove it.
When I run `wp --url=example.com/foo site option get _site_transient_foo5`
Then STDOUT should be:
"""
bar5
"""

When I run `wp --url=example.com/foo transient get foo6 --network`
Then STDOUT should be:
"""
bar6
"""

When I run `wp transient delete --expired --network`
Then STDOUT should be:
"""
Success: 2 expired transients deleted from the database.
"""

When I try `wp transient get foo`
Then STDERR should be:
"""
Warning: Transient with key "foo" is not set.
"""

When I run `wp transient get foo2`
Then STDOUT should be:
"""
bar2
"""

When I try `wp transient get foo3 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo3" is not set.
"""

When I run `wp transient get foo4 --network`
Then STDOUT should be:
"""
bar4
"""

When I try `wp --url=example.com/foo transient get foo5 --network`
Then STDERR should be:
"""
Warning: Transient with key "foo5" is not set.
"""

When I run `wp --url=example.com/foo transient get foo6 --network`
Then STDOUT should be:
"""
bar6
"""
Loading