|
Lines 22-27
use Modern::Perl;
Link Here
|
| 22 |
|
22 |
|
| 23 |
use Carp; |
23 |
use Carp; |
| 24 |
use List::MoreUtils qw( uniq ); |
24 |
use List::MoreUtils qw( uniq ); |
|
|
25 |
use Module::Load::Conditional qw( can_load ); |
| 25 |
use Text::Unaccent qw( unac_string ); |
26 |
use Text::Unaccent qw( unac_string ); |
| 26 |
|
27 |
|
| 27 |
use C4::Context; |
28 |
use C4::Context; |
|
Lines 41-46
use Koha::Club::Enrollments;
Link Here
|
| 41 |
use Koha::Account; |
42 |
use Koha::Account; |
| 42 |
use Koha::Subscription::Routinglists; |
43 |
use Koha::Subscription::Routinglists; |
| 43 |
|
44 |
|
|
|
45 |
if ( ! can_load( modules => { 'Koha::NorwegianPatronDB' => undef } ) ) { |
| 46 |
warn "Unable to load Koha::NorwegianPatronDB"; |
| 47 |
} |
| 48 |
|
| 44 |
use base qw(Koha::Object); |
49 |
use base qw(Koha::Object); |
| 45 |
|
50 |
|
| 46 |
our $RESULTSET_PATRON_ID_MAPPING = { |
51 |
our $RESULTSET_PATRON_ID_MAPPING = { |
|
Lines 110-116
sub trim_whitespaces {
Link Here
|
| 110 |
my( $self ) = @_; |
115 |
my( $self ) = @_; |
| 111 |
|
116 |
|
| 112 |
my $schema = Koha::Database->new->schema; |
117 |
my $schema = Koha::Database->new->schema; |
| 113 |
my @columns = $schema->source('Borrowers')->columns; |
118 |
my @columns = $schema->source($self->_type)->columns; |
| 114 |
|
119 |
|
| 115 |
for my $column( @columns ) { |
120 |
for my $column( @columns ) { |
| 116 |
my $value = $self->$column; |
121 |
my $value = $self->$column; |
|
Lines 123-129
sub trim_whitespaces {
Link Here
|
| 123 |
} |
128 |
} |
| 124 |
|
129 |
|
| 125 |
sub store { |
130 |
sub store { |
| 126 |
my( $self ) = @_; |
131 |
my ($self) = @_; |
| 127 |
|
132 |
|
| 128 |
$self->_result->result_source->schema->txn_do( |
133 |
$self->_result->result_source->schema->txn_do( |
| 129 |
sub { |
134 |
sub { |
|
Lines 138-147
sub store {
Link Here
|
| 138 |
# We are in a transaction but the table is not locked |
143 |
# We are in a transaction but the table is not locked |
| 139 |
$self->fixup_cardnumber; |
144 |
$self->fixup_cardnumber; |
| 140 |
} |
145 |
} |
|
|
146 |
unless ( $self->in_storage ) { #AddMember |
| 147 |
|
| 148 |
unless( $self->category->in_storage ) { |
| 149 |
Koha::Exceptions::Object::FKConstraint->throw( |
| 150 |
broken_fk => 'categorycode', |
| 151 |
value => $self->categorycode, |
| 152 |
); |
| 153 |
} |
| 154 |
|
| 155 |
$self->trim_whitespaces; |
| 156 |
|
| 157 |
# Generate a valid userid/login if needed |
| 158 |
$self->userid($self->generate_userid) |
| 159 |
if not $self->userid or not $self->has_valid_userid; |
| 160 |
|
| 161 |
# Add expiration date if it isn't already there |
| 162 |
unless ( $self->dateexpiry ) { |
| 163 |
$self->dateexpiry( $self->category->get_expiry_date ); |
| 164 |
} |
| 165 |
|
| 166 |
# Add enrollment date if it isn't already there |
| 167 |
unless ( $self->dateenrolled ) { |
| 168 |
$self->dateenrolled(dt_from_string); |
| 169 |
} |
| 170 |
|
| 171 |
# Set the privacy depending on the patron's category |
| 172 |
my $default_privacy = $self->category->default_privacy || q{}; |
| 173 |
$default_privacy = |
| 174 |
$default_privacy eq 'default' ? 1 |
| 175 |
: $default_privacy eq 'never' ? 2 |
| 176 |
: $default_privacy eq 'forever' ? 0 |
| 177 |
: undef; |
| 178 |
$self->privacy($default_privacy); |
| 179 |
|
| 180 |
unless ( defined $self->privacy_guarantor_checkouts ) { |
| 181 |
$self->privacy_guarantor_checkouts(0); |
| 182 |
} |
| 183 |
|
| 184 |
# Make a copy of the plain text password for later use |
| 185 |
my $plain_text_password = $self->password; |
| 186 |
|
| 187 |
# Create a disabled account if no password provided |
| 188 |
$self->password( $self->password |
| 189 |
? Koha::AuthUtils::hash_password( $self->password ) |
| 190 |
: '!' ); |
| 191 |
|
| 192 |
# We don't want invalid dates in the db (mysql has a bad habit of inserting 0000-00-00) |
| 193 |
$self->dateofbirth(undef) unless $self->dateofbirth; |
| 194 |
$self->debarred(undef) unless $self->debarred; |
| 195 |
|
| 196 |
# Set default values if not set |
| 197 |
$self->sms_provider_id(undef) unless $self->sms_provider_id; |
| 198 |
$self->guarantorid(undef) unless $self->guarantorid; |
| 199 |
|
| 200 |
$self->borrowernumber(undef); |
| 201 |
|
| 202 |
$self = $self->SUPER::store; |
| 203 |
|
| 204 |
# If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a |
| 205 |
# cronjob will use for syncing with NL |
| 206 |
if ( C4::Context->preference('NorwegianPatronDBEnable') |
| 207 |
&& C4::Context->preference('NorwegianPatronDBEnable') == 1 ) |
| 208 |
{ |
| 209 |
Koha::Database->new->schema->resultset('BorrowerSync') |
| 210 |
->create( |
| 211 |
{ |
| 212 |
'borrowernumber' => $self->borrowernumber, |
| 213 |
'synctype' => 'norwegianpatrondb', |
| 214 |
'sync' => 1, |
| 215 |
'syncstatus' => 'new', |
| 216 |
'hashed_pin' => |
| 217 |
Koha::NorwegianPatronDB::NLEncryptPIN( |
| 218 |
$plain_text_password), |
| 219 |
} |
| 220 |
); |
| 221 |
} |
| 222 |
|
| 223 |
$self->add_enrolment_fee_if_needed; |
| 224 |
|
| 225 |
logaction( "MEMBERS", "CREATE", $self->borrowernumber, "" ) |
| 226 |
if C4::Context->preference("BorrowersLog"); |
| 227 |
} |
| 228 |
else { #ModMember |
| 229 |
$self = $self->SUPER::store; |
| 230 |
} |
| 141 |
|
231 |
|
| 142 |
$self->SUPER::store; |
|
|
| 143 |
} |
232 |
} |
| 144 |
); |
233 |
); |
|
|
234 |
return $self; |
| 145 |
} |
235 |
} |
| 146 |
|
236 |
|
| 147 |
=head3 delete |
237 |
=head3 delete |
| 148 |
- |
|
|