Bug 12426: Allow resend for sent messages
[koha.git] / C4 / SMS.pm
index b4b1992..1cd67b9 100644 (file)
--- a/C4/SMS.pm
+++ b/C4/SMS.pm
@@ -4,18 +4,18 @@ package C4::SMS;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 NAME
 
@@ -23,8 +23,8 @@ C4::SMS - send SMS messages
 
 =head1 SYNOPSIS
 
-my $success = C4::SMS->send_sms( message     => 'This is my text message',
-                                 destination => '212-555-1212' );
+my $success = C4::SMS->send_sms({ message     => 'This is my text message',
+                                  destination => '212-555-1212' });
 
 =head1 DESCRIPTION
 
@@ -40,7 +40,7 @@ use C4::Context;
 use vars qw( $VERSION );
 
 BEGIN {
-    $VERSION = 0.03;
+    $VERSION = 3.07.00.049;
 }
 
 =head1 METHODS
@@ -75,17 +75,26 @@ sub send_sms {
     return unless $driver;
 
     # warn "using driver: $driver to send message to $params->{'destination'}";
-    
-    # Create a sender
-    my $sender = SMS::Send->new( $driver,
+
+    my ($sent, $sender);
+    eval {
+        # Create a sender
+        $sender = SMS::Send->new( $driver,
                                  _login    => C4::Context->preference('SMSSendUsername'),
                                  _password => C4::Context->preference('SMSSendPassword'),
                             );
     
-    # Send a message
-    my $sent = $sender->send_sms( to   => $params->{'destination'},
+        # Send a 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 ($@) {
+        warn $@;
+        return;
+    }
     # warn 'failure' unless $sent;
     return $sent;
 }