https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42404
--- Comment #49 from Tomás Cohen Arazi (tcohen) <[email protected]> --- Created attachment 209368 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209368&action=edit Bug 42404: (follow-up) Fix replace behaviour in BatchImportCoverImages The way BatchImportCoverImages replaced existing covers had three problems. The first two were reported by Lucas on comment #45: 1. Replacing a biblio's covers used $biblio->cover_images, which also includes the covers of its items, so the item level covers were deleted too. tools/upload-cover-image.pl only deleted the biblio level ones when uploading a single image. 2. The existing covers were deleted for every line of the mapping file, so when several images were mapped to the same record, each one deleted the previous one and only one image was kept, even with AllowMultipleCovers enabled. 3. tools/upload-cover-image.pl always replaced existing covers when the AllowMultipleCovers system preference was disabled. The job only looked at the 'replace' parameter, so API consumers could attach several covers to a record when the library does not allow it. This patch: - Only deletes the biblio level covers (itemnumber IS NULL) when replacing a biblio's covers. Item covers are only replaced when importing with target=item_id. - Removes the existing covers of a record only once per job when AllowMultipleCovers is enabled, so all the images in the file are kept. When it is disabled each image replaces the previous one, so the record ends up with the last one. - Replaces existing covers when AllowMultipleCovers is disabled, whatever the 'replace' parameter says. The check lives in the job so every caller gets it. The API spec documents the behaviour. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/BackgroundJob/BatchImportCoverImages.t \ xt/api.t => SUCCESS: Tests pass! 3. Revert the changes to Koha/BackgroundJob/BatchImportCoverImages.pm and repeat 2 => FAIL: Item level covers are deleted, only one image is kept when several are mapped to the same record, and two covers are attached to a record with AllowMultipleCovers disabled 4. Restore the changes and restart services: k$ restart_all 5. Enable LocalCoverImages, AllowMultipleCovers and RESTBasicAuth 6. Go to record 1 and upload a cover image (Images tab -> Upload) 7. In the holdings table, pick an item: Edit -> Upload image, upload another image 8. Create a zip with two images and an idlink.txt mapping both to record 1: k$ mkdir /tmp/covers && cd /tmp/covers k$ cp /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/img/koha-logo.png a.png k$ cp a.png b.png k$ printf "1\ta.png\n1\tb.png\n" > idlink.txt k$ python3 -m zipfile -c covers.zip idlink.txt a.png b.png 9. Upload it, replacing existing covers: k$ curl -u koha:koha -F [email protected] \ "http://localhost:8081/api/v1/cover_images/batch?replace=true" => SUCCESS: A job id is returned 10. Check the job in Administration -> Manage jobs => SUCCESS: 2 images imported 11. Go to record 1 => SUCCESS: The record cover uploaded in 6 is gone, the two new images are there => SUCCESS: The item cover uploaded in 7 is still there 12. Disable AllowMultipleCovers and repeat 9 => SUCCESS: Record 1 has a single record level cover 13. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list -- [email protected] To unsubscribe send an email to [email protected] website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
