improved logging

This commit is contained in:
Luca Haid
2025-07-22 09:02:32 +02:00
parent 213500dcd0
commit e2a8d67eee
2 changed files with 29 additions and 1 deletions

View File

@@ -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();

View File

@@ -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");