Hi,
I am trying to create a simple app to take action after a new file is uploaded so I created a simple code inside my Application.php
<?php
declare(strict_types=1);
namespace OCA\NotifyTest\AppInfo;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\Node\PostCreateEvent;
class Application extends App implements IBootstrap {
public const APP_ID = 'notifytest';
public function __construct() {
parent::__construct(self::APP_ID);
}
public function register(IRegistrationContext $context): void {
}
public function boot(IBootContext $context): void {
try {
/** @var IEventDispatcher $dispatcher */
$dispatcher = $context->getServerContainer()->get(IEventDispatcher::class);
$dispatcher->addListener(PostCreateEvent::class, function (PostCreateEvent $event) use ($logPath): void {
$node = $event->getNode();
$path = $node->getPath();
error_log("PostCreateEvent ausgelöst für: {$path}");
});
error_log('addListener für PostCreateEvent wurde erfolgreich registriert');
} catch (\Throwable $e) {
error_log('Fehler in boot(): ' . $e->getMessage());
}
}
}
``` The boot method is triggered but the event Listener gets not called after file upload does anybody has an idea what I am doing wrong?
The Event should be available at \OCP\Files: https://docs.nextcloud.com/server/stable/developer_manual/basics/events.html#ocp-event-dispatcher
Thanks