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

(-)a/Koha/Patron/Message/Preference.pm (-22 / +30 lines)
Lines 198-208 sub message_transport_types { Link Here
198
        if ($self->{'_message_transport_types'}) {
198
        if ($self->{'_message_transport_types'}) {
199
            return $self->{'_message_transport_types'};
199
            return $self->{'_message_transport_types'};
200
        }
200
        }
201
        map { $self->{'_message_transport_types'}->{$_->message_transport_type} =
201
        map {
202
                Koha::Patron::Message::Transports->find({
202
            my $transport = Koha::Patron::Message::Transports->find({
203
                    message_attribute_id => $self->message_attribute_id,
203
                message_attribute_id => $self->message_attribute_id,
204
                    message_transport_type => $_->message_transport_type,
204
                message_transport_type => $_->message_transport_type,
205
                    is_digest => $self->wants_digest})->letter_code }
205
                is_digest => $self->wants_digest
206
            });
207
            unless ($transport) {
208
                my $logger = Koha::Logger->get;
209
                $logger->warn(
210
                    $self->message_name . ' has no transport with '.
211
                    $_->message_transport_type . ' (digest: '.
212
                    ($self->wants_digest ? 'yes':'no').').'
213
                );
214
            }
215
            $self->{'_message_transport_types'}->{$_->message_transport_type}
216
                = $transport ? $transport->letter_code : ' ';
217
        }
206
        Koha::Patron::Message::Transport::Preferences->search({
218
        Koha::Patron::Message::Transport::Preferences->search({
207
            borrower_message_preference_id => $self->borrower_message_preference_id,
219
            borrower_message_preference_id => $self->borrower_message_preference_id,
208
        })->as_list;
220
        })->as_list;
Lines 354-360 sub validate { Link Here
354
    if (defined $self->wants_digest) {
366
    if (defined $self->wants_digest) {
355
        my $transports = Koha::Patron::Message::Transports->search({
367
        my $transports = Koha::Patron::Message::Transports->search({
356
            message_attribute_id => $self->message_attribute_id,
368
            message_attribute_id => $self->message_attribute_id,
357
            is_digest            => $self->wants_digest,
369
            is_digest            => $self->wants_digest ? 1 : 0,
358
        });
370
        });
359
        Koha::Exceptions::BadParameter->throw(
371
        Koha::Exceptions::BadParameter->throw(
360
            error => (!$self->wants_digest ? 'No d' : 'D').'igest not available '.
372
            error => (!$self->wants_digest ? 'No d' : 'D').'igest not available '.
Lines 377-387 sub _set_message_transport_types { Link Here
377
    $self->_validate_message_transport_types({ message_transport_types => $types });
389
    $self->_validate_message_transport_types({ message_transport_types => $types });
378
    foreach my $type (@$types) {
390
    foreach my $type (@$types) {
379
        unless (exists $self->{'_message_transport_types'}->{$type}) {
391
        unless (exists $self->{'_message_transport_types'}->{$type}) {
380
            $self->{'_message_transport_types'}->{$type} =
392
            my $transport = Koha::Patron::Message::Transports->find({
381
            Koha::Patron::Message::Transports->find({
382
                message_attribute_id => $self->message_attribute_id,
393
                message_attribute_id => $self->message_attribute_id,
383
                message_transport_type => $type,
394
                message_transport_type => $type,
384
                is_digest => $self->wants_digest})->letter_code;
395
                is_digest => $self->wants_digest
396
            });
397
            unless ($transport) {
398
                Koha::Exceptions::ObjectNotFound->throw(
399
                    error => 'No transport configured for '.
400
                        $type . ' (digest: '.
401
                        ($self->wants_digest ? 'yes':'no').').'
402
                );
403
            }
404
            $self->{'_message_transport_types'}->{$type}
405
                = $transport->letter_code;
385
        }
406
        }
386
    }
407
    }
387
    return $self;
408
    return $self;
Lines 405-423 sub _validate_message_transport_types { Link Here
405
                    parameter => 'message_transport_type',
426
                    parameter => 'message_transport_type',
406
                );
427
                );
407
            }
428
            }
408
            my $tmp = (ref($self) eq __PACKAGE__) ? $self->unblessed : $params;
409
            unless (Koha::Patron::Message::Transports->find({
410
                    message_transport_type => $type,
411
                    message_attribute_id => $tmp->{'message_attribute_id'},
412
                    is_digest => $tmp->{'wants_digest'},
413
            })) {
414
                Koha::Exceptions::BadParameter->throw(
415
                    error => "Message transport option '$type' (".
416
                    ($tmp->{'wants_digest'} ? 'digest':'no digest').") for ".
417
                    $self->message_name . 'does not exist',
418
                    parameter => 'message_transport_type',
419
                );
420
            }
421
        }
429
        }
422
        return $types;
430
        return $types;
423
    }
431
    }
(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (-16 / +1 lines)
Lines 378-384 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
378
    };
378
    };
379
379
380
    subtest 'Bad parameter' => sub {
380
    subtest 'Bad parameter' => sub {
381
        plan tests => 19;
381
        plan tests => 16;
382
382
383
        $schema->storage->txn_begin;
383
        $schema->storage->txn_begin;
384
384
Lines 434-453 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
434
            .' => Koha::Exceptions::BadParameter');
434
            .' => Koha::Exceptions::BadParameter');
435
        is ($@->parameter, 'message_transport_type', 'The previous exception tells us it'
435
        is ($@->parameter, 'message_transport_type', 'The previous exception tells us it'
436
            .' was the message_transport_type.');
436
            .' was the message_transport_type.');
437
        eval {
438
            Koha::Patron::Message::Preference->new({
439
                borrowernumber => $patron->borrowernumber,
440
                message_attribute_id => $attribute->message_attribute_id,
441
                message_transport_types => ['sms'],
442
                wants_digest => 1,
443
            })->store };
444
        is (ref $@, 'Koha::Exceptions::BadParameter',
445
            'Adding a message preference with invalid message_transport_type'
446
            .' => Koha::Exceptions::BadParameter');
447
        is ($@->parameter, 'message_transport_type', 'The previous exception tells us it'
448
            .' was the message_transport_type.');
449
        like ($@->error, qr/^Message transport option/, 'Exception s because of given'
450
            .' message_transport_type is not a valid option.');
451
437
452
        eval {
438
        eval {
453
            Koha::Patron::Message::Preference->new({
439
            Koha::Patron::Message::Preference->new({
454
- 

Return to bug 17499