我正在开发一个NextCloud应用程序。
我有一个链接到另一个目录的目录,所以Nextcloud认为我使用了双倍的空间,但实际上并非如此,所以我想操纵文件缓存条目的大小。
我已经搜索了一点,但只找到一些过时的东西,其中使用挂钩,因为它是不推荐的,我想使用另一种技术。目前,我试图更新条目后,“NodeAddedToCache”或“FolderScannedEvent”使用Eventlistener类。但它似乎没有被执行,我真的不知道我应该如何测试/调试,因为我找不到一个很好的文档,哪些事件将在什么情况下被触发,或者在哪里我可以找到这个东西的脚本。
我的当前代码看起来像这样:
lib/AppInfo/Application.php
namespace OCA\Application\AppInfo;
use OCA\Application\Event\RegistrationEventListener;
use OCP\AppFramework\App;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\FolderScannedEvent;
class Application extends App {
public const APP_ID = 'application';
public function __construct(IEventDispatcher $dispatcher) {
parent::__construct(self::APP_ID);
$dispatcher->addServiceListener(FolderScannedEvent::class, RegistrationEventListener::class, 1);
}
}
字符串
RegistrationEventListener.php
<?php
namespace OCA\Application\Event;
use OC\Files\Storage\Storage;
use OCA\AdminAudit\AuditLogger;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\FolderScannedEvent;
class RegistrationEventListener implements IEventListener {
private $logger;
private $storage;
public function __construct(AuditLogger $logger, Storage $storage)
{
$this->logger = $logger;
$this->storage = $storage;
}
/**
* @inheritDoc
*/
public function handle(FolderScannedEvent|Event $event): void
{
if(is_link($event->getAbsolutePath())) {
$fileId = $this->storage->getCache()->getId($event->getAbsolutePath());
$this->storage->getCache()->update($fileId, [
'size' => 0
]);
}
}
}
型
1条答案
按热度按时间qhhrdooz1#
为了能够使用Nextcloud Filescanner事件,您应该像这样使用
Application
类的IBootstrap->register()
方法:AppInfo/Application.php
个字符串
你的监听器可能看起来像这样(
Listener/FileCacheListener.php
):型
您可以通过直接在文件系统上添加/更新/删除文件来检查是否调用了侦听器,然后调用
php occ files:scan --all
。请注意,上述事件仅在文件被扫描且已更改时才会触发。如果您想捕获单个事件(如文件上传等),您可以在这里找到一个工作示例。祝您好运:-)