Skip to content

Commit 85d9d7a

Browse files
authored
Make dependency to File Versions App optional (#314) (#317)
* Fixes [#307](#307) Signed-off-by: Robin Windey <ro.windey@gmail.com>
1 parent a58c1f4 commit 85d9d7a

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

lib/Service/OcrService.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class OcrService implements IOcrService {
5959
/** @var IGlobalSettingsService */
6060
private $globalSettingsService;
6161

62-
/** @var IVersionManager */
62+
/** @var ?IVersionManager */
6363
private $versionManager;
6464

6565
/** @var ISystemTagObjectMapper */
@@ -95,7 +95,7 @@ class OcrService implements IOcrService {
9595
public function __construct(
9696
IOcrProcessorFactory $ocrProcessorFactory,
9797
IGlobalSettingsService $globalSettingsService,
98-
IVersionManager $versionManager,
98+
?IVersionManager $versionManager,
9999
ISystemTagObjectMapper $systemTagObjectMapper,
100100
IUserManager $userManager,
101101
IFilesystem $filesystem,
@@ -289,6 +289,11 @@ private function createNewFileVersion(string $filePath, string $ocrContent, ?int
289289
* @param string $label The label to set
290290
*/
291291
private function setFileVersionsLabel(File $file, string $uid, string $label): void {
292+
if ($this->versionManager === null) {
293+
$this->logger->debug('Skipping setting file version label because file version app is not active');
294+
return;
295+
}
296+
292297
$fileMTime = $file->getMTime();
293298
$user = $this->userManager->get($uid);
294299
$versions = $this->versionManager->getVersionsForFile($user, $file);

tests/Unit/Service/OcrServiceTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,60 @@ public function testSetsFileVersionsLabelIfKeepOriginalFileVersionIsTrue() {
749749
$this->ocrService->runOcrProcess(42, 'usr', $settings);
750750
}
751751

752+
// Related to #307
753+
public function testRunOcrProcessWorksWithoutIVersionManager() {
754+
$settings = new WorkflowSettings('{"keepOriginalFileVersion": true}');
755+
$mimeType = 'application/pdf';
756+
$content = 'someFileContent';
757+
$ocrContent = 'someOcrProcessedFile';
758+
$ocrResult = new OcrProcessorResult($ocrContent, 'pdf', $ocrContent);
759+
760+
$fileMock = $this->createValidFileMock($mimeType, $content);
761+
$this->rootFolderGetById42ReturnValue = [$fileMock];
762+
763+
$this->ocrProcessor->expects($this->once())
764+
->method('ocrFile')
765+
->willReturn($ocrResult);
766+
767+
$viewMock = $this->createMock(IView::class);
768+
$this->viewFactory->expects($this->once())
769+
->method('create')
770+
->willReturn($viewMock);
771+
772+
$this->eventService->expects($this->once())
773+
->method('textRecognized')
774+
->with($ocrResult, $fileMock);
775+
776+
$logged = false;
777+
$this->logger->expects($this->atLeast(1))
778+
->method('debug')
779+
->with($this->callback(function ($message) use (&$logged) {
780+
if ($message === 'Skipping setting file version label because file version app is not active') {
781+
$logged = true;
782+
}
783+
return true;
784+
}));
785+
786+
$ocrService = new OcrService(
787+
$this->ocrProcessorFactory,
788+
$this->globalSettingsService,
789+
null, // No IVersionManager
790+
$this->systemTagObjectMapper,
791+
$this->userManager,
792+
$this->filesystem,
793+
$this->userSession,
794+
$this->rootFolder,
795+
$this->eventService,
796+
$this->viewFactory,
797+
$this->processingFileAccessor,
798+
$this->notificationService,
799+
$this->logger);
800+
801+
$ocrService->runOcrProcess(42, 'usr', $settings);
802+
803+
$this->assertTrue($logged, 'Expected debug log message not found');
804+
}
805+
752806
public static function dataProvider_InvalidNodes() {
753807
$folderMockCallable = function (self $testClass) {
754808
/** @var MockObject|Node */

tests/psalm-baseline.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,14 @@
287287
<code><![CDATA[$version]]></code>
288288
<code><![CDATA[$version]]></code>
289289
<code><![CDATA[$versionBackend]]></code>
290+
<code><![CDATA[?IVersionManager]]></code>
290291
<code><![CDATA[IMetadataVersion]]></code>
291292
<code><![CDATA[IMetadataVersionBackend]]></code>
292-
<code><![CDATA[IVersionManager]]></code>
293293
<code><![CDATA[NoUserException]]></code>
294294
</UndefinedClass>
295295
<UndefinedDocblockClass>
296296
<code><![CDATA[$this->versionManager]]></code>
297-
<code><![CDATA[IVersionManager]]></code>
297+
<code><![CDATA[?IVersionManager]]></code>
298298
</UndefinedDocblockClass>
299299
</file>
300300
<file src="lib/Settings/GlobalSettings.php">

0 commit comments

Comments
 (0)