# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
-## NOTE:
-## Parts of this module are used from cgi scripts that are detached from apache before
-## execution. For this reason, the C4::Koha::Log function has been used to capture
-## output for debugging purposes.
-
use Modern::Perl;
use DateTime;
sub GetModificationTemplates {
my ( $template_id ) = @_;
- C4::Koha::Log("C4::MarcModificationTemplates::GetModificationTemplates( $template_id )") if DEBUG;
warn("C4::MarcModificationTemplates::GetModificationTemplates( $template_id )") if DEBUG;
my $dbh = C4::Context->dbh;
sub GetModificationTemplateActions {
my ( $template_id ) = @_;
- C4::Koha::Log( "C4::MarcModificationTemplates::GetModificationTemplateActions( $template_id )" ) if DEBUG;
warn( "C4::MarcModificationTemplates::GetModificationTemplateActions( $template_id )" ) if DEBUG;
my $dbh = C4::Context->dbh;
push( @actions, $action );
}
- C4::Koha::Log( Data::Dumper::Dumper( @actions ) ) if DEBUG > 4;
warn( Data::Dumper::Dumper( @actions ) ) if DEBUG > 4;
return @actions;
$description
) = @_;
- C4::Koha::Log( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
- $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
- $to_regex_search, $to_regex_replace, $to_regex_modifiers, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
- $conditional_value, $conditional_regex, $description )" ) if DEBUG;
warn( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
$field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
$to_regex_search, $to_regex_replace, $to_regex_modifiers, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
sub ModifyRecordsWithTemplate {
my ( $template_id, $batch ) = @_;
- C4::Koha::Log( "C4::MarcModificationTemplates::ModifyRecordsWithTemplate( $template_id, $batch )" ) if DEBUG;
warn( "C4::MarcModificationTemplates::ModifyRecordsWithTemplate( $template_id, $batch )" ) if DEBUG;
while ( my $record = $batch->next() ) {
sub ModifyRecordWithTemplate {
my ( $template_id, $record ) = @_;
- C4::Koha::Log( "C4::MarcModificationTemplates::ModifyRecordWithTemplate( $template_id, $record )" ) if DEBUG;
warn( "C4::MarcModificationTemplates::ModifyRecordWithTemplate( $template_id, $record )" ) if DEBUG;
- C4::Koha::Log( "Unmodified Record:\n" . $record->as_formatted() ) if DEBUG >= 10;
warn( "Unmodified Record:\n" . $record->as_formatted() ) if DEBUG >= 10;
my $current_date = DateTime->now()->ymd();
}
}
- C4::Koha::Log( $record->as_formatted() ) if DEBUG >= 10;
warn( $record->as_formatted() ) if DEBUG >= 10;
}
}
=head1 NAME
-SimpleMARC - Perl modle for making simple MARC record alterations.
+SimpleMARC - Perl module for making simple MARC record alterations.
=head1 SYNOPSIS
sub copy_field {
my ( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n, $dont_erase ) = @_;
- C4::Koha::Log( "C4::SimpleMARC::copy_field( '$record', '$fromFieldName', '$fromSubfieldName', '$toFieldName', '$toSubfieldName', '$regex', '$n' )" ) if $debug;
if ( ! ( $record && $fromFieldName && $toFieldName ) ) { return; }
my @values = read_field( $record, $fromFieldName, $fromSubfieldName );
@values = ( $values[$n-1] ) if ( $n );
- C4::Koha::Log( "@values = read_field( $record, $fromFieldName, $fromSubfieldName )" ) if $debug >= 3;
if ( $regex and $regex->{search} ) {
$regex->{modifiers} //= q||;
if grep {/$modifier/} @available_modifiers;
}
foreach my $value ( @values ) {
- C4::Koha::Log( "\$value =~ s/$regex->{search}/$regex->{replace}/$modifiers" ) if ( $debug >= 3 );
for ( $modifiers ) {
when ( /^(ig|gi)$/ ) {
$value =~ s/$regex->{search}/$regex->{replace}/ig;
sub update_field {
my ( $record, $fieldName, $subfieldName, $dont_erase, @values ) = @_;
- C4::Koha::Log( "C4::SimpleMARC::update_field( $record, $fieldName, $subfieldName, $dont_erase, @values )" ) if $debug;
if ( ! ( $record && $fieldName ) ) { return; }
sub read_field {
my ( $record, $fieldName, $subfieldName, $n ) = @_;
- C4::Koha::Log( "C4::SimpleMARC::read_field( '$record', '$fieldName', '$subfieldName', '$n' )" ) if $debug;
my @fields = $record->field( $fieldName );
sub field_exists {
my ( $record, $fieldName, $subfieldName ) = @_;
- C4::Koha::Log( "C4::SimpleMARC::field_exists( $record, $fieldName, $subfieldName )" ) if $debug;
if ( ! $record ) { return; }
$return = $record->field( $fieldName ) && 1;
}
- C4::Koha::Log( "C4:SimpleMARC::field_exists: Returning '$return'" ) if $debug >= 2;
return $return;
}
sub field_equals {
my ( $record, $value, $fieldName, $subfieldName, $regex, $n ) = @_;
$n = 1 unless ( $n ); ## $n defaults to first field of a repeatable field series
- C4::Koha::Log( "C4::SimpleMARC::field_equals( '$record', '$value', '$fieldName', '$subfieldName', '$regex', '$n')" ) if $debug;
if ( ! $record ) { return; }
my $field_value = $field_values[$n-1];
if ( $regex ) {
- C4::Koha::Log( "Testing '$field_value' =~ m/$value/" ) if $debug >= 3;
return $field_value =~ m/$value/;
} else {
return $field_value eq $value;
sub move_field {
my ( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n ) = @_;
- C4::Koha::Log( "C4::SimpleMARC::move_field( '$record', '$fromFieldName', '$fromSubfieldName', '$toFieldName', '$toSubfieldName', '$regex', '$n' )" ) if $debug;
copy_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n , 'dont_erase' );
delete_field( $record, $fromFieldName, $fromSubfieldName, $n );
}
sub delete_field {
my ( $record, $fieldName, $subfieldName, $n ) = @_;
- C4::Koha::Log( "C4::SimpleMARC::delete_field( '$record', '$fieldName', '$subfieldName', '$n' )" ) if $debug;
my @fields = $record->field( $fieldName );