A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent. For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron.
Created attachment 159832 [details] [review] Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent. For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron. Test Plan: 1) Apply this patch 2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t 3) Download and install the Kitchen Sink plugin v2.4.0 https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0 4) Generate any notice or slip, such as a checkin or checkout notice 5) Note that all notices now end with "Thanks for using your local library!"
Created attachment 159932 [details] [review] Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent. For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron. Test Plan: 1) Apply this patch 2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t 3) Download and install the Kitchen Sink plugin v2.4.0 https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0 4) Generate any notice or slip, such as a checkin or checkout notice 5) Note that all notices now end with "Thanks for using your local library!" Signed-off-by: David Nind <david@davidnind.com>
Testing notes (using KTD): 1. Added an email address for a patron (for example, Mary Burton - mary@example.com) 2. Generated notice: Patron page > More > Send welcome email Note: With the v2.4.0 of the plugin it adds an 'I' in front of barcodes entered, so an existing barcode is never found when checking an item in or out (I'm assuming that is part of the code): "Check in message No item with barcode: I39999000011418"
Created attachment 162721 [details] [review] Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent. For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron. Test Plan: 1) Apply this patch 2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t 3) Download and install the Kitchen Sink plugin v2.4.0 https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0 4) Generate any notice or slip, such as a checkin or checkout notice 5) Note that all notices now end with "Thanks for using your local library!" Signed-off-by: David Nind <david@davidnind.com>
Created attachment 163614 [details] [review] Bug 35568: Add a transform_prepared_letter plugin hook to allow modification of notices created via GetPreparedLetter A plugin hook for GetPreparedLetter would be very useful. It could be used to add universal headers and/or footers to messages, attach news, and modify notices in other ways in whole or in part. It could even be used for call webhooks when certain types of notices are sent. For example, the MessageBee ( https://uniquelibrary.com/messagebee/ ) plugin for Koha generates YAML based notice content, which is then further processed by the before_send_messages hook. This process is unreliable due to the possible changes in data between the creation of the yaml and the reading of that yaml and transforming it into JSON with much more data. For example, the yaml may contain an issue_id, but that checkout may have been returned in the meantime. A hook like this would allow the MessageBee plugin to skip the yaml step and create the json data directly which is then sent to MessageBee for transmission to the patron. Test Plan: 1) Apply this patch 2) prove t/db_dependent/Koha/Plugins/Transform_prepared_letter_hook.t 3) Download and install the Kitchen Sink plugin v2.4.0 https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases/tag/v2.4.0 4) Generate any notice or slip, such as a checkin or checkout notice 5) Note that all notices now end with "Thanks for using your local library!" Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Simple hook, all working as designed and nothing contentious here. Test present too.. Passing QA (Lets also make sure it's added to the wiki page please)
Please remember to update the wiki: https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks
Pushed for 24.05! Well done everyone, thank you!
This appears to make a test fail - could be a merge issue? prove t/db_dependent/Koha/Plugins/Recall_hooks.t t/db_dependent/Koha/Plugins/Recall_hooks.t .. 1/4 # Failed test '->add_recall calls the after_recall_action hook with action add' # at t/db_dependent/Koha/Plugins/Recall_hooks.t line 94. # found warning: Plugin error (Test Plugin): Exception 'Koha::Exception' thrown 'transform_prepared_letter called with letter content Date: 04/22/2024 08:05 # found warning: Plugin error (Test Plugin): Exception 'Koha::Exception' thrown 'after_recall_action called with action: add, ref: Koha::Recall' # expected to find warning: (?^u:after_recall_action called with action: add, ref: Koha::Recall) # Looks like you failed 1 test of 1. t/db_dependent/Koha/Plugins/Recall_hooks.t .. 4/4 # Failed test 'after_recall_action hook' # at t/db_dependent/Koha/Plugins/Recall_hooks.t line 99. # Looks like you failed 1 test of 4. t/db_dependent/Koha/Plugins/Recall_hooks.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/4 subtests Test Summary Report ------------------- t/db_dependent/Koha/Plugins/Recall_hooks.t (Wstat: 256 Tests: 4 Failed: 1) Failed test: 4 Non-zero exit status: 1 Files=1, Tests=4, 1 wallclock secs ( 0.02 usr 0.00 sys + 1.45 cusr 0.09 csys = 1.56 CPU) Result: FAIL
I fixed the recalls test and just pushed.. removing additional_work_needed flag.
Unexpected warning caused by this change: $ prove t/db_dependent/Koha/REST/Plugin/PluginRoutes.t t/db_dependent/Koha/REST/Plugin/PluginRoutes.t .. 2/4 Plugin error (Test Plugin): Exception 'Koha::Exception' thrown 'transform_prepared_letter called with letter content Dear s9Npnm sx9amQ, We want to notify you that your password has been changed. If you did not change it yourself (or requested that change), please contact library staff. Your library. Thank you for using your local library!' t/db_dependent/Koha/REST/Plugin/PluginRoutes.t .. ok All tests successful. Files=1, Tests=4, 43 wallclock secs ( 0.03 usr 0.00 sys + 36.72 cusr 0.56 csys = 37.31 CPU) Result: PASS
Created attachment 167018 [details] [review] Bug 35568: Supress exception
(In reply to Kyle M Hall from comment #12) > Created attachment 167018 [details] [review] [review] > Bug 35568: Supress exception This this follow up be moved to its' own bug report?
Follow-up pushed, removing additional_work_needed keyword.
Enhancement will not be backported to 24.05.x series