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

(-)a/C4/Letters.pm (-73 / +8 lines)
Lines 38-43 use Koha::SMS::Providers; Link Here
38
use Koha::Email;
38
use Koha::Email;
39
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
39
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
40
use Koha::Patrons;
40
use Koha::Patrons;
41
use Koha::Subscriptions;
41
42
42
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
43
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
43
44
Lines 45-51 BEGIN { Link Here
45
    require Exporter;
46
    require Exporter;
46
    @ISA = qw(Exporter);
47
    @ISA = qw(Exporter);
47
    @EXPORT = qw(
48
    @EXPORT = qw(
48
        &GetLetters &GetLettersAvailableForALibrary &GetLetterTemplates &DelLetter &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &SendAlerts &GetPrintMessages &GetMessageTransportTypes
49
        &GetLetters &GetLettersAvailableForALibrary &GetLetterTemplates &DelLetter &GetPreparedLetter &GetWrappedLetter &SendAlerts &GetPrintMessages &GetMessageTransportTypes
49
    );
50
    );
50
}
51
}
51
52
Lines 265-335 sub DelLetter { Link Here
265
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
266
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
266
}
267
}
267
268
268
=head2 addalert ($borrowernumber, $subscriptionid)
269
270
    parameters : 
271
    - $borrowernumber : the number of the borrower subscribing to the alert
272
    - $subscriptionid
273
274
    create an alert and return the alertid (primary key)
275
276
=cut
277
278
sub addalert {
279
    my ( $borrowernumber, $subscriptionid) = @_;
280
    my $dbh = C4::Context->dbh;
281
    my $sth =
282
      $dbh->prepare(
283
        "insert into alert (borrowernumber, externalid) values (?,?)");
284
    $sth->execute( $borrowernumber, $subscriptionid );
285
286
    # get the alert number newly created and return it
287
    my $alertid = $dbh->{'mysql_insertid'};
288
    return $alertid;
289
}
290
291
=head2 delalert ($alertid)
292
293
    parameters :
294
    - alertid : the alert id
295
    deletes the alert
296
297
=cut
298
299
sub delalert {
300
    my $alertid = shift or die "delalert() called without valid argument (alertid)";    # it's gonna die anyway.
301
    $debug and warn "delalert: deleting alertid $alertid";
302
    my $sth = C4::Context->dbh->prepare("delete from alert where alertid=?");
303
    $sth->execute($alertid);
304
}
305
306
=head2 getalert ([$borrowernumber], [$subscriptionid])
307
308
    parameters :
309
    - $borrowernumber : the number of the borrower subscribing to the alert
310
    - $subscriptionid
311
    all parameters NON mandatory. If a parameter is omitted, the query is done without the corresponding parameter. For example, without $subscriptionid, returns all alerts for a borrower on a topic.
312
313
=cut
314
315
sub getalert {
316
    my ( $borrowernumber, $subscriptionid ) = @_;
317
    my $dbh   = C4::Context->dbh;
318
    my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
319
    my @bind;
320
    if ($borrowernumber and $borrowernumber =~ /^\d+$/) {
321
        $query .= " AND borrowernumber=?";
322
        push @bind, $borrowernumber;
323
    }
324
    if ($subscriptionid) {
325
        $query .= " AND externalid=?";
326
        push @bind, $subscriptionid;
327
    }
328
    my $sth = $dbh->prepare($query);
329
    $sth->execute(@bind);
330
    return $sth->fetchall_arrayref({});
331
}
332
333
=head2 SendAlerts
269
=head2 SendAlerts
334
270
335
    my $err = &SendAlerts($type, $externalid, $letter_code);
271
    my $err = &SendAlerts($type, $externalid, $letter_code);
Lines 378-399 sub SendAlerts { Link Here
378
             return;
314
             return;
379
315
380
        my %letter;
316
        my %letter;
381
        # find the list of borrowers to alert
317
        # find the list of subscribers to notify
382
        my $alerts = getalert( '', $subscriptionid );
318
        my $subscription = Koha::Subscriptions->find( $subscriptionid );
383
        foreach (@$alerts) {
319
        my $subscribers = $subscription->subscribers;
384
            my $patron = Koha::Patrons->find( $_->{borrowernumber} );
320
        while ( my $patron = $subscribers->next ) {
385
            next unless $patron; # Just in case
386
            my $email = $patron->email or next;
321
            my $email = $patron->email or next;
387
322
388
#                    warn "sending issues...";
323
#                    warn "sending issues...";
389
            my $userenv = C4::Context->userenv;
324
            my $userenv = C4::Context->userenv;
390
            my $library = Koha::Libraries->find( $_->{branchcode} );
325
            my $library = $patron->library;
391
            my $letter = GetPreparedLetter (
326
            my $letter = GetPreparedLetter (
392
                module => 'serial',
327
                module => 'serial',
393
                letter_code => $letter_code,
328
                letter_code => $letter_code,
394
                branchcode => $userenv->{branch},
329
                branchcode => $userenv->{branch},
395
                tables => {
330
                tables => {
396
                    'branches'    => $_->{branchcode},
331
                    'branches'    => $library->branchcode,
397
                    'biblio'      => $biblionumber,
332
                    'biblio'      => $biblionumber,
398
                    'biblioitems' => $biblionumber,
333
                    'biblioitems' => $biblionumber,
399
                    'borrowers'   => $patron->unblessed,
334
                    'borrowers'   => $patron->unblessed,
(-)a/Koha/Subscription.pm (+46 lines)
Lines 48-53 sub biblio { Link Here
48
    return scalar Koha::Biblios->find($self->biblionumber);
48
    return scalar Koha::Biblios->find($self->biblionumber);
49
}
49
}
50
50
51
=head3 subscribers
52
53
my $subscribers = $subscription->subscribers;
54
55
return a Koha::Patrons object
56
57
=cut
58
59
sub subscribers {
60
    my ($self) = @_;
61
    my $schema = Koha::Database->new->schema;
62
    my @borrowernumbers = $schema->resultset('Alert')->search({ externalid => $self->subscriptionid })->get_column( 'borrowernumber' )->all;
63
    return Koha::Patrons->search({ borrowernumber => {-in => \@borrowernumbers } });
64
}
65
66
=head3 add_subscriber
67
68
$subscription->add_subscriber( $patron );
69
70
Add a new subscriber (Koha::Patron) to this subscription
71
72
=cut
73
74
sub add_subscriber {
75
    my ( $self, $patron )  = @_;
76
    my $schema = Koha::Database->new->schema;
77
    my $rs = $schema->resultset('Alert');
78
    $rs->create({ externalid => $self->subscriptionid, borrowernumber => $patron->borrowernumber });
79
}
80
81
=head3 remove_subscriber
82
83
$subscription->remove_subscriber( $subscriber );
84
85
Remove a subscriber (Koha::Patron) from this subscription
86
87
=cut
88
89
sub remove_subscriber {
90
    my ($self, $patron) = @_;
91
    my $schema = Koha::Database->new->schema;
92
    my $rs = $schema->resultset('Alert');
93
    my $subscriber = $rs->find({ externalid => $self->subscriptionid, borrowernumber => $patron->borrowernumber });
94
    $subscriber->delete if $subscriber;
95
}
96
51
=head3 type
97
=head3 type
52
98
53
=cut
99
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/viewalerts.tt (-3 / +4 lines)
Lines 19-32 Link Here
19
    <span class="label">Subscription:</span> <a href="subscription-detail.pl?subscriptionid=[% subscriptionid %]">[% bibliotitle %] #[% subscriptionid %]</a>
19
    <span class="label">Subscription:</span> <a href="subscription-detail.pl?subscriptionid=[% subscriptionid %]">[% bibliotitle %] #[% subscriptionid %]</a>
20
</p>
20
</p>
21
21
22
[% IF ( alertloop ) %]
22
[% IF subscribers.count %]
23
    <table>
23
    <table>
24
        <tr>
24
        <tr>
25
            <th>Patron name</th>
25
            <th>Patron name</th>
26
        </tr>
26
        </tr>
27
        [% FOREACH alertloo IN alertloop %]
27
        [% FOREACH subscriber IN subscribers %]
28
        <tr>
28
        <tr>
29
            <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% alertloo.borrowernumber %]">[% alertloo.name %]</a></td>
29
            [%# FIXME use patron-title when 18403 will be pushed %]
30
            <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% subscriber.borrowernumber %]">[% subscriber.firstname %] [% subscriber.surname %]</a></td>
30
        </tr>
31
        </tr>
31
        [% END %]
32
        [% END %]
32
    </table>
33
    </table>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-alert-subscribe.tt (-2 / +2 lines)
Lines 24-30 Link Here
24
                                <p>Do you want to receive an email when a new issue for this subscription arrives?</p>
24
                                <p>Do you want to receive an email when a new issue for this subscription arrives?</p>
25
                                <h4>[% bibliotitle %]</h4>
25
                                <h4>[% bibliotitle %]</h4>
26
                                [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
26
                                [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
27
                                <input type="hidden" name="externalid" value="[% externalid %]">
27
                                <input type="hidden" name="subscriptionid" value="[% subscriptionid %]">
28
                                <input type="hidden" name="referer" value="[% referer %]">
28
                                <input type="hidden" name="referer" value="[% referer %]">
29
                                <input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
29
                                <input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
30
                                <input type="hidden" name="op" value="alert_confirmed">
30
                                <input type="hidden" name="op" value="alert_confirmed">
Lines 38-44 Link Here
38
                                <p>Please confirm that you do not want to receive email when a new issue arrives for this subscription.</p>
38
                                <p>Please confirm that you do not want to receive email when a new issue arrives for this subscription.</p>
39
                                <h4>[% bibliotitle %]</h4>
39
                                <h4>[% bibliotitle %]</h4>
40
                                [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
40
                                [% IF ( notes ) %]<p>[% notes %]</p>[% END %]
41
                                <input type="hidden" name="externalid" value="[% externalid %]">
41
                                <input type="hidden" name="subscriptionid" value="[% subscriptionid %]">
42
                                <input type="hidden" name="referer" value="[% referer %]">
42
                                <input type="hidden" name="referer" value="[% referer %]">
43
                                <input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
43
                                <input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
44
                                <input type="hidden" name="op" value="cancel_confirmed">
44
                                <input type="hidden" name="op" value="cancel_confirmed">
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt (-2 / +2 lines)
Lines 833-841 Link Here
833
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
833
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
834
                                    [% IF ( loggedinusername ) %]
834
                                    [% IF ( loggedinusername ) %]
835
                                        [% IF ( subscription.hasalert ) %]
835
                                        [% IF ( subscription.hasalert ) %]
836
                                            <span>You have subscribed to email notification on new issues. </span><a style="color:#000;" class="btn" title="Cancel email notification" href="/cgi-bin/koha/opac-alert-subscribe.pl?op=cancel&amp;externalid=[% subscription.subscriptionid %]&amp;biblionumber=[% subscription.biblionumber %]">Cancel email notification</a>
836
                                            <span>You have subscribed to email notification on new issues. </span><a style="color:#000;" class="btn" title="Cancel email notification" href="/cgi-bin/koha/opac-alert-subscribe.pl?op=cancel&amp;subscriptionid=[% subscription.subscriptionid %]&amp;biblionumber=[% subscription.biblionumber %]">Cancel email notification</a>
837
                                        [% ELSE %]
837
                                        [% ELSE %]
838
                                            <a style="color:#000;" class="btn" title="Subscribe to email notification on new issues" href="/cgi-bin/koha/opac-alert-subscribe.pl?externalid=[% subscription.subscriptionid %]&amp;biblionumber=[% subscription.biblionumber %]">Subscribe to email notification on new issues</a>
838
                                            <a style="color:#000;" class="btn" title="Subscribe to email notification on new issues" href="/cgi-bin/koha/opac-alert-subscribe.pl?subscriptionid=[% subscription.subscriptionid %]&amp;biblionumber=[% subscription.biblionumber %]">Subscribe to email notification on new issues</a>
839
                                        [% END %]
839
                                        [% END %]
840
                                    [% ELSE %]
840
                                    [% ELSE %]
841
                                        <span>You must log in if you want to subscribe to email notification on new issues</span>
841
                                        <span>You must log in if you want to subscribe to email notification on new issues</span>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-serial-issues.tt (-2 / +2 lines)
Lines 137-147 Link Here
137
                                    [% IF ( subscription_LOO.letter ) %]
137
                                    [% IF ( subscription_LOO.letter ) %]
138
                                        [% IF ( loggedinusername ) %]
138
                                        [% IF ( loggedinusername ) %]
139
                                            [% IF ( subscription_LOO.hasalert ) %]
139
                                            [% IF ( subscription_LOO.hasalert ) %]
140
                                                You have subscribed to email notification on new issues <a href="opac-alert-subscribe.pl?op=cancel&amp;externalid=[% subscription_LOO.subscriptionid %]&amp;referer=serial&amp;biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Cancel email notification">
140
                                                You have subscribed to email notification on new issues <a href="opac-alert-subscribe.pl?op=cancel&amp;subscriptionid=[% subscription_LOO.subscriptionid %]&amp;referer=serial&amp;biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Cancel email notification">
141
                                                    Cancel email notification
141
                                                    Cancel email notification
142
                                                </a>
142
                                                </a>
143
                                            [% ELSE %]
143
                                            [% ELSE %]
144
                                                <a href="opac-alert-subscribe.pl?externalid=[% subscription_LOO.subscriptionid %]&amp;referer=serial&amp;biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Subscribe to email notification on new issues">
144
                                                <a href="opac-alert-subscribe.pl?subscriptionid=[% subscription_LOO.subscriptionid %]&amp;referer=serial&amp;biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Subscribe to email notification on new issues">
145
                                                    Subscribe to email notification on new issues
145
                                                    Subscribe to email notification on new issues
146
                                                </a>
146
                                                </a>
147
                                            [% END %]
147
                                            [% END %]
(-)a/opac/opac-alert-subscribe.pl (-10 / +9 lines)
Lines 36-42 my $dbh = C4::Context->dbh; Link Here
36
36
37
my $sth;
37
my $sth;
38
my ( $template, $loggedinuser, $cookie );
38
my ( $template, $loggedinuser, $cookie );
39
my $externalid   = $query->param('externalid');
39
my $subscriptionid = $query->param('subscriptionid');
40
my $referer      = $query->param('referer') || 'detail';
40
my $referer      = $query->param('referer') || 'detail';
41
my $biblionumber = $query->param('biblionumber');
41
my $biblionumber = $query->param('biblionumber');
42
42
Lines 51-58 my $biblionumber = $query->param('biblionumber'); Link Here
51
    }
51
    }
52
);
52
);
53
53
54
my $subscription = Koha::Subscriptions->find( $subscriptionid );
55
my $logged_in_patron = Koha::Patrons->find( $loggedinuser );
56
54
if ( $op eq 'alert_confirmed' ) {
57
if ( $op eq 'alert_confirmed' ) {
55
    addalert( $loggedinuser, $externalid );
58
    $subscription->add_subscriber( $logged_in_patron );
56
    if ( $referer eq 'serial' ) {
59
    if ( $referer eq 'serial' ) {
57
        print $query->redirect(
60
        print $query->redirect(
58
            "opac-serial-issues.pl?biblionumber=$biblionumber");
61
            "opac-serial-issues.pl?biblionumber=$biblionumber");
Lines 64-75 if ( $op eq 'alert_confirmed' ) { Link Here
64
    }
67
    }
65
}
68
}
66
elsif ( $op eq 'cancel_confirmed' ) {
69
elsif ( $op eq 'cancel_confirmed' ) {
67
    my $alerts = getalert( $loggedinuser, $externalid );
70
    $subscription->remove_subscriber( $logged_in_patron );
68
    warn "CANCEL confirmed : $loggedinuser, $externalid".Data::Dumper::Dumper( $alerts );
71
    warn "CANCEL confirmed : $loggedinuser, $subscriptionid";
69
    foreach (@$alerts)
70
    {    # we are supposed to have only 1 result, but just in case...
71
        delalert( $_->{alertid} );
72
    }
73
    if ( $referer eq 'serial' ) {
72
    if ( $referer eq 'serial' ) {
74
        print $query->redirect(
73
        print $query->redirect(
75
            "opac-serial-issues.pl?biblionumber=$biblionumber");
74
            "opac-serial-issues.pl?biblionumber=$biblionumber");
Lines 83-95 elsif ( $op eq 'cancel_confirmed' ) { Link Here
83
82
84
}
83
}
85
else {
84
else {
86
    my $subscription = &GetSubscription($externalid);
85
    my $subscription = &GetSubscription($subscriptionid);
87
    $template->param(
86
    $template->param(
88
        referer        => $referer,
87
        referer        => $referer,
89
        "typeissue$op" => 1,
88
        "typeissue$op" => 1,
90
        bibliotitle    => $subscription->{bibliotitle},
89
        bibliotitle    => $subscription->{bibliotitle},
91
        notes          => $subscription->{notes},
90
        notes          => $subscription->{notes},
92
        externalid     => $externalid,
91
        subscriptionid     => $subscriptionid,
93
        biblionumber   => $biblionumber,
92
        biblionumber   => $biblionumber,
94
    );
93
    );
95
}
94
}
(-)a/opac/opac-detail.pl (-4 / +3 lines)
Lines 589-598 foreach my $subscription (@subscriptions) { Link Here
589
    $cell{latestserials} =
589
    $cell{latestserials} =
590
      GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
590
      GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
591
    if ( $borrowernumber ) {
591
    if ( $borrowernumber ) {
592
        my $sub = getalert($borrowernumber, $subscription->{subscriptionid});
592
        my $subscription_object = Koha::Subscriptions->find( $subscription->{subscriptionid} );
593
        if (@$sub[0]) {
593
        my $subscriber = $subscription_object->subscribers->find( $borrowernumber );
594
            $cell{hasalert} = 1;
594
        $cell{hasalert} = 1 if $subscriber;
595
        }
596
    }
595
    }
597
    push @subs, \%cell;
596
    push @subs, \%cell;
598
}
597
}
(-)a/opac/opac-serial-issues.pl (-9 / +7 lines)
Lines 62-71 if ( $selectview eq "full" ) { Link Here
62
    # now, check is there is an alert subscription for one of the subscriptions
62
    # now, check is there is an alert subscription for one of the subscriptions
63
    if ($loggedinuser) {
63
    if ($loggedinuser) {
64
        foreach (@$subscriptions) {
64
        foreach (@$subscriptions) {
65
            my $sub = getalert($loggedinuser, $_->{subscriptionid});
65
            my $subscription = Koha::Subscriptions->find( $_->{subscriptionid} );
66
            if ($sub) {
66
            my $subscriber = $subscription->subscribers->find( $loggedinuser );
67
                $_->{hasalert} = 1;
67
            $_->{hasalert} = 1 if $subscriber;
68
            }
69
        }
68
        }
70
    }
69
    }
71
70
Lines 100-111 else { Link Here
100
99
101
    my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
100
    my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
102
    # now, check is there is an alert subscription for one of the subscriptions
101
    # now, check is there is an alert subscription for one of the subscriptions
103
    if ($loggedinuser){
102
    if ($loggedinuser) {
104
        foreach (@$subscriptions) {
103
        foreach (@$subscriptions) {
105
            my $subscription = getalert($loggedinuser, $_->{subscriptionid});
104
            my $subscription = Koha::Subscriptions->find( $_->{subscriptionid} );
106
            if (@$subscription[0]) {
105
            my $subscriber = $subscription->subscribers->find( $loggedinuser );
107
                $_->{hasalert} = 1;
106
            $_->{hasalert} = 1 if $subscriber;
108
            }
109
        }
107
        }
110
    }
108
    }
111
109
(-)a/serials/viewalerts.pl (-20 / +13 lines)
Lines 23-36 use CGI qw ( -utf8 ); Link Here
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Context;
24
use C4::Context;
25
use C4::Output;
25
use C4::Output;
26
use C4::Koha;
27
use C4::Letters;
28
use C4::Serials;
29
26
30
my $dbh = C4::Context->dbh;
27
use Koha::Subscriptions;
31
28
32
my $input = new CGI;
29
my $input = new CGI;
33
my $print = $input->param('print');
34
30
35
my ($template, $loggedinuser, $cookie)
31
my ($template, $loggedinuser, $cookie)
36
    = get_template_and_user({template_name => 'serials/viewalerts.tt',
32
    = get_template_and_user({template_name => 'serials/viewalerts.tt',
Lines 41-60 my ($template, $loggedinuser, $cookie) Link Here
41
                 debug => 1,
37
                 debug => 1,
42
                 });
38
                 });
43
39
44
my $subscriptionid=$input->param('subscriptionid');
40
my $subscriptionid = $input->param('subscriptionid');
45
41
46
my $borrowers = getalert('', $subscriptionid);
42
my $subscription = Koha::Subscriptions->find( $subscriptionid );
47
my $subscription = GetSubscription($subscriptionid);
43
# FIXME raise a message if subscription does not exist (easy with 18403)
48
44
49
for my $borrowernumber (@$borrowers) {
45
my $subscribers = $subscription->subscribers;
50
    my $patron = Koha::Patrons->find( $borrowernumber );
46
51
    next unless $borrowernumber; # Just in case...
47
$template->param(
52
    $borrowers->{name} = join( ' ', $patron->firstname, $patron->surname );
48
    subscribers    => $subscribers,
53
}
49
    bibliotitle    => $subscription->biblio->title,
54
$template->param(alertloop => $borrowers,
50
    subscriptionid => $subscriptionid,
55
                bibliotitle => $subscription->{bibliotitle},
51
);
56
                subscriptionid => $subscriptionid,
57
                (uc(C4::Context->preference("marcflavour"))) => 1
58
                );
59
52
60
output_html_with_http_headers $input, $cookie, $template->output;
53
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/t/db_dependent/Koha/Subscription.t (-3 / +36 lines)
Lines 19-33 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
23
24
use Koha::Subscription;
24
use Koha::Subscription;
25
use Koha::Biblio;
25
use Koha::Biblio;
26
use t::lib::TestBuilder;
26
27
27
my $schema = Koha::Database->new->schema;
28
my $schema = Koha::Database->new->schema;
28
$schema->storage->txn_begin;
29
$schema->storage->txn_begin;
30
my $builder = t::lib::TestBuilder->new;
29
31
30
subtest 'Koha::Subscription::biblio' => sub {
32
subtest 'Koha::Subscription->biblio' => sub {
31
    plan tests => 1;
33
    plan tests => 1;
32
34
33
    my $biblio = Koha::Biblio->new()->store();
35
    my $biblio = Koha::Biblio->new()->store();
Lines 36-42 subtest 'Koha::Subscription::biblio' => sub { Link Here
36
    })->store();
38
    })->store();
37
39
38
    my $b = $subscription->biblio;
40
    my $b = $subscription->biblio;
39
    is($b->biblionumber, $biblio->biblionumber, 'Koha::Subscription::biblio returns the correct biblio');
41
    is($b->biblionumber, $biblio->biblionumber, 'Koha::Subscription->biblio returns the correct biblio');
42
};
43
44
subtest 'Notifications on new issues - add_subscriber|remove_subscriber|subscribers' => sub {
45
    plan tests => 5;
46
    my $subscriber_1 = $builder->build_object( { class => 'Koha::Patrons' });
47
    my $subscriber_2 = $builder->build_object( { class => 'Koha::Patrons' });
48
49
    my $subscription = Koha::Subscription->new({
50
        biblionumber => Koha::Biblio->new->store->biblionumber,
51
    })->store();
52
53
    my $subscribers = $subscription->subscribers;
54
    is( $subscribers->count, 0, '->subscribers should return 0 if there are no subscribers');
55
    is( ref($subscribers), 'Koha::Patrons', '->subscribers should return a Koha::Patrons object');
56
57
    $subscription->add_subscriber( $subscriber_1 );
58
    $subscription->add_subscriber( $subscriber_2 );
59
60
    $subscribers = $subscription->subscribers;
61
    is( $subscribers->count, 2, '->subscribers should return 2 if there are 2 subscribers' );
62
63
    $subscription->remove_subscriber( $subscriber_1 );
64
65
    $subscribers = $subscription->subscribers;
66
    is( $subscribers->count, 1, '->remove_subscriber should have remove the subscriber' );
67
68
    $subscription->remove_subscriber( $subscriber_1 ); # We do not explode if the patron is not a subscriber
69
70
    my $is_subscriber = $subscribers->find( $subscriber_2->borrowernumber );
71
    ok( $is_subscriber, 'This structure is used in the code and should work as expected' );
72
40
};
73
};
41
74
42
$schema->storage->txn_rollback;
75
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Letters.t (-39 / +5 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 75;
21
use Test::More tests => 64;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 48-53 use Koha::Acquisition::Bookseller::Contacts; Link Here
48
use Koha::Acquisition::Orders;
48
use Koha::Acquisition::Orders;
49
use Koha::Libraries;
49
use Koha::Libraries;
50
use Koha::Notice::Templates;
50
use Koha::Notice::Templates;
51
use Koha::Patrons;
52
use Koha::Subscriptions;
51
my $schema = Koha::Database->schema;
53
my $schema = Koha::Database->schema;
52
$schema->storage->txn_begin();
54
$schema->storage->txn_begin();
53
55
Lines 236-276 my $branchcode = 'FFL'; Link Here
236
my $letter14206_c = C4::Letters::getletter('my module', $overdue_rules->{"letter$i"}, $branchcode);
238
my $letter14206_c = C4::Letters::getletter('my module', $overdue_rules->{"letter$i"}, $branchcode);
237
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
239
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
238
240
239
# addalert
240
my $externalid = 'my external id';
241
my $alert_id = C4::Letters::addalert($borrowernumber, $externalid);
242
isnt( $alert_id, undef, 'addalert does not return undef' );
243
244
245
# getalert
246
my $alerts = C4::Letters::getalert();
247
is( @$alerts, 1, 'getalert should not fail without parameter' );
248
$alerts = C4::Letters::getalert($borrowernumber);
249
is( @$alerts, 1, 'addalert adds an alert' );
250
is( $alerts->[0]->{alertid}, $alert_id, 'addalert returns the alert id correctly' );
251
is( $alerts->[0]->{externalid}, $externalid, 'addalert stores the externalid correctly' );
252
253
$alerts = C4::Letters::getalert($borrowernumber);
254
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
255
$alerts = C4::Letters::getalert($borrowernumber, $externalid);
256
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
257
$alerts = C4::Letters::getalert($borrowernumber, 'another external id');
258
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
259
260
261
# delalert
262
eval {
263
    C4::Letters::delalert();
264
};
265
isnt( $@, undef, 'delalert without argument returns an error' );
266
$alerts = C4::Letters::getalert($borrowernumber);
267
is( @$alerts, 1, 'delalert without argument does not remove an alert' );
268
269
C4::Letters::delalert($alert_id);
270
$alerts = C4::Letters::getalert($borrowernumber);
271
is( @$alerts, 0, 'delalert removes an alert' );
272
273
274
# GetPreparedLetter
241
# GetPreparedLetter
275
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
242
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
276
243
Lines 509-516 my $borrowernumber = AddMember( Link Here
509
    dateofbirth  => $date,
476
    dateofbirth  => $date,
510
    email        => 'john.smith@test.de',
477
    email        => 'john.smith@test.de',
511
);
478
);
512
my $alert_id = C4::Letters::addalert($borrowernumber, $subscriptionid);
479
my $subscription = Koha::Subscriptions->find( $subscriptionid );
513
480
$subscription->add_subscriber( scalar Koha::Patrons->find( $borrowernumber ) );
514
481
515
my $err2;
482
my $err2;
516
warning_is {
483
warning_is {
517
- 

Return to bug 19855