Skip to content

Commit b080d03

Browse files
committed
Fix a blocking error with custom models
1 parent 413bc5b commit b080d03

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 4.1.1
2+
3+
### Bug Fix: ActivityLogger blocking exception on dynamically-loaded app models
4+
5+
- **`capturePreUpdateState()`**: Added `defined()` check before calling `constant($model)`. For dynamically-loaded app models (e.g. custom models stored in `DataModel` table), the PHP constant may not be available, causing a fatal `Error` that blocked the original PUT/DELETE request from executing.
6+
- **All catch blocks**: Changed `catch (\Exception $e)` to `catch (\Throwable $e)` in `capturePreUpdateState()`, `log()`, and `logAuth()`. PHP 8.x `constant()` throws an `Error` (not `Exception`) for undefined constants, which bypassed the safety net entirely. The ActivityLogger should never block normal API operations.
7+
8+
---
9+
110
## 4.1.0
211

312
### New Feature: Activity/Audit Logging System

src/Core/ActivityLogger.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ public function capturePreUpdateState($model, $field, $value) {
7676
if (!self::isEnabled()) return;
7777

7878
try {
79+
if (!defined($model)) {
80+
$this->preUpdateState = null;
81+
return;
82+
}
7983
$obj = new \Kyte\Core\ModelObject(constant($model));
8084
if ($obj->retrieve($field, $value)) {
8185
$this->preUpdateState = $obj->getAllParams();
8286
}
83-
} catch (\Exception $e) {
87+
} catch (\Throwable $e) {
8488
// Silently fail - don't break updates if pre-capture fails
8589
$this->preUpdateState = null;
8690
}
@@ -152,7 +156,7 @@ public function log($action, $modelName, $field, $value, $requestData, $response
152156
}
153157

154158
$log->create($logData);
155-
} catch (\Exception $e) {
159+
} catch (\Throwable $e) {
156160
error_log("ActivityLogger: Failed to log activity - " . $e->getMessage());
157161
}
158162

@@ -200,7 +204,7 @@ public function logAuth($action, $email, $success, $errorMessage = null) {
200204
];
201205

202206
$log->create($logData);
203-
} catch (\Exception $e) {
207+
} catch (\Throwable $e) {
204208
error_log("ActivityLogger: Failed to log auth event - " . $e->getMessage());
205209
}
206210

src/Core/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Version
55
{
66
const MAJOR=4;
77
const MINOR=1;
8-
const PATCH=0;
8+
const PATCH=1;
99

1010
public static function get()
1111
{

0 commit comments

Comments
 (0)