Bug 22155: Adapt uses of biblio_metadata.marcflavour to schema

This patch makes the code using Koha::Biblio::Metadata->marcflavour use
->schema instead for all interactions.

To test:
- Update the DB structure:
  $ updatedatabase
- Update the schema files:
  $ dbic
- Notice all the places in which biblio_metadata is used
  $ cd kohaclone
  $ git grep biblio_metadata
=> SUCCESS: They all use `schema` instead of marcflavour
- Notice all the places that use Koha::Biblio::Metadata:
  $ git grep Koha::Biblio::Metadata
=> SUCCESS: They all use the schema attribute when they used to use
marcflavour
- Run all the modified tests and scripts
=> SUCCESS: We are all good
- Sign off :-D

Note: while this seems like a minor change, the places in which plain
SQL is used really require understanding the queries and how they are
used, because some query results might be passed to some other method
that in turn uses the marcflavour attribute. I of course took that into
account but errare humanum est :-D

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2019-01-17 23:25:38 -03:00 committed by Nick Clemens
parent 598bdc9924
commit fd30cac85a
8 changed files with 13 additions and 14 deletions

View File

@ -101,7 +101,6 @@ use C4::Debug;
use Koha::Caches;
use Koha::Authority::Types;
use Koha::Acquisition::Currencies;
use Koha::Biblio::Metadata;
use Koha::Biblio::Metadatas;
use Koha::Holds;
use Koha::ItemTypes;
@ -1223,7 +1222,7 @@ sub GetXmlBiblio {
FROM biblio_metadata
WHERE biblionumber=?
AND format='marcxml'
AND marcflavour=?
AND `schema`=?
|, undef, $biblionumber, C4::Context->preference('marcflavour')
);
return $marcxml;
@ -3251,8 +3250,8 @@ sub _koha_delete_biblio_metadata {
$schema->txn_do(
sub {
$dbh->do( q|
INSERT INTO deletedbiblio_metadata (biblionumber, format, marcflavour, metadata)
SELECT biblionumber, format, marcflavour, metadata FROM biblio_metadata WHERE biblionumber=?
INSERT INTO deletedbiblio_metadata (biblionumber, format, `schema`, metadata)
SELECT biblionumber, format, `schema`, metadata FROM biblio_metadata WHERE biblionumber=?
|, undef, $biblionumber );
$dbh->do( q|DELETE FROM biblio_metadata WHERE biblionumber=?|,
undef, $biblionumber );
@ -3324,7 +3323,7 @@ sub ModBiblioMarc {
my $metadata = {
biblionumber => $biblionumber,
format => 'marcxml',
marcflavour => C4::Context->preference('marcflavour'),
schema => C4::Context->preference('marcflavour'),
};
$record->as_usmarc; # Bug 20126/10455 This triggers field length calculation

View File

@ -2311,7 +2311,7 @@ sub SearchItems {
$query .= qq{ AND $where_str };
}
$query .= q{ AND biblio_metadata.format = 'marcxml' AND biblio_metadata.marcflavour = ? };
$query .= q{ AND biblio_metadata.format = 'marcxml' AND biblio_metadata.schema = ? };
push @where_args, C4::Context->preference('marcflavour');
my @columns = Koha::Database->new()->schema()->resultset('Item')->result_source->columns;

View File

@ -79,7 +79,7 @@ This script has the following parameters :
my @metadatas = # Should be replaced by a call to C4::Search on zebra index
# Record-status when bug 15537 will be pushed
Koha::Biblio::Metadatas->search( { format => 'marcxml', marcflavour => C4::Context->preference('marcflavour'), metadata => { LIKE => '%<leader>_____d%' } } );
Koha::Biblio::Metadatas->search( { format => 'marcxml', schema => C4::Context->preference('marcflavour'), metadata => { LIKE => '%<leader>_____d%' } } );
my $total_records_count = @metadatas;
my $deleted_records_count = 0;

View File

@ -152,7 +152,7 @@ sub biblios_to_sanitize {
SELECT biblionumber
FROM biblio_metadata
WHERE format = 'marcxml'
AND marcflavour = ?
AND `schema` = ?
AND metadata LIKE "%&amp;amp;%"
};
return @{ $dbh->selectcol_arrayref( $query, { Slice => {} }, C4::Context->preference('marcflavour') ) };

View File

@ -73,7 +73,7 @@ my $query = qq{
SELECT biblionumber, metadata
FROM biblio_metadata
WHERE format='marcxml'
AND marcflavour = ?
AND `schema` = ?
};
if($length) {
$query .= "LIMIT $length";

View File

@ -63,7 +63,7 @@ my $count_sth = $dbh->prepare(
SELECT COUNT(biblionumber)
FROM biblio_metadata
WHERE format='marcxml'
AND marcflavour=?
AND `schema`=?
AND (
ExtractValue(metadata,'//datafield[@tag="440"]/subfield[@code="a"]')
OR ExtractValue(metadata,'//datafield[@tag="440"]/subfield[@code="v"]')
@ -79,7 +79,7 @@ my $bibs_sth = $dbh->prepare(
SELECT biblionumber
FROM biblio_metadata
WHERE format='marcxml'
AND marcflavour=?
AND `schema`=?
AND (
ExtractValue(metadata,'//datafield[@tag="440"]/subfield[@code="a"]')
OR ExtractValue(metadata,'//datafield[@tag="440"]/subfield[@code="v"]')

View File

@ -34,7 +34,7 @@ use Koha::Database;
use Koha::Biblio;
use Koha::Biblioitem;
use Koha::Exporter::Record;
use Koha::Biblio::Metadata;
use Koha::Biblio::Metadatas;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
@ -59,7 +59,7 @@ $biblio_2->append_fields(
my ($biblionumber_2, $biblioitemnumber_2) = AddBiblio($biblio_2, '');
my $bad_biblio = Koha::Biblio->new()->store();
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', marcflavour => C4::Context->preference('marcflavour') } )->store();
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', schema => C4::Context->preference('marcflavour') } )->store();
my $bad_biblionumber = $bad_biblio->id;
my $builder = t::lib::TestBuilder->new;

View File

@ -362,7 +362,7 @@ subtest 'Bug 19725: OAI-PMH ListRecords and ListIdentifiers should use biblio_me
$record->append_fields(MARC::Field->new(999, '', '', z => '_'));
ModBiblio( $record, $biblionumber );
my $from_dt = dt_from_string(
Koha::Biblio::Metadatas->find({ biblionumber => $biblionumber, format => 'marcxml', marcflavour => 'MARC21' })->timestamp
Koha::Biblio::Metadatas->find({ biblionumber => $biblionumber, format => 'marcxml', schema => 'MARC21' })->timestamp
);
my $from = $from_dt->ymd . 'T' . $from_dt->hms . 'Z';
$oaidc[0]->{header}->{datestamp} = $from;