mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-17 22:03:44 +02:00
Whoops, don't store the model until we've successfully completed the transaction internals
This commit is contained in:
@@ -334,20 +334,18 @@ class Server extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves an audit entry to the database for the server.
|
||||
* Returns a fresh AuditLog model for the server. This model is not saved to the
|
||||
* database when created, so it is up to the caller to correctly store it as needed.
|
||||
*
|
||||
* @param string $action
|
||||
* @param array $metadata
|
||||
* @return \Pterodactyl\Models\AuditLog
|
||||
*/
|
||||
public function newAuditEvent(string $action, array $metadata): AuditLog
|
||||
public function newAuditEvent(string $action, array $metadata = []): AuditLog
|
||||
{
|
||||
$model = AuditLog::factory($action, $metadata)->fill([
|
||||
return AuditLog::factory($action, $metadata)->fill([
|
||||
'server_id' => $this->id,
|
||||
]);
|
||||
$model->save();
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -366,9 +364,8 @@ class Server extends Model
|
||||
*/
|
||||
public function audit(string $action, Closure $callback)
|
||||
{
|
||||
$model = $this->newAuditEvent($action, []);
|
||||
|
||||
return $this->getConnection()->transaction(function () use ($callback, &$model) {
|
||||
return $this->getConnection()->transaction(function () use ($action, $callback) {
|
||||
$model = $this->newAuditEvent($action);
|
||||
$response = $callback($model, $this);
|
||||
$model->save();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user