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

--- Comment #13 from Martin Renvoize (ashimema) 
<[email protected]> ---
Created attachment 209019
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209019&action=edit
Bug 43638: Add patron_image_imports.pl cron job

Add misc/cronjobs/patron_image_imports.pl. It polls the file transport of
every active patron image import account for new zip archives and loose
image files, and imports them with Koha::Patron::Image::Import (Bug
43637), matching the images to patrons with the matchpoint of the account
(card number, username or a unique patron attribute).

Each file is moved on the file transport to a "processed" or an "error"
directory, and logged once per account and file name in
patron_image_import_log, so that running the cron job repeatedly is safe.
Accounts with an invalid matchpoint, or that cannot connect, are skipped
and the problem is logged. Without -c it only lists what it would do.

To test:
You need Bug 43637 and all the patches of this bug. Everything below is
done in KTD.
1. Apply the patches and, in "ktd --shell", run
     updatedatabase
     restart_all
2. Create a file transport that reads from a local directory. The
   Administration > File transports form only offers FTP and SFTP, so, if
   you have no FTP or SFTP server to use, create a "local" transport
   directly. In "ktd --shell":
     mkdir -p /tmp/patron-images
   then in "ktd --dbshell" (outside the shell):
     INSERT INTO file_transports (name, transport, download_directory,
upload_directory)
     VALUES ('Patron images (local)', 'local', '/tmp/patron-images',
'/tmp/patron-images');
3. Go to Tools > Patrons and circulation > Schedule patron image imports,
   click "New account" and enter:
   - Name: Staff photos
   - File transport: Patron images (local)
   - Active: checked
   - Field to use for patron matching: Card number
   then Save
   => The account is listed, with Active "Yes"
4. Pick three patrons that have no photo (A, B and C) and note their card
   numbers. In "ktd --shell", put any small image in a file (here
   sample.png) and make these files in /tmp/patron-images, with the card
   numbers as file names:
     cd /tmp/patron-images
     cp sample.png <card number of A>.png
     cp sample.png <card number of B>.png
     cp sample.png <card number of C>.png
     python3 -m zipfile -c batch.zip <card number of B>.png <card number of
C>.png
     rm <card number of B>.png <card number of C>.png
     cp sample.png 99999999999.png
   (The zip holds the images of B and C, A has a loose image, and the last
   file matches no patron.)
5. From the Koha directory, do a test run:
     perl misc/cronjobs/patron_image_imports.pl
   => It says "Test run only" and lists the 3 files ("Processing: ...").
      Nothing is imported: the files are still where they were, and no
      patron has a photo
6. Run it for real:
     perl misc/cronjobs/patron_image_imports.pl -c -v
   => (The files can be listed in any order)
      Processing: batch.zip
        2 imported, 0 errors
      Processing: 99999999999.png
        PATRON_NOT_FOUND
      Processing: <card number of A>.png
        imported
7. Check the result:
   - Patrons A, B and C now have a photo on their patron record
   - In /tmp/patron-images, the imported files (batch.zip and A's image)
     have been moved to the "processed" directory and the file that did
     not match any patron is in the "error" directory
   - In "ktd --dbshell":
       SELECT patron_image_import_account_id, filename, status, details
       FROM patron_image_import_log;
     => 3 rows: batch.zip and A's image are "processed", 99999999999.png
        is an "error" (PATRON_NOT_FOUND)
8. Run the command of step 6 again
   => Nothing to process. Now copy sample.png to
      /tmp/patron-images/<card number of A>.png once more and run it again
   => "Already processed: <card number of A>.png": a file name is only
      processed once for an account, the file stays where it is and
      nothing is imported or logged again
9. Back on Tools > Schedule patron image imports, delete the account
   ("Delete", then "Yes, delete")
   => The account is gone, its rows in patron_image_import_log too, and
      the photos that were imported are still there
10. Run $ prove t/db_dependent/Koha/Patron/Image/Import.t \
                t/db_dependent/Koha/PatronImageImportAccounts.t \
                t/db_dependent/Koha/PatronImageImportLogs.t \
                t/db_dependent/cronjobs/patron_image_imports.t
    => All pass

Co-Authored-By: Claude Sonnet 5 <[email protected]>

-- 
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