projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
don't look up encryption config every record, RT#28526
[freeside.git]
/
FS
/
FS
/
Record.pm
diff --git
a/FS/FS/Record.pm
b/FS/FS/Record.pm
index
991c56e
..
b2ab713
100644
(file)
--- a/
FS/FS/Record.pm
+++ b/
FS/FS/Record.pm
@@
-56,12
+56,18
@@
my $rsa_decrypt;
our $conf = '';
our $conf_encryption = '';
our $conf = '';
our $conf_encryption = '';
+our $conf_encryptionmodule = '';
+our $conf_encryptionpublickey = '';
+our $conf_encryptionprivatekey = '';
FS::UID->install_callback( sub {
eval "use FS::Conf;";
die $@ if $@;
$conf = FS::Conf->new;
FS::UID->install_callback( sub {
eval "use FS::Conf;";
die $@ if $@;
$conf = FS::Conf->new;
- $conf_encryption = $conf->exists('encryption');
+ $conf_encryption = $conf->exists('encryption');
+ $conf_encryptionmodule = $conf->config('encryptionmodule');
+ $conf_encryptionpublickey = $conf->config('encryptionpublickey');
+ $conf_encryptionprivatekey = $conf->config('encryptionprivatekey');
$money_char = $conf->config('money_char') || '$';
my $nw_coords = $conf->exists('geocode-require_nw_coordinates');
$lat_lower = $nw_coords ? 1 : -90;
$money_char = $conf->config('money_char') || '$';
my $nw_coords = $conf->exists('geocode-require_nw_coordinates');
$lat_lower = $nw_coords ? 1 : -90;
@@
-399,10
+405,17
@@
sub qsearch {
my @real_fields = grep exists($record->{$_}), real_fields($table);
my $statement .= "SELECT $select FROM $stable";
my @real_fields = grep exists($record->{$_}), real_fields($table);
my $statement .= "SELECT $select FROM $stable";
- $statement .= " $addl_from" if $addl_from;
+ my $alias_main;
+ if ( $addl_from ) {
+ $statement .= " $addl_from";
+ # detect aliasing of the main table
+ if ( $addl_from =~ /^\s*AS\s+(\w+)/i ) {
+ $alias_main = $1;
+ }
+ }
if ( @real_fields ) {
$statement .= ' WHERE '. join(' AND ',
if ( @real_fields ) {
$statement .= ' WHERE '. join(' AND ',
- get_real_fields($table, $record, \@real_fields));
+ get_real_fields($table, $record, \@real_fields
, $alias_main
));
}
$statement .= " $extra_sql" if defined($extra_sql);
}
$statement .= " $extra_sql" if defined($extra_sql);
@@
-489,6
+502,8
@@
sub qsearch {
$sth->finish;
$sth->finish;
+ #below was refactored out to _from_hashref, this should use it at some point
+
my @return;
if ( eval 'scalar(@FS::'. $table. '::ISA);' ) {
if ( eval 'FS::'. $table. '->can(\'new\')' eq \&new ) {
my @return;
if ( eval 'scalar(@FS::'. $table. '::ISA);' ) {
if ( eval 'FS::'. $table. '->can(\'new\')' eq \&new ) {
@@
-749,6
+764,8
@@
sub get_real_fields {
my $table = shift;
my $record = shift;
my $real_fields = shift;
my $table = shift;
my $record = shift;
my $real_fields = shift;
+ my $alias_main = shift; # defaults to undef
+ $alias_main ||= $table;
## could be optimized more for readability
return (
## could be optimized more for readability
return (
@@
-756,7
+773,7
@@
sub get_real_fields {
my $op = '=';
my $column = $_;
my $op = '=';
my $column = $_;
- my $table_column = $qsearch_qualify_columns ? "$
table
.$column" : $column;
+ my $table_column = $qsearch_qualify_columns ? "$
alias_main
.$column" : $column;
my $type = dbdef->table($table)->column($column)->type;
my $value = $record->{$column};
$value = $value->{'value'} if ref($value);
my $type = dbdef->table($table)->column($column)->type;
my $value = $record->{$column};
$value = $value->{'value'} if ref($value);
@@
-876,6
+893,7
@@
sub qsearchs { # $result_record = &FS::Record:qsearchs('table',\%hash);
my $table = $_[0];
my(@result) = qsearch(@_);
cluck "warning: Multiple records in scalar search ($table)"
my $table = $_[0];
my(@result) = qsearch(@_);
cluck "warning: Multiple records in scalar search ($table)"
+ #.join(' / ', map "$_=>".$_[1]->{$_}, keys %{ $_[1] } )
if scalar(@result) > 1;
#should warn more vehemently if the search was on a primary key?
scalar(@result) ? ($result[0]) : ();
if scalar(@result) > 1;
#should warn more vehemently if the search was on a primary key?
scalar(@result) ? ($result[0]) : ();
@@
-1283,7
+1301,7
@@
sub insert {
# Encrypt before the database
if ( defined(eval '@FS::'. $table . '::encrypted_fields')
&& scalar( eval '@FS::'. $table . '::encrypted_fields')
# Encrypt before the database
if ( defined(eval '@FS::'. $table . '::encrypted_fields')
&& scalar( eval '@FS::'. $table . '::encrypted_fields')
- && $conf
->exists('encryption')
+ && $conf
_encryption
) {
foreach my $field (eval '@FS::'. $table . '::encrypted_fields') {
next if $field eq 'payinfo'
) {
foreach my $field (eval '@FS::'. $table . '::encrypted_fields') {
next if $field eq 'payinfo'
@@
-1524,7
+1542,7
@@
sub replace {
# Encrypt for replace
my $saved = {};
# Encrypt for replace
my $saved = {};
- if ( $conf
->exists('encryption')
+ if ( $conf
_encryption
&& defined(eval '@FS::'. $new->table . '::encrypted_fields')
&& scalar( eval '@FS::'. $new->table . '::encrypted_fields')
) {
&& defined(eval '@FS::'. $new->table . '::encrypted_fields')
&& scalar( eval '@FS::'. $new->table . '::encrypted_fields')
) {
@@
-1800,6
+1818,7
@@
sub process_batch_import {
format_xml_formats => $opt->{format_xml_formats},
format_asn_formats => $opt->{format_asn_formats},
format_row_callbacks => $opt->{format_row_callbacks},
format_xml_formats => $opt->{format_xml_formats},
format_asn_formats => $opt->{format_asn_formats},
format_row_callbacks => $opt->{format_row_callbacks},
+ format_hash_callbacks => $opt->{format_hash_callbacks},
#per-import
job => $job,
file => $file,
#per-import
job => $job,
file => $file,
@@
-1808,7
+1827,9
@@
sub process_batch_import {
params => { map { $_ => $param->{$_} } @pass_params },
#?
default_csv => $opt->{default_csv},
params => { map { $_ => $param->{$_} } @pass_params },
#?
default_csv => $opt->{default_csv},
+ preinsert_callback => $opt->{preinsert_callback},
postinsert_callback => $opt->{postinsert_callback},
postinsert_callback => $opt->{postinsert_callback},
+ insert_args_callback => $opt->{insert_args_callback},
);
if ( $opt->{'batch_namecol'} ) {
);
if ( $opt->{'batch_namecol'} ) {
@@
-1845,6
+1866,8
@@
Class method for batch imports. Available params:
=item format_row_callbacks
=item format_row_callbacks
+=item format_hash_callbacks - After parsing, before object creation
+
=item fields - Alternate way to specify import, specifying import fields directly as a listref
=item preinsert_callback
=item fields - Alternate way to specify import, specifying import fields directly as a listref
=item preinsert_callback
@@
-1887,7
+1910,7
@@
sub batch_import {
my( $type, $header, $sep_char,
$fixedlength_format, $xml_format, $asn_format,
my( $type, $header, $sep_char,
$fixedlength_format, $xml_format, $asn_format,
- $parser_opt, $row_callback, @fields );
+ $parser_opt, $row_callback,
$hash_callback,
@fields );
my $postinsert_callback = '';
$postinsert_callback = $param->{'postinsert_callback'}
my $postinsert_callback = '';
$postinsert_callback = $param->{'postinsert_callback'}
@@
-1895,6
+1918,9
@@
sub batch_import {
my $preinsert_callback = '';
$preinsert_callback = $param->{'preinsert_callback'}
if $param->{'preinsert_callback'};
my $preinsert_callback = '';
$preinsert_callback = $param->{'preinsert_callback'}
if $param->{'preinsert_callback'};
+ my $insert_args_callback = '';
+ $insert_args_callback = $param->{'insert_args_callback'}
+ if $param->{'insert_args_callback'};
if ( $param->{'format'} ) {
if ( $param->{'format'} ) {
@@
-1940,6
+1966,11
@@
sub batch_import {
? $param->{'format_row_callbacks'}{ $param->{'format'} }
: '';
? $param->{'format_row_callbacks'}{ $param->{'format'} }
: '';
+ $hash_callback =
+ $param->{'format_hash_callbacks'}
+ ? $param->{'format_hash_callbacks'}{ $param->{'format'} }
+ : '';
+
@fields = @{ $formats->{ $format } };
} elsif ( $param->{'fields'} ) {
@fields = @{ $formats->{ $format } };
} elsif ( $param->{'fields'} ) {
@@
-1949,6
+1980,7
@@
sub batch_import {
$sep_char = ',';
$fixedlength_format = '';
$row_callback = '';
$sep_char = ',';
$fixedlength_format = '';
$row_callback = '';
+ $hash_callback = '';
@fields = @{ $param->{'fields'} };
} else {
@fields = @{ $param->{'fields'} };
} else {
@@
-2174,6
+2206,8
@@
sub batch_import {
$hash{custnum} = $2;
}
$hash{custnum} = $2;
}
+ %hash = &{$hash_callback}(%hash) if $hash_callback;
+
#my $table = $param->{table};
my $class = "FS::$table";
#my $table = $param->{table};
my $class = "FS::$table";
@@
-2204,7
+2238,12
@@
sub batch_import {
next if exists $param->{skiprow} && $param->{skiprow};
}
next if exists $param->{skiprow} && $param->{skiprow};
}
- my $error = $record->insert;
+ my @insert_args = ();
+ if ( $insert_args_callback ) {
+ @insert_args = &{$insert_args_callback}($record, $param);
+ }
+
+ my $error = $record->insert(@insert_args);
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
@@
-2254,7
+2293,7
@@
sub _h_statement {
;
# If we're encrypting then don't store the payinfo in the history
;
# If we're encrypting then don't store the payinfo in the history
- if ( $conf
&& $conf->exists('encryption')
&& $self->table ne 'banned_pay' ) {
+ if ( $conf
_encryption
&& $self->table ne 'banned_pay' ) {
@fields = grep { $_ ne 'payinfo' } @fields;
}
@fields = grep { $_ ne 'payinfo' } @fields;
}
@@
-3185,7
+3224,7
@@
sub encrypt {
my ($self, $value) = @_;
my $encrypted = $value;
my ($self, $value) = @_;
my $encrypted = $value;
- if ($conf
->exists('encryption')
) {
+ if ($conf
_encryption
) {
if ($self->is_encrypted($value)) {
# Return the original value if it isn't plaintext.
$encrypted = $value;
if ($self->is_encrypted($value)) {
# Return the original value if it isn't plaintext.
$encrypted = $value;
@@
-3228,7
+3267,7
@@
You should generally not have to worry about calling this, as the system handles
sub decrypt {
my ($self,$value) = @_;
my $decrypted = $value; # Will return the original value if it isn't encrypted or can't be decrypted.
sub decrypt {
my ($self,$value) = @_;
my $decrypted = $value; # Will return the original value if it isn't encrypted or can't be decrypted.
- if ($conf
->exists('encryption')
&& $self->is_encrypted($value)) {
+ if ($conf
_encryption
&& $self->is_encrypted($value)) {
$self->loadRSA;
if (ref($rsa_decrypt) =~ /::RSA/) {
my $encrypted = unpack ("u*", $value);
$self->loadRSA;
if (ref($rsa_decrypt) =~ /::RSA/) {
my $encrypted = unpack ("u*", $value);
@@
-3244,8
+3283,8
@@
sub loadRSA {
#Initialize the Module
$rsa_module = 'Crypt::OpenSSL::RSA'; # The Default
#Initialize the Module
$rsa_module = 'Crypt::OpenSSL::RSA'; # The Default
- if ($conf
->exists('encryptionmodule') && $conf->config('encryptionmodule')
ne '') {
- $rsa_module = $conf
->config('encryptionmodule')
;
+ if ($conf
_encryptionmodule && $conf_encryptionmodule
ne '') {
+ $rsa_module = $conf
_encryptionmodule
;
}
if (!$rsa_loaded) {
}
if (!$rsa_loaded) {
@@
-3253,14
+3292,14
@@
sub loadRSA {
$rsa_loaded++;
}
# Initialize Encryption
$rsa_loaded++;
}
# Initialize Encryption
- if ($conf
->exists('encryptionpublickey') && $conf->config('encryptionpublickey')
ne '') {
- my $public_key = join("\n",$conf
->config('encryptionpublickey')
);
+ if ($conf
_encryptionpublickey && $conf_encryptionpublickey
ne '') {
+ my $public_key = join("\n",$conf
_encryptionpublickey
);
$rsa_encrypt = $rsa_module->new_public_key($public_key);
}
# Intitalize Decryption
$rsa_encrypt = $rsa_module->new_public_key($public_key);
}
# Intitalize Decryption
- if ($conf
->exists('encryptionprivatekey') && $conf->config('encryptionprivatekey')
ne '') {
- my $private_key = join("\n",$conf
->config('encryptionprivatekey')
);
+ if ($conf
_encryptionprivatekey && $conf_encryptionprivatekey
ne '') {
+ my $private_key = join("\n",$conf
_encryptionprivatekey
);
$rsa_decrypt = $rsa_module->new_private_key($private_key);
}
}
$rsa_decrypt = $rsa_module->new_private_key($private_key);
}
}