&GetAuthorisedValues
&FixEncoding
&GetKohaAuthorisedValues
+ &GetManagedTagSubfields
+
$DEBUG
);
return \%values;
}
+=head2 GetManagedTagSubfields
+
+=over 4
+
+$res = GetManagedTagSubfields();
+
+Returns a reference to a big hash of hash, with the Marc structure fro the given frameworkcode
+$forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones
+$frameworkcode : the framework code to read
+
+=back
+
+=back
+
+=cut
+
+sub GetManagedTagSubfields{
+ my $dbh=C4::Context->dbh;
+ my $rq=$dbh->prepare(qq|
+SELECT
+ DISTINCT CONCAT( marc_subfield_structure.tagfield, tagsubfield ) AS tagsubfield,
+ marc_subfield_structure.liblibrarian as subfielddesc,
+ marc_tag_structure.liblibrarian as tagdesc
+FROM marc_subfield_structure
+ LEFT JOIN marc_tag_structure
+ ON marc_tag_structure.tagfield = marc_subfield_structure.tagfield
+ AND marc_tag_structure.frameworkcode = marc_subfield_structure.frameworkcode
+WHERE marc_subfield_structure.tab>=0
+ORDER BY tagsubfield|);
+ $rq->execute;
+ my $data=$rq->fetchall_arrayref({});
+ return $data;
+}
1;
&getRecords
&buildQuery
&NZgetRecords
+ &EditBiblios
);
# make all your functions, whether exported or not;
my %subfieldstosearch;
while ( ( my $column ) = $sth2->fetchrow ) {
my ( $tagfield, $tagsubfield ) =
- &GetMarcFromKohaField( $dbh, "items." . $column, "" );
+ &GetMarcFromKohaField( "items." . $column, "" );
$subfieldstosearch{$column} = $tagsubfield;
}
my $times;
}
+=head2 EditBiblios
+
+($countchanged,$listunchanged) = EditBiblios($listbiblios, $tagsubfield,$initvalue,$targetvalue,$test);
+
+this function changes all the values $initvalue in subfield $tag$subfield in any record in $listbiblios
+test parameter if set donot perform change to records in database.
+
+=over 2
+
+=item C<input arg:>
+
+ * $listbiblios is an array ref to marcrecords to be changed
+ * $tagsubfield is the reference of the subfield to change.
+ * $initvalue is the value to search the record for
+ * $targetvalue is the value to set the subfield to
+ * $test is to be set only not to perform changes in database.
+
+=item C<Output arg:>
+ * $countchanged counts all the changes performed.
+ * $listunchanged contains the list of all the biblionumbers of records unchanged.
+
+=item C<usage in the script:>
+
+=back
+
+my ($countchanged, $listunchanged) = EditBiblios($results->{RECORD}, $tagsubfield,$initvalue,$targetvalue);;
+#If one wants to display unchanged records, you should get biblios foreach @$listunchanged
+$template->param(countchanged => $countchanged, loopunchanged=>$listunchanged);
+
+=cut
+sub EditBiblios{
+ my ($listbiblios,$tagsubfield,$initvalue,$targetvalue,$test)=@_;
+ my $countmatched;
+ my @unmatched;
+ my ($tag,$subfield)=($1,$2) if ($tagsubfield=~/^(\d{1,3})(.)$/);
+ my ($bntag,$bnsubf) = GetMarcFromKohaField('biblio.biblionumber');
+
+ foreach my $usmarc (@$listbiblios){
+ my $record=MARC::Record->new_from_usmarc($usmarc);
+ my $biblionumber;
+ if ($bntag>10){
+ $biblionumber = $record->subfield($bntag,$bnsubf);
+ }else {
+ $biblionumber=$record->field($bntag)->data;
+ }
+ #GetBiblionumber is to be written.
+ #Could be replaced by TransformMarcToKoha (But Would be longer)
+ if ($record->field($tag)){
+ foreach my $field ($record->field($tag)){
+ if ($field->delete_subfield('code' =>$subfield,'match'=>qr($initvalue))){
+ $countmatched++;
+ $field->update($subfield,$targetvalue) if ($targetvalue);
+ }
+ }
+# warn $record->as_formatted;
+ ModBiblio($record,$biblionumber,GetFrameworkCode($biblionumber)) unless ($test);
+ } else {
+ push @unmatched, $biblionumber;
+ }
+ }
+ return ($countmatched,\@unmatched);
+}
+
#----------------------------------------------------------------------
#
# Non-Zebra GetRecords#