Skip to content

Commit

Permalink
delete notification when referenced entity is deleted (#414)
Browse files Browse the repository at this point in the history
Signed-off-by: Vinzenz Rosenkranz <vinzenz.rosenkranz@uni-tuebingen.de>
  • Loading branch information
v1r0x authored Dec 19, 2022
1 parent 12d8f18 commit f7e56b2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## 0.9.12
### Fixed
- App not useable when a notifications with a reference to a deleted entity exists

## 0.9.11
### Fixed
- Error on page access with no installed plugins (because Plugin directory is missing)
Expand Down
10 changes: 10 additions & 0 deletions app/Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Notification extends Model
{
public $incrementing = false;
}
3 changes: 3 additions & 0 deletions app/Observers/EntityObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Observers;

use App\Entity;
use App\Notification;
use App\Notifications\EntityUpdated;
use App\User;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand Down Expand Up @@ -37,5 +38,7 @@ public function saving(Entity $entity)
public function deleted(Entity $entity)
{
Entity::where('root_entity_id', $entity->root_entity_id)->where('rank', '>', $entity->rank)->decrement('rank');
// Delete notifications where the deleted entity is referenced
Notification::whereRaw("(data::json->>'resource')::json->>'id' = ?", [$entity->id])->delete();
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "spacialist",
"version": "0.9.7",
"version": "0.9.12",
"description": "A Virtual Research Environment for the Spatial Humanities",
"repository": {
"type": "git",
Expand Down

0 comments on commit f7e56b2

Please sign in to comment.