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

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

Return to bug 19017