Bug 22789: Set non_priority column as boolean in schema
[koha-ffzg.git] / C4 / AuthoritiesMarc.pm
index 0d90b37..bd25837 100644 (file)
@@ -29,7 +29,7 @@ use C4::Charset;
 use C4::Log;
 use Koha::MetadataRecord::Authority;
 use Koha::Authorities;
-use Koha::Authority::MergeRequest;
+use Koha::Authority::MergeRequests;
 use Koha::Authority::Types;
 use Koha::Authority;
 use Koha::Libraries;
@@ -113,13 +113,10 @@ sub SearchAuthorities {
     $sortby="" unless $sortby;
     my $query;
     my $qpquery = '';
-    my $QParser;
-    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
     my $attr = '';
         # the marclist may contain "mainentry". In this case, search the tag_to_report, that depends on
         # the authtypecode. Then, search on $a of this tag_to_report
         # also store main entry MARC tag, to extract it at end of search
-    my $mainentrytag;
     ##first set the authtype search and may be multiple authorities
     if ($authtypecode) {
         my $n=0;
@@ -133,9 +130,6 @@ sub SearchAuthorities {
         if ($n>1){
             while ($n>1){$query= "\@or ".$query;$n--;}
         }
-        if ($QParser) {
-            $qpquery .= '(authtype:' . join('|| authtype:', @auths) . ')';
-        }
     }
 
     my $dosearch;
@@ -203,9 +197,6 @@ sub SearchAuthorities {
             $q2 .= $attr;
             $dosearch = 1;
             ++$attr_cnt;
-            if ($QParser) {
-                $qpquery .= " $tags->[$i]:\"$value->[$i]\"";
-            }
         }    #if value
     }
     ##Add how many queries generated
@@ -226,21 +217,8 @@ sub SearchAuthorities {
     } elsif ($sortby eq 'AuthidDsc') {
         $orderstring = '@attr 7=2 @attr 4=109 @attr 1=Local-Number 0';
     }
-    if ($QParser) {
-        $qpquery .= ' all:all' unless $value->[0];
-
-        if ( $value->[0] =~ m/^qp=(.*)$/ ) {
-            $qpquery = $1;
-        }
-
-        $qpquery .= " #$sortby" unless $sortby eq '';
-
-        $QParser->parse( $qpquery );
-        $query = $QParser->target_syntax('authorityserver');
-    } else {
-        $query=($query?$query:"\@attr 1=_ALLRECORDS \@attr 2=103 ''");
-        $query="\@or $orderstring $query" if $orderstring;
-    }
+    $query=($query?$query:"\@attr 1=_ALLRECORDS \@attr 2=103 ''");
+    $query="\@or $orderstring $query" if $orderstring;
 
     $offset = 0 if not defined $offset or $offset < 0;
     my $counter = $offset;
@@ -575,7 +553,8 @@ sub AddAuthority {
         my $marcorgcode = C4::Context->preference('MARCOrgCode');
         if ( $userenv && $userenv->{'branch'} ) {
             $library = Koha::Libraries->find( $userenv->{'branch'} );
-            $marcorgcode = $library->get_effective_marcorgcode;
+            # userenv's library could not exist because of a trick in misc/commit_file.pl (see FIXME and set_userenv statement)
+            $marcorgcode = $library ? $library->get_effective_marcorgcode : $marcorgcode;
         }
                if (!$record->leader) {
                        $record->leader($leader);
@@ -669,6 +648,11 @@ sub DelAuthority {
     my $authid = $params->{authid} || return;
     my $skip_merge = $params->{skip_merge};
     my $dbh = C4::Context->dbh;
+
+    # Remove older pending merge requests for $authid to itself. (See bug 22437)
+    my $condition = { authid => $authid, authid_new => [undef, 0, $authid], done => 0 };
+    Koha::Authority::MergeRequests->search($condition)->delete;
+
     merge({ mergefrom => $authid }) if !$skip_merge;
     $dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid );
     logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
@@ -757,14 +741,8 @@ sub FindDuplicateAuthority {
     my $auth_tag_to_report = Koha::Authority::Types->find($authtypecode)->auth_tag_to_report;
 #     warn "record :".$record->as_formatted."  auth_tag_to_report :$auth_tag_to_report";
     # build a request for SearchAuthorities
-    my $QParser;
-    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
-    my $op;
-    if ($QParser) {
-        $op = '&&';
-    } else {
-        $op = 'AND';
-    }
+    my $op = 'AND';
+    $authtypecode =~ s#/#\\/#; # GENRE/FORM contains forward slash which is a reserved character
     my $query='at:'.$authtypecode.' ';
     my $filtervalues=qr([\001-\040\Q!'"`#$%&*+,-./:;<=>?@(){[}_|~\E\]]);
     if ($record->field($auth_tag_to_report)) {