Bug 33039 - Add ability to specify a template for serial subscription "Published on (text)" field
Summary: Add ability to specify a template for serial subscription "Published on (text...
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Serials (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Kyle M Hall
QA Contact: Marcel de Rooy
URL:
Keywords:
: 31792 (view as bug list)
Depends on:
Blocks: 35867 33030 33041
  Show dependency treegraph
 
Reported: 2023-02-22 15:07 UTC by Kyle M Hall
Modified: 2024-04-05 20:58 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact: Caroline Cyr La Rose
Documentation submission: https://gitlab.com/koha-community/koha-manual/-/merge_requests/854
Text to go in the release notes:
Version(s) released in:
23.11.00


Attachments
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field (11.98 KB, patch)
2023-02-22 15:26 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 33039: Update Schema File [DO NOT PUSH] (1.50 KB, patch)
2023-02-22 15:26 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field (13.58 KB, patch)
2023-02-22 16:40 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 33039: Update Schema File [DO NOT PUSH] (1.50 KB, patch)
2023-02-22 16:40 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 33039: Update Schema File [DO NOT PUSH] (1.57 KB, patch)
2023-03-21 14:16 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 33039: Update Schema File [DO NOT PUSH] (1.57 KB, patch)
2023-03-21 14:16 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 33039: Update Schema File [DO NOT PUSH] (1.57 KB, patch)
2023-03-21 14:16 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 32924: (follow-up) Add left margin to 'Show mine only' label (1.12 KB, patch)
2023-03-21 16:29 UTC, Laura Escamilla
Details | Diff | Splinter Review
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field (13.65 KB, patch)
2023-03-22 13:19 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 33039: Update Schema File [DO NOT PUSH] (1.57 KB, patch)
2023-03-22 13:19 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field (13.67 KB, patch)
2023-07-06 11:07 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 33039: Update Schema File [DO NOT PUSH] (1.57 KB, patch)
2023-07-06 11:07 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field (13.76 KB, patch)
2023-07-07 09:34 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 33039: Update Schema File [DO NOT PUSH] (1.66 KB, patch)
2023-07-07 09:34 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 33039: Incorrect date value stored when 'Published on' or 'Expected on' are empty (2.06 KB, text/plain)
2024-03-29 21:49 UTC, Hammat wele
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle M Hall 2023-02-22 15:07:37 UTC
Some libraries would like to have the text version of the serials "published on" field auto-generated from a template. This template should be definable at the subscription level.
Comment 1 Kyle M Hall 2023-02-22 15:26:51 UTC
Created attachment 147167 [details] [review]
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field

Some libraries would like to have the text version of the serials
"published on" field auto-generated from a template. This template
should be definable at the subscription level.

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
3) Restart all the things!
4) Create or edit a new subscription
5) Edit the "Publication date template", create a template toolkit
   template.
   Keys available are the Koha::Subscription object as 'subscription'
   and the following serial table columns as keys:
    serialseq
    serialseq_x
    serialseq_y
    serialseq_z
    subscriptionid
    biblionumber
    status
    planneddate
    publisheddate
    publisheddateext
    notes
    routingnotes
   So your example template could be "[% subscription.subscriptionid %] [% biblionumber %]"
6) Generate the next serial
7) Note the next issue has a "Date published (text)" field based on the
   template you set!
Comment 2 Kyle M Hall 2023-02-22 15:26:57 UTC
Created attachment 147168 [details] [review]
Bug 33039: Update Schema File [DO NOT PUSH]
Comment 3 Kyle M Hall 2023-02-22 16:40:17 UTC
Created attachment 147173 [details] [review]
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field

Some libraries would like to have the text version of the serials
"published on" field auto-generated from a template. This template
should be definable at the subscription level.

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
3) Restart all the things!
4) Create or edit a new subscription
5) Edit the "Publication date template", create a template toolkit
   template.
   Keys available are the Koha::Subscription object as 'subscription'
   and the following serial table columns as keys:
    serialseq
    serialseq_x
    serialseq_y
    serialseq_z
    subscriptionid
    biblionumber
    status
    planneddate
    publisheddate
    publisheddateext
    notes
    routingnotes
   So your example template could be "[% subscription.subscriptionid %] [% biblionumber %]"
6) Generate the next serial
7) Note the next issue has a "Date published (text)" field based on the
   template you set!
Comment 4 Kyle M Hall 2023-02-22 16:40:25 UTC
Created attachment 147174 [details] [review]
Bug 33039: Update Schema File [DO NOT PUSH]
Comment 5 Laura Escamilla 2023-03-01 14:49:17 UTC
(In reply to Kyle M Hall from comment #3)
> Created attachment 147173 [details] [review] [review]
> Bug 33039: Add ability to specify a template for serial subscription
> "Published on (text)" field
> 
> Some libraries would like to have the text version of the serials
> "published on" field auto-generated from a template. This template
> should be definable at the subscription level.
> 
> Test Plan:
> 1) Apply this patch
> 2) Run updatedatabase.pl
> 3) Restart all the things!
> 4) Create or edit a new subscription
> 5) Edit the "Publication date template", create a template toolkit
>    template.
>    Keys available are the Koha::Subscription object as 'subscription'
>    and the following serial table columns as keys:
>     serialseq
>     serialseq_x
>     serialseq_y
>     serialseq_z
>     subscriptionid
>     biblionumber
>     status
>     planneddate
>     publisheddate
>     publisheddateext
>     notes
>     routingnotes
>    So your example template could be "[% subscription.subscriptionid %] [%
> biblionumber %]"
> 6) Generate the next serial
> 7) Note the next issue has a "Date published (text)" field based on the
>    template you set!

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 6 ByWater Sandboxes 2023-03-21 14:16:15 UTC
Created attachment 148470 [details] [review]
Bug 33039: Update Schema File [DO NOT PUSH]

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 7 ByWater Sandboxes 2023-03-21 14:16:21 UTC Comment hidden (obsolete)
Comment 8 ByWater Sandboxes 2023-03-21 14:16:27 UTC Comment hidden (obsolete)
Comment 9 Laura Escamilla 2023-03-21 16:29:14 UTC Comment hidden (obsolete)
Comment 10 ByWater Sandboxes 2023-03-22 13:19:28 UTC
Created attachment 148534 [details] [review]
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field

Some libraries would like to have the text version of the serials
"published on" field auto-generated from a template. This template
should be definable at the subscription level.

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
3) Restart all the things!
4) Create or edit a new subscription
5) Edit the "Publication date template", create a template toolkit
   template.
   Keys available are the Koha::Subscription object as 'subscription'
   and the following serial table columns as keys:
    serialseq
    serialseq_x
    serialseq_y
    serialseq_z
    subscriptionid
    biblionumber
    status
    planneddate
    publisheddate
    publisheddateext
    notes
    routingnotes
   So your example template could be "[% subscription.subscriptionid %] [% biblionumber %]"
6) Generate the next serial
7) Note the next issue has a "Date published (text)" field based on the
   template you set!

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 11 ByWater Sandboxes 2023-03-22 13:19:29 UTC
Created attachment 148535 [details] [review]
Bug 33039: Update Schema File [DO NOT PUSH]

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 12 Marcel de Rooy 2023-04-28 07:19:13 UTC
Looking here
Comment 13 Marcel de Rooy 2023-04-28 07:35:12 UTC
+use Carp qw( croak );
Shouldnt we use exceptions now ?
PERL26: Koha::Exceptions (Approved on Apr 26, 2017)
Instead of die or croak when meeting unfavorable conditions in our code, we should raise exceptions via Koha::Exceptions.
Comment 14 Marcel de Rooy 2023-04-28 07:54:02 UTC
+        if ( index( $template, '[%' ) != -1 ) { # Much faster than regex
No problem, but 'much' sounds like exaggerating :) Just in memory..
The variable name could be confusing btw. It is template code.

This call worries me:
+            my $tt = Template->new(
+                {
+                    EVAL_PERL   => 1,
+                    ABSOLUTE    => 1,
+                    PLUGIN_BASE => 'Koha::Template::Plugin',
+                    COMPILE_EXT => $use_template_cache ? '.ttc' : '',
+                    COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
+                    FILTERS      => {},
+                    ENCODING     => 'UTF-8',
+                }
+            ) or die Template->error();
Would prefer to see calling something central like in C4::Templates or in C4::Letters instead.

+            $schema->txn_begin;
+            try {
+                my $text;
+                $tt->process(
Please explain why a process call would need a transaction. Can we just remove it ?

Could generating alternative text via a Koha plugin be easier somehow? And without needing a db revision ?
Note that we already have:
Koha/Plugins/Base.pm:    $args->{'template'} = Template->new( { ABSOLUTE => 1, ENCODING => 'UTF-8' } );
Comment 15 Kyle M Hall 2023-04-28 16:09:39 UTC
(In reply to Marcel de Rooy from comment #14)
> +        if ( index( $template, '[%' ) != -1 ) { # Much faster than regex
> No problem, but 'much' sounds like exaggerating :) Just in memory..

https://stackoverflow.com/questions/30744379/unanchored-substring-searching-index-vs-regex

> 
> This call worries me:
> +            my $tt = Template->new(
> +                {
> +                    EVAL_PERL   => 1,
> +                    ABSOLUTE    => 1,
> +                    PLUGIN_BASE => 'Koha::Template::Plugin',
> +                    COMPILE_EXT => $use_template_cache ? '.ttc' : '',
> +                    COMPILE_DIR => $use_template_cache ?
> C4::Context->config('template_cache_dir') : '',
> +                    FILTERS      => {},
> +                    ENCODING     => 'UTF-8',
> +                }
> +            ) or die Template->error();
> Would prefer to see calling something central like in C4::Templates or in
> C4::Letters instead.

Bug 33041 already handles that

> 
> +            $schema->txn_begin;
> +            try {
> +                my $text;
> +                $tt->process(
> Please explain why a process call would need a transaction. Can we just
> remove it ?

Please have a look at C4::Letters. This is now standard procedure for template processing.


> Could generating alternative text via a Koha plugin be easier somehow? And
> without needing a db revision ?
> Note that we already have:
> Koha/Plugins/Base.pm:    $args->{'template'} = Template->new( { ABSOLUTE =>
> 1, ENCODING => 'UTF-8' } );

That sounds more complicated. If you want to write a POC for that I'd be happy to take a look.
Comment 16 Kyle M Hall 2023-07-06 11:07:41 UTC
Created attachment 153089 [details] [review]
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field

Some libraries would like to have the text version of the serials
"published on" field auto-generated from a template. This template
should be definable at the subscription level.

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
3) Restart all the things!
4) Create or edit a new subscription
5) Edit the "Publication date template", create a template toolkit
   template.
   Keys available are the Koha::Subscription object as 'subscription'
   and the following serial table columns as keys:
    serialseq
    serialseq_x
    serialseq_y
    serialseq_z
    subscriptionid
    biblionumber
    status
    planneddate
    publisheddate
    publisheddateext
    notes
    routingnotes
   So your example template could be "[% subscription.subscriptionid %] [% biblionumber %]"
6) Generate the next serial
7) Note the next issue has a "Date published (text)" field based on the
   template you set!

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 17 Kyle M Hall 2023-07-06 11:07:48 UTC
Created attachment 153090 [details] [review]
Bug 33039: Update Schema File [DO NOT PUSH]

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 18 Marcel de Rooy 2023-07-07 09:34:10 UTC
Created attachment 153138 [details] [review]
Bug 33039: Add ability to specify a template for serial subscription "Published on (text)" field

Some libraries would like to have the text version of the serials
"published on" field auto-generated from a template. This template
should be definable at the subscription level.

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
3) Restart all the things!
4) Create or edit a new subscription
5) Edit the "Publication date template", create a template toolkit
   template.
   Keys available are the Koha::Subscription object as 'subscription'
   and the following serial table columns as keys:
    serialseq
    serialseq_x
    serialseq_y
    serialseq_z
    subscriptionid
    biblionumber
    status
    planneddate
    publisheddate
    publisheddateext
    notes
    routingnotes
   So your example template could be "[% subscription.subscriptionid %] [% biblionumber %]"
6) Generate the next serial
7) Note the next issue has a "Date published (text)" field based on the
   template you set!

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 19 Marcel de Rooy 2023-07-07 09:34:12 UTC
Created attachment 153139 [details] [review]
Bug 33039: Update Schema File [DO NOT PUSH]

Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 20 Tomás Cohen Arazi 2023-07-14 12:01:09 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 21 Martin Renvoize 2023-07-18 11:38:19 UTC
Enhancement, no backport for 23.05.x series.
Comment 22 Nick Clemens (kidclamp) 2024-01-22 19:31:03 UTC
*** Bug 31792 has been marked as a duplicate of this bug. ***
Comment 23 Hammat wele 2024-03-29 21:49:20 UTC Comment hidden (obsolete)
Comment 24 Caroline Cyr La Rose 2024-04-05 20:58:24 UTC
Please set the status to 'Needs documenting' when there is a new field visible to the user. Thanks! :)