diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index 186095183a..ebbb3fc517 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -96,7 +96,7 @@ public function entity(): BelongsTo } /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function origin() { diff --git a/app/Observers/CampaignObserver.php b/app/Observers/CampaignObserver.php index 268c13530c..ed1017ca69 100644 --- a/app/Observers/CampaignObserver.php +++ b/app/Observers/CampaignObserver.php @@ -13,6 +13,7 @@ use App\Models\CampaignSetting; use App\Models\UserLog; use App\Notifications\Header; +use App\Services\Campaign\SearchCleanupService; use App\Services\EntityMappingService; use App\Services\ImageService; use App\Services\Users\CampaignService; @@ -157,6 +158,7 @@ public function saved(Campaign $campaign) */ public function deleted(Campaign $campaign) { + SearchCleanupService::cleanup($campaign); ImageService::cleanup($campaign); UserCache::clear(); } diff --git a/app/Services/Campaign/SearchCleanupService.php b/app/Services/Campaign/SearchCleanupService.php new file mode 100644 index 0000000000..0b5cf1aeed --- /dev/null +++ b/app/Services/Campaign/SearchCleanupService.php @@ -0,0 +1,21 @@ +getKeys(); + + $client->index('entities')->deleteDocuments(['filter' => 'campaign_id = ' . $campaign->id]); + } +} diff --git a/app/Services/Users/CleanupService.php b/app/Services/Users/CleanupService.php index 95be75ce82..c8f8d92507 100644 --- a/app/Services/Users/CleanupService.php +++ b/app/Services/Users/CleanupService.php @@ -8,6 +8,7 @@ use App\Models\CampaignUser; use App\Models\CommunityEventEntry; use App\Models\Feature; +use App\Services\Campaign\SearchCleanupService; use App\Services\ImageService; use App\Traits\UserAware; use Illuminate\Support\Facades\Log; @@ -43,6 +44,7 @@ protected function removeCampaigns(): self // Delete a campaign if no one is left in it. Since we did the "with", it's cached, hence checking on 1 if ($member->campaign->members->count() <= 1) { + SearchCleanupService::cleanup($member->campaign); ImageService::cleanup($member->campaign); $member->campaign->delete(); }