forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserObserver.php
More file actions
32 lines (29 loc) · 858 Bytes
/
UserObserver.php
File metadata and controls
32 lines (29 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
namespace ProcessMaker\Observers;
use ProcessMaker\Exception\ReferentialIntegrityException;
use ProcessMaker\Models\Comment;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\User;
class UserObserver
{
/**
* Handle the user "deleting" event.
*
* @param User $user
* @throws ReferentialIntegrityException
*/
public function deleting(User $user)
{
//Validate if the user has Request processes assigned
//An user can not be deleted if it has requests
$query = ProcessRequest::where('user_id', $user->id);
$count = $query->count();
if ($count > 0) {
throw new ReferentialIntegrityException($user, $query->first());
}
//Remove comments
Comment::query()
->where('user_id', $user->id)
->delete();
}
}