-
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.
Merge pull request #41 from GDATASoftwareAG/tag_on_upload
Tag on upload
- Loading branch information
Showing
6 changed files
with
168 additions
and
32 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
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,55 @@ | ||
<?php | ||
|
||
namespace OCA\GDataVaas; | ||
|
||
use OCA\GDataVaas\Service\TagService; | ||
use OCA\GDataVaas\Service\VerdictService; | ||
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 CacheEntryListener implements IEventListener | ||
{ | ||
private LoggerInterface $logger; | ||
|
||
private TagService $tagService; | ||
|
||
private VerdictService $verdictService; | ||
|
||
public function __construct(LoggerInterface $logger, TagService $tagService, VerdictService $verdictService) | ||
{ | ||
$this->logger = $logger; | ||
$this->tagService = $tagService; | ||
$this->verdictService = $verdictService; | ||
} | ||
|
||
public static function register(IRegistrationContext $context): void { | ||
$context->registerEventListener(CacheEntryInsertedEvent::class, CacheEntryListener::class); | ||
$context->registerEventListener(CacheEntryUpdatedEvent::class, CacheEntryListener::class); | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
if (!$event instanceof AbstractCacheEvent) { | ||
return; | ||
} | ||
|
||
$storage = $event->getStorage(); | ||
$path = $event->getPath(); | ||
$fileId = $event->getFileId(); | ||
|
||
if (self::shouldTag($path) && !$this->tagService->hasAnyVaasTag($fileId)) { | ||
$this->logger->debug("Handling " . get_class($event) . " for " . $path); | ||
|
||
$this->verdictService->tagLastScannedFile($storage->getLocalFile($path), $fileId); | ||
} | ||
} | ||
|
||
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
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