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 262-332 sub DelLetter { Link Here
262
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
263
    , undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
263
}
264
}
264
265
265
=head2 addalert ($borrowernumber, $subscriptionid)
266
267
    parameters : 
268
    - $borrowernumber : the number of the borrower subscribing to the alert
269
    - $subscriptionid
270
271
    create an alert and return the alertid (primary key)
272
273
=cut
274
275
sub addalert {
276
    my ( $borrowernumber, $subscriptionid) = @_;
277
    my $dbh = C4::Context->dbh;
278
    my $sth =
279
      $dbh->prepare(
280
        "insert into alert (borrowernumber, externalid) values (?,?)");
281
    $sth->execute( $borrowernumber, $subscriptionid );
282
283
    # get the alert number newly created and return it
284
    my $alertid = $dbh->{'mysql_insertid'};
285
    return $alertid;
286
}
287
288
=head2 delalert ($alertid)
289
290
    parameters :
291
    - alertid : the alert id
292
    deletes the alert
293
294
=cut
295
296
sub delalert {
297
    my $alertid = shift or die "delalert() called without valid argument (alertid)";    # it's gonna die anyway.
298
    $debug and warn "delalert: deleting alertid $alertid";
299
    my $sth = C4::Context->dbh->prepare("delete from alert where alertid=?");
300
    $sth->execute($alertid);
301
}
302
303
=head2 getalert ([$borrowernumber], [$subscriptionid])
304
305
    parameters :
306
    - $borrowernumber : the number of the borrower subscribing to the alert
307
    - $subscriptionid
308
    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.
309
310
=cut
311
312
sub getalert {
313
    my ( $borrowernumber, $subscriptionid ) = @_;
314
    my $dbh   = C4::Context->dbh;
315
    my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
316
    my @bind;
317
    if ($borrowernumber and $borrowernumber =~ /^\d+$/) {
318
        $query .= " AND borrowernumber=?";
319
        push @bind, $borrowernumber;
320
    }
321
    if ($subscriptionid) {
322
        $query .= " AND externalid=?";
323
        push @bind, $subscriptionid;
324
    }
325
    my $sth = $dbh->prepare($query);
326
    $sth->execute(@bind);
327
    return $sth->fetchall_arrayref({});
328
}
329
330
=head2 SendAlerts
266
=head2 SendAlerts
331
267
332
    my $err = &SendAlerts($type, $externalid, $letter_code);
268
    my $err = &SendAlerts($type, $externalid, $letter_code);
Lines 375-396 sub SendAlerts { Link Here
375
             return;
311
             return;
376
312
377
        my %letter;
313
        my %letter;
378
        # find the list of borrowers to alert
314
        # find the list of subscribers to notify
379
        my $alerts = getalert( '', $subscriptionid );
315
        my $subscription = Koha::Subscriptions->find( $subscriptionid );
380
        foreach (@$alerts) {
316
        my $subscribers = $subscription->subscribers;
381
            my $patron = Koha::Patrons->find( $_->{borrowernumber} );
317
        while ( my $patron = $subscribers->next ) {
382
            next unless $patron; # Just in case
383
            my $email = $patron->email or next;
318
            my $email = $patron->email or next;
384
319
385
#                    warn "sending issues...";
320
#                    warn "sending issues...";
386
            my $userenv = C4::Context->userenv;
321
            my $userenv = C4::Context->userenv;
387
            my $library = Koha::Libraries->find( $_->{branchcode} );
322
            my $library = $patron->library;
388
            my $letter = GetPreparedLetter (
323
            my $letter = GetPreparedLetter (
389
                module => 'serial',
324
                module => 'serial',
390
                letter_code => $letter_code,
325
                letter_code => $letter_code,
391
                branchcode => $userenv->{branch},
326
                branchcode => $userenv->{branch},
392
                tables => {
327
                tables => {
393
                    'branches'    => $_->{branchcode},
328
                    'branches'    => $library->branchcode,
394
                    'biblio'      => $biblionumber,
329
                    'biblio'      => $biblionumber,
395
                    'biblioitems' => $biblionumber,
330
                    'biblioitems' => $biblionumber,
396
                    'borrowers'   => $patron->unblessed,
331
                    '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 828-836 Link Here
828
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
828
                                [% IF ( subscription.letter ) %]<span class="email_notifications">
829
                                    [% IF ( loggedinusername ) %]
829
                                    [% IF ( loggedinusername ) %]
830
                                        [% IF ( subscription.hasalert ) %]
830
                                        [% IF ( subscription.hasalert ) %]
831
                                            <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>
831
                                            <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>
832
                                        [% ELSE %]
832
                                        [% ELSE %]
833
                                            <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>
833
                                            <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>
834
                                        [% END %]
834
                                        [% END %]
835
                                    [% ELSE %]
835
                                    [% ELSE %]
836
                                        <span>You must log in if you want to subscribe to email notification on new issues</span>
836
                                        <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 584-593 foreach my $subscription (@subscriptions) { Link Here
584
    $cell{latestserials} =
584
    $cell{latestserials} =
585
      GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
585
      GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
586
    if ( $borrowernumber ) {
586
    if ( $borrowernumber ) {
587
        my $sub = getalert($borrowernumber, $subscription->{subscriptionid});
587
        my $subscription_object = Koha::Subscriptions->find( $subscription->{subscriptionid} );
588
        if (@$sub[0]) {
588
        my $subscriber = $subscription_object->subscribers->find( $borrowernumber );
589
            $cell{hasalert} = 1;
589
        $cell{hasalert} = 1 if $subscriber;
590
        }
591
    }
590
    }
592
    push @subs, \%cell;
591
    push @subs, \%cell;
593
}
592
}
(-)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 (-22 / +14 lines)
Lines 18-37 Link Here
18
# You should have received a copy of the GNU General Public License
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use strict;
21
use Modern::Perl;
22
use warnings;
23
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
24
use C4::Auth;
23
use C4::Auth;
25
use C4::Context;
24
use C4::Context;
26
use C4::Output;
25
use C4::Output;
27
use C4::Koha;
28
use C4::Letters;
29
use C4::Serials;
30
26
31
my $dbh = C4::Context->dbh;
27
use Koha::Subscriptions;
32
28
33
my $input = new CGI;
29
my $input = new CGI;
34
my $print = $input->param('print');
35
30
36
my ($template, $loggedinuser, $cookie)
31
my ($template, $loggedinuser, $cookie)
37
    = get_template_and_user({template_name => 'serials/viewalerts.tt',
32
    = get_template_and_user({template_name => 'serials/viewalerts.tt',
Lines 42-61 my ($template, $loggedinuser, $cookie) Link Here
42
                 debug => 1,
37
                 debug => 1,
43
                 });
38
                 });
44
39
45
my $subscriptionid=$input->param('subscriptionid');
40
my $subscriptionid = $input->param('subscriptionid');
46
41
47
my $borrowers = getalert('', $subscriptionid);
42
my $subscription = Koha::Subscriptions->find( $subscriptionid );
48
my $subscription = GetSubscription($subscriptionid);
43
# FIXME raise a message if subscription does not exist (easy with 18403)
49
44
50
for my $borrowernumber (@$borrowers) {
45
my $subscribers = $subscription->subscribers;
51
    my $patron = Koha::Patrons->find( $borrowernumber );
46
52
    next unless $borrowernumber; # Just in case...
47
$template->param(
53
    $borrowers->{name} = join( ' ', $patron->firstname, $patron->surname );
48
    subscribers    => $subscribers,
54
}
49
    bibliotitle    => $subscription->biblio->title,
55
$template->param(alertloop => $borrowers,
50
    subscriptionid => $subscriptionid,
56
                bibliotitle => $subscription->{bibliotitle},
51
);
57
                subscriptionid => $subscriptionid,
58
                (uc(C4::Context->preference("marcflavour"))) => 1
59
                );
60
52
61
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 235-275 my $branchcode = 'FFL'; Link Here
235
my $letter14206_c = C4::Letters::getletter('my module', $overdue_rules->{"letter$i"}, $branchcode);
237
my $letter14206_c = C4::Letters::getletter('my module', $overdue_rules->{"letter$i"}, $branchcode);
236
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
238
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
237
239
238
# addalert
239
my $externalid = 'my external id';
240
my $alert_id = C4::Letters::addalert($borrowernumber, $externalid);
241
isnt( $alert_id, undef, 'addalert does not return undef' );
242
243
244
# getalert
245
my $alerts = C4::Letters::getalert();
246
is( @$alerts, 1, 'getalert should not fail without parameter' );
247
$alerts = C4::Letters::getalert($borrowernumber);
248
is( @$alerts, 1, 'addalert adds an alert' );
249
is( $alerts->[0]->{alertid}, $alert_id, 'addalert returns the alert id correctly' );
250
is( $alerts->[0]->{externalid}, $externalid, 'addalert stores the externalid correctly' );
251
252
$alerts = C4::Letters::getalert($borrowernumber);
253
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
254
$alerts = C4::Letters::getalert($borrowernumber, $externalid);
255
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
256
$alerts = C4::Letters::getalert($borrowernumber, 'another external id');
257
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
258
259
260
# delalert
261
eval {
262
    C4::Letters::delalert();
263
};
264
isnt( $@, undef, 'delalert without argument returns an error' );
265
$alerts = C4::Letters::getalert($borrowernumber);
266
is( @$alerts, 1, 'delalert without argument does not remove an alert' );
267
268
C4::Letters::delalert($alert_id);
269
$alerts = C4::Letters::getalert($borrowernumber);
270
is( @$alerts, 0, 'delalert removes an alert' );
271
272
273
# GetPreparedLetter
240
# GetPreparedLetter
274
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
241
t::lib::Mocks::mock_preference('OPACBaseURL', 'http://thisisatest.com');
275
242
Lines 508-515 my $borrowernumber = AddMember( Link Here
508
    dateofbirth  => $date,
475
    dateofbirth  => $date,
509
    email        => 'john.smith@test.de',
476
    email        => 'john.smith@test.de',
510
);
477
);
511
my $alert_id = C4::Letters::addalert($borrowernumber, $subscriptionid);
478
my $subscription = Koha::Subscriptions->find( $subscriptionid );
512
479
$subscription->add_subscriber( scalar Koha::Patrons->find( $borrowernumber ) );
513
480
514
my $err2;
481
my $err2;
515
warning_is {
482
warning_is {
516
- 

Return to bug 19855