The DeleteHandler does not dispatch useful events that are analogs to the other pull-related events PULL_PREPULL and PULL_ENTITY_VALUE. It would be helpful to have such an event, and the ability to prevent the delete from completing.

Use cases would include unpublishing blocks when their object is delete from Salesforce, and blocking a user (for example block a user that owns content instead of deleting the user and reassigning the content) instead of deleting them.

Probably only one would be needed, but until #3065207: Allow modules to prevent the entities's data records from being deleted lands in core it is hard to have modules prevent an entity from being deleted during sync when under some project specific set of conditions, and even with that update to core there are likely times it makes more sense to handle preventing deleting in the context of the SF Suite events then core events.

Comments

acrosman created an issue. See original summary.

aaronbauman’s picture

Yeah, this makes sense to me, unfortunately.
I have wanted to use core entity hooks whenever possible, but increasingly it seems like they're not sufficient to inject biz logic where we need it.

acrosman’s picture

Assigned: Unassigned » acrosman
Category: Feature request » Task

Since you're on board with the concept and all the patterns and plumbing look to be in place already I will try to toss together at least an initial patch in the next couple days.

acrosman’s picture

Issue tags: +Needs tests
StatusFileSize
new4.21 KB

Here is a first pass. Largely untested, and it needs formal test code anyway, but it's a start.

This is based on the SalesforcePushAllowedEvent event, and I tried to follow that design pattern so it is in keeping with the other elements of the module. The new event is SalesforceDeleteAllowedEvent and is triggered from DeleteHandler in salesforce_pull.

acrosman’s picture

Title: Add Predelete events to prevent deletion » Add DeleteAllowed event to prevent deletion
StatusFileSize
new4.07 KB

That's embarrassing. Let's try that again...

acrosman’s picture

Assigned: acrosman » Unassigned
Status: Active » Needs review
StatusFileSize
new4.48 KB

Existing tests now pass in my local environment. Still needs tests for the new event, but I don't see a sample test for PullAllowed. If there is a pattern for this kind of event test around I'd love to see it.

acrosman’s picture

  • AaronBauman committed 2c81194 on 8.x-4.x authored by acrosman
    Issue #3090974 by acrosman: Add DeleteAllowed event to prevent deletion
    
  • AaronBauman committed 6e15506 on 8.x-4.x authored by acrosman
    Issue #3090974 by acrosman: Add DeleteAllowed event to prevent deletion
    
aaronbauman’s picture

Status: Needs review » Fixed

This is in.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.