Skip to content
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

Issue-1154: Add Support for Handling Deleted Articles #1159

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

renatonascalves
Copy link

@renatonascalves renatonascalves commented Sep 10, 2024

Summary

This PR adds support for handling scenarios where the Apple News API reports that an article does not exist anymore, by removing the associated metadata in WordPress. This aims to prevent error messages from being thrown when information on deleted articles is requested. Fixes #1154

Description

Implemented a check to remove the "Publish to Apple News" postmeta data in WordPress when the News API returns a 404 error code, indicating that the article does not exist. This ensures that WordPress does not continue to attempt fetching data for articles that have been deleted from Apple News.

Use Case

This functionality is particularly useful when a post is deleted directly in iCloud News Publisher but still exists in WordPress. With this update, the postmeta in WordPress will be automatically updated to reflect the deletion, based on the News API's response, thus avoiding unnecessary fetch requests and error messages.

Acceptance Criteria

  • When the News API reports a 404 error for an article, the associated "Publish to Apple News" postmeta (including API ID, last updated date, etc.) is deleted from WordPress.
  • This behavior is confirmed through the addition of a unit test.

Testing Instructions

  1. Ensure that the unit test for the new behavior passes.
  2. Manually test by simulating a 404 response from the News API for an article and verify that the corresponding postmeta is deleted in WordPress.

@renatonascalves renatonascalves marked this pull request as ready for review September 11, 2024 16:34
Comment on lines +53 to +57
$retval = \Apple_News::has_uninitialized_error();

if ( is_wp_error( $retval ) ) {
return $retval;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently only fixing this in this endpoint, since I needed to test the new behavior for deleted articles.

A separate issue will handle it for the other endpoints.

Copy link

@kingkool68 kingkool68 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

admin/apple-actions/class-api-action.php Outdated Show resolved Hide resolved
admin/apple-actions/index/class-get.php Outdated Show resolved Hide resolved
@renatonascalves
Copy link
Author

This pr is approved but currently blocked pending some testing on a live/testing site (tested only locally). Please, do not merge before it.

@kingkool68
Copy link

kingkool68 commented Sep 19, 2024

tl;dr: After testing this out locally the only thing that didn't happen was seeing any sort of error message after updating the post after deleting the Apple News article via iCloud.

Testing this out locally using the following steps:

  • Publish an article and confirm it is live in Apple News.
  • Log in to iCloud Apple News and delete the article in Apple News (not WordPress).
  • Try to update the article, any update will do, and confirm you see this error message
    • I did not see any sort of error message after updating the article
  • Click save and reload the page.
  • Confirm any apple_news related meta keys are removed.
  • Confirm saving the post resends/reindexes the post in Apple News (with a new articleId)

Post meta after my article was published on Apple News:
Screenshot 2024-09-19 at 11 05 38 AM

Post meta after the article was deleted via icloud and then updated in WordPress:
Screenshot 2024-09-19 at 11 10 55 AM

Once the article is deleted via iCloud any subsequent updates in WordPress aren't reflected in Apple News. The article is never re-published on Apple News again. I think this is the desired behavior here but I can see how this would be confusing to a normal editor. Viewing the Apple News Index in the WordPress admin (Apple news --> Articles) shows the Apple News status as LIVE and Sync Status as "Needs to be updated"

Screenshot 2024-09-19 at 11 30 21 AM

Environment:

  • WordPress 6.6.2
  • The Apple News plugin from this branch uploaded to WordPress as a zip file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support for Handling Deleted Articles
2 participants