diff --git a/DBEntity.updated.php b/DBEntity.updated.php index 5414a2e9..4c039b54 100644 --- a/DBEntity.updated.php +++ b/DBEntity.updated.php @@ -131,5 +131,10 @@ abstract class DBEntity $this->changes = []; } + function getTableName(): string + { + return $this->getTable()->getName(); + } + use \Nette\SmartObject; } diff --git a/Web/Models/Repositories/Logs.php b/Web/Models/Repositories/Logs.php index 6f7d3937..13d2f592 100644 --- a/Web/Models/Repositories/Logs.php +++ b/Web/Models/Repositories/Logs.php @@ -28,7 +28,7 @@ class Logs return $this->toLog($this->logs->get($id)); } - function create(int $user, string $table, string $model, int $type, $object, $changes): void + function create(int $user, string $table, string $model, int $type, $object, $changes, ?string $ip = NULL, ?string $useragent = NULL): void { if (OPENVK_ROOT_CONF["openvk"]["preferences"]["logs"] === true) { $fobject = (is_array($object) ? $object : $object->unwrap()); @@ -65,8 +65,8 @@ class Logs $log->setXdiff_Old(json_encode($nobject)); $log->setXdiff_New(json_encode($_changes)); $log->setTs(time()); - $log->setIp(CurrentUser::i()->getIP()); - $log->setUserAgent(CurrentUser::i()->getUserAgent()); + $log->setIp($ip ?? CurrentUser::i()->getIP()); + $log->setUserAgent($useragent ?? CurrentUser::i()->getUserAgent()); $log->save(); } } diff --git a/Web/Presenters/AuthPresenter.php b/Web/Presenters/AuthPresenter.php index 4bca557a..f569dd63 100644 --- a/Web/Presenters/AuthPresenter.php +++ b/Web/Presenters/AuthPresenter.php @@ -130,7 +130,7 @@ final class AuthPresenter extends OpenVKPresenter } $this->authenticator->authenticate($chUser->getId()); - (new Logs)->create($user->getId(), "profiles", "openvk\\Web\\Models\\Entities\\User", 0, $user, $user); + (new Logs)->create($user->getId(), "profiles", "openvk\\Web\\Models\\Entities\\User", 0, $user, $user, $_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_USER_AGENT"]); $this->redirect("/id" . $user->getId()); $user->save(); }