-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from trendwerk/1-delete-data
Delete data
- Loading branch information
Showing
6 changed files
with
137 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Feature: Delete fake data | ||
|
||
Scenario: Generate and delete posts | ||
Given a WP install | ||
|
||
And a image.yml file: | ||
""" | ||
Trendwerk\Faker\Entity\Image: | ||
image{1..1}: | ||
data: '<image()>' | ||
""" | ||
|
||
And a post.yml file: | ||
""" | ||
Trendwerk\Faker\Entity\Post: | ||
post{1..10}: | ||
post_content: <paragraphs(4, true)> | ||
post_title: '<sentence()>' | ||
""" | ||
|
||
When I run `wp faker fake image.yml post.yml` | ||
When I run `wp faker delete --yes` | ||
Then STDOUT should contain: | ||
""" | ||
Removed 1 attachment. | ||
Removed 10 posts. | ||
""" | ||
|
||
When I run `wp post list --meta_key=_fake --format=count` | ||
Then STDOUT should be: | ||
""" | ||
0 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
<?php | ||
namespace Trendwerk\Faker\Entity; | ||
|
||
use WP_Query; | ||
|
||
abstract class Attachment extends Post | ||
{ | ||
public $data; | ||
public $post_type = 'attachment'; | ||
public $post_status = 'inherit'; | ||
|
||
public static function delete() | ||
{ | ||
$query = new WP_Query([ | ||
'fields' => 'ids', | ||
'meta_query' => [ | ||
[ | ||
'key' => '_fake', | ||
'value' => true, | ||
], | ||
], | ||
'post_status' => 'any', | ||
'post_type' => 'attachment', | ||
'posts_per_page' => -1, | ||
]); | ||
|
||
foreach ($query->posts as $id) { | ||
wp_delete_attachment($id, true); | ||
} | ||
|
||
return count($query->posts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters