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

(-)a/C4/Reserves.pm (-10 / +27 lines)
Lines 1889-1911 sub _koha_notify_reserve { Link Here
1889
    );
1889
    );
1890
1890
1891
    my $notification_sent = 0; #Keeping track if a Hold_filled message is sent. If no message can be sent, then default to a print message.
1891
    my $notification_sent = 0; #Keeping track if a Hold_filled message is sent. If no message can be sent, then default to a print message.
1892
    my $do_not_lock = ( exists $ENV{_} && $ENV{_} =~ m|prove| ) || $ENV{KOHA_TESTING};
1892
    my $send_notification = sub {
1893
    my $send_notification = sub {
1893
        my ( $mtt, $letter_code ) = (@_);
1894
        my ( $mtt, $letter_code, $wants_digest ) = (@_);
1894
        return unless defined $letter_code;
1895
        return unless defined $letter_code;
1895
        $letter_params{letter_code} = $letter_code;
1896
        $letter_params{letter_code}            = $letter_code;
1896
        $letter_params{message_transport_type} = $mtt;
1897
        $letter_params{message_transport_type} = $mtt;
1897
        my $letter =  C4::Letters::GetPreparedLetter ( %letter_params );
1898
        my $letter = C4::Letters::GetPreparedLetter(%letter_params);
1898
        unless ($letter) {
1899
        unless ($letter) {
1899
            warn "Could not find a letter called '$letter_params{'letter_code'}' for $mtt in the 'reserves' module";
1900
            warn "Could not find a letter called '$letter_params{'letter_code'}' for $mtt in the 'reserves' module";
1900
            return;
1901
            return;
1901
        }
1902
        }
1902
1903
1903
        C4::Letters::EnqueueLetter( {
1904
        unless ($wants_digest) {
1904
            letter => $letter,
1905
            C4::Letters::EnqueueLetter(
1905
            borrowernumber => $borrowernumber,
1906
                {
1906
            from_address => $from_email_address,
1907
                    letter                 => $letter,
1907
            message_transport_type => $mtt,
1908
                    borrowernumber         => $borrowernumber,
1908
        } );
1909
                    from_address           => $from_email_address,
1910
                    message_transport_type => $mtt,
1911
                }
1912
            );
1913
        } else {
1914
            C4::Context->dbh->do(q|LOCK TABLE message_queue READ|)  unless $do_not_lock;
1915
            C4::Context->dbh->do(q|LOCK TABLE message_queue WRITE|) unless $do_not_lock;
1916
            my $message = C4::Message->find_last_message( $patron->unblessed, $letter_code, $mtt );
1917
            unless ($message) {
1918
                C4::Context->dbh->do(q|UNLOCK TABLES|) unless $do_not_lock;
1919
                C4::Message->enqueue( $letter, $patron, $mtt );
1920
            } else {
1921
                $message->append($letter);
1922
                $message->update;
1923
            }
1924
            C4::Context->dbh->do(q|UNLOCK TABLES|) unless $do_not_lock;
1925
        }
1909
    };
1926
    };
1910
1927
1911
    while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
1928
    while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
Lines 1916-1922 sub _koha_notify_reserve { Link Here
1916
            or ( $mtt eq 'phone' and not $patron->phone ) # No phone number to call
1933
            or ( $mtt eq 'phone' and not $patron->phone ) # No phone number to call
1917
        );
1934
        );
1918
1935
1919
        &$send_notification($mtt, $letter_code);
1936
        &$send_notification($mtt, $letter_code, $messagingprefs->{wants_digest});
1920
        $notification_sent++;
1937
        $notification_sent++;
1921
    }
1938
    }
1922
    #Making sure that a print notification is sent if no other transport types can be utilized.
1939
    #Making sure that a print notification is sent if no other transport types can be utilized.
(-)a/installer/data/mysql/atomicupdate/bug_8838.pl (+37 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "8838",
5
    description => "Add digest option for HOLD notice",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{
11
            INSERT INTO `letter` VALUES (NULL,'reserves','HOLDDGST','','Hold available for pickup (digest)',0,'Hold(s) available for pickup','You have one or more holds available for pickup:\r\n----\r\nTitle: [% hold.biblio.title %]\r\nAuthor: [% hold.biblio.author %]\r\nCopy: [% hold.item.copynumber %]\r\nLocation: [% hold.branch.branchname %]\r\nWaiting since: [% hold.waitingdate %]:\r\n[% hold.branch.branchaddress1 %]\r\n[% hold.branch.branchaddress2 %]\r\n[% hold.branch.branchaddress3 %]\r\n[% hold.branch.branchcity %] [% hold.branch.branchzip %]\r\n----','email','default','2023-08-29 18:42:15');
12
        });
13
14
        $dbh->do(q{
15
            INSERT INTO message_transports VALUES
16
            ( 4, "email", 1, "reserves", "HOLDDGST", "" ),
17
            ( 4, "sms", 1, "reserves", "HOLDDGST", "" ),
18
            ( 4, "phone", 1, "reserves", "HOLDDGST", "");
19
        });
20
21
        # Print useful stuff here
22
        # tables
23
        say $out "Added new table 'XXX'";
24
        say $out "Added column 'XXX.YYY'";
25
26
        # sysprefs
27
        say $out "Added new system preference 'XXX'";
28
        say $out "Updated system preference 'XXX'";
29
        say $out "Removed system preference 'XXX'";
30
31
        # permissions
32
        say $out "Added new permission 'XXX'";
33
34
        # letters
35
        say $out "Added new letter 'XXX' (TRANSPORT)";
36
    },
37
};
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+23 lines)
Lines 1771-1776 tables: Link Here
1771
            - "<<branches.branchaddress3>>"
1771
            - "<<branches.branchaddress3>>"
1772
            - "<<branches.branchcity>> <<branches.branchzip>>"
1772
            - "<<branches.branchcity>> <<branches.branchzip>>"
1773
1773
1774
        - module: reserves
1775
          code: HOLDDGST
1776
          branchcode: ""
1777
          name: "Hold(s) available for pickup"
1778
          is_html: 0
1779
          title: "Hold(s) available for pickup"
1780
          message_transport_type: email
1781
          lang: default
1782
          content:
1783
            - "You have one or more holds available for pickup:"
1784
            - "----"
1785
            - "Title: [% hold.biblio.title %]"
1786
            - "Author: [% hold.biblio.author %]"
1787
            - "Copy: [% hold.item.copynumber %]"
1788
            - "Waiting since: [% hold.waitingdate %]"
1789
            - "Waitng at: [% hold.branch.branchname %]"
1790
            - "[% hold.branch.branchaddress1 %]"
1791
            - "[% hold.branch.branchaddress2 %]"
1792
            - "[% hold.branch.branchaddress3 %]"
1793
            - "[% hold.branch.branchcity %] [% hold.branch.branchzip %]"
1794
            - "----"
1795
            - "Thank you!"
1796
1774
        - module: reserves
1797
        - module: reserves
1775
          code: HOLD
1798
          code: HOLD
1776
          branchcode: ""
1799
          branchcode: ""
(-)a/installer/data/mysql/mandatory/sample_notices_message_transports.sql (+3 lines)
Lines 19-24 values Link Here
19
(4, 'sms',   0, 'reserves',    'HOLD'),
19
(4, 'sms',   0, 'reserves',    'HOLD'),
20
(4, 'phone', 0, 'reserves',    'HOLD'),
20
(4, 'phone', 0, 'reserves',    'HOLD'),
21
(4, 'itiva', 0, 'reserves',    'HOLD'),
21
(4, 'itiva', 0, 'reserves',    'HOLD'),
22
(4, 'email', 1, 'reserves',    'HOLDDGST'),
23
(4, 'sms',   1, 'reserves',    'HOLDDGST'),
24
(4, 'phone', 1, 'reserves',    'HOLDDGST'),
22
(5, 'email', 0, 'circulation', 'CHECKIN'),
25
(5, 'email', 0, 'circulation', 'CHECKIN'),
23
(5, 'sms',   0, 'circulation', 'CHECKIN'),
26
(5, 'sms',   0, 'circulation', 'CHECKIN'),
24
(5, 'phone', 0, 'circulation', 'CHECKIN'),
27
(5, 'phone', 0, 'circulation', 'CHECKIN'),
(-)a/t/db_dependent/Reserves.t (-2 / +104 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 77;
20
use Test::More tests => 78;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 1773-1775 subtest 'DefaultHoldExpiration tests' => sub { Link Here
1773
1773
1774
    $schema->txn_rollback;
1774
    $schema->txn_rollback;
1775
};
1775
};
1776
- 
1776
1777
subtest 'HOLDDGST tests' => sub {
1778
1779
    plan tests => 2;
1780
    $schema->storage->txn_begin;
1781
1782
    my $branch = $builder->build_object({
1783
        class => 'Koha::Libraries',
1784
        value => {
1785
            branchemail => 'branch@e.mail',
1786
            branchreplyto => 'branch@reply.to',
1787
            pickup_location => 1
1788
        }
1789
    });
1790
    my $item = $builder->build_sample_item({
1791
        homebranch => $branch->branchcode,
1792
        holdingbranch => $branch->branchcode
1793
    });
1794
    my $item2 = $builder->build_sample_item({
1795
        homebranch => $branch->branchcode,
1796
        holdingbranch => $branch->branchcode
1797
    });
1798
1799
    my $wants_hold_and_email = {
1800
        wants_digest => '1',
1801
        transports => {
1802
            sms => 'HOLDDGST',
1803
            email => 'HOLDDGST',
1804
            },
1805
        letter_code => 'HOLDDGST'
1806
    };
1807
1808
    my $mp = Test::MockModule->new( 'C4::Members::Messaging' );
1809
1810
    $mp->mock("GetMessagingPreferences",$wants_hold_and_email);
1811
1812
    $dbh->do('DELETE FROM letter');
1813
1814
    my $email_hold_notice = $builder->build({
1815
            source => 'Letter',
1816
            value => {
1817
                message_transport_type => 'email',
1818
                branchcode => '',
1819
                code => 'HOLDDGST',
1820
                module => 'reserves',
1821
                lang => 'default',
1822
            }
1823
        });
1824
1825
    my $sms_hold_notice = $builder->build({
1826
            source => 'Letter',
1827
            value => {
1828
                message_transport_type => 'sms',
1829
                branchcode => '',
1830
                code => 'HOLDDGST',
1831
                module => 'reserves',
1832
                lang=>'default',
1833
            }
1834
        });
1835
1836
    my $hold_borrower = $builder->build({
1837
            source => 'Borrower',
1838
            value => {
1839
                smsalertnumber=>'5555555551',
1840
                email=>'a@c.com',
1841
            }
1842
        })->{borrowernumber};
1843
1844
    C4::Reserves::AddReserve(
1845
        {
1846
            branchcode     => $item->homebranch,
1847
            borrowernumber => $hold_borrower,
1848
            biblionumber   => $item->biblionumber,
1849
        }
1850
    );
1851
1852
    C4::Reserves::AddReserve(
1853
        {
1854
            branchcode     => $item2->homebranch,
1855
            borrowernumber => $hold_borrower,
1856
            biblionumber   => $item2->biblionumber,
1857
        }
1858
    );
1859
1860
    ModReserveAffect($item->itemnumber, $hold_borrower, 0);
1861
    ModReserveAffect($item2->itemnumber, $hold_borrower, 0);
1862
1863
    my $sms_count = $schema->resultset('MessageQueue')->search({
1864
            letter_code     => 'HOLDDGST',
1865
            message_transport_type => 'sms',
1866
            borrowernumber => $hold_borrower,
1867
        })->count;
1868
    is($sms_count, 1 ,"Only one sms hold digest message created for two holds");
1869
1870
    my $email_count = $schema->resultset('MessageQueue')->search({
1871
            letter_code     => 'HOLDDGST',
1872
            message_transport_type => 'email',
1873
            borrowernumber => $hold_borrower,
1874
        })->count;
1875
    is($email_count, 1 ,"Only one email hold digest message created for two holds");
1876
1877
    $schema->txn_rollback;
1878
};

Return to bug 8838