|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Copyright 2017 Biblibre |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Pod::Usage; |
| 23 |
use Module::Load; |
| 24 |
use Getopt::Long; |
| 25 |
|
| 26 |
use Koha::Patrons; |
| 27 |
|
| 28 |
my ( $help, $area, $confirm, $list_area ); |
| 29 |
my $area_option = ''; |
| 30 |
|
| 31 |
GetOptions( |
| 32 |
'h|help' => \$help, |
| 33 |
'a|area=s' => \$area, |
| 34 |
'c|confirm' => \$confirm, |
| 35 |
'o|option=s' => \$area_option, |
| 36 |
'l|list-area' => \$list_area |
| 37 |
) || pod2usage(1); |
| 38 |
|
| 39 |
if ($help) { |
| 40 |
pod2usage(1); |
| 41 |
} |
| 42 |
|
| 43 |
if ($list_area) { |
| 44 |
print " - Fr: Checks french mobile number. options: '+33', '0033' \n"; |
| 45 |
|
| 46 |
exit; |
| 47 |
} |
| 48 |
|
| 49 |
my $module = "C4::SMSNumber::" . ucfirst($area); |
| 50 |
load $module, qw/check/; |
| 51 |
|
| 52 |
my $patrons = Koha::Patrons->search({}); |
| 53 |
while ( my $patron = $patrons->next() ) { |
| 54 |
my $number = $patron->smsalertnumber(); |
| 55 |
my $id = $patron->id(); |
| 56 |
|
| 57 |
next unless $number; |
| 58 |
|
| 59 |
my $valid = $module->check($number, $area_option); |
| 60 |
next if $valid; |
| 61 |
|
| 62 |
print "Patron n° $id has an invalid phone number for area $area ($number).\n"; |
| 63 |
|
| 64 |
my $replacement = $module->transform($number, $area_option); |
| 65 |
if ($replacement ne $number) { |
| 66 |
print "$number => $replacement\n\n"; |
| 67 |
$patron->set({ smsalertnumber => $replacement})->store if $confirm; |
| 68 |
} else { |
| 69 |
print "Can't find a replacement\n\n"; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
=head1 NAME |
| 74 |
|
| 75 |
check_smsalertnumber - This script check and transform SMS alert number. |
| 76 |
|
| 77 |
=head1 SYNOPSIS |
| 78 |
|
| 79 |
check_smsalertnumber.pl -a|--area fr [-h|--help] [-c|--confirm] [-o|--country-option] [-l|--liste-mode] |
| 80 |
|
| 81 |
Check SMS alert number and transform them if a replacement is found (--confirm). Mode |
| 82 |
can be found/added in C4/Number. add --list-area option to this script to get the |
| 83 |
available list. |
| 84 |
|
| 85 |
=head1 OPTIONS |
| 86 |
|
| 87 |
=over |
| 88 |
|
| 89 |
=item B<-h|--help> |
| 90 |
|
| 91 |
Print a brief help message |
| 92 |
|
| 93 |
=item B<-a|--area> |
| 94 |
|
| 95 |
Specify the area template to use. See --list-area to get all available area |
| 96 |
|
| 97 |
=item B<-c|--confirm> |
| 98 |
|
| 99 |
If this option is passed to the script, replacement are stored in database |
| 100 |
|
| 101 |
=item B<-o|--country-option> |
| 102 |
|
| 103 |
Mode option. Modes could need additional option(s) |
| 104 |
|
| 105 |
=item B<-l|--list> |
| 106 |
|
| 107 |
Print a list of available areas |
| 108 |
|
| 109 |
=back |
| 110 |
|
| 111 |
=head1 AUTHOR |
| 112 |
|
| 113 |
Alex Arnaud <alex.arnaud@biblibre.com> |
| 114 |
|
| 115 |
=head1 COPYRIGHT |
| 116 |
|
| 117 |
Copyright 2016 BibLibre |
| 118 |
|
| 119 |
=head1 LICENSE |
| 120 |
|
| 121 |
This file is part of Koha. |
| 122 |
|
| 123 |
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 |
| 124 |
Foundation; either version 3 of the License, or (at your option) any later version. |
| 125 |
|
| 126 |
You should have received a copy of the GNU General Public License along |
| 127 |
with Koha; if not, write to the Free Software Foundation, Inc., |
| 128 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 129 |
|
| 130 |
=cut |