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

(-)a/C4/Serials.pm (-10 / +70 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-48 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;
43
use Koha::Subscription::Histories;
44
use Koha::SharedContent;
46
use Koha::SharedContent;
45
use Scalar::Util qw( looks_like_number );
47
use Koha::Subscription::Histories;
48
use Koha::Subscriptions;
46
49
47
# Define statuses
50
# Define statuses
48
use constant {
51
use constant {
Lines 893-898 sub GetNextSeq { Link Here
893
            my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale );
896
            my $newlastvalue3string = _numeration( $newlastvalue3, $pattern->{numbering3}, $locale );
894
            $calculated =~ s/\{Z\}/$newlastvalue3string/g;
897
            $calculated =~ s/\{Z\}/$newlastvalue3string/g;
895
        }
898
        }
899
896
    }
900
    }
897
901
898
    return ($calculated,
902
    return ($calculated,
Lines 1286-1292 sub ModSubscription { Link Here
1286
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1290
    $biblionumber, $callnumber, $notes, $letter, $manualhistory,
1287
    $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1291
    $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount,
1288
    $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq,
1292
    $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq,
1289
    $itemtype, $previousitemtype, $mana_id, $ccode
1293
    $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
1290
    ) = @_;
1294
    ) = @_;
1291
1295
1292
    my $subscription = Koha::Subscriptions->find($subscriptionid);
1296
    my $subscription = Koha::Subscriptions->find($subscriptionid);
Lines 1330-1335 sub ModSubscription { Link Here
1330
            previousitemtype  => $previousitemtype,
1334
            previousitemtype  => $previousitemtype,
1331
            mana_id           => $mana_id,
1335
            mana_id           => $mana_id,
1332
            ccode             => $ccode,
1336
            ccode             => $ccode,
1337
            published_on_template => $published_on_template,
1333
        }
1338
        }
1334
    )->store;
1339
    )->store;
1335
    # FIXME Must be $subscription->serials
1340
    # FIXME Must be $subscription->serials
Lines 1367-1373 sub NewSubscription { Link Here
1367
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1372
    $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity,
1368
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1373
    $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes,
1369
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1374
    $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod,
1370
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
1375
    $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode,
1376
    $published_on_template,
1371
    ) = @_;
1377
    ) = @_;
1372
    my $dbh = C4::Context->dbh;
1378
    my $dbh = C4::Context->dbh;
1373
1379
Lines 1410-1416 sub NewSubscription { Link Here
1410
            itemtype          => $itemtype,
1416
            itemtype          => $itemtype,
1411
            previousitemtype  => $previousitemtype,
1417
            previousitemtype  => $previousitemtype,
1412
            mana_id           => $mana_id,
1418
            mana_id           => $mana_id,
1413
            ccode             => $ccode
1419
            ccode             => $ccode,
1420
            published_on_template => $published_on_template,
1414
        }
1421
        }
1415
    )->store;
1422
    )->store;
1416
    $subscription->discard_changes;
1423
    $subscription->discard_changes;
Lines 1586-1591 sub NewIssue { Link Here
1586
1593
1587
    my $subscription = Koha::Subscriptions->find( $subscriptionid );
1594
    my $subscription = Koha::Subscriptions->find( $subscriptionid );
1588
1595
1596
    if ( my $template = $subscription->published_on_template ) {
1597
        # If we detect a TT opening tag, run string through Template Toolkit Processor
1598
        if ( index( $template, '[%' ) != -1 ) { # Much faster than regex
1599
            my $use_template_cache = C4::Context->config('template_cache_dir')
1600
              && defined $ENV{GATEWAY_INTERFACE};
1601
1602
            my $tt = Template->new(
1603
                {
1604
                    EVAL_PERL   => 1,
1605
                    ABSOLUTE    => 1,
1606
                    PLUGIN_BASE => 'Koha::Template::Plugin',
1607
                    COMPILE_EXT => $use_template_cache ? '.ttc' : '',
1608
                    COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
1609
                    FILTERS      => {},
1610
                    ENCODING     => 'UTF-8',
1611
                }
1612
            ) or die Template->error();
1613
1614
            my $schema = Koha::Database->new->schema;
1615
1616
            $schema->txn_begin;
1617
            try {
1618
                $tt->process(
1619
                    \$template,
1620
                    {
1621
                        subscription      => $subscription,
1622
                        serialseq         => $serialseq,
1623
                        serialseq_x       => $subscription->lastvalue1(),
1624
                        serialseq_y       => $subscription->lastvalue2(),
1625
                        serialseq_z       => $subscription->lastvalue3(),
1626
                        subscriptionid    => $subscriptionid,
1627
                        biblionumber      => $biblionumber,
1628
                        status            => $status,
1629
                        planneddate       => $planneddate,
1630
                        publisheddate     => $publisheddate,
1631
                        publisheddatetext => $publisheddatetext,
1632
                        notes             => $notes,
1633
                        routingnotes      => $routingnotes,
1634
                    },
1635
                    \$publisheddatetext
1636
                );
1637
            }
1638
            catch {
1639
                croak "ERROR PROCESSING TEMPLATE: $_ :: " . $template->error();
1640
            }
1641
            finally {
1642
                $schema->txn_rollback;
1643
            };
1644
        } else {
1645
            $publisheddatetext = $template;
1646
        }
1647
    }
1648
1589
    my $serial = Koha::Serial->new(
1649
    my $serial = Koha::Serial->new(
1590
        {
1650
        {
1591
            serialseq         => $serialseq,
1651
            serialseq         => $serialseq,
Lines 1599-1605 sub NewIssue { Link Here
1599
            publisheddate     => $publisheddate,
1659
            publisheddate     => $publisheddate,
1600
            publisheddatetext => $publisheddatetext,
1660
            publisheddatetext => $publisheddatetext,
1601
            notes             => $notes,
1661
            notes             => $notes,
1602
            routingnotes      => $routingnotes
1662
            routingnotes      => $routingnotes,
1603
        }
1663
        }
1604
    )->store();
1664
    )->store();
1605
1665
(-)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 5458-5463 CREATE TABLE `subscription` ( Link Here
5458
  `previousitemtype` varchar(10) DEFAULT NULL,
5458
  `previousitemtype` varchar(10) DEFAULT NULL,
5459
  `mana_id` int(11) DEFAULT NULL,
5459
  `mana_id` int(11) DEFAULT NULL,
5460
  `ccode` varchar(80) DEFAULT NULL COMMENT 'collection code to assign to serial items',
5460
  `ccode` varchar(80) DEFAULT NULL COMMENT 'collection code to assign to serial items',
5461
  `published_on_template` TEXT DEFAULT NULL COMMENT 'Template Toolkit syntax to generate the default "Published on (text)" field when receiving an issue this serial',
5461
  PRIMARY KEY (`subscriptionid`),
5462
  PRIMARY KEY (`subscriptionid`),
5462
  KEY `subscription_ibfk_1` (`periodicity`),
5463
  KEY `subscription_ibfk_1` (`periodicity`),
5463
  KEY `subscription_ibfk_2` (`numberpattern`),
5464
  KEY `subscription_ibfk_2` (`numberpattern`),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (+4 lines)
Lines 389-394 fieldset.rows table { clear: none; margin: 0; } Link Here
389
                                        </select>
389
                                        </select>
390
                                        <span class="required">Required</span>
390
                                        <span class="required">Required</span>
391
                                    </li>
391
                                    </li>
392
                                    <li>
393
                                        <label for="published_on_template">Publication date template:</label>
394
                                        <textarea id="published_on_template" name="published_on_template">[% published_on_template | html %]</textarea>
395
                                    </li>
392
                                    <li>
396
                                    <li>
393
                                        <label for="locale">Locale:</label>
397
                                        <label for="locale">Locale:</label>
394
                                        <select id="locale" name="locale">
398
                                        <select id="locale" name="locale">
(-)a/serials/subscription-add.pl (-3 / +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 445-450 sub redirect_mod_subscription { Link Here
445
    my $previousitemtype  = $query->param('previousitemtype');
446
    my $previousitemtype  = $query->param('previousitemtype');
446
    my $skip_serialseq    = $query->param('skip_serialseq');
447
    my $skip_serialseq    = $query->param('skip_serialseq');
447
    my $ccode             = $query->param('ccode');
448
    my $ccode             = $query->param('ccode');
449
    my $published_on_template = $query->param('published_on_template');
448
450
449
    my $mana_id;
451
    my $mana_id;
450
    if ( $query->param('mana_id') ne "" ) {
452
    if ( $query->param('mana_id') ne "" ) {
Lines 480-486 sub redirect_mod_subscription { Link Here
480
        $status, $biblionumber, $callnumber, $notes, $letter,
482
        $status, $biblionumber, $callnumber, $notes, $letter,
481
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
483
        $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount,
482
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
484
        $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid,
483
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode
485
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
484
    );
486
    );
485
487
486
    my @additional_fields;
488
    my @additional_fields;
487
- 

Return to bug 33039