-
Notifications
You must be signed in to change notification settings - Fork 328
Closed
Labels
P0High priorityHigh priorityQA: EngRequires specialized QA by an engineerRequires specialized QA by an engineerTeam SIssues for Squad 1Issues for Squad 1Type: EnhancementImprovement of an existing featureImprovement of an existing feature
Description
Feature Description
When the plugin is reset, delete all posts created within each registered custom post type
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When the plugin is reset, all posts belonging to the custom post type and related post meta registered by Site Kit are deleted.
Implementation Brief
- Update
includes/Core/Util/Reset.php- Add
delete_postsmethod- Accepts a $scope argument.
- When
$scopeisnetwork:- Retrieve all sites using get_sites (following the established pattern used in other reset methods).
- Otherwise:
- Use only the current site ID via
get_current_blog_id().
- Use only the current site ID via
- Loop over the collected site IDs and for each:
- Query and delete posts of type
googlesitekit_email_logand it's related post meta values.
- Query and delete posts of type
- Use direct
wpdbqueries for performance instead of core wrapper functions.
- Invoke
delete_postsinallmethod passing correctscopefor both single and multisite
- Add
Test Coverage
- Update
tests/phpunit/integration/Core/Util/ResetTest.phpto verify that posts of typegooglesitekit_email_logare deleted on reset
QA Brief
QA:Eng required as developer access required to create test Email_Log posts currently.
- Enable the
proactiveUserEngagementfeature flag. - Edit the Email Log post type definition so that it shows in the WP Ui.
- Update this section:
site-kit-wp/includes/Core/Email_Reporting/Email_Log.php
Lines 101 to 109 in eb3daf7
register_post_type( self::POST_TYPE, array( 'public' => false, 'map_meta_cap' => true, 'rewrite' => false, 'query_var' => false, ) ); - To the following
register_post_type(
self::POST_TYPE,
array(
'label' => 'Email Log',
'labels' => array(
'name' => 'Email Log',
'singular_name' => 'Email Log',
'menu_name' => 'Email Log',
'all_items' => 'All Email Logs',
'view_item' => 'View Email Log',
'add_new_item' => 'Add New Email Log',
'edit_item' => 'Edit Email Log',
'update_item' => 'Update Email Log',
'search_items' => 'Search Email Logs',
'not_found' => 'No email logs found',
'not_found_in_trash' => 'No email logs found in trash',
),
'public' => true,
'map_meta_cap' => true,
'rewrite' => false,
'query_var' => false,
)
);
- Update this section:
site-kit-wp/includes/Core/Email_Reporting/Email_Log.php
Lines 262 to 271 in d5671c7
register_post_status( $status, array( 'public' => false, 'internal' => true, 'exclude_from_search' => true, 'show_in_admin_all_list' => false, 'show_in_admin_status_list' => false, ) ); - To the following (this is so you can see posts with our custom statuses in the admin):
register_post_status(
$status,
array(
'public' => true,
'internal' => false,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
)
);
- Create an Email Log post using this code somewhere in the plugin (it's important to use this code because the admin can't create posts with our custom statuses without more significant customisation of plugin JS).
$post_id = wp_insert_post(
array(
'post_type' => \Google\Site_Kit\Core\Email_Reporting\Email_Log::POST_TYPE,
'post_status' => \Google\Site_Kit\Core\Email_Reporting\Email_Log::STATUS_SENT,
'post_title' => 'Test Email Log',
'meta_input' => array(
\Google\Site_Kit\Core\Email_Reporting\Email_Log::META_REPORT_FREQUENCY => 'weekly',
\Google\Site_Kit\Core\Email_Reporting\Email_Log::META_BATCH_ID => 'batch-123',
\Google\Site_Kit\Core\Email_Reporting\Email_Log::META_SEND_ATTEMPTS => 1,
),
)
);
- Reset the plugin - see that the posts you created have been deleted.
Changelog entry
- Extend the Reset utility class to delete remaining error reporting logs
Metadata
Metadata
Assignees
Labels
P0High priorityHigh priorityQA: EngRequires specialized QA by an engineerRequires specialized QA by an engineerTeam SIssues for Squad 1Issues for Squad 1Type: EnhancementImprovement of an existing featureImprovement of an existing feature