fix(persons): delete person avatar when deleting a person

fixes #419
This commit is contained in:
Yassine Doghri 2023-12-28 13:58:19 +00:00
parent 30a3473863
commit c1ec98c956
1 changed files with 6 additions and 0 deletions

View File

@ -14,6 +14,7 @@ use App\Entities\Person;
use App\Models\PersonModel;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\RedirectResponse;
use Modules\Media\Models\MediaModel;
class PersonController extends BaseController
{
@ -151,6 +152,11 @@ class PersonController extends BaseController
public function delete(): RedirectResponse
{
if ($this->person->avatar_id !== null) {
// delete avatar to prevent collision if recreating person
(new MediaModel())->deleteMedia($this->person->avatar);
}
(new PersonModel())->delete($this->person->id);
return redirect()->route('person-list')