From 1be37f0d79c04fff19f1e9d1d484d0ffcba95527 Mon Sep 17 00:00:00 2001 From: Michal Kleiner Date: Mon, 21 Jun 2021 17:22:24 +1200 Subject: [PATCH] Ensure joining object is deleted from draft when it's removed from live Applies to non-versioned owner objects. --- src/Models/DataObjectTaxonomyTerm.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Models/DataObjectTaxonomyTerm.php b/src/Models/DataObjectTaxonomyTerm.php index 1458138..5d7bed3 100644 --- a/src/Models/DataObjectTaxonomyTerm.php +++ b/src/Models/DataObjectTaxonomyTerm.php @@ -52,7 +52,23 @@ public function onBeforeDelete() /** - * Ensure the linking object is published to Live stage after writing the owner object that doesn't have versioning. + * Ensure the linking object is deleted from Draft when it's deleted from Live for a non-versioned owner object + */ + public function onAfterDelete() + { + if ($this->OwnerObject() && $this->OwnerObject()->hasExtension(Versioned::class) === false) { + if (Versioned::get_stage() === Versioned::LIVE) { + Versioned::withVersionedMode(function () { + Versioned::set_stage(Versioned::DRAFT); + $this->delete(); + }); + } + } + } + + + /** + * Ensure the linking object is published to Live stage after writing a non-versioned owner object */ public function onAfterWrite() {