-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Remove data from Salesforce when posts are deleted/unpublished #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: vip-2449-ingest-api-vip_agentforce_post_ingestion_complete-action
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements post deletion handling for the Salesforce Agentforce integration, enabling the system to remove posts from Salesforce when they are unpublished or permanently deleted in WordPress. The implementation tracks ingested posts via metadata and provides comprehensive failure handling through a new Deletion_Failure class.
Key Changes:
- Added post deletion tracking via meta key to identify previously ingested posts
- Implemented deletion hooks for unpublishing (
transition_post_status) and permanent deletion (before_delete_post) - Created
Deletion_Failureclass for structured error reporting, mirroring the existingIngestion_Failurepattern
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| vip-agentforce.php | Added require statement for the new Deletion_Failure class |
| modules/ingestion/class-ingestion.php | Added meta tracking constant, deletion hooks, and helper methods for handling post unpublishing and deletion from Salesforce |
| modules/ingestion/class-deletion-failure.php | New data class to encapsulate deletion failure information with structured error reporting |
| tests/phpunit/test-ingestion-deletion.php | Comprehensive test suite covering deletion scenarios, meta tracking, hook registration, and failure handling |
| tests/phpunit/doubles/class-ingestion-with-failing-delete-api.php | Test double that simulates API deletion failures for testing error handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
So this PR should help handle post deletions/unpublishing. It still won't handle the case where a deletion has occurred out of band - i.e. a deletion using a SQL query. That'll come later, in the form of a
wpcommand for forcing deletions.Requires #8 to be merged.
Pre-review checklist
Please make sure the items below have been covered before requesting a review:
Pre-deploy checklist
Steps to Test
Click here to view testing steps
Manual Testing: Post Deletion from Salesforce
Prerequisites
vip dev-env start/wp/log/debug.log. Clear it out before running any of the tests below. i.e.error_log()output: appears in terminal (not debug.log)vip-agentforce.php:Test 1: Unpublish Triggers Deletion (publish � draft)
Goal: Verify unpublishing a post triggers deletion from Salesforce.
vip-agentforce.php:vip dev-env shell -- wp post create --post_title="Test Unpublish" --post_status=publish --porcelainNote the returned post ID (e.g.,
123).vip dev-env shell -- grep -E "(Attempting to delete|deleted from Salesforce successfully)" /wp/log/debug.logExpected: Log shows
Attempting to delete post from Salesforcefollowed byPost deleted from Salesforce successfully.Test 2: Trash Triggers Deletion (publish � trash)
Goal: Verify trashing a post triggers deletion from Salesforce.
Keep the filter from Test 1 in place
Create a published post:
vip dev-env shell -- wp post create --post_title="Test Trash" --post_status=publish --porcelainNote the returned post ID.
--force):vip dev-env shell -- grep "Post deleted from Salesforce successfully" /wp/log/debug.logExpected: Log shows
Post deleted from Salesforce successfully- trashing triggers deletion.Test 3: Permanent Delete Triggers Deletion
Goal: Verify permanently deleting a published post triggers deletion.
Keep the filter from Test 1 in place
Create a published post:
vip dev-env shell -- wp post create --post_title="Test Delete" --post_status=publish --porcelainNote the returned post ID.
--force):vip dev-env shell -- grep "Post deleted from Salesforce successfully" /wp/log/debug.logExpected: Log shows deletion success - permanent deletion of published post triggers Salesforce deletion.
Test 4: No Deletion Without Ingestion Meta
Goal: Verify no deletion occurs when post was never ingested (no tracking meta).
Remove the test filter from
vip-agentforce.phpClear the debug log:
vip dev-env shell -- wp post create --post_title="Test No Filter" --post_status=publish --porcelainNote the returned post ID.
vip dev-env shell -- grep "not previously ingested" /wp/log/debug.logExpected: Log shows
Post was not previously ingested, skipping deletion- post has no ingestion tracking meta, so no deletion is attempted.Test 5: Draft Delete Doesn't Trigger Deletion
Goal: Verify deleting a draft post doesn't trigger Salesforce deletion.
vip-agentforce.php:vip dev-env shell -- wp post create --post_title="Test Draft Delete" --post_status=draft --porcelainNote the returned post ID.
vip dev-env shell -- grep "not published" /wp/log/debug.logExpected: Log shows
Deleted post was not published, skipping Salesforce deletion- draft posts were never in Salesforce, so no deletion needed.Test 6: Deletion Failure Hook Fires on API Error
Goal: Verify
vip_agentforce_post_deletion_failedaction fires when deletion fails.Ingestion::init()at the bottom ofmodules/ingestion/class-ingestion.php(line 461):// Ingestion::init(); // TEST: Commented out for failure testingvip-agentforce.php(after the module requires):vip dev-env shell -- wp post create --post_title="Test Deletion Failure" --post_status=draft --porcelainNote the returned post ID, then publish it:
Expected: Terminal shows
DELETION FAILED HOOK FIREDwith JSON containingfailure_code,post_id,record_id, anderror_message.Test 7: Deletion Failure Contains Correct Data
Goal: Verify the
Deletion_Failureobject contains expected properties.Keep the test code from Test 6 in place
Clear the debug log:
vip dev-env shell -- wp post create --post_title="Test Failure Data" --post_status=draft --porcelainNote the post ID, then:
Expected: The JSON output should contain:
failure_code:"delete_api_error"post_id: The post ID you createdrecord_id: Format101_1_<POST_ID>(site_blog_post)error_code:"vip_agentforce_delete_api_error"error_message:"Simulated delete API failure for testing"Cleanup
Uncomment
Ingestion::init()inmodules/ingestion/class-ingestion.php(line 461)Remove the test code from
vip-agentforce.phpDelete test posts (enter shell interactively):