*/ class VersionAuthorListener implements IEventListener { public function __construct( private IVersionManager $versionManager, private IUserSession $userSession, ) { } /** * @abstract handles events from a nodes version being changed * @param Event $event the event that triggered this listener to activate */ public function handle(Event $event): void { if ($event instanceof NodeWrittenEvent) { $this->post_write_hook($event->getNode()); } } /** * @abstract handles the NodeWrittenEvent, and sets the metadata for the associated node * @param Node $node the node that is currently being written */ public function post_write_hook(Node $node): void { $user = $this->userSession->getUser(); // Do not handle folders or users that we cannot get metadata from if ($node instanceof Folder || is_null($user)) { return; } // check if our version manager supports setting the metadata if ($this->versionManager instanceof IMetadataVersionBackend) { $revision = $this->versionManager->getRevision($node); $author = $user->getUID(); $this->versionManager->setMetadataValue($node, $revision, Plugin::AUTHOR, $author); } } }