From e2a8d67eee4ab839804fbede75f6e4d52a99bbaa Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Tue, 22 Jul 2025 09:02:32 +0200 Subject: [PATCH] improved logging --- .../ConstructionConsentController.php | 21 ++++++++++++++++++- .../ConstructionConsentOwnerController.php | 9 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php index 5e7394113..ac2f4a312 100644 --- a/application/ConstructionConsent/ConstructionConsentController.php +++ b/application/ConstructionConsent/ConstructionConsentController.php @@ -1112,6 +1112,22 @@ class ConstructionConsentController extends mfBaseController { $projectId = $this->request->project_id; $importData = json_decode(file_get_contents('php://input'), true); + // save full post request and project id to file as log with metadata like user id etc as json file +// MFUPLOAD_FILE_SAVE_PATH . /ConstructionConsentImports + + $logData = [ + "user_id" => $this->me->id, + "project_id" => $projectId, + "import_data" => $importData, + "timestamp" => date("Y-m-d H:i:s") + ]; + $logFileName = MFUPLOAD_FILE_SAVE_PATH . "/ConstructionConsentImports/import_" . date("Ymd_His") . "_user_{$this->me->id}_project_{$projectId}.json"; + if (!file_exists(dirname($logFileName))) { + mkdir(dirname($logFileName), 0777, true); + } + file_put_contents($logFileName, json_encode($logData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + + if (empty($importData) || !is_array($importData)) { $this->layout()->setFlash("Keine Daten gefunden", "error"); return $this->redirect("ConstructionConsent"); } if (!is_numeric($projectId) || $projectId < 1) { $this->layout()->setFlash("Projekt nicht gefunden", "error"); return $this->redirect("ConstructionConsent"); } if (!($consentProject = new ConstructionConsentProject($projectId))->id) { $this->layout()->setFlash("Projekt nicht gefunden", "error"); return $this->redirect("ConstructionConsent"); } @@ -1178,7 +1194,10 @@ class ConstructionConsentController extends mfBaseController { $journal = ConstructionConsentJournal::create([ "constructionconsent_id" => $consentRecord->id, - "text" => "Import: Eigentümer $firstname $lastname wurde hinzugefügt" + "text" => + $ownerRecord->company ? + "Import: Eigentümer $ownerRecord->company wurde hinzugefügt" : + "Import: Eigentümer $firstname $lastname wurde hinzugefügt" ]); $journal->save(); diff --git a/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php b/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php index 4b4d4713f..e8a59c51c 100644 --- a/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php +++ b/application/ConstructionConsentOwner/ConstructionConsentOwnerController.php @@ -156,6 +156,15 @@ class ConstructionConsentOwnerController extends mfBaseController $file->delete(); } + $journal = ConstructionConsentJournal::create([ + "constructionconsent_id" => $consent->id, + "text" => + $owner->company ? + "Eigentümer $owner->company wurde gelöscht" : + "Eigentümer $owner->firstname $owner->lastname wurde gelöscht" + ]); + $journal->save(); + $owner->delete(); $this->layout()->setFlash("Besitzer gelöscht!", "success");