From 71523b9816b1162f30ca8d682b8d410edc6d9cfc Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 17 Apr 2023 14:45:18 +0200 Subject: [PATCH] AbstractTranscriptionEvent: Add File param Signed-off-by: Marcel Klehr --- lib/private/SpeechToText/TranscriptionJob.php | 8 ++++++++ .../Events/AbstractTranscriptionEvent.php | 11 ++++++++++- .../SpeechToText/Events/TranscriptionFailedEvent.php | 5 ++++- .../Events/TranscriptionSuccessfulEvent.php | 3 ++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/private/SpeechToText/TranscriptionJob.php b/lib/private/SpeechToText/TranscriptionJob.php index d8abf9a9c34..fd175e774a5 100644 --- a/lib/private/SpeechToText/TranscriptionJob.php +++ b/lib/private/SpeechToText/TranscriptionJob.php @@ -35,6 +35,7 @@ use OCP\PreConditionNotMetException; use OCP\SpeechToText\Events\TranscriptionFailedEvent; use OCP\SpeechToText\Events\TranscriptionSuccessfulEvent; use OCP\SpeechToText\ISpeechToTextManager; +use Psr\Log\LoggerInterface; class TranscriptionJob extends QueuedJob { public function __construct( @@ -42,6 +43,7 @@ class TranscriptionJob extends QueuedJob { private ISpeechToTextManager $speechToTextManager, private IEventDispatcher $eventDispatcher, private IRootFolder $rootFolder, + private LoggerInterface $logger, ) { parent::__construct($timeFactory); } @@ -52,12 +54,15 @@ class TranscriptionJob extends QueuedJob { */ protected function run($argument) { $fileId = $argument['fileId']; + $file = null; try { $file = current($this->rootFolder->getById($fileId)); if (!($file instanceof File)) { + $this->logger->warning('Transcription of file ' . $fileId . ' failed. The file could not be found'); $this->eventDispatcher->dispatchTyped( new TranscriptionFailedEvent( $fileId, + null, 'File not found', ) ); @@ -67,13 +72,16 @@ class TranscriptionJob extends QueuedJob { $this->eventDispatcher->dispatchTyped( new TranscriptionSuccessfulEvent( $fileId, + $file, $result, ) ); } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException $e) { + $this->logger->warning('Transcription of file ' . $fileId . ' failed', ['exception' => $e]); $this->eventDispatcher->dispatchTyped( new TranscriptionFailedEvent( $fileId, + $file, $e->getMessage(), ) ); diff --git a/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php b/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php index 5b00315f74c..0f906a7604b 100644 --- a/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php +++ b/lib/public/SpeechToText/Events/AbstractTranscriptionEvent.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCP\SpeechToText\Events; use OCP\EventDispatcher\Event; +use OCP\Files\File; /** * @since 27.0.0 @@ -35,7 +36,8 @@ abstract class AbstractTranscriptionEvent extends Event { * @since 27.0.0 */ public function __construct( - private int $fileIdId + private int $fileIdId, + private ?File $file, ) { parent::__construct(); } @@ -46,4 +48,11 @@ abstract class AbstractTranscriptionEvent extends Event { public function getFileId(): int { return $this->fileIdId; } + + /** + * @since 27.0.0 + */ + public function getFile(): ?File { + return $this->file; + } } diff --git a/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php b/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php index b7e44d91c69..02777b7ebc0 100644 --- a/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php +++ b/lib/public/SpeechToText/Events/TranscriptionFailedEvent.php @@ -26,6 +26,8 @@ declare(strict_types=1); namespace OCP\SpeechToText\Events; +use OCP\Files\File; + class TranscriptionFailedEvent extends AbstractTranscriptionEvent { /** @@ -33,9 +35,10 @@ class TranscriptionFailedEvent extends AbstractTranscriptionEvent { */ public function __construct( int $fileId, + ?File $file, private string $errorMessage ) { - parent::__construct($fileId); + parent::__construct($fileId, $file); } /** diff --git a/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php b/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php index 816dabafbb4..b37a07e3a22 100644 --- a/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php +++ b/lib/public/SpeechToText/Events/TranscriptionSuccessfulEvent.php @@ -35,9 +35,10 @@ class TranscriptionSuccessfulEvent extends AbstractTranscriptionEvent { */ public function __construct( int $fileId, + ?File $file, private string $transcript ) { - parent::__construct($fileId); + parent::__construct($fileId, $file); } /** -- 2.39.5