https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42405

--- Comment #13 from Tomás Cohen Arazi (tcohen) <[email protected]> ---
Created attachment 209372
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209372&action=edit
Bug 42405: (follow-up) Fix replace behaviour in single cover image endpoints

POST /biblios/{biblio_id}/cover_images and
POST /items/{item_id}/cover_images had two problems when replacing
existing covers. They are the same Lucas reported for the batch import
on bug 42404 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.

2. The AllowMultipleCovers system preference was ignored, so API
   consumers could attach several covers to a record when the library
   does not allow it. tools/upload-cover-image.pl always replaced
   existing covers when it was disabled.

This patch only deletes the biblio level covers (itemnumber IS NULL)
when replacing a biblio's covers, and replaces existing covers when
AllowMultipleCovers is disabled, whatever the 'replace' parameter says.
The logic is in a _replace_covers helper shared by both endpoints. The
API spec documents the behaviour.

This matches what bug 42404 does for the batch import.

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ yarn api:bundle
  k$ restart_all
  k$ prove t/db_dependent/api/v1/cover_images_single.t \
           xt/api.t
=> SUCCESS: Tests pass!
3. Revert the changes to Koha/REST/V1/CoverImages.pm and repeat 2
=> FAIL: Item level covers are deleted, and covers pile up 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 an image for one of its items (holdings
   table: Edit -> Upload image)
7. Upload a record cover, replacing existing ones:
  k$ curl -u koha:koha \
       -F file=@/kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/img/koha-logo.png
\
       "http://localhost:8081/api/v1/biblios/1/cover_images?replace=true";
=> SUCCESS: 201 with a cover_image_id
8. Go to record 1
=> SUCCESS: The item cover uploaded in 6 is still there
9. Disable AllowMultipleCovers, repeat 7 twice without ?replace=true
=> SUCCESS: Record 1 has a single record level cover
10. 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/

Reply via email to