Corrections diverses. - #11
Conversation
… forme valeur1-valeur2
There was a problem hiding this comment.
Pull request overview
This PR updates the ExtractOcr Omeka S module with multiple extraction/packaging improvements, including new TSV output variants, better job behavior, and an upgrade path for existing installs.
Changes:
- Add a second TSV export mode (full TSV vs grouped-by-word) and update extraction/storage logic accordingly.
- Introduce an upgrade script to migrate filenames/settings and bump module metadata (version + constraints).
- Add composer metadata, update translations/docs, and improve operational characteristics (memory clearing, CLI tool checks).
Reviewed changes
Copilot reviewed 10 out of 13 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
src/Job/ExtractOcr.php |
Adds new TSV format handling, content-only mode, CLI checks, and memory management improvements. |
src/Form/ConfigForm.php |
Updates admin config options to expose the new TSV formats and documentation link. |
Module.php |
Updates install checks/messages, adds deferred job dispatch and EasyAdmin integration, extends format handling. |
data/scripts/upgrade.php |
New upgrade script to migrate settings and rename derivative files/DB sources. |
config/module.ini |
Bumps module version and updates Omeka version constraint. |
config/module.config.php |
Adjusts translator loader config and defaults (notably content property default). |
README.md |
Expands documentation to explain formats and recommended usage. |
language/template.pot |
Regenerates POT with new/updated strings. |
language/fr.po |
Updates French translations for new/changed strings. |
language/fr.mo |
Adds compiled French translation binary. |
composer.json / composer.lock |
Adds Composer package metadata for the module. |
.gitignore |
Expands ignored paths (vendor/node/phpunit/etc.). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $extensions = [ | ||
| \ExtractOcr\Job\ExtractOcr::FORMAT_ALTO => 'alto.xml', | ||
| \ExtractOcr\Job\ExtractOcr::FORMAT_PDF2XML => 'xml', | ||
| \ExtractOcr\Job\ExtractOcr::FORMAT_TSV => 'tsv', | ||
| \ExtractOcr\Job\ExtractOcr::FORMAT_TSV_BY_WORD => 'tsv', | ||
| ]; | ||
| $settings = $services->get('Omeka\Settings'); | ||
| $targetTypesFiles = $settings->get('extractocr_types_files') ?: []; | ||
| $targetTypesFiles = array_intersect($targetTypesFiles, array_flip($extensions)); | ||
| $targetTypesMedia = $settings->get('extractocr_types_media') ?: []; | ||
| $targetTypesMedia = array_intersect($targetTypesMedia, array_flip($extensions)); | ||
| if (!$targetTypesFiles && !$targetTypesMedia ) { | ||
| $targetContentStore = $settings->get('extractocr_content_store') ?: []; | ||
| $targetContentStore = array_intersect($targetContentStore, ['item', 'media_pdf', 'media_extracted']); | ||
| if (!$targetTypesFiles && !$targetTypesMedia && !$targetContentStore) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
In extractOcr(), the filtering of configured formats is broken: array_intersect($targetTypesFiles, array_flip($extensions)) compares selected mime types against extension strings, so $targetTypesFiles/$targetTypesMedia will always end up empty and automatic extraction on item update won’t run as expected. This method also still uses legacy extension/filename conventions (xml, tsv) and uses the selected format string as mediaType when checking existing OCR media; that won’t match the actual media types produced by the job (e.g. the new TSV-by-word format maps to text/tab-separated-values and file extensions like by-word.tsv, full.tsv, pdf2xml.xml). Align the format filtering + extension/mediaType mapping here with src/Job/ExtractOcr::perform() so existing files/medias are detected correctly and jobs aren’t skipped or re-dispatched unnecessarily.
| ], | ||
| 'attributes' => [ | ||
| 'id' => 'item_ids', | ||
| 'placeholder' => '2-6 8 38-52 80-', // @ translate |
There was a problem hiding this comment.
The translator extraction marker is written as // @ translate (with a space). If your translation tooling relies on the exact @translate token, this placeholder string may be missed during POT generation; change it to // @translate for consistency with the rest of the module.
| 'placeholder' => '2-6 8 38-52 80-', // @ translate | |
| 'placeholder' => '2-6 8 38-52 80-', // @translate |
| #: src/Job/ExtractOcr.php:130 | ||
| #: Module.php:487 | ||
| msgid "Extract OCR: Extract ocr from files" | ||
| msgstr "Extract OCR : extraire l’ocr des fichierse" |
There was a problem hiding this comment.
There’s a typo in the French translation: “fichierse” should be “fichiers”.
| msgstr "Extract OCR : extraire l’ocr des fichierse" | |
| msgstr "Extract OCR : extraire l’ocr des fichiers" |
| $newFilepath = substr_replace($filepath, '.by-word.tsv', -4); | ||
| $result = @rename($filepath, $newFilepath); | ||
| if (!$result) { | ||
| $message = new Message( | ||
| $translator->translate('The file "%s" cannot be renamed.'), // @translate | ||
| $filename | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
On rename failure, a Message is created but never logged, shown to the user, or used to fail the upgrade. As a result, file renames can silently fail and leave the installation in a partially-upgraded state. Consider reporting these failures via $messenger->addError() / $logger->err() and/or throwing ModuleCannotInstallException when renames are required for correctness.
| allows smaller files and a slightly faster search, but a slighly less accurate | ||
| display. For alto, it is a valid but basic alto that does not contains metadata | ||
| about fonts or structure. | ||
|
|
||
| There are two tsv formats: the words can be stored globally, so the index is | ||
| smaller and the search is quicker, or one by one, so an exact search can be done | ||
| when there are multiple words and the search wrapped with `"`. The tsv format | ||
| does not allows to display the transcription in IIIF viewers, but it allows to |
There was a problem hiding this comment.
Minor wording/spelling issues in this updated documentation section make it harder to read: e.g. “slighly” → “slightly”, “does not contains” → “does not contain”, and “does not allows” → “does not allow”. Consider proofreading these lines.
| allows smaller files and a slightly faster search, but a slighly less accurate | |
| display. For alto, it is a valid but basic alto that does not contains metadata | |
| about fonts or structure. | |
| There are two tsv formats: the words can be stored globally, so the index is | |
| smaller and the search is quicker, or one by one, so an exact search can be done | |
| when there are multiple words and the search wrapped with `"`. The tsv format | |
| does not allows to display the transcription in IIIF viewers, but it allows to | |
| allows smaller files and a slightly faster search, but a slightly less accurate | |
| display. For alto, it is a valid but basic alto that does not contain metadata | |
| about fonts or structure. | |
| There are two tsv formats: the words can be stored globally, so the index is | |
| smaller and the search is quicker, or one by one, so an exact search can be done | |
| when there are multiple words and the search wrapped with `"`. The tsv format | |
| does not allow to display the transcription in IIIF viewers, but it allows to |
| 'The command-line utility pdftotext is not available. Install the package poppler-utils.' //@translate | ||
| ); | ||
| } | ||
|
|
||
| if ((int) shell_exec('hash pdftohtml 2>&- || echo 1')) { | ||
| throw new ModuleCannotInstallException( | ||
| 'The command-line utility pdftohtml is not available. Install the package poppler-utils.' //@translate |
There was a problem hiding this comment.
These install-time exception messages are now hardcoded strings (not passed through $t->translate()), so they won’t be localized even though they’re marked //@translate and appear in the POT. Consider translating them before throwing ModuleCannotInstallException (consistent with the other install checks below).
| 'The command-line utility pdftotext is not available. Install the package poppler-utils.' //@translate | |
| ); | |
| } | |
| if ((int) shell_exec('hash pdftohtml 2>&- || echo 1')) { | |
| throw new ModuleCannotInstallException( | |
| 'The command-line utility pdftohtml is not available. Install the package poppler-utils.' //@translate | |
| $t->translate('The command-line utility pdftotext is not available. Install the package poppler-utils.') // @translate | |
| ); | |
| } | |
| if ((int) shell_exec('hash pdftohtml 2>&- || echo 1')) { | |
| throw new ModuleCannotInstallException( | |
| $t->translate('The command-line utility pdftohtml is not available. Install the package poppler-utils.') // @translate |
| 'options' => [ | ||
| 'label' => 'Create file for formats', // @translate | ||
| 'info' => 'For more info on formats, see readme.', // @translate | ||
| 'documentation' => 'https://gitlab.com/Daniel-KM/Omeka-S-module-ExtractOcr#extract-ocr-modue-for-omeka-s', |
There was a problem hiding this comment.
The documentation URL has a typo (extract-ocr-modue-for-omeka-s), which makes the help link in the admin config form incorrect. Update it to the correct anchor in the README so admins can reach the referenced documentation.
| 'documentation' => 'https://gitlab.com/Daniel-KM/Omeka-S-module-ExtractOcr#extract-ocr-modue-for-omeka-s', | |
| 'documentation' => 'https://gitlab.com/Daniel-KM/Omeka-S-module-ExtractOcr#extract-ocr-module-for-omeka-s', |
| #: data/scripts/upgrade.php:152 data/scripts/upgrade.php:184 | ||
| #, php-format | ||
| msgid "The file \"%s\" cannot be renamed." | ||
| msgstr "Le dossier « %s » ne peut pas être renommé." |
There was a problem hiding this comment.
The French translation for “The file "%s" cannot be renamed.” currently says “Le dossier …” (folder) instead of “Le fichier …” (file), which changes the meaning and is confusing in upgrade error reporting. Update the msgstr accordingly.
| msgstr "Le dossier « %s » ne peut pas être renommé." | |
| msgstr "Le fichier « %s » ne peut pas être renommé." |
| $translator->translate('The file "%s" cannot be renamed.'), // @translate | ||
| $filename | ||
| ); |
There was a problem hiding this comment.
On rename failure in the /pdf2xml loop, a Message is created but never emitted. This can silently leave old filenames on disk while the DB/settings are updated, leading to mismatches. Report/handle the failure (messenger/logger and/or abort the upgrade) so admins know remediation is needed.
| $translator->translate('The file "%s" cannot be renamed.'), // @translate | |
| $filename | |
| ); | |
| $translator->translate('The file "%1$s" cannot be renamed to "%2$s".'), // @translate | |
| $filepath, | |
| $newFilepath | |
| ); | |
| $logger->err((string) $message); | |
| throw new ModuleCannotInstallException((string) $message); |
No description provided.