X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FSMS.pm;h=eff72b358c0a5e2af6c09c88c002f2e5fb7fe047;hb=86a0a7d80b71908582dfc40c981734c5828112fc;hp=1cd67b97e43dcf70759ee3b3643c24e2fcdd4550;hpb=0cb82c8d02cc4b672b169c8b0261c4bb6360cd00;p=srvgit
diff --git a/C4/SMS.pm b/C4/SMS.pm
index 1cd67b97e4..eff72b358c 100644
--- a/C4/SMS.pm
+++ b/C4/SMS.pm
@@ -1,6 +1,8 @@
package C4::SMS;
# Copyright 2007 Liblime
+# Copyright 2015 Biblibre
+# Copyright 2016 Catalyst
#
# This file is part of Koha.
#
@@ -28,7 +30,23 @@ my $success = C4::SMS->send_sms({ message => 'This is my text message',
=head1 DESCRIPTION
+A wrapper for SMS::Send.
+Can use a yaml file for config, the path to which is in the koha-conf.xml
+__KOHA_CONF_DIR__/sms_send/
+
+Each file needs to be in the format of
+__KOHA_CONF_DIR__/sms_send/.yaml
+
+For example for SMS::Send::UK::Kapow the config would be
+
+/etc/koha/sites/instancename/sms_send/UK/Kapow.yaml for package install
+or
+/etc/koha/sms_send/UK/Kapow.yaml for tarball
+
+A underscore character is prepended to all parameter names so they are
+treated as driver-specific options (leading underscore must not appear
+in config file).
=cut
@@ -36,12 +54,9 @@ use strict;
use warnings;
use C4::Context;
+use File::Spec;
-use vars qw( $VERSION );
-BEGIN {
- $VERSION = 3.07.00.049;
-}
=head1 METHODS
@@ -74,21 +89,40 @@ sub send_sms {
my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver();
return unless $driver;
- # warn "using driver: $driver to send message to $params->{'destination'}";
-
my ($sent, $sender);
+
+ my $subpath = $driver;
+ $subpath =~ s|::|/|g;
+
+ my $sms_send_config = C4::Context->config('sms_send_config');
+ my $conf_file = defined $sms_send_config
+ ? File::Spec->catfile( $sms_send_config, $subpath )
+ : $subpath;
+ $conf_file .= q{.yaml};
+
+ my %args;
+ if ( -f $conf_file ) {
+ require YAML;
+ my $conf = YAML::LoadFile( $conf_file );
+ %args = map { q{_} . $_ => $conf->{$_} } keys %$conf;
+ }
+
eval {
# Create a sender
- $sender = SMS::Send->new( $driver,
- _login => C4::Context->preference('SMSSendUsername'),
- _password => C4::Context->preference('SMSSendPassword'),
- );
-
+ $sender = SMS::Send->new(
+ $driver,
+ _login => C4::Context->preference('SMSSendUsername'),
+ _password => C4::Context->preference('SMSSendPassword'),
+ %args,
+ );
+
# Send a message
- $sent = $sender->send_sms( to => $params->{'destination'},
- text => $params->{'message'},
- );
+ $sent = $sender->send_sms(
+ to => $params->{destination},
+ text => $params->{message},
+ );
};
+
#We might die because SMS::Send $driver is not defined or the sms-number has a bad format
#Catch those errors and fail the sms-sending gracefully.
if ($@) {