From 066434912c9ce9479f929c98a51673d70071f174 Mon Sep 17 00:00:00 2001 From: Matt McNaney Date: Wed, 4 Aug 2021 14:59:24 -0400 Subject: [PATCH] Added function to remove shortcuts when a sponsor is deleted. --- class/Factory/SponsorFactory.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/class/Factory/SponsorFactory.php b/class/Factory/SponsorFactory.php index 359d46a..212f174 100644 --- a/class/Factory/SponsorFactory.php +++ b/class/Factory/SponsorFactory.php @@ -60,7 +60,18 @@ public static function delete(int $id) { $sponsor = self::build($id); $sponsor->deleted = true; - return self::save($sponsor); + $result = self::save($sponsor); + self::removeShortcuts($sponsor); + return $result; + } + + private static function removeShortcuts(Sponsor $sponsor) + { + $db = Database::getDB(); + $tbl = $db->addTable('access_shortcuts'); + $tbl->addFieldConditional('url', 'volunteer:' . $sponsor->id); + $db->setLimit(1); + $db->delete(); } /**