Lines 29-34
use MARC::File::USMARC;
Link Here
|
29 |
use MARC::File::XML; |
29 |
use MARC::File::XML; |
30 |
use POSIX qw(strftime); |
30 |
use POSIX qw(strftime); |
31 |
use Module::Load::Conditional qw(can_load); |
31 |
use Module::Load::Conditional qw(can_load); |
|
|
32 |
use String::Similarity; |
32 |
|
33 |
|
33 |
use C4::Koha; |
34 |
use C4::Koha; |
34 |
use C4::Log; # logaction |
35 |
use C4::Log; # logaction |
Lines 100-105
BEGIN {
Link Here
|
100 |
&CountBiblioInOrders |
101 |
&CountBiblioInOrders |
101 |
&GetSubscriptionsId |
102 |
&GetSubscriptionsId |
102 |
&GetHolds |
103 |
&GetHolds |
|
|
104 |
|
105 |
&GetMarcPermissionsRules |
106 |
&GetMarcPermissionsModules |
107 |
&ModMarcPermissionsRule |
108 |
&AddMarcPermissionsRule |
109 |
&DelMarcPermissionsRule |
103 |
); |
110 |
); |
104 |
|
111 |
|
105 |
# To modify something |
112 |
# To modify something |
Lines 128-133
BEGIN {
Link Here
|
128 |
# they are useful in a few circumstances, so they are exported, |
135 |
# they are useful in a few circumstances, so they are exported, |
129 |
# but don't use them unless you are a core developer ;-) |
136 |
# but don't use them unless you are a core developer ;-) |
130 |
push @EXPORT, qw( |
137 |
push @EXPORT, qw( |
|
|
138 |
&ApplyMarcPermissions |
131 |
&ModBiblioMarc |
139 |
&ModBiblioMarc |
132 |
); |
140 |
); |
133 |
|
141 |
|
Lines 225-239
bib to add, while the second argument is the desired MARC
Link Here
|
225 |
framework code. |
233 |
framework code. |
226 |
|
234 |
|
227 |
This function also accepts a third, optional argument: a hashref |
235 |
This function also accepts a third, optional argument: a hashref |
228 |
to additional options. The only defined option is C<defer_marc_save>, |
236 |
to additional options. Defined options are: |
229 |
which if present and mapped to a true value, causes C<AddBiblio> |
237 |
|
230 |
to omit the call to save the MARC in C<bibilioitems.marc> |
238 |
C<defer_marc_save> |
231 |
and C<biblioitems.marcxml> This option is provided B<only> |
239 |
|
232 |
for the use of scripts such as C<bulkmarcimport.pl> that may need |
240 |
If present and mapped to a true value, causes C<AddBiblio> to omit the call |
233 |
to do some manipulation of the MARC record for item parsing before |
241 |
to save the MARC in C<bibilioitems.marc> and C<biblioitems.marcxml> This |
234 |
saving it and which cannot afford the performance hit of saving |
242 |
option is provided B<only> for the use of scripts such as |
235 |
the MARC record twice. Consequently, do not use that option |
243 |
C<bulkmarcimport.pl> that may need to do some manipulation of the MARC |
236 |
unless you can guarantee that C<ModBiblioMarc> will be called. |
244 |
record for item parsing before saving it and which cannot afford the |
|
|
245 |
performance hit of saving the MARC record twice. Consequently, do not use |
246 |
that option unless you can guarantee that C<ModBiblioMarc> will be called. |
247 |
|
248 |
C<filter> |
249 |
|
250 |
Optional hashref defining permission filters from the |
251 |
marc_permissions_modules table in form of {module => filter}. Three |
252 |
predefined filter modules exists: |
253 |
|
254 |
* source |
255 |
* category |
256 |
* borrower |
237 |
|
257 |
|
238 |
=cut |
258 |
=cut |
239 |
|
259 |
|
Lines 266-272
sub AddBiblio {
Link Here
|
266 |
_koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); |
286 |
_koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); |
267 |
|
287 |
|
268 |
# now add the record |
288 |
# now add the record |
269 |
ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save; |
289 |
ModBiblioMarc( $record, $biblionumber, $frameworkcode, $options->{filter} ) unless $defer_marc_save; |
270 |
|
290 |
|
271 |
# update OAI-PMH sets |
291 |
# update OAI-PMH sets |
272 |
if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { |
292 |
if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { |
Lines 295-306
in the C<biblio> and C<biblioitems> tables, as well as
Link Here
|
295 |
which fields are used to store embedded item, biblioitem, |
315 |
which fields are used to store embedded item, biblioitem, |
296 |
and biblionumber data for indexing. |
316 |
and biblionumber data for indexing. |
297 |
|
317 |
|
|
|
318 |
This function also accepts a forth, optional argument: a hashref defining |
319 |
permission filters from the marc_permissions_modules table in form of |
320 |
{module => filter}. Three predefined filter modules exists: |
321 |
|
322 |
* source |
323 |
* category |
324 |
* borrower |
325 |
|
298 |
Returns 1 on success 0 on failure |
326 |
Returns 1 on success 0 on failure |
299 |
|
327 |
|
300 |
=cut |
328 |
=cut |
301 |
|
329 |
|
302 |
sub ModBiblio { |
330 |
sub ModBiblio { |
303 |
my ( $record, $biblionumber, $frameworkcode ) = @_; |
331 |
my ( $record, $biblionumber, $frameworkcode, $filter ) = @_; |
|
|
332 |
|
304 |
if (!$record) { |
333 |
if (!$record) { |
305 |
carp 'No record passed to ModBiblio'; |
334 |
carp 'No record passed to ModBiblio'; |
306 |
return 0; |
335 |
return 0; |
Lines 338-350
sub ModBiblio {
Link Here
|
338 |
_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber ); |
367 |
_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber ); |
339 |
|
368 |
|
340 |
# load the koha-table data object |
369 |
# load the koha-table data object |
341 |
my $oldbiblio = TransformMarcToKoha( $dbh, $record, $frameworkcode ); |
370 |
my $oldbiblio = TransformMarcToKoha( $dbh, $record, $frameworkcode, undef, $biblionumber, $filter ); |
342 |
|
371 |
|
343 |
# update MARC subfield that stores biblioitems.cn_sort |
372 |
# update MARC subfield that stores biblioitems.cn_sort |
344 |
_koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); |
373 |
_koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); |
345 |
|
374 |
|
346 |
# update the MARC record (that now contains biblio and items) with the new record data |
375 |
# update the MARC record (that now contains biblio and items) with the new record data |
347 |
&ModBiblioMarc( $record, $biblionumber, $frameworkcode ); |
376 |
&ModBiblioMarc( $record, $biblionumber, $frameworkcode, $filter); |
348 |
|
377 |
|
349 |
# modify the other koha tables |
378 |
# modify the other koha tables |
350 |
_koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); |
379 |
_koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); |
Lines 1228-1234
$frameworkcode is optional. If not given, then the default framework is used.
Link Here
|
1228 |
sub GetMarcSubfieldStructureFromKohaField { |
1257 |
sub GetMarcSubfieldStructureFromKohaField { |
1229 |
my ($kohafield, $frameworkcode) = @_; |
1258 |
my ($kohafield, $frameworkcode) = @_; |
1230 |
|
1259 |
|
1231 |
return undef unless $kohafield; |
1260 |
return unless $kohafield; |
1232 |
$frameworkcode //= ''; |
1261 |
$frameworkcode //= ''; |
1233 |
|
1262 |
|
1234 |
my $dbh = C4::Context->dbh; |
1263 |
my $dbh = C4::Context->dbh; |
Lines 2589-2595
our $inverted_field_map;
Link Here
|
2589 |
|
2618 |
|
2590 |
=head2 TransformMarcToKoha |
2619 |
=head2 TransformMarcToKoha |
2591 |
|
2620 |
|
2592 |
$result = TransformMarcToKoha( $dbh, $record, $frameworkcode ) |
2621 |
$result = TransformMarcToKoha( $dbh, $record, $frameworkcode, $biblionumber, $filter ) |
2593 |
|
2622 |
|
2594 |
Extract data from a MARC bib record into a hashref representing |
2623 |
Extract data from a MARC bib record into a hashref representing |
2595 |
Koha biblio, biblioitems, and items fields. |
2624 |
Koha biblio, biblioitems, and items fields. |
Lines 2600-2606
hash_ref
Link Here
|
2600 |
=cut |
2629 |
=cut |
2601 |
|
2630 |
|
2602 |
sub TransformMarcToKoha { |
2631 |
sub TransformMarcToKoha { |
2603 |
my ( $dbh, $record, $frameworkcode, $limit_table ) = @_; |
2632 |
my ( $dbh, $record, $frameworkcode, $limit_table, $biblionumber, $filter ) = @_; |
2604 |
|
2633 |
|
2605 |
my $result = {}; |
2634 |
my $result = {}; |
2606 |
if (!defined $record) { |
2635 |
if (!defined $record) { |
Lines 2623-2628
sub TransformMarcToKoha {
Link Here
|
2623 |
$tables{'biblioitems'} = 1; |
2652 |
$tables{'biblioitems'} = 1; |
2624 |
} |
2653 |
} |
2625 |
|
2654 |
|
|
|
2655 |
# apply permissions |
2656 |
if ( C4::Context->preference('MARCPermissions') && $biblionumber && $filter) { |
2657 |
$record = ApplyMarcPermissions({ |
2658 |
biblionumber => $biblionumber, |
2659 |
record => $record, |
2660 |
frameworkcode => $frameworkcode, |
2661 |
filter => $filter, |
2662 |
nolog => 1 |
2663 |
}); |
2664 |
} |
2665 |
|
2626 |
# traverse through record |
2666 |
# traverse through record |
2627 |
MARCFIELD: foreach my $field ( $record->fields() ) { |
2667 |
MARCFIELD: foreach my $field ( $record->fields() ) { |
2628 |
my $tag = $field->tag(); |
2668 |
my $tag = $field->tag(); |
Lines 3389-3395
sub _koha_delete_biblioitems {
Link Here
|
3389 |
|
3429 |
|
3390 |
=head2 ModBiblioMarc |
3430 |
=head2 ModBiblioMarc |
3391 |
|
3431 |
|
3392 |
&ModBiblioMarc($newrec,$biblionumber,$frameworkcode); |
3432 |
&ModBiblioMarc($newrec,$biblionumber,$frameworkcode,$filter); |
3393 |
|
3433 |
|
3394 |
Add MARC data for a biblio to koha |
3434 |
Add MARC data for a biblio to koha |
3395 |
|
3435 |
|
Lines 3400-3406
Function exported, but should NOT be used, unless you really know what you're do
Link Here
|
3400 |
sub ModBiblioMarc { |
3440 |
sub ModBiblioMarc { |
3401 |
# pass the MARC::Record to this function, and it will create the records in |
3441 |
# pass the MARC::Record to this function, and it will create the records in |
3402 |
# the marc field |
3442 |
# the marc field |
3403 |
my ( $record, $biblionumber, $frameworkcode ) = @_; |
3443 |
my ( $record, $biblionumber, $frameworkcode, $filter ) = @_; |
|
|
3444 |
|
3404 |
if ( !$record ) { |
3445 |
if ( !$record ) { |
3405 |
carp 'ModBiblioMarc passed an undefined record'; |
3446 |
carp 'ModBiblioMarc passed an undefined record'; |
3406 |
return; |
3447 |
return; |
Lines 3446-3451
sub ModBiblioMarc {
Link Here
|
3446 |
$f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005; |
3487 |
$f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005; |
3447 |
} |
3488 |
} |
3448 |
|
3489 |
|
|
|
3490 |
# apply permissions |
3491 |
if ( C4::Context->preference('MARCPermissions') ) { |
3492 |
$record = ApplyMarcPermissions({ |
3493 |
biblionumber => $biblionumber, |
3494 |
record => $record, |
3495 |
frameworkcode => $frameworkcode, |
3496 |
filter => $filter |
3497 |
}); |
3498 |
} |
3499 |
|
3449 |
$sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?"); |
3500 |
$sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?"); |
3450 |
$sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding), $biblionumber ); |
3501 |
$sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding), $biblionumber ); |
3451 |
$sth->finish; |
3502 |
$sth->finish; |
Lines 3804-3809
sub RemoveAllNsb {
Link Here
|
3804 |
return $record; |
3855 |
return $record; |
3805 |
} |
3856 |
} |
3806 |
|
3857 |
|
|
|
3858 |
=head2 ApplyMarcPermissions |
3859 |
|
3860 |
my $record = ApplyMarcPermissions($arguments) |
3861 |
|
3862 |
Applies marc permission rules to a record. |
3863 |
|
3864 |
C<$arguments> is expected to be a hashref with below keys defined. |
3865 |
|
3866 |
=over 4 |
3867 |
|
3868 |
=item C<biblionumber> |
3869 |
biblionumber of old record |
3870 |
|
3871 |
=item C<record> |
3872 |
record that will modify old record |
3873 |
|
3874 |
=item C<frameworkcode> |
3875 |
only tags included in framework will be processed |
3876 |
|
3877 |
=item C<filter> |
3878 |
hashref containing at least one filter module from the marc_permissions_modules |
3879 |
table in form {module => filter}. Three predefined filter modules exists: |
3880 |
|
3881 |
* source |
3882 |
* category |
3883 |
* borrower |
3884 |
|
3885 |
=item C<log> |
3886 |
optional reference to array that will be filled with rule evaluation log |
3887 |
entries. |
3888 |
|
3889 |
=item C<nolog> |
3890 |
optional boolean which when true disables logging to action log. |
3891 |
|
3892 |
=back |
3893 |
|
3894 |
Returns: |
3895 |
|
3896 |
=over 4 |
3897 |
|
3898 |
=item C<$record> |
3899 |
|
3900 |
new MARC record based on C<record> with C<filter> applied. If no old |
3901 |
record for C<biblionumber> can be found, C<record> is returned unchanged. |
3902 |
Default action when no matching filter found is to leave old record unchanged. |
3903 |
|
3904 |
=back |
3905 |
|
3906 |
=cut |
3907 |
|
3908 |
sub ApplyMarcPermissions { |
3909 |
my $arguments = shift; |
3910 |
my $biblionumber = $arguments->{biblionumber}; |
3911 |
my $new_record = $arguments->{record}; |
3912 |
my $frameworkcode = $arguments->{frameworkcode} || ''; |
3913 |
|
3914 |
if ( !$biblionumber ) { |
3915 |
carp 'ApplyMarcPermissions called on undefined biblionumber'; |
3916 |
return; |
3917 |
} |
3918 |
if ( !$new_record ) { |
3919 |
carp 'ApplyMarcPermissions called on undefined record'; |
3920 |
return; |
3921 |
} |
3922 |
my $filter = $arguments->{filter} |
3923 |
or return $new_record; |
3924 |
|
3925 |
my $log = $arguments->{log} || []; |
3926 |
my $nolog = $arguments->{nolog}; |
3927 |
|
3928 |
my $dbh = C4::Context->dbh; |
3929 |
|
3930 |
my $is_regex = sub { |
3931 |
my ( $tag, $m ) = @_; |
3932 |
# tag is not exactly same as possible regex |
3933 |
$tag ne $m && |
3934 |
|
3935 |
# wildcard |
3936 |
$m ne '*' && |
3937 |
|
3938 |
# valid tagDataType |
3939 |
$m !~ /^(0[1-9A-z][\dA-Z]) | |
3940 |
([1-9A-z][\dA-z]{2})$/x && |
3941 |
|
3942 |
# nor valid controltagDataType |
3943 |
$m !~ /00[1-9A-Za-z]{1}/ && |
3944 |
|
3945 |
# so we try it as a regex |
3946 |
$tag =~ /^$m$/ |
3947 |
}; |
3948 |
|
3949 |
my $old_record = GetMarcBiblio($biblionumber); |
3950 |
if ( $old_record ) { |
3951 |
my $ret_record = MARC::Record->new(); |
3952 |
my $perm = GetMarcPermissions() or return $new_record; |
3953 |
my $marc_struct = GetMarcStructure(1, $frameworkcode); |
3954 |
my $similarity_pref = C4::Context->preference("MARCPermissionsCorrectionSimilarity"); |
3955 |
$similarity_pref = defined $similarity_pref && |
3956 |
$similarity_pref >= 0 && |
3957 |
$similarity_pref <= 100 ? |
3958 |
$similarity_pref/100.0 : undef; |
3959 |
|
3960 |
# First came the leader ... |
3961 |
$ret_record->leader($old_record->leader()); |
3962 |
|
3963 |
# ... and then came all the tags in the framework |
3964 |
for my $tag (sort keys %{$marc_struct}) { |
3965 |
my @old_fields = $old_record->field($tag); |
3966 |
my @new_fields = $new_record->field($tag); |
3967 |
next unless @old_fields or @new_fields; |
3968 |
|
3969 |
my @perms = ( |
3970 |
$perm->{'*'}, |
3971 |
( # regex tags |
3972 |
map { $perm->{$_} } |
3973 |
grep { $is_regex->( $tag, $_ ) } sort keys %{$perm} |
3974 |
), |
3975 |
$perm->{$tag} |
3976 |
); |
3977 |
|
3978 |
# There can be more than one field for each tag, so we have to |
3979 |
# iterate all fields and distinguish which are new, removed or |
3980 |
# modified |
3981 |
my $max_fields = ($#old_fields, $#new_fields) |
3982 |
[$#old_fields< $#new_fields]; |
3983 |
for ( my $i_field = 0; $i_field <= $max_fields; $i_field++ ) { |
3984 |
my $old_field = $old_fields[$i_field]; |
3985 |
my $new_field = $new_fields[$i_field]; |
3986 |
|
3987 |
# Existing field |
3988 |
if ( $old_field and $new_field ) { |
3989 |
# Control fields |
3990 |
if ( $old_field->is_control_field() ) { |
3991 |
# Existing control field |
3992 |
if ( $old_field and $new_field ) { |
3993 |
my $on_existing = GetMarcPermissionsAction('on_existing', $filter, @perms); |
3994 |
if ( defined $on_existing->{action} ) { |
3995 |
push @{$log}, |
3996 |
{ |
3997 |
rule => $on_existing->{rule}, |
3998 |
event => "existing", |
3999 |
action => $on_existing->{action}, |
4000 |
tag => $tag, |
4001 |
subfieldcode => undef, |
4002 |
filter => $filter |
4003 |
}; |
4004 |
if ( $on_existing->{action} eq 'skip' ) { |
4005 |
$ret_record->insert_fields_ordered($old_field); |
4006 |
next; |
4007 |
} elsif ( $on_existing->{action} eq 'overwrite' ) { |
4008 |
$ret_record->insert_fields_ordered($new_field); |
4009 |
next; |
4010 |
} elsif ( $on_existing->{action} eq 'add' ) { |
4011 |
$ret_record->insert_fields_ordered($old_field); |
4012 |
$ret_record->insert_fields_ordered($new_field); |
4013 |
next; |
4014 |
} elsif ( $on_existing->{action} eq 'add_or_correct' ) { |
4015 |
if ( $similarity_pref ) { |
4016 |
my $similarity = similarity $old_field->data(), $new_field->data(); |
4017 |
if ( $similarity >= $similarity_pref ) { |
4018 |
$ret_record->insert_fields_ordered($new_field); |
4019 |
} else { |
4020 |
$ret_record->insert_fields_ordered($old_field); |
4021 |
$ret_record->insert_fields_ordered($new_field); |
4022 |
} |
4023 |
} else { |
4024 |
$ret_record->insert_fields_ordered($old_field); |
4025 |
} |
4026 |
} |
4027 |
} else { # default to skip |
4028 |
$ret_record->insert_fields_ordered($old_field); |
4029 |
next; |
4030 |
} |
4031 |
# New control field |
4032 |
} elsif ( not $old_field and $new_field ) { |
4033 |
my $on_new = GetMarcPermissionsAction('on_new', $filter, @perms); |
4034 |
if ( defined $on_new->{action} ) { |
4035 |
push @{$log}, |
4036 |
{ |
4037 |
rule => $on_new->{rule}, |
4038 |
event => "new", |
4039 |
action => $on_new->{action}, |
4040 |
tag => $tag, |
4041 |
subfieldcode => undef, |
4042 |
filter => $filter |
4043 |
}; |
4044 |
if ( $on_new->{action} eq 'skip' ) { |
4045 |
next; |
4046 |
} elsif ( $on_new->{action} eq 'add' ) { |
4047 |
$ret_record->insert_fields_ordered($new_field); |
4048 |
next; |
4049 |
} |
4050 |
} |
4051 |
# Removed control field |
4052 |
} elsif ( $old_field and not $new_field ) { |
4053 |
my $on_removed = GetMarcPermissionsAction('on_removed', $filter, @perms); |
4054 |
if ( defined $on_removed->{action} ) { |
4055 |
push @{$log}, |
4056 |
{ |
4057 |
rule => $on_removed->{rule}, |
4058 |
event => "removed", |
4059 |
action => $on_removed->{action}, |
4060 |
tag => $tag, |
4061 |
subfieldcode => undef |
4062 |
}; |
4063 |
if ( $on_removed->{action} eq 'skip' ) { |
4064 |
$ret_record->insert_fields_ordered($old_field); |
4065 |
next; |
4066 |
} elsif ( $on_removed->{action} eq 'remove' ) { |
4067 |
next; |
4068 |
} |
4069 |
} else { # default to skip |
4070 |
$ret_record->insert_fields_ordered($old_field); |
4071 |
next; |
4072 |
} |
4073 |
} |
4074 |
# Indicators and subfields |
4075 |
} else { |
4076 |
# Indicators |
4077 |
my @old_ind = map { $old_field->indicator($_) } (1,2); |
4078 |
my @new_ind = map { $new_field->indicator($_) } (1,2); |
4079 |
my @ind = ('',''); |
4080 |
|
4081 |
for my $i ((0,1)) { |
4082 |
my @ind_perms = ( |
4083 |
@perms, |
4084 |
$perm->{$tag}->{subfields}->{ 'i' . ( $i + 1 ) } |
4085 |
); |
4086 |
|
4087 |
# Existing indicator |
4088 |
if ( defined $old_ind[$i] and defined $new_ind[$i] ) { |
4089 |
my $on_existing = GetMarcPermissionsAction('on_existing', $filter, @ind_perms); |
4090 |
if ( defined $on_existing->{action} ) { |
4091 |
push @{$log}, |
4092 |
{ |
4093 |
rule => $on_existing->{rule}, |
4094 |
event => "existing", |
4095 |
action => $on_existing->{action}, |
4096 |
tag => $tag, |
4097 |
subfieldcode => 'i' . ( $i + 1 ), |
4098 |
filter => $filter |
4099 |
}; |
4100 |
if ( $on_existing->{action} eq 'skip' ) { |
4101 |
$ind[$i] = $old_ind[$i]; |
4102 |
} elsif ( $on_existing->{action} eq 'overwrite' ) { |
4103 |
$ind[$i] = $new_ind[$i]; |
4104 |
} |
4105 |
} else { # default to skip |
4106 |
$ind[$i] = $old_ind[$i]; |
4107 |
} |
4108 |
# New indicator |
4109 |
} elsif ( not defined $old_ind[$i] and defined $new_ind[$i] ) { |
4110 |
my $on_new = GetMarcPermissionsAction('on_new', $filter, @ind_perms); |
4111 |
if ( defined $on_new->{action} ) { |
4112 |
push @{$log}, |
4113 |
{ |
4114 |
rule => $on_new->{rule}, |
4115 |
event => "new", |
4116 |
action => $on_new->{action}, |
4117 |
tag => $tag, |
4118 |
subfieldcode => 'i' . ( $i + 1 ), |
4119 |
filter => $filter |
4120 |
}; |
4121 |
if ( $on_new->{action} eq 'skip' ) { |
4122 |
$ind[$i] = $old_ind[$i]; |
4123 |
} elsif ( $on_new->{action} eq 'add' ) { |
4124 |
$ind[$i] = $new_ind[$i]; |
4125 |
} |
4126 |
} |
4127 |
# Removed indicator |
4128 |
} elsif ( defined $old_ind[$i] and not defined $new_ind[$i] ) { |
4129 |
my $on_removed = GetMarcPermissionsAction('on_removed', $filter, @ind_perms); |
4130 |
if ( defined $on_removed->{action} ) { |
4131 |
push @{$log}, |
4132 |
{ |
4133 |
rule => $on_removed->{rule}, |
4134 |
event => "removed", |
4135 |
action => $on_removed->{action}, |
4136 |
tag => $tag, |
4137 |
subfieldcode => 'i' . ( $i + 1 ), |
4138 |
filter => $filter |
4139 |
}; |
4140 |
if ( $on_removed->{action} eq 'skip' ) { |
4141 |
$ind[$i] = $old_ind[$i]; |
4142 |
} elsif ( $on_removed->{action} eq 'remove' ) { |
4143 |
$ind[$i] = ''; |
4144 |
} |
4145 |
} else { # default to skip |
4146 |
$ind[$i] = $old_ind[$i]; |
4147 |
} |
4148 |
} |
4149 |
} |
4150 |
|
4151 |
# Subfields |
4152 |
my @subfields = (); |
4153 |
my %proccessed_subcodes = (); |
4154 |
|
4155 |
# Try to preserve subfield order by first processing |
4156 |
# subfields from the old record, and then subfields from |
4157 |
# the framework structure unless include in old record. |
4158 |
my @sorted_subfields = ( |
4159 |
map { shift @{$_} } $old_field->subfields(), |
4160 |
() = sort keys %{ $marc_struct->{$tag} } |
4161 |
); |
4162 |
for my $subcode ( @sorted_subfields ) { |
4163 |
next if $proccessed_subcodes{$subcode}; |
4164 |
$proccessed_subcodes{$subcode} = 1; |
4165 |
next unless ref $marc_struct->{$tag}{$subcode} eq 'HASH'; |
4166 |
my @old_subfields = $old_field->subfield($subcode); |
4167 |
my @new_subfields = $new_field->subfield($subcode); |
4168 |
next unless @old_subfields or @new_subfields; |
4169 |
|
4170 |
my @subfield_perms = ( |
4171 |
@perms, |
4172 |
$perm->{'*'}->{subfields}->{'*'}, |
4173 |
$perm->{$tag}->{subfields}->{'*'}, |
4174 |
( # tag->regex |
4175 |
map { $perm->{$tag}->{subfields}->{$_} } |
4176 |
grep { |
4177 |
# subcode is not exactly same as |
4178 |
# possible regex |
4179 |
$subcode ne $_ && |
4180 |
|
4181 |
# wildcard, not checking for valid |
4182 |
# subfieldcodeDataType since it |
4183 |
# contains too many regex characters |
4184 |
$_ !~ /^(\*)$/ && |
4185 |
|
4186 |
# so we try it as a regex |
4187 |
$subcode =~ /$_/ |
4188 |
} sort |
4189 |
keys %{ $perm->{$tag}->{subfields} } |
4190 |
), |
4191 |
( # regex->* |
4192 |
map { $perm->{$_}->{subfields}->{'*'} } |
4193 |
grep { $is_regex->( $tag, $_ ) } |
4194 |
sort keys %{$perm} |
4195 |
), |
4196 |
$perm->{'*'}->{subfields}->{$subcode}, |
4197 |
( # regex->subcode |
4198 |
map { $perm->{$_}->{subfields}->{$subcode} } |
4199 |
grep { $is_regex->( $tag, $_ ) } |
4200 |
sort keys %{$perm} |
4201 |
), |
4202 |
$perm->{$tag}->{subfields}->{$subcode} |
4203 |
); |
4204 |
|
4205 |
# Existing subfield |
4206 |
if ( @old_subfields and @new_subfields ) { |
4207 |
my $on_existing = GetMarcPermissionsAction('on_existing', $filter, @subfield_perms); |
4208 |
if ( defined $on_existing->{action} ) { |
4209 |
push @{$log}, |
4210 |
{ |
4211 |
rule => $on_existing->{rule}, |
4212 |
event => "existing", |
4213 |
action => $on_existing->{action}, |
4214 |
tag => $tag, |
4215 |
subfieldcode => $subcode, |
4216 |
filter => $filter |
4217 |
}; |
4218 |
if ( $on_existing->{action} eq 'skip' ) { |
4219 |
push(@subfields, map {($subcode,$_)} @old_subfields); |
4220 |
next; |
4221 |
} elsif ( $on_existing->{action} eq 'overwrite' ) { |
4222 |
push(@subfields, map {($subcode,$_)} @new_subfields); |
4223 |
next; |
4224 |
} elsif ( $on_existing->{action} eq 'add' ) { |
4225 |
push(@subfields, map {($subcode,$_)} @old_subfields); |
4226 |
push(@subfields, map {($subcode,$_)} @new_subfields); |
4227 |
next; |
4228 |
} elsif ( $on_existing->{action} eq 'add_or_correct' ) { |
4229 |
if ( $similarity_pref ) { |
4230 |
my @corrected_vals = (); |
4231 |
|
4232 |
# correct all old subfields |
4233 |
for ( my $i_new = 0; $i_new <= $#new_subfields; $i_new++ ) { |
4234 |
my $new_val = $new_subfields[$i_new]; |
4235 |
for ( my $i_old = 0; $i_old <= $#old_subfields; $i_old++ ) { |
4236 |
my $old_val = $old_subfields[$i_old]; |
4237 |
next if not defined $old_val or not defined $new_val; |
4238 |
my $similarity = similarity $old_val, $new_val; |
4239 |
if ( $similarity >= $similarity_pref ) { |
4240 |
$corrected_vals[$i_old] = $new_val; |
4241 |
$new_subfields[$i_new] = undef; |
4242 |
$old_subfields[$i_old] = undef; |
4243 |
last; |
4244 |
} |
4245 |
} |
4246 |
} |
4247 |
|
4248 |
# insert all unchanged old subfields |
4249 |
map { |
4250 |
$corrected_vals[$_] = $old_subfields[$_] |
4251 |
if defined $old_subfields[$_] |
4252 |
} 0 .. $#old_subfields; |
4253 |
|
4254 |
|
4255 |
# append all remaning new subfields |
4256 |
map {push @corrected_vals, $_ if defined} @new_subfields; |
4257 |
|
4258 |
push(@subfields, map {($subcode,$_)} @corrected_vals); |
4259 |
} else { |
4260 |
push(@subfields, map {($subcode,$_)} @old_subfields); |
4261 |
} |
4262 |
} |
4263 |
} else { # default to skip |
4264 |
push(@subfields, map {($subcode,$_)} @old_subfields); |
4265 |
next; |
4266 |
} |
4267 |
# New subfield |
4268 |
} elsif ( not @old_subfields and @new_subfields ) { |
4269 |
my $on_new = GetMarcPermissionsAction('on_new', $filter, @subfield_perms); |
4270 |
if ( defined $on_new->{action} ) { |
4271 |
push @{$log}, |
4272 |
{ |
4273 |
rule => $on_new->{rule}, |
4274 |
event => "new", |
4275 |
action => $on_new->{action}, |
4276 |
tag => $tag, |
4277 |
subfieldcode => $subcode, |
4278 |
filter => $filter |
4279 |
}; |
4280 |
if ( $on_new->{action} eq 'skip' ) { |
4281 |
next; |
4282 |
} elsif ( $on_new->{action} eq 'add' ) { |
4283 |
push(@subfields, map {($subcode,$_)} @new_subfields); |
4284 |
next; |
4285 |
} |
4286 |
} |
4287 |
# Removed subfield |
4288 |
} elsif ( @old_subfields and not @new_subfields ) { |
4289 |
my $on_removed = GetMarcPermissionsAction('on_removed', $filter, @subfield_perms); |
4290 |
if ( defined $on_removed->{action} ) { |
4291 |
push @{$log}, |
4292 |
{ |
4293 |
rule => $on_removed->{rule}, |
4294 |
event => "removed", |
4295 |
action => $on_removed->{action}, |
4296 |
tag => $tag, |
4297 |
subfieldcode => $subcode, |
4298 |
filter => $filter |
4299 |
}; |
4300 |
if ( $on_removed->{action} eq 'skip' ) { |
4301 |
push(@subfields, ($subcode => @old_subfields)); |
4302 |
next; |
4303 |
} elsif ( $on_removed->{action} eq 'remove' ) { |
4304 |
next; |
4305 |
} |
4306 |
} else { # default to skip |
4307 |
push(@subfields, ($subcode => @old_subfields)); |
4308 |
next; |
4309 |
} |
4310 |
} |
4311 |
} # / for each subfield |
4312 |
$ret_record->insert_grouped_field(MARC::Field->new($tag, $ind[0], $ind[1], @subfields)); |
4313 |
} |
4314 |
# New field |
4315 |
} elsif ( not $old_field and $new_field ) { |
4316 |
my $on_new = GetMarcPermissionsAction('on_new', $filter, @perms); |
4317 |
if ( defined $on_new->{action} ) { |
4318 |
push @{$log}, |
4319 |
{ |
4320 |
rule => $on_new->{rule}, |
4321 |
event => "new", |
4322 |
action => $on_new->{action}, |
4323 |
tag => $tag, |
4324 |
subfieldcode => undef, |
4325 |
filter => $filter |
4326 |
}; |
4327 |
if ( $on_new->{action} eq 'skip' ) { |
4328 |
next; |
4329 |
} elsif ( $on_new->{action} eq 'add' ) { |
4330 |
$ret_record->insert_fields_ordered($new_field); |
4331 |
next; |
4332 |
} |
4333 |
} |
4334 |
# Removed field |
4335 |
} elsif ( $old_field and not $new_field ) { |
4336 |
my $on_removed = GetMarcPermissionsAction('on_removed', $filter, @perms); |
4337 |
if ( defined $on_removed->{action} ) { |
4338 |
push @{$log}, |
4339 |
{ |
4340 |
rule => $on_removed->{rule}, |
4341 |
event => "removed", |
4342 |
action => $on_removed->{action}, |
4343 |
tag => $tag, |
4344 |
subfieldcode => undef, |
4345 |
filter => $filter |
4346 |
}; |
4347 |
if ( $on_removed->{action} eq 'skip' ) { |
4348 |
$ret_record->insert_grouped_field($old_field); |
4349 |
next; |
4350 |
} elsif ( $on_removed->{action} eq 'remove' ) { |
4351 |
next; |
4352 |
} |
4353 |
} else { # default to skip |
4354 |
$ret_record->insert_grouped_field($old_field); |
4355 |
next; |
4356 |
} |
4357 |
} |
4358 |
} # / for each field |
4359 |
} # / for each tag |
4360 |
if ( !$nolog && C4::Context->preference("MARCPermissionsLog") ) { |
4361 |
my $log_str = ''; |
4362 |
my $n = $#{$log}; |
4363 |
for my $l ( @{$log} ) { |
4364 |
$log_str .= "{\n"; |
4365 |
my $kn = keys %{$l}; |
4366 |
for my $k ( sort keys %{$l} ) { |
4367 |
if ( $k eq 'filter' ) { |
4368 |
$log_str .= " filter => {\n"; |
4369 |
my $fkn = keys %{ $l->{$k} }; |
4370 |
for my $fk ( sort keys %{ $l->{$k} } ) { |
4371 |
$log_str .= ' ' |
4372 |
. $fk . ' => ' |
4373 |
. $l->{$k}->{$fk} |
4374 |
. ( --$fkn ? ',' : '' ) . "\n"; |
4375 |
} |
4376 |
$log_str .= " }" . ( --$kn ? ',' : '' ) . "\n"; |
4377 |
} |
4378 |
else { |
4379 |
$log_str .= ' ' |
4380 |
. $k . ' => ' |
4381 |
. $l->{$k} |
4382 |
. ( --$kn ? ',' : '' ) . "\n" |
4383 |
if defined $l->{$k}; |
4384 |
} |
4385 |
} |
4386 |
$log_str .= '}' . ( $n-- ? ",\n" : '' ); |
4387 |
} |
4388 |
logaction( "CATALOGUING", "MODIFY", $biblionumber, $log_str ); |
4389 |
} |
4390 |
return $ret_record; |
4391 |
} |
4392 |
return $new_record; |
4393 |
} |
4394 |
|
4395 |
|
4396 |
=head2 GetMarcPermissions |
4397 |
|
4398 |
my $marc_permissions = GetMarcPermissions() |
4399 |
|
4400 |
Loads MARC field permissions from the marc_permissions table. |
4401 |
|
4402 |
Returns: |
4403 |
|
4404 |
=over 4 |
4405 |
|
4406 |
=item C<$marc_permissions> |
4407 |
|
4408 |
hashref with permissions structure for use with GetMarcPermissionsAction. |
4409 |
|
4410 |
=back |
4411 |
|
4412 |
=cut |
4413 |
|
4414 |
sub GetMarcPermissions { |
4415 |
my $dbh = C4::Context->dbh; |
4416 |
my $rule_count = 0; |
4417 |
my %perms = (); |
4418 |
|
4419 |
my $query = ' |
4420 |
SELECT `marc_permissions`.*, |
4421 |
`marc_permissions_modules`.`name`, |
4422 |
`marc_permissions_modules`.`description`, |
4423 |
`marc_permissions_modules`.`specificity` |
4424 |
FROM `marc_permissions` |
4425 |
LEFT JOIN `marc_permissions_modules` ON `module` = `marc_permissions_modules`.`id` |
4426 |
ORDER BY `marc_permissions_modules`.`specificity`, `id` |
4427 |
'; |
4428 |
my $sth = $dbh->prepare($query); |
4429 |
$sth->execute(); |
4430 |
while ( my $row = $sth->fetchrow_hashref ) { |
4431 |
$rule_count++; |
4432 |
if ( defined $row->{tagsubfield} and $row->{tagsubfield} ) { |
4433 |
$perms{ $row->{tagfield} }->{subfields}->{ $row->{tagsubfield} } |
4434 |
->{on_existing}->{ $row->{name} }->{ $row->{filter} } = |
4435 |
{ action => $row->{on_existing}, rule => $row->{'id'} }; |
4436 |
$perms{ $row->{tagfield} }->{subfields}->{ $row->{tagsubfield} } |
4437 |
->{on_new}->{ $row->{name} }->{ $row->{filter} } = |
4438 |
{ action => $row->{on_new}, rule => $row->{'id'} }; |
4439 |
$perms{ $row->{tagfield} }->{subfields}->{ $row->{tagsubfield} } |
4440 |
->{on_removed}->{ $row->{name} }->{ $row->{filter} } = |
4441 |
{ action => $row->{on_removed}, rule => $row->{'id'} }; |
4442 |
} |
4443 |
else { |
4444 |
$perms{ $row->{tagfield} }->{on_existing}->{ $row->{name} } |
4445 |
->{ $row->{filter} } = |
4446 |
{ action => $row->{on_existing}, rule => $row->{'id'} }; |
4447 |
$perms{ $row->{tagfield} }->{on_new}->{ $row->{name} } |
4448 |
->{ $row->{filter} } = |
4449 |
{ action => $row->{on_new}, rule => $row->{'id'} }; |
4450 |
$perms{ $row->{tagfield} }->{on_removed}->{ $row->{name} } |
4451 |
->{ $row->{filter} } = |
4452 |
{ action => $row->{on_removed}, rule => $row->{'id'} }; |
4453 |
} |
4454 |
} |
4455 |
|
4456 |
return unless $rule_count; |
4457 |
return \%perms; |
4458 |
} |
4459 |
|
4460 |
=head2 GetMarcPermissionsAction |
4461 |
|
4462 |
my $action = GetMarcPermissionsAction($event, $filter, @permissions) |
4463 |
|
4464 |
Gets action based on C<$event>, C<$filter> and C<@permissions>. |
4465 |
|
4466 |
=over 4 |
4467 |
|
4468 |
=item C<$event> |
4469 |
|
4470 |
which event: 'on_existing', 'on_new' or 'on_removed' |
4471 |
|
4472 |
=item C<$filter> |
4473 |
|
4474 |
hashref containing at least one filter module from the marc_permissions_modules |
4475 |
table in form {module => filter}. Three predefined filter modules exists: |
4476 |
|
4477 |
* source |
4478 |
* category |
4479 |
* borrower |
4480 |
|
4481 |
=item C<@permissions> |
4482 |
|
4483 |
list of permission structures in order of specificity from least to most |
4484 |
specific. |
4485 |
|
4486 |
=back |
4487 |
|
4488 |
Returns: |
4489 |
|
4490 |
=over 4 |
4491 |
|
4492 |
=item C<$action> |
4493 |
|
4494 |
hashref defining matching action. |
4495 |
|
4496 |
=back |
4497 |
|
4498 |
=cut |
4499 |
|
4500 |
sub GetMarcPermissionsAction { |
4501 |
my $what = shift or return; |
4502 |
my $filter = shift or return; |
4503 |
my @perms = @_; |
4504 |
|
4505 |
my $modules = GetMarcPermissionsModules(); |
4506 |
|
4507 |
my $action = undef; |
4508 |
for my $perm (@perms) { |
4509 |
next if not defined $perm; |
4510 |
next if not defined $perm->{$what}; |
4511 |
my $tmp_action = undef; |
4512 |
|
4513 |
for my $module ( @{$modules} ) { |
4514 |
if (defined $perm->{$what}->{ $module->{'name'} } |
4515 |
and |
4516 |
defined $perm->{$what}->{ $module->{'name'} }->{'*'}->{action} ) |
4517 |
{ |
4518 |
$tmp_action = $perm->{$what}->{ $module->{'name'} }->{'*'}; |
4519 |
} |
4520 |
if ( defined $filter->{ $module->{'name'} } |
4521 |
and defined $perm->{$what}->{ $module->{'name'} } |
4522 |
and defined $perm->{$what}->{ $module->{'name'} } |
4523 |
->{ $filter->{ $module->{'name'} } }->{action} ) |
4524 |
{ |
4525 |
$tmp_action = $perm->{$what}->{ $module->{'name'} } |
4526 |
->{ $filter->{ $module->{'name'} } }; |
4527 |
} |
4528 |
} |
4529 |
|
4530 |
$action = $tmp_action if defined $tmp_action; |
4531 |
} |
4532 |
|
4533 |
return $action; |
4534 |
} |
4535 |
|
4536 |
=head2 GetMarcPermissionsRules |
4537 |
|
4538 |
my $rules = GetMarcPermissionsRules() |
4539 |
|
4540 |
Returns: |
4541 |
|
4542 |
=over 4 |
4543 |
|
4544 |
=item C<$rules> |
4545 |
|
4546 |
array (in list context, arrayref otherwise) of hashrefs from marc_permissions |
4547 |
table in order of module specificity and rule id. |
4548 |
|
4549 |
=back |
4550 |
|
4551 |
=cut |
4552 |
|
4553 |
sub GetMarcPermissionsRules { |
4554 |
my $dbh = C4::Context->dbh; |
4555 |
my @rules = (); |
4556 |
|
4557 |
my $query = ' |
4558 |
SELECT `marc_permissions`.`id`, |
4559 |
`marc_permissions`.`tagfield`, |
4560 |
`marc_permissions`.`tagsubfield`, |
4561 |
`marc_permissions`.`filter`, |
4562 |
`marc_permissions`.`on_existing`, |
4563 |
`marc_permissions`.`on_new`, |
4564 |
`marc_permissions`.`on_removed`, |
4565 |
`marc_permissions_modules`.`name` as `module`, |
4566 |
`marc_permissions_modules`.`description`, |
4567 |
`marc_permissions_modules`.`specificity` |
4568 |
FROM `marc_permissions` |
4569 |
LEFT JOIN `marc_permissions_modules` ON `module` = `marc_permissions_modules`.`id` |
4570 |
ORDER BY `marc_permissions_modules`.`specificity`, `id` |
4571 |
'; |
4572 |
my $sth = $dbh->prepare($query); |
4573 |
$sth->execute(); |
4574 |
while ( my $row = $sth->fetchrow_hashref ) { |
4575 |
push(@rules, $row); |
4576 |
} |
4577 |
|
4578 |
return wantarray ? @rules : \@rules; |
4579 |
} |
4580 |
|
4581 |
=head2 GetMarcPermissionsModules |
4582 |
|
4583 |
my $modules = GetMarcPermissionsModules() |
4584 |
|
4585 |
Returns: |
4586 |
|
4587 |
=over 4 |
4588 |
|
4589 |
=item C<$modules> |
4590 |
|
4591 |
array (in list context, arrayref otherwise) of hashrefs from |
4592 |
marc_permissions_modules table in order of specificity. |
4593 |
|
4594 |
=back |
4595 |
|
4596 |
=cut |
4597 |
|
4598 |
sub GetMarcPermissionsModules { |
4599 |
my $dbh = C4::Context->dbh; |
4600 |
my @modules = (); |
4601 |
|
4602 |
my $query = ' |
4603 |
SELECT * |
4604 |
FROM `marc_permissions_modules` |
4605 |
ORDER BY `specificity` |
4606 |
'; |
4607 |
my $sth = $dbh->prepare($query); |
4608 |
$sth->execute(); |
4609 |
while ( my $row = $sth->fetchrow_hashref ) { |
4610 |
push(@modules, $row); |
4611 |
} |
4612 |
|
4613 |
return wantarray ? @modules : \@modules; |
4614 |
} |
4615 |
|
4616 |
=head2 ModMarcPermissionsRule |
4617 |
|
4618 |
my $success = ModMarcPermissionsRule($id, $fields) |
4619 |
|
4620 |
Modifies rule in the marc_permissions table. |
4621 |
|
4622 |
=over 4 |
4623 |
|
4624 |
=item C<$id> |
4625 |
|
4626 |
rule id to modify |
4627 |
|
4628 |
=item C<$fields> |
4629 |
|
4630 |
hashref defining the table fields |
4631 |
|
4632 |
* tagfield - required |
4633 |
* tagsubfield |
4634 |
* module - required |
4635 |
* filter - required |
4636 |
* on_existing - required |
4637 |
* on_new - required |
4638 |
* on_removed - required |
4639 |
|
4640 |
=back |
4641 |
|
4642 |
Returns: |
4643 |
|
4644 |
=over 4 |
4645 |
|
4646 |
=item C<$success> |
4647 |
|
4648 |
undef if an error occurs, otherwise true. |
4649 |
|
4650 |
=back |
4651 |
|
4652 |
=cut |
4653 |
|
4654 |
sub ModMarcPermissionsRule { |
4655 |
my ($id, $f) = @_; |
4656 |
my $dbh = C4::Context->dbh; |
4657 |
my $query = ' |
4658 |
UPDATE `marc_permissions` |
4659 |
SET |
4660 |
tagfield = ?, |
4661 |
tagsubfield = ?, |
4662 |
module = ?, |
4663 |
filter = ?, |
4664 |
on_existing = ?, |
4665 |
on_new = ?, |
4666 |
on_removed = ? |
4667 |
WHERE |
4668 |
id = ? |
4669 |
'; |
4670 |
my $sth = $dbh->prepare($query); |
4671 |
return $sth->execute ( |
4672 |
$f->{tagfield}, |
4673 |
$f->{tagsubfield}, |
4674 |
$f->{module}, |
4675 |
$f->{filter}, |
4676 |
$f->{on_existing}, |
4677 |
$f->{on_new}, |
4678 |
$f->{on_removed}, |
4679 |
$id |
4680 |
); |
4681 |
} |
4682 |
|
4683 |
=head2 AddMarcPermissionsRule |
4684 |
|
4685 |
my $success = AddMarcPermissionsRule($fields) |
4686 |
|
4687 |
Add rule to the marc_permissions table. |
4688 |
|
4689 |
=over 4 |
4690 |
|
4691 |
=item C<$fields> |
4692 |
|
4693 |
hashref defining the table fields |
4694 |
|
4695 |
tagfield - required |
4696 |
tagsubfield |
4697 |
module - required |
4698 |
filter - required |
4699 |
on_existing - required |
4700 |
on_new - required |
4701 |
on_removed - required |
4702 |
|
4703 |
=back |
4704 |
|
4705 |
Returns: |
4706 |
|
4707 |
=over 4 |
4708 |
|
4709 |
=item C<$success> |
4710 |
|
4711 |
undef if an error occurs, otherwise true. |
4712 |
|
4713 |
=back |
4714 |
|
4715 |
=cut |
4716 |
|
4717 |
sub AddMarcPermissionsRule { |
4718 |
my $f = shift; |
4719 |
my $dbh = C4::Context->dbh; |
4720 |
my $query = ' |
4721 |
INSERT INTO `marc_permissions` |
4722 |
( |
4723 |
tagfield, |
4724 |
tagsubfield, |
4725 |
module, |
4726 |
filter, |
4727 |
on_existing, |
4728 |
on_new, |
4729 |
on_removed |
4730 |
) |
4731 |
VALUES (?, ?, ?, ?, ?, ?, ?) |
4732 |
'; |
4733 |
my $sth = $dbh->prepare($query); |
4734 |
return $sth->execute ( |
4735 |
$f->{tagfield}, |
4736 |
$f->{tagsubfield}, |
4737 |
$f->{module}, |
4738 |
$f->{filter}, |
4739 |
$f->{on_existing}, |
4740 |
$f->{on_new}, |
4741 |
$f->{on_removed} |
4742 |
); |
4743 |
} |
4744 |
|
4745 |
=head2 DelMarcPermissionsRule |
4746 |
|
4747 |
my $success = DelMarcPermissionsRule($id) |
4748 |
|
4749 |
Deletes rule from the marc_permissions table. |
4750 |
|
4751 |
=over 4 |
4752 |
|
4753 |
=item C<$id> |
4754 |
|
4755 |
rule id to delete |
4756 |
|
4757 |
=back |
4758 |
|
4759 |
Returns: |
4760 |
|
4761 |
=over 4 |
4762 |
|
4763 |
=item C<$success> |
4764 |
|
4765 |
undef if an error occurs, otherwise true. |
4766 |
|
4767 |
=back |
4768 |
|
4769 |
=cut |
4770 |
|
4771 |
sub DelMarcPermissionsRule { |
4772 |
my $id = shift; |
4773 |
my $dbh = C4::Context->dbh; |
4774 |
my $query = ' |
4775 |
DELETE FROM `marc_permissions` |
4776 |
WHERE |
4777 |
id = ? |
4778 |
'; |
4779 |
my $sth = $dbh->prepare($query); |
4780 |
return $sth->execute($id); |
4781 |
} |
4782 |
|
3807 |
1; |
4783 |
1; |
3808 |
|
4784 |
|
3809 |
|
4785 |
|