Lines 28-33
use MARC::File::USMARC;
Link Here
|
28 |
use MARC::File::XML; |
28 |
use MARC::File::XML; |
29 |
use POSIX qw(strftime); |
29 |
use POSIX qw(strftime); |
30 |
use Module::Load::Conditional qw(can_load); |
30 |
use Module::Load::Conditional qw(can_load); |
|
|
31 |
use String::Similarity; |
31 |
|
32 |
|
32 |
use C4::Koha; |
33 |
use C4::Koha; |
33 |
use C4::Log; # logaction |
34 |
use C4::Log; # logaction |
Lines 105-110
BEGIN {
Link Here
|
105 |
&CountBiblioInOrders |
106 |
&CountBiblioInOrders |
106 |
&GetSubscriptionsId |
107 |
&GetSubscriptionsId |
107 |
&GetHolds |
108 |
&GetHolds |
|
|
109 |
|
110 |
&GetMarcPermissionsRules |
111 |
&GetMarcPermissionsModules |
112 |
&ModMarcPermissionsRule |
113 |
&AddMarcPermissionsRule |
114 |
&DelMarcPermissionsRule |
108 |
); |
115 |
); |
109 |
|
116 |
|
110 |
# To modify something |
117 |
# To modify something |
Lines 133-138
BEGIN {
Link Here
|
133 |
# they are useful in a few circumstances, so they are exported, |
140 |
# they are useful in a few circumstances, so they are exported, |
134 |
# but don't use them unless you are a core developer ;-) |
141 |
# but don't use them unless you are a core developer ;-) |
135 |
push @EXPORT, qw( |
142 |
push @EXPORT, qw( |
|
|
143 |
&ApplyMarcPermissions |
136 |
&ModBiblioMarc |
144 |
&ModBiblioMarc |
137 |
); |
145 |
); |
138 |
|
146 |
|
Lines 230-244
bib to add, while the second argument is the desired MARC
Link Here
|
230 |
framework code. |
238 |
framework code. |
231 |
|
239 |
|
232 |
This function also accepts a third, optional argument: a hashref |
240 |
This function also accepts a third, optional argument: a hashref |
233 |
to additional options. The only defined option is C<defer_marc_save>, |
241 |
to additional options. Defined options are: |
234 |
which if present and mapped to a true value, causes C<AddBiblio> |
242 |
|
235 |
to omit the call to save the MARC in C<bibilioitems.marc> |
243 |
C<defer_marc_save> |
236 |
and C<biblioitems.marcxml> This option is provided B<only> |
244 |
|
237 |
for the use of scripts such as C<bulkmarcimport.pl> that may need |
245 |
If present and mapped to a true value, causes C<AddBiblio> to omit the call |
238 |
to do some manipulation of the MARC record for item parsing before |
246 |
to save the MARC in C<bibilioitems.marc> and C<biblioitems.marcxml> This |
239 |
saving it and which cannot afford the performance hit of saving |
247 |
option is provided B<only> for the use of scripts such as |
240 |
the MARC record twice. Consequently, do not use that option |
248 |
C<bulkmarcimport.pl> that may need to do some manipulation of the MARC |
241 |
unless you can guarantee that C<ModBiblioMarc> will be called. |
249 |
record for item parsing before saving it and which cannot afford the |
|
|
250 |
performance hit of saving the MARC record twice. Consequently, do not use |
251 |
that option unless you can guarantee that C<ModBiblioMarc> will be called. |
252 |
|
253 |
C<filter> |
254 |
|
255 |
Optional hashref defining permission filters from the |
256 |
marc_permissions_modules table in form of {module => filter}. Three |
257 |
predefined filter modules exists: |
258 |
|
259 |
* source |
260 |
* category |
261 |
* borrower |
242 |
|
262 |
|
243 |
=cut |
263 |
=cut |
244 |
|
264 |
|
Lines 271-277
sub AddBiblio {
Link Here
|
271 |
_koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); |
291 |
_koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode ); |
272 |
|
292 |
|
273 |
# now add the record |
293 |
# now add the record |
274 |
ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save; |
294 |
ModBiblioMarc( $record, $biblionumber, $frameworkcode, $options->{filter} ) unless $defer_marc_save; |
275 |
|
295 |
|
276 |
# update OAI-PMH sets |
296 |
# update OAI-PMH sets |
277 |
if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { |
297 |
if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { |
Lines 300-311
in the C<biblio> and C<biblioitems> tables, as well as
Link Here
|
300 |
which fields are used to store embedded item, biblioitem, |
320 |
which fields are used to store embedded item, biblioitem, |
301 |
and biblionumber data for indexing. |
321 |
and biblionumber data for indexing. |
302 |
|
322 |
|
|
|
323 |
This function also accepts a forth, optional argument: a hashref defining |
324 |
permission filters from the marc_permissions_modules table in form of |
325 |
{module => filter}. Three predefined filter modules exists: |
326 |
|
327 |
* source |
328 |
* category |
329 |
* borrower |
330 |
|
303 |
Returns 1 on success 0 on failure |
331 |
Returns 1 on success 0 on failure |
304 |
|
332 |
|
305 |
=cut |
333 |
=cut |
306 |
|
334 |
|
307 |
sub ModBiblio { |
335 |
sub ModBiblio { |
308 |
my ( $record, $biblionumber, $frameworkcode ) = @_; |
336 |
my ( $record, $biblionumber, $frameworkcode, $filter ) = @_; |
|
|
337 |
|
309 |
if (!$record) { |
338 |
if (!$record) { |
310 |
carp 'No record passed to ModBiblio'; |
339 |
carp 'No record passed to ModBiblio'; |
311 |
return 0; |
340 |
return 0; |
Lines 343-355
sub ModBiblio {
Link Here
|
343 |
_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber ); |
372 |
_koha_marc_update_bib_ids( $record, $frameworkcode, $biblionumber, $biblioitemnumber ); |
344 |
|
373 |
|
345 |
# load the koha-table data object |
374 |
# load the koha-table data object |
346 |
my $oldbiblio = TransformMarcToKoha( $record, $frameworkcode ); |
375 |
my $oldbiblio = TransformMarcToKoha( $dbh, $record, $frameworkcode, undef, $biblionumber, $filter ); |
347 |
|
376 |
|
348 |
# update MARC subfield that stores biblioitems.cn_sort |
377 |
# update MARC subfield that stores biblioitems.cn_sort |
349 |
_koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); |
378 |
_koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); |
350 |
|
379 |
|
351 |
# update the MARC record (that now contains biblio and items) with the new record data |
380 |
# update the MARC record (that now contains biblio and items) with the new record data |
352 |
&ModBiblioMarc( $record, $biblionumber, $frameworkcode ); |
381 |
&ModBiblioMarc( $record, $biblionumber, $frameworkcode, $filter); |
353 |
|
382 |
|
354 |
# modify the other koha tables |
383 |
# modify the other koha tables |
355 |
_koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); |
384 |
_koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); |
Lines 2677-2683
sub TransformHtmlToMarc {
Link Here
|
2677 |
|
2706 |
|
2678 |
=head2 TransformMarcToKoha |
2707 |
=head2 TransformMarcToKoha |
2679 |
|
2708 |
|
2680 |
$result = TransformMarcToKoha( $record, $frameworkcode ) |
2709 |
$result = TransformMarcToKoha( $record, $frameworkcode, $biblionumber, $filter ) |
2681 |
|
2710 |
|
2682 |
Extract data from a MARC bib record into a hashref representing |
2711 |
Extract data from a MARC bib record into a hashref representing |
2683 |
Koha biblio, biblioitems, and items fields. |
2712 |
Koha biblio, biblioitems, and items fields. |
Lines 2688-2694
hash_ref
Link Here
|
2688 |
=cut |
2717 |
=cut |
2689 |
|
2718 |
|
2690 |
sub TransformMarcToKoha { |
2719 |
sub TransformMarcToKoha { |
2691 |
my ( $record, $frameworkcode, $limit_table ) = @_; |
2720 |
my ( $record, $frameworkcode, $limit_table, $biblionumber, $filter ) = @_; |
2692 |
|
2721 |
|
2693 |
my $result = {}; |
2722 |
my $result = {}; |
2694 |
if (!defined $record) { |
2723 |
if (!defined $record) { |
Lines 2709-2714
sub TransformMarcToKoha {
Link Here
|
2709 |
$tables{'biblioitems'} = 1; |
2738 |
$tables{'biblioitems'} = 1; |
2710 |
} |
2739 |
} |
2711 |
|
2740 |
|
|
|
2741 |
# apply permissions |
2742 |
if ( C4::Context->preference('MARCPermissions') && $biblionumber && $filter) { |
2743 |
$record = ApplyMarcPermissions({ |
2744 |
biblionumber => $biblionumber, |
2745 |
record => $record, |
2746 |
frameworkcode => $frameworkcode, |
2747 |
filter => $filter, |
2748 |
nolog => 1 |
2749 |
}); |
2750 |
} |
2751 |
|
2712 |
# traverse through record |
2752 |
# traverse through record |
2713 |
MARCFIELD: foreach my $field ( $record->fields() ) { |
2753 |
MARCFIELD: foreach my $field ( $record->fields() ) { |
2714 |
my $tag = $field->tag(); |
2754 |
my $tag = $field->tag(); |
Lines 3004-3013
sub ModZebra {
Link Here
|
3004 |
# replaced by a zebraqueue table, that is filled with ModZebra to run. |
3044 |
# replaced by a zebraqueue table, that is filled with ModZebra to run. |
3005 |
# the table is emptied by rebuild_zebra.pl script (using the -z switch) |
3045 |
# the table is emptied by rebuild_zebra.pl script (using the -z switch) |
3006 |
my $check_sql = "SELECT COUNT(*) FROM zebraqueue |
3046 |
my $check_sql = "SELECT COUNT(*) FROM zebraqueue |
3007 |
WHERE server = ? |
3047 |
WHERE server = ? |
3008 |
AND biblio_auth_number = ? |
3048 |
AND biblio_auth_number = ? |
3009 |
AND operation = ? |
3049 |
AND operation = ? |
3010 |
AND done = 0"; |
3050 |
AND done = 0"; |
3011 |
my $check_sth = $dbh->prepare_cached($check_sql); |
3051 |
my $check_sth = $dbh->prepare_cached($check_sql); |
3012 |
$check_sth->execute( $server, $biblionumber, $op ); |
3052 |
$check_sth->execute( $server, $biblionumber, $op ); |
3013 |
my ($count) = $check_sth->fetchrow_array; |
3053 |
my ($count) = $check_sth->fetchrow_array; |
Lines 3467-3473
sub _koha_delete_biblioitems {
Link Here
|
3467 |
|
3507 |
|
3468 |
=head2 ModBiblioMarc |
3508 |
=head2 ModBiblioMarc |
3469 |
|
3509 |
|
3470 |
&ModBiblioMarc($newrec,$biblionumber,$frameworkcode); |
3510 |
&ModBiblioMarc($newrec,$biblionumber,$frameworkcode,$filter); |
3471 |
|
3511 |
|
3472 |
Add MARC data for a biblio to koha |
3512 |
Add MARC data for a biblio to koha |
3473 |
|
3513 |
|
Lines 3478-3484
Function exported, but should NOT be used, unless you really know what you're do
Link Here
|
3478 |
sub ModBiblioMarc { |
3518 |
sub ModBiblioMarc { |
3479 |
# pass the MARC::Record to this function, and it will create the records in |
3519 |
# pass the MARC::Record to this function, and it will create the records in |
3480 |
# the marc field |
3520 |
# the marc field |
3481 |
my ( $record, $biblionumber, $frameworkcode ) = @_; |
3521 |
my ( $record, $biblionumber, $frameworkcode, $filter ) = @_; |
|
|
3522 |
|
3482 |
if ( !$record ) { |
3523 |
if ( !$record ) { |
3483 |
carp 'ModBiblioMarc passed an undefined record'; |
3524 |
carp 'ModBiblioMarc passed an undefined record'; |
3484 |
return; |
3525 |
return; |
Lines 3524-3529
sub ModBiblioMarc {
Link Here
|
3524 |
$f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005; |
3565 |
$f005->update(sprintf("%4d%02d%02d%02d%02d%04.1f",@a)) if $f005; |
3525 |
} |
3566 |
} |
3526 |
|
3567 |
|
|
|
3568 |
# apply permissions |
3569 |
if ( C4::Context->preference('MARCPermissions') ) { |
3570 |
$record = ApplyMarcPermissions({ |
3571 |
biblionumber => $biblionumber, |
3572 |
record => $record, |
3573 |
frameworkcode => $frameworkcode, |
3574 |
filter => $filter |
3575 |
}); |
3576 |
} |
3577 |
|
3527 |
$sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?"); |
3578 |
$sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?"); |
3528 |
$sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding), $biblionumber ); |
3579 |
$sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding), $biblionumber ); |
3529 |
$sth->finish; |
3580 |
$sth->finish; |
Lines 3820-3825
sub RemoveAllNsb {
Link Here
|
3820 |
return $record; |
3871 |
return $record; |
3821 |
} |
3872 |
} |
3822 |
|
3873 |
|
|
|
3874 |
=head2 ApplyMarcPermissions |
3875 |
|
3876 |
my $record = ApplyMarcPermissions($arguments) |
3877 |
|
3878 |
Applies marc permission rules to a record. |
3879 |
|
3880 |
C<$arguments> is expected to be a hashref with below keys defined. |
3881 |
|
3882 |
=over 4 |
3883 |
|
3884 |
=item C<biblionumber> |
3885 |
biblionumber of old record |
3886 |
|
3887 |
=item C<record> |
3888 |
record that will modify old record |
3889 |
|
3890 |
=item C<frameworkcode> |
3891 |
only tags included in framework will be processed |
3892 |
|
3893 |
=item C<filter> |
3894 |
hashref containing at least one filter module from the marc_permissions_modules |
3895 |
table in form {module => filter}. Three predefined filter modules exists: |
3896 |
|
3897 |
* source |
3898 |
* category |
3899 |
* borrower |
3900 |
|
3901 |
=item C<log> |
3902 |
optional reference to array that will be filled with rule evaluation log |
3903 |
entries. |
3904 |
|
3905 |
=item C<nolog> |
3906 |
optional boolean which when true disables logging to action log. |
3907 |
|
3908 |
=back |
3909 |
|
3910 |
Returns: |
3911 |
|
3912 |
=over 4 |
3913 |
|
3914 |
=item C<$record> |
3915 |
|
3916 |
new MARC record based on C<record> with C<filter> applied. If no old |
3917 |
record for C<biblionumber> can be found, C<record> is returned unchanged. |
3918 |
Default action when no matching filter found is to leave old record unchanged. |
3919 |
|
3920 |
=back |
3921 |
|
3922 |
=cut |
3923 |
|
3924 |
sub ApplyMarcPermissions { |
3925 |
my $arguments = shift; |
3926 |
my $biblionumber = $arguments->{biblionumber}; |
3927 |
my $new_record = $arguments->{record}; |
3928 |
my $frameworkcode = $arguments->{frameworkcode} || ''; |
3929 |
|
3930 |
if ( !$biblionumber ) { |
3931 |
carp 'ApplyMarcPermissions called on undefined biblionumber'; |
3932 |
return; |
3933 |
} |
3934 |
if ( !$new_record ) { |
3935 |
carp 'ApplyMarcPermissions called on undefined record'; |
3936 |
return; |
3937 |
} |
3938 |
my $filter = $arguments->{filter} |
3939 |
or return $new_record; |
3940 |
|
3941 |
my $log = $arguments->{log} || []; |
3942 |
my $nolog = $arguments->{nolog}; |
3943 |
|
3944 |
my $dbh = C4::Context->dbh; |
3945 |
|
3946 |
my $is_regex = sub { |
3947 |
my ( $tag, $m ) = @_; |
3948 |
# tag is not exactly same as possible regex |
3949 |
$tag ne $m && |
3950 |
|
3951 |
# wildcard |
3952 |
$m ne '*' && |
3953 |
|
3954 |
# valid tagDataType |
3955 |
$m !~ /^(0[1-9A-z][\dA-Z]) | |
3956 |
([1-9A-z][\dA-z]{2})$/x && |
3957 |
|
3958 |
# nor valid controltagDataType |
3959 |
$m !~ /00[1-9A-Za-z]{1}/ && |
3960 |
|
3961 |
# so we try it as a regex |
3962 |
$tag =~ /^$m$/ |
3963 |
}; |
3964 |
|
3965 |
my $old_record = GetMarcBiblio($biblionumber); |
3966 |
if ( $old_record ) { |
3967 |
my $ret_record = MARC::Record->new(); |
3968 |
my $perm = GetMarcPermissions() or return $new_record; |
3969 |
my $marc_struct = GetMarcStructure(1, $frameworkcode); |
3970 |
my $similarity_pref = C4::Context->preference("MARCPermissionsCorrectionSimilarity"); |
3971 |
$similarity_pref = defined $similarity_pref && |
3972 |
$similarity_pref >= 0 && |
3973 |
$similarity_pref <= 100 ? |
3974 |
$similarity_pref/100.0 : undef; |
3975 |
|
3976 |
# First came the leader ... |
3977 |
$ret_record->leader($old_record->leader()); |
3978 |
|
3979 |
# ... and then came all the tags in the framework |
3980 |
for my $tag (sort keys %{$marc_struct}) { |
3981 |
my @old_fields = $old_record->field($tag); |
3982 |
my @new_fields = $new_record->field($tag); |
3983 |
next unless @old_fields or @new_fields; |
3984 |
|
3985 |
my @perms = ( |
3986 |
$perm->{'*'}, |
3987 |
( # regex tags |
3988 |
map { $perm->{$_} } |
3989 |
grep { $is_regex->( $tag, $_ ) } sort keys %{$perm} |
3990 |
), |
3991 |
$perm->{$tag} |
3992 |
); |
3993 |
|
3994 |
# There can be more than one field for each tag, so we have to |
3995 |
# iterate all fields and distinguish which are new, removed or |
3996 |
# modified |
3997 |
my $max_fields = ($#old_fields, $#new_fields) |
3998 |
[$#old_fields< $#new_fields]; |
3999 |
for ( my $i_field = 0; $i_field <= $max_fields; $i_field++ ) { |
4000 |
my $old_field = $old_fields[$i_field]; |
4001 |
my $new_field = $new_fields[$i_field]; |
4002 |
|
4003 |
# Existing field |
4004 |
if ( $old_field and $new_field ) { |
4005 |
# Control fields |
4006 |
if ( $old_field->is_control_field() ) { |
4007 |
# Existing control field |
4008 |
if ( $old_field and $new_field ) { |
4009 |
my $on_existing = GetMarcPermissionsAction('on_existing', $filter, @perms); |
4010 |
if ( defined $on_existing->{action} ) { |
4011 |
push @{$log}, |
4012 |
{ |
4013 |
rule => $on_existing->{rule}, |
4014 |
event => "existing", |
4015 |
action => $on_existing->{action}, |
4016 |
tag => $tag, |
4017 |
subfieldcode => undef, |
4018 |
filter => $filter |
4019 |
}; |
4020 |
if ( $on_existing->{action} eq 'skip' ) { |
4021 |
$ret_record->insert_fields_ordered($old_field); |
4022 |
next; |
4023 |
} elsif ( $on_existing->{action} eq 'overwrite' ) { |
4024 |
$ret_record->insert_fields_ordered($new_field); |
4025 |
next; |
4026 |
} elsif ( $on_existing->{action} eq 'add' ) { |
4027 |
$ret_record->insert_fields_ordered($old_field); |
4028 |
$ret_record->insert_fields_ordered($new_field); |
4029 |
next; |
4030 |
} elsif ( $on_existing->{action} eq 'add_or_correct' ) { |
4031 |
if ( $similarity_pref ) { |
4032 |
my $similarity = similarity $old_field->data(), $new_field->data(); |
4033 |
if ( $similarity >= $similarity_pref ) { |
4034 |
$ret_record->insert_fields_ordered($new_field); |
4035 |
} else { |
4036 |
$ret_record->insert_fields_ordered($old_field); |
4037 |
$ret_record->insert_fields_ordered($new_field); |
4038 |
} |
4039 |
} else { |
4040 |
$ret_record->insert_fields_ordered($old_field); |
4041 |
} |
4042 |
} |
4043 |
} else { # default to skip |
4044 |
$ret_record->insert_fields_ordered($old_field); |
4045 |
next; |
4046 |
} |
4047 |
# New control field |
4048 |
} elsif ( not $old_field and $new_field ) { |
4049 |
my $on_new = GetMarcPermissionsAction('on_new', $filter, @perms); |
4050 |
if ( defined $on_new->{action} ) { |
4051 |
push @{$log}, |
4052 |
{ |
4053 |
rule => $on_new->{rule}, |
4054 |
event => "new", |
4055 |
action => $on_new->{action}, |
4056 |
tag => $tag, |
4057 |
subfieldcode => undef, |
4058 |
filter => $filter |
4059 |
}; |
4060 |
if ( $on_new->{action} eq 'skip' ) { |
4061 |
next; |
4062 |
} elsif ( $on_new->{action} eq 'add' ) { |
4063 |
$ret_record->insert_fields_ordered($new_field); |
4064 |
next; |
4065 |
} |
4066 |
} |
4067 |
# Removed control field |
4068 |
} elsif ( $old_field and not $new_field ) { |
4069 |
my $on_removed = GetMarcPermissionsAction('on_removed', $filter, @perms); |
4070 |
if ( defined $on_removed->{action} ) { |
4071 |
push @{$log}, |
4072 |
{ |
4073 |
rule => $on_removed->{rule}, |
4074 |
event => "removed", |
4075 |
action => $on_removed->{action}, |
4076 |
tag => $tag, |
4077 |
subfieldcode => undef |
4078 |
}; |
4079 |
if ( $on_removed->{action} eq 'skip' ) { |
4080 |
$ret_record->insert_fields_ordered($old_field); |
4081 |
next; |
4082 |
} elsif ( $on_removed->{action} eq 'remove' ) { |
4083 |
next; |
4084 |
} |
4085 |
} else { # default to skip |
4086 |
$ret_record->insert_fields_ordered($old_field); |
4087 |
next; |
4088 |
} |
4089 |
} |
4090 |
# Indicators and subfields |
4091 |
} else { |
4092 |
# Indicators |
4093 |
my @old_ind = map { $old_field->indicator($_) } (1,2); |
4094 |
my @new_ind = map { $new_field->indicator($_) } (1,2); |
4095 |
my @ind = ('',''); |
4096 |
|
4097 |
for my $i ((0,1)) { |
4098 |
my @ind_perms = ( |
4099 |
@perms, |
4100 |
$perm->{$tag}->{subfields}->{ 'i' . ( $i + 1 ) } |
4101 |
); |
4102 |
|
4103 |
# Existing indicator |
4104 |
if ( defined $old_ind[$i] and defined $new_ind[$i] ) { |
4105 |
my $on_existing = GetMarcPermissionsAction('on_existing', $filter, @ind_perms); |
4106 |
if ( defined $on_existing->{action} ) { |
4107 |
push @{$log}, |
4108 |
{ |
4109 |
rule => $on_existing->{rule}, |
4110 |
event => "existing", |
4111 |
action => $on_existing->{action}, |
4112 |
tag => $tag, |
4113 |
subfieldcode => 'i' . ( $i + 1 ), |
4114 |
filter => $filter |
4115 |
}; |
4116 |
if ( $on_existing->{action} eq 'skip' ) { |
4117 |
$ind[$i] = $old_ind[$i]; |
4118 |
} elsif ( $on_existing->{action} eq 'overwrite' ) { |
4119 |
$ind[$i] = $new_ind[$i]; |
4120 |
} |
4121 |
} else { # default to skip |
4122 |
$ind[$i] = $old_ind[$i]; |
4123 |
} |
4124 |
# New indicator |
4125 |
} elsif ( not defined $old_ind[$i] and defined $new_ind[$i] ) { |
4126 |
my $on_new = GetMarcPermissionsAction('on_new', $filter, @ind_perms); |
4127 |
if ( defined $on_new->{action} ) { |
4128 |
push @{$log}, |
4129 |
{ |
4130 |
rule => $on_new->{rule}, |
4131 |
event => "new", |
4132 |
action => $on_new->{action}, |
4133 |
tag => $tag, |
4134 |
subfieldcode => 'i' . ( $i + 1 ), |
4135 |
filter => $filter |
4136 |
}; |
4137 |
if ( $on_new->{action} eq 'skip' ) { |
4138 |
$ind[$i] = $old_ind[$i]; |
4139 |
} elsif ( $on_new->{action} eq 'add' ) { |
4140 |
$ind[$i] = $new_ind[$i]; |
4141 |
} |
4142 |
} |
4143 |
# Removed indicator |
4144 |
} elsif ( defined $old_ind[$i] and not defined $new_ind[$i] ) { |
4145 |
my $on_removed = GetMarcPermissionsAction('on_removed', $filter, @ind_perms); |
4146 |
if ( defined $on_removed->{action} ) { |
4147 |
push @{$log}, |
4148 |
{ |
4149 |
rule => $on_removed->{rule}, |
4150 |
event => "removed", |
4151 |
action => $on_removed->{action}, |
4152 |
tag => $tag, |
4153 |
subfieldcode => 'i' . ( $i + 1 ), |
4154 |
filter => $filter |
4155 |
}; |
4156 |
if ( $on_removed->{action} eq 'skip' ) { |
4157 |
$ind[$i] = $old_ind[$i]; |
4158 |
} elsif ( $on_removed->{action} eq 'remove' ) { |
4159 |
$ind[$i] = ''; |
4160 |
} |
4161 |
} else { # default to skip |
4162 |
$ind[$i] = $old_ind[$i]; |
4163 |
} |
4164 |
} |
4165 |
} |
4166 |
|
4167 |
# Subfields |
4168 |
my @subfields = (); |
4169 |
my %proccessed_subcodes = (); |
4170 |
|
4171 |
# Try to preserve subfield order by first processing |
4172 |
# subfields from the old record, and then subfields from |
4173 |
# the framework structure unless include in old record. |
4174 |
my @sorted_subfields = ( |
4175 |
map { shift @{$_} } $old_field->subfields(), |
4176 |
() = sort keys %{ $marc_struct->{$tag} } |
4177 |
); |
4178 |
for my $subcode ( @sorted_subfields ) { |
4179 |
next if $proccessed_subcodes{$subcode}; |
4180 |
$proccessed_subcodes{$subcode} = 1; |
4181 |
next unless ref $marc_struct->{$tag}{$subcode} eq 'HASH'; |
4182 |
my @old_subfields = $old_field->subfield($subcode); |
4183 |
my @new_subfields = $new_field->subfield($subcode); |
4184 |
next unless @old_subfields or @new_subfields; |
4185 |
|
4186 |
my @subfield_perms = ( |
4187 |
@perms, |
4188 |
$perm->{'*'}->{subfields}->{'*'}, |
4189 |
$perm->{$tag}->{subfields}->{'*'}, |
4190 |
( # tag->regex |
4191 |
map { $perm->{$tag}->{subfields}->{$_} } |
4192 |
grep { |
4193 |
# subcode is not exactly same as |
4194 |
# possible regex |
4195 |
$subcode ne $_ && |
4196 |
|
4197 |
# wildcard, not checking for valid |
4198 |
# subfieldcodeDataType since it |
4199 |
# contains too many regex characters |
4200 |
$_ !~ /^(\*)$/ && |
4201 |
|
4202 |
# so we try it as a regex |
4203 |
$subcode =~ /$_/ |
4204 |
} sort |
4205 |
keys %{ $perm->{$tag}->{subfields} } |
4206 |
), |
4207 |
( # regex->* |
4208 |
map { $perm->{$_}->{subfields}->{'*'} } |
4209 |
grep { $is_regex->( $tag, $_ ) } |
4210 |
sort keys %{$perm} |
4211 |
), |
4212 |
$perm->{'*'}->{subfields}->{$subcode}, |
4213 |
( # regex->subcode |
4214 |
map { $perm->{$_}->{subfields}->{$subcode} } |
4215 |
grep { $is_regex->( $tag, $_ ) } |
4216 |
sort keys %{$perm} |
4217 |
), |
4218 |
$perm->{$tag}->{subfields}->{$subcode} |
4219 |
); |
4220 |
|
4221 |
# Existing subfield |
4222 |
if ( @old_subfields and @new_subfields ) { |
4223 |
my $on_existing = GetMarcPermissionsAction('on_existing', $filter, @subfield_perms); |
4224 |
if ( defined $on_existing->{action} ) { |
4225 |
push @{$log}, |
4226 |
{ |
4227 |
rule => $on_existing->{rule}, |
4228 |
event => "existing", |
4229 |
action => $on_existing->{action}, |
4230 |
tag => $tag, |
4231 |
subfieldcode => $subcode, |
4232 |
filter => $filter |
4233 |
}; |
4234 |
if ( $on_existing->{action} eq 'skip' ) { |
4235 |
push(@subfields, map {($subcode,$_)} @old_subfields); |
4236 |
next; |
4237 |
} elsif ( $on_existing->{action} eq 'overwrite' ) { |
4238 |
push(@subfields, map {($subcode,$_)} @new_subfields); |
4239 |
next; |
4240 |
} elsif ( $on_existing->{action} eq 'add' ) { |
4241 |
push(@subfields, map {($subcode,$_)} @old_subfields); |
4242 |
push(@subfields, map {($subcode,$_)} @new_subfields); |
4243 |
next; |
4244 |
} elsif ( $on_existing->{action} eq 'add_or_correct' ) { |
4245 |
if ( $similarity_pref ) { |
4246 |
my @corrected_vals = (); |
4247 |
|
4248 |
# correct all old subfields |
4249 |
for ( my $i_new = 0; $i_new <= $#new_subfields; $i_new++ ) { |
4250 |
my $new_val = $new_subfields[$i_new]; |
4251 |
for ( my $i_old = 0; $i_old <= $#old_subfields; $i_old++ ) { |
4252 |
my $old_val = $old_subfields[$i_old]; |
4253 |
next if not defined $old_val or not defined $new_val; |
4254 |
my $similarity = similarity $old_val, $new_val; |
4255 |
if ( $similarity >= $similarity_pref ) { |
4256 |
$corrected_vals[$i_old] = $new_val; |
4257 |
$new_subfields[$i_new] = undef; |
4258 |
$old_subfields[$i_old] = undef; |
4259 |
last; |
4260 |
} |
4261 |
} |
4262 |
} |
4263 |
|
4264 |
# insert all unchanged old subfields |
4265 |
map { |
4266 |
$corrected_vals[$_] = $old_subfields[$_] |
4267 |
if defined $old_subfields[$_] |
4268 |
} 0 .. $#old_subfields; |
4269 |
|
4270 |
|
4271 |
# append all remaning new subfields |
4272 |
map {push @corrected_vals, $_ if defined} @new_subfields; |
4273 |
|
4274 |
push(@subfields, map {($subcode,$_)} @corrected_vals); |
4275 |
} else { |
4276 |
push(@subfields, map {($subcode,$_)} @old_subfields); |
4277 |
} |
4278 |
} |
4279 |
} else { # default to skip |
4280 |
push(@subfields, map {($subcode,$_)} @old_subfields); |
4281 |
next; |
4282 |
} |
4283 |
# New subfield |
4284 |
} elsif ( not @old_subfields and @new_subfields ) { |
4285 |
my $on_new = GetMarcPermissionsAction('on_new', $filter, @subfield_perms); |
4286 |
if ( defined $on_new->{action} ) { |
4287 |
push @{$log}, |
4288 |
{ |
4289 |
rule => $on_new->{rule}, |
4290 |
event => "new", |
4291 |
action => $on_new->{action}, |
4292 |
tag => $tag, |
4293 |
subfieldcode => $subcode, |
4294 |
filter => $filter |
4295 |
}; |
4296 |
if ( $on_new->{action} eq 'skip' ) { |
4297 |
next; |
4298 |
} elsif ( $on_new->{action} eq 'add' ) { |
4299 |
push(@subfields, map {($subcode,$_)} @new_subfields); |
4300 |
next; |
4301 |
} |
4302 |
} |
4303 |
# Removed subfield |
4304 |
} elsif ( @old_subfields and not @new_subfields ) { |
4305 |
my $on_removed = GetMarcPermissionsAction('on_removed', $filter, @subfield_perms); |
4306 |
if ( defined $on_removed->{action} ) { |
4307 |
push @{$log}, |
4308 |
{ |
4309 |
rule => $on_removed->{rule}, |
4310 |
event => "removed", |
4311 |
action => $on_removed->{action}, |
4312 |
tag => $tag, |
4313 |
subfieldcode => $subcode, |
4314 |
filter => $filter |
4315 |
}; |
4316 |
if ( $on_removed->{action} eq 'skip' ) { |
4317 |
push(@subfields, ($subcode => @old_subfields)); |
4318 |
next; |
4319 |
} elsif ( $on_removed->{action} eq 'remove' ) { |
4320 |
next; |
4321 |
} |
4322 |
} else { # default to skip |
4323 |
push(@subfields, ($subcode => @old_subfields)); |
4324 |
next; |
4325 |
} |
4326 |
} |
4327 |
} # / for each subfield |
4328 |
$ret_record->insert_grouped_field(MARC::Field->new($tag, $ind[0], $ind[1], @subfields)); |
4329 |
} |
4330 |
# New field |
4331 |
} elsif ( not $old_field and $new_field ) { |
4332 |
my $on_new = GetMarcPermissionsAction('on_new', $filter, @perms); |
4333 |
if ( defined $on_new->{action} ) { |
4334 |
push @{$log}, |
4335 |
{ |
4336 |
rule => $on_new->{rule}, |
4337 |
event => "new", |
4338 |
action => $on_new->{action}, |
4339 |
tag => $tag, |
4340 |
subfieldcode => undef, |
4341 |
filter => $filter |
4342 |
}; |
4343 |
if ( $on_new->{action} eq 'skip' ) { |
4344 |
next; |
4345 |
} elsif ( $on_new->{action} eq 'add' ) { |
4346 |
$ret_record->insert_fields_ordered($new_field); |
4347 |
next; |
4348 |
} |
4349 |
} |
4350 |
# Removed field |
4351 |
} elsif ( $old_field and not $new_field ) { |
4352 |
my $on_removed = GetMarcPermissionsAction('on_removed', $filter, @perms); |
4353 |
if ( defined $on_removed->{action} ) { |
4354 |
push @{$log}, |
4355 |
{ |
4356 |
rule => $on_removed->{rule}, |
4357 |
event => "removed", |
4358 |
action => $on_removed->{action}, |
4359 |
tag => $tag, |
4360 |
subfieldcode => undef, |
4361 |
filter => $filter |
4362 |
}; |
4363 |
if ( $on_removed->{action} eq 'skip' ) { |
4364 |
$ret_record->insert_grouped_field($old_field); |
4365 |
next; |
4366 |
} elsif ( $on_removed->{action} eq 'remove' ) { |
4367 |
next; |
4368 |
} |
4369 |
} else { # default to skip |
4370 |
$ret_record->insert_grouped_field($old_field); |
4371 |
next; |
4372 |
} |
4373 |
} |
4374 |
} # / for each field |
4375 |
} # / for each tag |
4376 |
if ( !$nolog && C4::Context->preference("MARCPermissionsLog") ) { |
4377 |
my $log_str = ''; |
4378 |
my $n = $#{$log}; |
4379 |
for my $l ( @{$log} ) { |
4380 |
$log_str .= "{\n"; |
4381 |
my $kn = keys %{$l}; |
4382 |
for my $k ( sort keys %{$l} ) { |
4383 |
if ( $k eq 'filter' ) { |
4384 |
$log_str .= " filter => {\n"; |
4385 |
my $fkn = keys %{ $l->{$k} }; |
4386 |
for my $fk ( sort keys %{ $l->{$k} } ) { |
4387 |
$log_str .= ' ' |
4388 |
. $fk . ' => ' |
4389 |
. $l->{$k}->{$fk} |
4390 |
. ( --$fkn ? ',' : '' ) . "\n"; |
4391 |
} |
4392 |
$log_str .= " }" . ( --$kn ? ',' : '' ) . "\n"; |
4393 |
} |
4394 |
else { |
4395 |
$log_str .= ' ' |
4396 |
. $k . ' => ' |
4397 |
. $l->{$k} |
4398 |
. ( --$kn ? ',' : '' ) . "\n" |
4399 |
if defined $l->{$k}; |
4400 |
} |
4401 |
} |
4402 |
$log_str .= '}' . ( $n-- ? ",\n" : '' ); |
4403 |
} |
4404 |
logaction( "CATALOGUING", "MODIFY", $biblionumber, $log_str ); |
4405 |
} |
4406 |
return $ret_record; |
4407 |
} |
4408 |
return $new_record; |
4409 |
} |
4410 |
|
4411 |
|
4412 |
=head2 GetMarcPermissions |
4413 |
|
4414 |
my $marc_permissions = GetMarcPermissions() |
4415 |
|
4416 |
Loads MARC field permissions from the marc_permissions table. |
4417 |
|
4418 |
Returns: |
4419 |
|
4420 |
=over 4 |
4421 |
|
4422 |
=item C<$marc_permissions> |
4423 |
|
4424 |
hashref with permissions structure for use with GetMarcPermissionsAction. |
4425 |
|
4426 |
=back |
4427 |
|
4428 |
=cut |
4429 |
|
4430 |
sub GetMarcPermissions { |
4431 |
my $dbh = C4::Context->dbh; |
4432 |
my $rule_count = 0; |
4433 |
my %perms = (); |
4434 |
|
4435 |
my $query = ' |
4436 |
SELECT `marc_permissions`.*, |
4437 |
`marc_permissions_modules`.`name`, |
4438 |
`marc_permissions_modules`.`description`, |
4439 |
`marc_permissions_modules`.`specificity` |
4440 |
FROM `marc_permissions` |
4441 |
LEFT JOIN `marc_permissions_modules` ON `module` = `marc_permissions_modules`.`id` |
4442 |
ORDER BY `marc_permissions_modules`.`specificity`, `id` |
4443 |
'; |
4444 |
my $sth = $dbh->prepare($query); |
4445 |
$sth->execute(); |
4446 |
while ( my $row = $sth->fetchrow_hashref ) { |
4447 |
$rule_count++; |
4448 |
if ( defined $row->{tagsubfield} and $row->{tagsubfield} ) { |
4449 |
$perms{ $row->{tagfield} }->{subfields}->{ $row->{tagsubfield} } |
4450 |
->{on_existing}->{ $row->{name} }->{ $row->{filter} } = |
4451 |
{ action => $row->{on_existing}, rule => $row->{'id'} }; |
4452 |
$perms{ $row->{tagfield} }->{subfields}->{ $row->{tagsubfield} } |
4453 |
->{on_new}->{ $row->{name} }->{ $row->{filter} } = |
4454 |
{ action => $row->{on_new}, rule => $row->{'id'} }; |
4455 |
$perms{ $row->{tagfield} }->{subfields}->{ $row->{tagsubfield} } |
4456 |
->{on_removed}->{ $row->{name} }->{ $row->{filter} } = |
4457 |
{ action => $row->{on_removed}, rule => $row->{'id'} }; |
4458 |
} |
4459 |
else { |
4460 |
$perms{ $row->{tagfield} }->{on_existing}->{ $row->{name} } |
4461 |
->{ $row->{filter} } = |
4462 |
{ action => $row->{on_existing}, rule => $row->{'id'} }; |
4463 |
$perms{ $row->{tagfield} }->{on_new}->{ $row->{name} } |
4464 |
->{ $row->{filter} } = |
4465 |
{ action => $row->{on_new}, rule => $row->{'id'} }; |
4466 |
$perms{ $row->{tagfield} }->{on_removed}->{ $row->{name} } |
4467 |
->{ $row->{filter} } = |
4468 |
{ action => $row->{on_removed}, rule => $row->{'id'} }; |
4469 |
} |
4470 |
} |
4471 |
|
4472 |
return unless $rule_count; |
4473 |
return \%perms; |
4474 |
} |
4475 |
|
4476 |
=head2 GetMarcPermissionsAction |
4477 |
|
4478 |
my $action = GetMarcPermissionsAction($event, $filter, @permissions) |
4479 |
|
4480 |
Gets action based on C<$event>, C<$filter> and C<@permissions>. |
4481 |
|
4482 |
=over 4 |
4483 |
|
4484 |
=item C<$event> |
4485 |
|
4486 |
which event: 'on_existing', 'on_new' or 'on_removed' |
4487 |
|
4488 |
=item C<$filter> |
4489 |
|
4490 |
hashref containing at least one filter module from the marc_permissions_modules |
4491 |
table in form {module => filter}. Three predefined filter modules exists: |
4492 |
|
4493 |
* source |
4494 |
* category |
4495 |
* borrower |
4496 |
|
4497 |
=item C<@permissions> |
4498 |
|
4499 |
list of permission structures in order of specificity from least to most |
4500 |
specific. |
4501 |
|
4502 |
=back |
4503 |
|
4504 |
Returns: |
4505 |
|
4506 |
=over 4 |
4507 |
|
4508 |
=item C<$action> |
4509 |
|
4510 |
hashref defining matching action. |
4511 |
|
4512 |
=back |
4513 |
|
4514 |
=cut |
4515 |
|
4516 |
sub GetMarcPermissionsAction { |
4517 |
my $what = shift or return; |
4518 |
my $filter = shift or return; |
4519 |
my @perms = @_; |
4520 |
|
4521 |
my $modules = GetMarcPermissionsModules(); |
4522 |
|
4523 |
my $action = undef; |
4524 |
for my $perm (@perms) { |
4525 |
next if not defined $perm; |
4526 |
next if not defined $perm->{$what}; |
4527 |
my $tmp_action = undef; |
4528 |
|
4529 |
for my $module ( @{$modules} ) { |
4530 |
if (defined $perm->{$what}->{ $module->{'name'} } |
4531 |
and |
4532 |
defined $perm->{$what}->{ $module->{'name'} }->{'*'}->{action} ) |
4533 |
{ |
4534 |
$tmp_action = $perm->{$what}->{ $module->{'name'} }->{'*'}; |
4535 |
} |
4536 |
if ( defined $filter->{ $module->{'name'} } |
4537 |
and defined $perm->{$what}->{ $module->{'name'} } |
4538 |
and defined $perm->{$what}->{ $module->{'name'} } |
4539 |
->{ $filter->{ $module->{'name'} } }->{action} ) |
4540 |
{ |
4541 |
$tmp_action = $perm->{$what}->{ $module->{'name'} } |
4542 |
->{ $filter->{ $module->{'name'} } }; |
4543 |
} |
4544 |
} |
4545 |
|
4546 |
$action = $tmp_action if defined $tmp_action; |
4547 |
} |
4548 |
|
4549 |
return $action; |
4550 |
} |
4551 |
|
4552 |
=head2 GetMarcPermissionsRules |
4553 |
|
4554 |
my $rules = GetMarcPermissionsRules() |
4555 |
|
4556 |
Returns: |
4557 |
|
4558 |
=over 4 |
4559 |
|
4560 |
=item C<$rules> |
4561 |
|
4562 |
array (in list context, arrayref otherwise) of hashrefs from marc_permissions |
4563 |
table in order of module specificity and rule id. |
4564 |
|
4565 |
=back |
4566 |
|
4567 |
=cut |
4568 |
|
4569 |
sub GetMarcPermissionsRules { |
4570 |
my $dbh = C4::Context->dbh; |
4571 |
my @rules = (); |
4572 |
|
4573 |
my $query = ' |
4574 |
SELECT `marc_permissions`.`id`, |
4575 |
`marc_permissions`.`tagfield`, |
4576 |
`marc_permissions`.`tagsubfield`, |
4577 |
`marc_permissions`.`filter`, |
4578 |
`marc_permissions`.`on_existing`, |
4579 |
`marc_permissions`.`on_new`, |
4580 |
`marc_permissions`.`on_removed`, |
4581 |
`marc_permissions_modules`.`name` as `module`, |
4582 |
`marc_permissions_modules`.`description`, |
4583 |
`marc_permissions_modules`.`specificity` |
4584 |
FROM `marc_permissions` |
4585 |
LEFT JOIN `marc_permissions_modules` ON `module` = `marc_permissions_modules`.`id` |
4586 |
ORDER BY `marc_permissions_modules`.`specificity`, `id` |
4587 |
'; |
4588 |
my $sth = $dbh->prepare($query); |
4589 |
$sth->execute(); |
4590 |
while ( my $row = $sth->fetchrow_hashref ) { |
4591 |
push(@rules, $row); |
4592 |
} |
4593 |
|
4594 |
return wantarray ? @rules : \@rules; |
4595 |
} |
4596 |
|
4597 |
=head2 GetMarcPermissionsModules |
4598 |
|
4599 |
my $modules = GetMarcPermissionsModules() |
4600 |
|
4601 |
Returns: |
4602 |
|
4603 |
=over 4 |
4604 |
|
4605 |
=item C<$modules> |
4606 |
|
4607 |
array (in list context, arrayref otherwise) of hashrefs from |
4608 |
marc_permissions_modules table in order of specificity. |
4609 |
|
4610 |
=back |
4611 |
|
4612 |
=cut |
4613 |
|
4614 |
sub GetMarcPermissionsModules { |
4615 |
my $dbh = C4::Context->dbh; |
4616 |
my @modules = (); |
4617 |
|
4618 |
my $query = ' |
4619 |
SELECT * |
4620 |
FROM `marc_permissions_modules` |
4621 |
ORDER BY `specificity` |
4622 |
'; |
4623 |
my $sth = $dbh->prepare($query); |
4624 |
$sth->execute(); |
4625 |
while ( my $row = $sth->fetchrow_hashref ) { |
4626 |
push(@modules, $row); |
4627 |
} |
4628 |
|
4629 |
return wantarray ? @modules : \@modules; |
4630 |
} |
4631 |
|
4632 |
=head2 ModMarcPermissionsRule |
4633 |
|
4634 |
my $success = ModMarcPermissionsRule($id, $fields) |
4635 |
|
4636 |
Modifies rule in the marc_permissions table. |
4637 |
|
4638 |
=over 4 |
4639 |
|
4640 |
=item C<$id> |
4641 |
|
4642 |
rule id to modify |
4643 |
|
4644 |
=item C<$fields> |
4645 |
|
4646 |
hashref defining the table fields |
4647 |
|
4648 |
* tagfield - required |
4649 |
* tagsubfield |
4650 |
* module - required |
4651 |
* filter - required |
4652 |
* on_existing - required |
4653 |
* on_new - required |
4654 |
* on_removed - required |
4655 |
|
4656 |
=back |
4657 |
|
4658 |
Returns: |
4659 |
|
4660 |
=over 4 |
4661 |
|
4662 |
=item C<$success> |
4663 |
|
4664 |
undef if an error occurs, otherwise true. |
4665 |
|
4666 |
=back |
4667 |
|
4668 |
=cut |
4669 |
|
4670 |
sub ModMarcPermissionsRule { |
4671 |
my ($id, $f) = @_; |
4672 |
my $dbh = C4::Context->dbh; |
4673 |
my $query = ' |
4674 |
UPDATE `marc_permissions` |
4675 |
SET |
4676 |
tagfield = ?, |
4677 |
tagsubfield = ?, |
4678 |
module = ?, |
4679 |
filter = ?, |
4680 |
on_existing = ?, |
4681 |
on_new = ?, |
4682 |
on_removed = ? |
4683 |
WHERE |
4684 |
id = ? |
4685 |
'; |
4686 |
my $sth = $dbh->prepare($query); |
4687 |
return $sth->execute ( |
4688 |
$f->{tagfield}, |
4689 |
$f->{tagsubfield}, |
4690 |
$f->{module}, |
4691 |
$f->{filter}, |
4692 |
$f->{on_existing}, |
4693 |
$f->{on_new}, |
4694 |
$f->{on_removed}, |
4695 |
$id |
4696 |
); |
4697 |
} |
4698 |
|
4699 |
=head2 AddMarcPermissionsRule |
4700 |
|
4701 |
my $success = AddMarcPermissionsRule($fields) |
4702 |
|
4703 |
Add rule to the marc_permissions table. |
4704 |
|
4705 |
=over 4 |
4706 |
|
4707 |
=item C<$fields> |
4708 |
|
4709 |
hashref defining the table fields |
4710 |
|
4711 |
tagfield - required |
4712 |
tagsubfield |
4713 |
module - required |
4714 |
filter - required |
4715 |
on_existing - required |
4716 |
on_new - required |
4717 |
on_removed - required |
4718 |
|
4719 |
=back |
4720 |
|
4721 |
Returns: |
4722 |
|
4723 |
=over 4 |
4724 |
|
4725 |
=item C<$success> |
4726 |
|
4727 |
undef if an error occurs, otherwise true. |
4728 |
|
4729 |
=back |
4730 |
|
4731 |
=cut |
4732 |
|
4733 |
sub AddMarcPermissionsRule { |
4734 |
my $f = shift; |
4735 |
my $dbh = C4::Context->dbh; |
4736 |
my $query = ' |
4737 |
INSERT INTO `marc_permissions` |
4738 |
( |
4739 |
tagfield, |
4740 |
tagsubfield, |
4741 |
module, |
4742 |
filter, |
4743 |
on_existing, |
4744 |
on_new, |
4745 |
on_removed |
4746 |
) |
4747 |
VALUES (?, ?, ?, ?, ?, ?, ?) |
4748 |
'; |
4749 |
my $sth = $dbh->prepare($query); |
4750 |
return $sth->execute ( |
4751 |
$f->{tagfield}, |
4752 |
$f->{tagsubfield}, |
4753 |
$f->{module}, |
4754 |
$f->{filter}, |
4755 |
$f->{on_existing}, |
4756 |
$f->{on_new}, |
4757 |
$f->{on_removed} |
4758 |
); |
4759 |
} |
4760 |
|
4761 |
=head2 DelMarcPermissionsRule |
4762 |
|
4763 |
my $success = DelMarcPermissionsRule($id) |
4764 |
|
4765 |
Deletes rule from the marc_permissions table. |
4766 |
|
4767 |
=over 4 |
4768 |
|
4769 |
=item C<$id> |
4770 |
|
4771 |
rule id to delete |
4772 |
|
4773 |
=back |
4774 |
|
4775 |
Returns: |
4776 |
|
4777 |
=over 4 |
4778 |
|
4779 |
=item C<$success> |
4780 |
|
4781 |
undef if an error occurs, otherwise true. |
4782 |
|
4783 |
=back |
4784 |
|
4785 |
=cut |
4786 |
|
4787 |
sub DelMarcPermissionsRule { |
4788 |
my $id = shift; |
4789 |
my $dbh = C4::Context->dbh; |
4790 |
my $query = ' |
4791 |
DELETE FROM `marc_permissions` |
4792 |
WHERE |
4793 |
id = ? |
4794 |
'; |
4795 |
my $sth = $dbh->prepare($query); |
4796 |
return $sth->execute($id); |
4797 |
} |
4798 |
|
3823 |
1; |
4799 |
1; |
3824 |
|
4800 |
|
3825 |
|
4801 |
|