Skip to content

Gracefully handle already done ocr - #308

Merged
R0Wi merged 5 commits into
masterfrom
bugfix/ocr-skip-error
May 1, 2025
Merged

R0Wi merged 5 commits into
masterfrom
bugfix/ocr-skip-error

Conversation

@XueSheng-GIT

Copy link
Copy Markdown
Collaborator

Throw OcrResultEmptyException if OCRmyPDF returns exit code 6 (ExitCode.already_done_ocr).
Fix of #293

@R0Wi:
Not sure whether existing check for empty file is still required for 'Local'? There's no such check for 'Remote'.

if (!$ocrFileContent) {
throw new OcrResultEmptyException('OCRmyPDF did not produce any output for file ' . $file->getPath());
}

Also not sure about the requirement for additional tests.

Throw OcrResultEmptyException if OCRmyPDF returns exit code 6
(ExitCode.already_done_ocr).
Fix of #293

Signed-off-by: XueSheng-GIT <Michael.Frase@gmx.de>
@R0Wi

R0Wi commented Apr 27, 2025

Copy link
Copy Markdown
Contributor

Thanks for this PR @XueSheng-GIT 👍 At a first glance, the code LGTM. I need to check why some of the tests are failing but I also encountered this Undefined constant OCP\IUser::MAX_USERID_LENGTH error locally. Might be a problem with the current Nextcloud master (NC32).

@R0Wi: Not sure whether existing check for empty file is still required for 'Local'? There's no such check for 'Remote'.

I don't think it was intended that I didn't add it to the "Remote"-implementation. As far as I remember this check was to ensure that we never overwrite the original PDF with an empty payload. Also this was slightly adjusted to cover #232. I would suggest leave it there for now, I'm working on a common base class for "Local" and "Remote" anyways so I will move it there

Also not sure about the requirement for additional tests.

Would be brilliant if you could provide 2 additional test cases. Let me know if you need help with the implementation of the PHPUnits

@XueSheng-GIT

Copy link
Copy Markdown
Collaborator Author

@R0Wi Undefined constant OCP\IUser::MAX_USERID_LENGTH could be related to nextcloud/server@1ada991.
To be honest, I didn't use XDebug so far. Thus, I'll first need to setup a local dev environment to dig deeper. At the moment I struggle a bit to find time. I don't mind if you can have a look at this issue. Otherwise I'll have a closer look sometime during the next weeks.

@R0Wi

R0Wi commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

I can take a look into the tests, no problem. If you need a quick NC dev setup, I can recommend using the Nextcloud Devcontainer or directly run the IDE within Github Codespaces.

@R0Wi
R0Wi force-pushed the bugfix/ocr-skip-error branch from 15b9d64 to 9ad521e Compare April 28, 2025 20:10
@R0Wi

R0Wi commented May 1, 2025

Copy link
Copy Markdown
Contributor

@R0Wi Undefined constant OCP\IUser::MAX_USERID_LENGTH could be related to nextcloud/server@1ada991.

@XueSheng-GIT you were right, I needed to update the OCP composer package to reflect the latest NC code changes. Otherwise it ran into conflicts with the function signature.

I added some tests and I'm trying to finalize those soon.

@R0Wi
R0Wi force-pushed the bugfix/ocr-skip-error branch 2 times, most recently from b688064 to 71ed5cf Compare May 1, 2025 19:12
@R0Wi
R0Wi force-pushed the bugfix/ocr-skip-error branch from 71ed5cf to c2a81c4 Compare May 1, 2025 19:18
@sonarqubecloud

sonarqubecloud Bot commented May 1, 2025

Copy link
Copy Markdown

@R0Wi
R0Wi marked this pull request as ready for review May 1, 2025 19:20
@R0Wi
R0Wi merged commit 10332e9 into master May 1, 2025
@R0Wi
R0Wi deleted the bugfix/ocr-skip-error branch May 1, 2025 19:20
@R0Wi R0Wi linked an issue May 1, 2025 that may be closed by this pull request
@R0Wi

R0Wi commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

The backport to stable31 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-stable31 stable31
# Navigate to the new working tree
cd .worktrees/backport-stable31
# Create a new branch
git switch --create backport-308-to-stable31
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick ---mainline 1 10332e96f984fa643743daa9ea50ecbac28289af
# Push it to GitHub
git push --set-upstream origin backport-308-to-stable31
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-stable31

Then, create a pull request where the base branch is stable31 and the compare/head branch is backport-308-to-stable31.

R0Wi added a commit that referenced this pull request Jul 6, 2025
* Gracefully handle already done ocr

Throw OcrResultEmptyException if OCRmyPDF returns exit code 6
(ExitCode.already_done_ocr).
Fix of #293

Signed-off-by: XueSheng-GIT <Michael.Frase@gmx.de>

* Update composer.lock to get latest OCP

* Update psalm baseline

* Introduce OcrAlreadyDoneException and add tests

* Add additional integration tests for new result code handling

---------

Signed-off-by: XueSheng-GIT <Michael.Frase@gmx.de>
Co-authored-by: Robin Windey <ro.windey@gmail.com>
R0Wi added a commit that referenced this pull request Jul 6, 2025
…#319)

* Gracefully handle already done ocr (#308) [Backport #308 to stable31]

* Gracefully handle already done ocr

Throw OcrResultEmptyException if OCRmyPDF returns exit code 6
(ExitCode.already_done_ocr).
Fix of #293

Signed-off-by: XueSheng-GIT <Michael.Frase@gmx.de>

* Update composer.lock to get latest OCP

* Update psalm baseline

* Introduce OcrAlreadyDoneException and add tests

* Add additional integration tests for new result code handling

---------

Signed-off-by: XueSheng-GIT <Michael.Frase@gmx.de>
Co-authored-by: Robin Windey <ro.windey@gmail.com>

* Apply php-cs-fixer changes (according to new OC ruleset)

---------

Signed-off-by: XueSheng-GIT <Michael.Frase@gmx.de>
Co-authored-by: XueSheng-GIT <Michael.Frase@gmx.de>
Co-authored-by: R0Wi <R0Wi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF with text layer errors if OCR_MODE_SKIP_FILE is set

2 participants