Skip to content

Commit

Permalink
Label current version to prevent expiry of original
Browse files Browse the repository at this point in the history
  • Loading branch information
XueSheng-GIT authored Oct 10, 2024
1 parent ad3c1d5 commit 8da531a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/Service/OcrService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OCA\WorkflowOcr\Service;

use OC\User\NoUserException;
use OCA\Files_Versions\Versions\IVersionManager;
use OCA\WorkflowOcr\Exception\OcrResultEmptyException;
use OCA\WorkflowOcr\Helper\IProcessingFileAccessor;
use OCA\WorkflowOcr\Model\WorkflowSettings;
Expand All @@ -52,6 +53,9 @@ class OcrService implements IOcrService {
/** @var IGlobalSettingsService */
private $globalSettingsService;

/** @var IVersionManager */
private $versionManager;

/** @var ISystemTagObjectMapper */
private $systemTagObjectMapper;

Expand Down Expand Up @@ -82,6 +86,7 @@ class OcrService implements IOcrService {
public function __construct(
IOcrProcessorFactory $ocrProcessorFactory,
IGlobalSettingsService $globalSettingsService,
IVersionManager $versionManager,
ISystemTagObjectMapper $systemTagObjectMapper,
IUserManager $userManager,
IFilesystem $filesystem,
Expand All @@ -93,6 +98,7 @@ public function __construct(
LoggerInterface $logger) {
$this->ocrProcessorFactory = $ocrProcessorFactory;
$this->globalSettingsService = $globalSettingsService;
$this->versionManager = $versionManager;
$this->systemTagObjectMapper = $systemTagObjectMapper;
$this->userManager = $userManager;
$this->filesystem = $filesystem;
Expand Down Expand Up @@ -133,6 +139,20 @@ public function runOcrProcess(int $fileId, string $uid, WorkflowSettings $settin

// Only create a new file version if the file OCR result was not empty #130
if ($result->getRecognizedText() !== '') {
$fileMTime = $file->getMTime();
$user = $this->userManager->get($uid);
$versions = $this->versionManager->getVersionsForFile($user, $file);

foreach ($versions as $version) {
$versionTimestamp = $version->getTimestamp();
$versionLabel = $version->getMetadataValue('label');

if ($fileMTime === $versionTimestamp && ($versionLabel === null || $versionLabel === '')) {
// Add label to current file version to prevent its expiry
$this->versionManager->setMetadataValue($file, $version->getRevisionId(), 'label', 'PreOCR');
}
}

$newFilePath = $originalFileExtension === $newFileExtension ?
$filePath :
$filePath . ".pdf";
Expand Down

0 comments on commit 8da531a

Please sign in to comment.