-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On-upload: Tag files immediately #38
Tag uploaded files with "Unscanned"
- Loading branch information
Philip Stadermann
committed
Jun 12, 2024
1 parent
60ad9ee
commit ba5f400
Showing
4 changed files
with
69 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace OCA\GDataVaas; | ||
|
||
use OCA\GDataVaas\Service\TagService; | ||
use OCP\AppFramework\Bootstrap\IRegistrationContext; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Cache\AbstractCacheEvent; | ||
use OCP\Files\Cache\CacheEntryInsertedEvent; | ||
use OCP\Files\Cache\CacheEntryUpdatedEvent; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class EventListener implements IEventListener | ||
{ | ||
private LoggerInterface $logger; | ||
|
||
private TagService $tagService; | ||
|
||
public function __construct(LoggerInterface $logger, TagService $tagService) | ||
{ | ||
$this->logger = $logger; | ||
$this->tagService = $tagService; | ||
} | ||
|
||
public static function register(IRegistrationContext $context): void { | ||
$context->registerEventListener(CacheEntryInsertedEvent::class, EventListener::class); | ||
$context->registerEventListener(CacheEntryUpdatedEvent::class, EventListener::class); | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
if (!$event instanceof AbstractCacheEvent) { | ||
return; | ||
} | ||
|
||
$path = $event->getPath(); | ||
$fileId = $event->getFileId(); | ||
|
||
if (self::shouldTag($path) && !$this->tagService->hasAnyVaasTag($fileId)) { | ||
$this->tagService->setTag($event->getFileId(), TagService::UNSCANNED); | ||
} | ||
} | ||
|
||
private static function shouldTag(string $path): bool { | ||
return str_starts_with($path, 'files/'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters