Skip to content

Commit 12f2e5e

Browse files
committed
Merge branch 'master' into enforce-php74-compat
2 parents 4319f63 + 4519ea6 commit 12f2e5e

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
sudo: false
2-
dist: trusty
1+
os: linux
2+
dist: xenial
33

44
language: php
55
php: 7.4
66

7+
services:
8+
- mysql
9+
710
notifications:
811
email:
912
on_success: never
@@ -71,6 +74,7 @@ jobs:
7174
- stage: test
7275
php: 5.6
7376
env: WP_VERSION=3.7.11
77+
dist: trusty
7478
- stage: test
7579
php: 5.6
7680
env: WP_VERSION=trunk

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"wp-cli/wp-cli": "^2"
15+
"wp-cli/wp-cli": "dev-master"
1616
},
1717
"require-dev": {
1818
"wp-cli/cache-command": "^1 || ^2",

features/site-empty.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ Feature: Empty a WordPress site of its data
66
And download:
77
| path | url |
88
| {CACHE_DIR}/large-image.jpg | http://wp-cli.org/behat-data/large-image.jpg |
9+
And a insert_link_data.sql file:
10+
"""
11+
INSERT INTO `wp_links` (`link_url`, `link_name`, `link_image`, `link_target`, `link_description`, `link_visible`, `link_owner`, `link_rating`, `link_rel`, `link_notes`, `link_rss`)
12+
VALUES ('http://wordpress.org/', 'test', '', '', 'test', 'Y', 1, 0, '', '', '')
13+
"""
14+
15+
When I run `wp db query "SOURCE insert_link_data.sql;"`
16+
Then STDERR should be empty
17+
18+
When I run `wp db query "SELECT COUNT(link_id) FROM wp_links;"`
19+
Then STDOUT should be:
20+
"""
21+
COUNT(link_id)
22+
1
23+
"""
924

1025
When I run `wp media import {CACHE_DIR}/large-image.jpg --post_id=1`
1126
Then the wp-content/uploads/large-image.jpg file should exist
@@ -63,6 +78,13 @@ Feature: Empty a WordPress site of its data
6378
0
6479
"""
6580

81+
When I run `wp db query "SELECT COUNT(link_id) FROM wp_links;"`
82+
Then STDOUT should be:
83+
"""
84+
COUNT(link_id)
85+
0
86+
"""
87+
6688
Scenario: Empty a site and its uploads directory
6789
Given a WP multisite installation
6890
And I run `wp site create --slug=foo`

src/Site_Command.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,34 @@ private function empty_taxonomies() {
115115
}
116116
}
117117

118+
/**
119+
* Delete all links, link_category terms, and related cache.
120+
*/
121+
private function empty_links() {
122+
global $wpdb;
123+
124+
// Remove links and related cached data.
125+
$links_query = "SELECT link_id FROM {$wpdb->links}";
126+
$links = new QueryIterator( $links_query, 10000 );
127+
128+
// Remove bookmarks cache group.
129+
wp_cache_delete( 'get_bookmarks', 'bookmark' );
130+
131+
while ( $links->valid() ) {
132+
$link_id = $links->current()->link_id;
133+
134+
// Remove cache for the link.
135+
wp_delete_object_term_relationships( $link_id, 'link_category' );
136+
wp_cache_delete( $link_id, 'bookmark' );
137+
clean_object_term_cache( $link_id, 'link' );
138+
139+
$links->next();
140+
}
141+
142+
// Empty the table once link related cache and term is removed.
143+
$wpdb->query( "TRUNCATE {$wpdb->links}" );
144+
}
145+
118146
/**
119147
* Insert default terms.
120148
*/
@@ -211,7 +239,7 @@ private function reset_options() {
211239
* ## EXAMPLES
212240
*
213241
* $ wp site empty
214-
* Are you sure you want to empty the site at http://www.example.com of all posts, comments, and terms? [y/n] y
242+
* Are you sure you want to empty the site at http://www.example.com of all posts, links, comments, and terms? [y/n] y
215243
* Success: The site at 'http://www.example.com' was emptied.
216244
*
217245
* @subcommand empty
@@ -223,9 +251,10 @@ public function empty_( $args, $assoc_args ) {
223251
$upload_message = ', and delete its uploads directory';
224252
}
225253

226-
WP_CLI::confirm( "Are you sure you want to empty the site at '" . site_url() . "' of all posts, comments, and terms" . $upload_message . '?', $assoc_args );
254+
WP_CLI::confirm( "Are you sure you want to empty the site at '" . site_url() . "' of all posts, links, comments, and terms" . $upload_message . '?', $assoc_args );
227255

228256
$this->empty_posts();
257+
$this->empty_links();
229258
$this->empty_comments();
230259
$this->empty_taxonomies();
231260
$this->insert_default_terms();

0 commit comments

Comments
 (0)