diff options
author | yemkareems <yemkareems@gmail.com> | 2024-06-20 11:36:21 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-20 11:36:21 +0530 |
commit | a05a04c1a2c6028a3d9d81113fca81add61845ef (patch) | |
tree | f9f3699c0ee38b9e823fb7b83859d3b4054fb8dc | |
parent | 2593f5f0365fb74358f170ba4ce9a4c8f50ad5af (diff) | |
parent | eae23867f2faa2f0683eac549d2dd287d7d78215 (diff) | |
download | nextcloud-server-a05a04c1a2c6028a3d9d81113fca81add61845ef.tar.gz nextcloud-server-a05a04c1a2c6028a3d9d81113fca81add61845ef.zip |
Merge pull request #45845 from nextcloud/fix/log-rename-to-use-internal-path
fix: rename split into two as before rename and after rename
-rw-r--r-- | apps/admin_audit/lib/Actions/Files.php | 29 | ||||
-rw-r--r-- | apps/admin_audit/lib/AppInfo/Application.php | 10 |
2 files changed, 34 insertions, 5 deletions
diff --git a/apps/admin_audit/lib/Actions/Files.php b/apps/admin_audit/lib/Actions/Files.php index 5ecfe106b74..ee40a4e1476 100644 --- a/apps/admin_audit/lib/Actions/Files.php +++ b/apps/admin_audit/lib/Actions/Files.php @@ -8,6 +8,7 @@ declare(strict_types=1); namespace OCA\AdminAudit\Actions; use OCP\Files\Events\Node\BeforeNodeReadEvent; +use OCP\Files\Events\Node\BeforeNodeRenamedEvent; use OCP\Files\Events\Node\BeforeNodeWrittenEvent; use OCP\Files\Events\Node\NodeCopiedEvent; use OCP\Files\Events\Node\NodeCreatedEvent; @@ -25,6 +26,8 @@ use Psr\Log\LoggerInterface; * @package OCA\AdminAudit\Actions */ class Files extends Action { + + private array $renamedNodes = []; /** * Logs file read actions * @@ -52,16 +55,33 @@ class Files extends Action { /** * Logs rename actions of files * - * @param NodeRenamedEvent $event + * @param BeforeNodeRenamedEvent $event */ - public function rename(NodeRenamedEvent $event): void { + public function beforeRename(BeforeNodeRenamedEvent $event): void { try { $source = $event->getSource(); + $this->renamedNodes[$source->getId()] = $source; + } catch (InvalidPathException|NotFoundException $e) { + \OCP\Server::get(LoggerInterface::class)->error( + "Exception thrown in file rename: ".$e->getMessage(), ['app' => 'admin_audit', 'exception' => $e] + ); + return; + } + } + + /** + * Logs rename actions of files + * + * @param NodeRenamedEvent $event + */ + public function afterRename(NodeRenamedEvent $event): void { + try { $target = $event->getTarget(); + $originalSource = $this->renamedNodes[$target->getId()]; $params = [ 'newid' => $target->getId(), - 'oldpath' => mb_substr($source->getPath(), 5), - 'newpath' => mb_substr($target->getPath(), 5), + 'oldpath' => mb_substr($originalSource->getInternalPath(), 5), + 'newpath' => mb_substr($target->getInternalPath(), 5), ]; } catch (InvalidPathException|NotFoundException $e) { \OCP\Server::get(LoggerInterface::class)->error( @@ -77,6 +97,7 @@ class Files extends Action { ); } + /** * Logs creation of files * diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index 62ab65b95b9..b8b80841539 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -32,6 +32,7 @@ use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengePassed; use OCP\Console\ConsoleEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Events\Node\BeforeNodeReadEvent; +use OCP\Files\Events\Node\BeforeNodeRenamedEvent; use OCP\Files\Events\Node\BeforeNodeWrittenEvent; use OCP\Files\Events\Node\NodeCopiedEvent; use OCP\Files\Events\Node\NodeCreatedEvent; @@ -180,9 +181,16 @@ class Application extends App implements IBootstrap { ); $eventDispatcher->addListener( + BeforeNodeRenamedEvent::class, + function (BeforeNodeRenamedEvent $event) use ($fileActions) { + $fileActions->beforeRename($event); + } + ); + + $eventDispatcher->addListener( NodeRenamedEvent::class, function (NodeRenamedEvent $event) use ($fileActions) { - $fileActions->rename($event); + $fileActions->afterRename($event); } ); |