View | Details | Raw Unified | Return to bug 33039
Collapse All | Expand All

(-)a/C4/Serials.pm (-10 / +72 lines)
Lines 20-28 package C4::Serials; Link Here
20
20
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use C4::Auth qw( haspermission );
23
use Carp qw( croak );
24
use C4::Context;
25
use DateTime;
26
use Date::Calc qw(
24
use Date::Calc qw(
27
    Add_Delta_Days
25
    Add_Delta_Days
28
    Add_Delta_YM
26
    Add_Delta_YM
Lines 31-49 use Date::Calc qw( Link Here
31
    N_Delta_YMD
29
    N_Delta_YMD
32
    Today
30
    Today
33
);
31
);
32
use DateTime;
34
use POSIX qw( strftime );
33
use POSIX qw( strftime );
34
use Scalar::Util qw( looks_like_number );
35
use Try::Tiny;
36
37
use C4::Auth qw( haspermission );
35
use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
38
use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
39
use C4::Context;
36
use C4::Log qw( logaction );    # logaction
40
use C4::Log qw( logaction );    # logaction
37
use C4::Serials::Frequency qw( GetSubscriptionFrequency );
41
use C4::Serials::Frequency qw( GetSubscriptionFrequency );
38
use C4::Serials::Numberpattern;
42
use C4::Serials::Numberpattern;
39
use Koha::AdditionalFieldValues;
43
use Koha::AdditionalFieldValues;
40
use Koha::Biblios;
44
use Koha::Biblios;
41
use Koha::Serial;
45
use Koha::Serial;
42
use Koha::Subscriptions;
46
use Koha::SharedContent;
43
use Koha::Subscription::Histories;
47
use Koha::Subscription::Histories;
48
use Koha::Subscriptions;
44
use Koha::Suggestions;
49
use Koha::Suggestions;
45
use Koha::SharedContent;
46
use Scalar::Util qw( looks_like_number );
47
50
48
# Define statuses
51
# Define statuses
49
use constant {
52
use constant {
Lines 894-899 sub GetNextSeq { Link Here
894
            my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale );
897
            my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale );
895
            $calculated =~ s/\{Z\}/$newlastvalue3string/g;
898
            $calculated =~ s/\{Z\}/$newlastvalue3string/g;
896
        }
899
        }
900
897
    }
901
    }
898
902
899
    return ($calculated,
903
    return ($calculated,
Lines 1287-1293 sub ModSubscription { Link Here
1287
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1291
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1288
    $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1292
    $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1289
    $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq,
1293
    $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq,
1290
    $itemtype, $previousitemtype, $mana_id, $ccode
1294
    $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
1291
    ) = @_;
1295
    ) = @_;
1292
1296
1293
    my $subscription = Koha::Subscriptions->find($subscriptionid);
1297
    my $subscription = Koha::Subscriptions->find($subscriptionid);
Lines 1331-1336 sub ModSubscription { Link Here
1331
            previousitemtype  => $previousitemtype,
1335
            previousitemtype  => $previousitemtype,
1332
            mana_id           => $mana_id,
1336
            mana_id           => $mana_id,
1333
            ccode             => $ccode,
1337
            ccode             => $ccode,
1338
            published_on_template => $published_on_template,
1334
        }
1339
        }
1335
    )->store;
1340
    )->store;
1336
    # FIXME Must be $subscription->serials
1341
    # FIXME Must be $subscription->serials
Lines 1368-1374 sub NewSubscription { Link Here
1368
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1373
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1369
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1374
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1370
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1375
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1371
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
1376
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode,
1377
    $published_on_template,
1372
    ) = @_;
1378
    ) = @_;
1373
    my $dbh = C4::Context->dbh;
1379
    my $dbh = C4::Context->dbh;
1374
1380
Lines 1411-1417 sub NewSubscription { Link Here
1411
            itemtype          => $itemtype,
1417
            itemtype          => $itemtype,
1412
            previousitemtype  => $previousitemtype,
1418
            previousitemtype  => $previousitemtype,
1413
            mana_id           => $mana_id,
1419
            mana_id           => $mana_id,
1414
            ccode             => $ccode
1420
            ccode             => $ccode,
1421
            published_on_template => $published_on_template,
1415
        }
1422
        }
1416
    )->store;
1423
    )->store;
1417
    $subscription->discard_changes;
1424
    $subscription->discard_changes;
Lines 1587-1592 sub NewIssue { Link Here
1587
1594
1588
    my $subscription = Koha::Subscriptions->find( $subscriptionid );
1595
    my $subscription = Koha::Subscriptions->find( $subscriptionid );
1589
1596
1597
    if ( my $template = $subscription->published_on_template ) {
1598
        # If we detect a TT opening tag, run string through Template Toolkit Processor
1599
        if ( index( $template, '[%' ) != -1 ) { # Much faster than regex
1600
            my $use_template_cache = C4::Context->config('template_cache_dir')
1601
              && defined $ENV{GATEWAY_INTERFACE};
1602
1603
            my $tt = Template->new(
1604
                {
1605
                    EVAL_PERL   => 1,
1606
                    ABSOLUTE    => 1,
1607
                    PLUGIN_BASE => 'Koha::Template::Plugin',
1608
                    COMPILE_EXT => $use_template_cache ? '.ttc' : '',
1609
                    COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
1610
                    FILTERS      => {},
1611
                    ENCODING     => 'UTF-8',
1612
                }
1613
            ) or die Template->error();
1614
1615
            my $schema = Koha::Database->new->schema;
1616
1617
            $schema->txn_begin;
1618
            try {
1619
                my $text;
1620
                $tt->process(
1621
                    \$template,
1622
                    {
1623
                        subscription      => $subscription,
1624
                        serialseq         => $serialseq,
1625
                        serialseq_x       => $subscription->lastvalue1(),
1626
                        serialseq_y       => $subscription->lastvalue2(),
1627
                        serialseq_z       => $subscription->lastvalue3(),
1628
                        subscriptionid    => $subscriptionid,
1629
                        biblionumber      => $biblionumber,
1630
                        status            => $status,
1631
                        planneddate       => $planneddate,
1632
                        publisheddate     => $publisheddate,
1633
                        publisheddatetext => $publisheddatetext,
1634
                        notes             => $notes,
1635
                        routingnotes      => $routingnotes,
1636
                    },
1637
                    \$text
1638
                );
1639
                $publisheddatetext = $text;
1640
            }
1641
            catch {
1642
                croak "ERROR PROCESSING TEMPLATE: $_ :: " . $template->error();
1643
            }
1644
            finally {
1645
                $schema->txn_rollback;
1646
            };
1647
        } else {
1648
            $publisheddatetext = $template;
1649
        }
1650
    }
1651
1590
    my $serial = Koha::Serial->new(
1652
    my $serial = Koha::Serial->new(
1591
        {
1653
        {
1592
            serialseq         => $serialseq,
1654
            serialseq         => $serialseq,
Lines 1600-1606 sub NewIssue { Link Here
1600
            publisheddate     => $publisheddate,
1662
            publisheddate     => $publisheddate,
1601
            publisheddatetext => $publisheddatetext,
1663
            publisheddatetext => $publisheddatetext,
1602
            notes             => $notes,
1664
            notes             => $notes,
1603
            routingnotes      => $routingnotes
1665
            routingnotes      => $routingnotes,
1604
        }
1666
        }
1605
    )->store();
1667
    )->store();
1606
1668
(-)a/installer/data/mysql/atomicupdate/bug_33039.pl (+18 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "33039",
5
    description => "Add published on template to serial subscriptions table",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        if( !column_exists( 'subscription', 'published_on_template' ) ) {
11
          $dbh->do(q{
12
              ALTER TABLE subscription
13
              ADD COLUMN `published_on_template` TEXT DEFAULT NULL COMMENT 'Template Toolkit syntax to generate the default "Published on (text)" field when receiving an issue this serial'
14
              AFTER `ccode`
15
          });
16
        }
17
    },
18
};
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 5516-5521 CREATE TABLE `subscription` ( Link Here
5516
  `previousitemtype` varchar(10) DEFAULT NULL,
5516
  `previousitemtype` varchar(10) DEFAULT NULL,
5517
  `mana_id` int(11) DEFAULT NULL,
5517
  `mana_id` int(11) DEFAULT NULL,
5518
  `ccode` varchar(80) DEFAULT NULL COMMENT 'collection code to assign to serial items',
5518
  `ccode` varchar(80) DEFAULT NULL COMMENT 'collection code to assign to serial items',
5519
  `published_on_template` TEXT DEFAULT NULL COMMENT 'Template Toolkit syntax to generate the default "Published on (text)" field when receiving an issue this serial',
5519
  PRIMARY KEY (`subscriptionid`),
5520
  PRIMARY KEY (`subscriptionid`),
5520
  KEY `subscription_ibfk_1` (`periodicity`),
5521
  KEY `subscription_ibfk_1` (`periodicity`),
5521
  KEY `subscription_ibfk_2` (`numberpattern`),
5522
  KEY `subscription_ibfk_2` (`numberpattern`),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (+4 lines)
Lines 373-378 fieldset.rows table { clear: none; margin: 0; } Link Here
373
                                        </select>
373
                                        </select>
374
                                        <span class="required">Required</span>
374
                                        <span class="required">Required</span>
375
                                    </li>
375
                                    </li>
376
                                    <li>
377
                                        <label for="published_on_template">Publication date template:</label>
378
                                        <textarea id="published_on_template" name="published_on_template">[% published_on_template | html %]</textarea>
379
                                    </li>
376
                                    <li>
380
                                    <li>
377
                                        <label for="locale">Locale:</label>
381
                                        <label for="locale">Locale:</label>
378
                                        <select id="locale" name="locale">
382
                                        <select id="locale" name="locale">
(-)a/serials/subscription-add.pl (-2 / +4 lines)
Lines 330-335 sub redirect_add_subscription { Link Here
330
    my $previousitemtype  = $query->param('previousitemtype');
330
    my $previousitemtype  = $query->param('previousitemtype');
331
    my $skip_serialseq    = $query->param('skip_serialseq');
331
    my $skip_serialseq    = $query->param('skip_serialseq');
332
    my $ccode             = $query->param('ccode');
332
    my $ccode             = $query->param('ccode');
333
    my $published_on_template = $query->param('published_on_template');
333
334
334
    my $mana_id;
335
    my $mana_id;
335
    if ( $query->param('mana_id') ne "" ) {
336
    if ( $query->param('mana_id') ne "" ) {
Lines 356-362 sub redirect_add_subscription { Link Here
356
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
357
        join(";",@irregularity), $numberpattern, $locale, $callnumber,
357
        $manualhistory, $internalnotes, $serialsadditems,
358
        $manualhistory, $internalnotes, $serialsadditems,
358
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
359
        $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate,
359
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
360
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
360
    );
361
    );
361
    if ( (C4::Context->preference('Mana') == 1) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
362
    if ( (C4::Context->preference('Mana') == 1) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){
362
        my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription');
363
        my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription');
Lines 438-443 sub redirect_mod_subscription { Link Here
438
    my $previousitemtype  = $query->param('previousitemtype');
439
    my $previousitemtype  = $query->param('previousitemtype');
439
    my $skip_serialseq    = $query->param('skip_serialseq');
440
    my $skip_serialseq    = $query->param('skip_serialseq');
440
    my $ccode             = $query->param('ccode');
441
    my $ccode             = $query->param('ccode');
442
    my $published_on_template = $query->param('published_on_template');
441
443
442
    my $mana_id;
444
    my $mana_id;
443
    if ( $query->param('mana_id') ne "" ) {
445
    if ( $query->param('mana_id') ne "" ) {
Lines 473-479 sub redirect_mod_subscription { Link Here
473
        $status, $biblionumber, $callnumber, $notes, $letter,
475
        $status, $biblionumber, $callnumber, $notes, $letter,
474
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
476
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
475
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
477
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
476
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
478
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
477
    );
479
    );
478
480
479
    my @additional_fields;
481
    my @additional_fields;
(-)a/t/db_dependent/Koha/Items.t (-3 / +7 lines)
Lines 1775-1781 subtest 'move_to_biblio() tests' => sub { Link Here
1775
1775
1776
subtest 'search_ordered' => sub {
1776
subtest 'search_ordered' => sub {
1777
1777
1778
    plan tests => 6;
1778
    plan tests => 9;
1779
1779
1780
    $schema->storage->txn_begin;
1780
    $schema->storage->txn_begin;
1781
1781
Lines 1837-1843 subtest 'search_ordered' => sub { Link Here
1837
                value => {
1837
                value => {
1838
                    biblionumber  => $biblio->biblionumber,
1838
                    biblionumber  => $biblio->biblionumber,
1839
                    periodicity   => $sub_freq->{id},
1839
                    periodicity   => $sub_freq->{id},
1840
                    numberpattern => $sub_np->{id}
1840
                    numberpattern => $sub_np->{id},
1841
                    published_on_template => "[% publisheddatetext %] [% biblionumber %]",
1841
                }
1842
                }
1842
            }
1843
            }
1843
        );
1844
        );
Lines 1892-1897 subtest 'search_ordered' => sub { Link Here
1892
            [ $item3->itemnumber, $item2->itemnumber, $item1->itemnumber ],
1893
            [ $item3->itemnumber, $item2->itemnumber, $item1->itemnumber ],
1893
            "serial - order by enumchron" );
1894
            "serial - order by enumchron" );
1894
1895
1896
        is( $serial1->publisheddatetext, "publisheddatetext " . $biblio->biblionumber, "Column publisheddatetext rendered correctly from template for serial1" );
1897
        is( $serial2->publisheddatetext, "publisheddatetext " . $biblio->biblionumber, "Column publisheddatetext rendered correctly from template for serial2" );
1898
        is( $serial3->publisheddatetext, "publisheddatetext " . $biblio->biblionumber, "Column publisheddatetext rendered correctly from template for serial3" );
1899
1895
    }
1900
    }
1896
1901
1897
    $schema->storage->txn_rollback;
1902
    $schema->storage->txn_rollback;
1898
- 

Return to bug 33039