From ff2040d9dc51a0efbc0ff2d56f741deb1ed4133a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 8 Nov 2018 15:35:50 +0000 Subject: [PATCH] Bug 21079: DBRev 18.06.00.056 Signed-off-by: Nick Clemens --- Koha.pm | 2 +- .../bug_21079_map_illrequestattributes.perl | 99 ----------------- installer/data/mysql/updatedatabase.pl | 100 ++++++++++++++++++ 3 files changed, 101 insertions(+), 100 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl diff --git a/Koha.pm b/Koha.pm index e0a3f86986..8611f60582 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "18.06.00.055"; +$VERSION = "18.06.00.056"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl b/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl deleted file mode 100644 index e1b1857738..0000000000 --- a/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl +++ /dev/null @@ -1,99 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - - # All attributes we're potentially interested in - my $ff_req = $dbh->selectall_arrayref( - 'SELECT a.illrequest_id, a.type, a.value '. - 'FROM illrequests r, illrequestattributes a '. - 'WHERE r.illrequest_id = a.illrequest_id '. - 'AND r.backend = "FreeForm"', - { Slice => {} } - ); - - # Before we go any further, identify whether we've done - # this before, we test for the presence of "container_title" - # We stop as soon as we find one - foreach my $req(@{$ff_req}) { - if ($req->{type} eq 'container_title') { - warn "Upgrade already carried out"; - } - } - - # Transform into a hashref with the key of the request ID - my $requests = {}; - foreach my $request(@{$ff_req}) { - my $id = $request->{illrequest_id}; - if (!exists $requests->{$id}) { - $requests->{$id} = {}; - } - $requests->{$id}->{$request->{type}} = $request->{value}; - } - - # Transform any article requests - my $transformed = {}; - foreach my $id(keys %{$requests}) { - if (lc($requests->{$id}->{type}) eq 'article') { - $transformed->{$id} = $requests->{$id}; - $transformed->{$id}->{type} = 'article'; - $transformed->{$id}->{container_title} = $transformed->{$id}->{title} - if defined $transformed->{$id}->{title} && - length $transformed->{$id}->{title} > 0; - $transformed->{$id}->{title} = $transformed->{$id}->{article_title} - if defined $transformed->{$id}->{article_title} && - length $transformed->{$id}->{article_title} > 0; - $transformed->{$id}->{author} = $transformed->{$id}->{article_author} - if defined $transformed->{$id}->{article_author} && - length $transformed->{$id}->{article_author} > 0; - $transformed->{$id}->{pages} = $transformed->{$id}->{article_pages} - if defined $transformed->{$id}->{article_pages} && - length $transformed->{$id}->{article_pages} > 0; - } - } - - # Now write back the transformed data - # Rather than selectively replace, we just remove all attributes we've - # transformed and re-write them - my @changed = keys %{$transformed}; - my $changed_str = join(',', @changed); - - if (scalar @changed > 0) { - my ($raise_error) = $dbh->{RaiseError}; - $dbh->{AutoCommit} = 0; - $dbh->{RaiseError} = 1; - eval { - my $del = $dbh->do( - "DELETE FROM illrequestattributes ". - "WHERE illrequest_id IN ($changed_str)" - ); - foreach my $reqid(keys %{$transformed}) { - my $attr = $transformed->{$reqid}; - foreach my $key(keys %{$attr}) { - my $sth = $dbh->prepare( - 'INSERT INTO illrequestattributes '. - '(illrequest_id, type, value) '. - 'VALUES '. - '(?, ?, ?)' - ); - $sth->execute( - $reqid, - $key, - $attr->{$key} - ); - } - } - $dbh->commit; - }; - - if ($@) { - warn "Upgrade to $DBversion failed: $@\n"; - eval { $dbh->rollback }; - } else { - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 21079 - Unify metadata schema across backends)\n"; - } - - $dbh->{AutoCommit} = 1; - $dbh->{RaiseError} = $raise_error; - } - -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 4f6aaa2257..eb576533bb 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -16934,6 +16934,106 @@ if( CheckVersion( $DBversion ) ) { print "Upgrade to $DBversion done (Bug 12365: Add column issuingrules.note)\n"; } +$DBversion = '18.06.00.056'; +if( CheckVersion( $DBversion ) ) { + + # All attributes we're potentially interested in + my $ff_req = $dbh->selectall_arrayref( + 'SELECT a.illrequest_id, a.type, a.value '. + 'FROM illrequests r, illrequestattributes a '. + 'WHERE r.illrequest_id = a.illrequest_id '. + 'AND r.backend = "FreeForm"', + { Slice => {} } + ); + + # Before we go any further, identify whether we've done + # this before, we test for the presence of "container_title" + # We stop as soon as we find one + foreach my $req(@{$ff_req}) { + if ($req->{type} eq 'container_title') { + warn "Upgrade already carried out"; + } + } + + # Transform into a hashref with the key of the request ID + my $requests = {}; + foreach my $request(@{$ff_req}) { + my $id = $request->{illrequest_id}; + if (!exists $requests->{$id}) { + $requests->{$id} = {}; + } + $requests->{$id}->{$request->{type}} = $request->{value}; + } + + # Transform any article requests + my $transformed = {}; + foreach my $id(keys %{$requests}) { + if (lc($requests->{$id}->{type}) eq 'article') { + $transformed->{$id} = $requests->{$id}; + $transformed->{$id}->{type} = 'article'; + $transformed->{$id}->{container_title} = $transformed->{$id}->{title} + if defined $transformed->{$id}->{title} && + length $transformed->{$id}->{title} > 0; + $transformed->{$id}->{title} = $transformed->{$id}->{article_title} + if defined $transformed->{$id}->{article_title} && + length $transformed->{$id}->{article_title} > 0; + $transformed->{$id}->{author} = $transformed->{$id}->{article_author} + if defined $transformed->{$id}->{article_author} && + length $transformed->{$id}->{article_author} > 0; + $transformed->{$id}->{pages} = $transformed->{$id}->{article_pages} + if defined $transformed->{$id}->{article_pages} && + length $transformed->{$id}->{article_pages} > 0; + } + } + + # Now write back the transformed data + # Rather than selectively replace, we just remove all attributes we've + # transformed and re-write them + my @changed = keys %{$transformed}; + my $changed_str = join(',', @changed); + + if (scalar @changed > 0) { + my ($raise_error) = $dbh->{RaiseError}; + $dbh->{AutoCommit} = 0; + $dbh->{RaiseError} = 1; + eval { + my $del = $dbh->do( + "DELETE FROM illrequestattributes ". + "WHERE illrequest_id IN ($changed_str)" + ); + foreach my $reqid(keys %{$transformed}) { + my $attr = $transformed->{$reqid}; + foreach my $key(keys %{$attr}) { + my $sth = $dbh->prepare( + 'INSERT INTO illrequestattributes '. + '(illrequest_id, type, value) '. + 'VALUES '. + '(?, ?, ?)' + ); + $sth->execute( + $reqid, + $key, + $attr->{$key} + ); + } + } + $dbh->commit; + }; + + if ($@) { + warn "Upgrade to $DBversion failed: $@\n"; + eval { $dbh->rollback }; + } else { + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 21079 - Unify metadata schema across backends)\n"; + } + + $dbh->{AutoCommit} = 1; + $dbh->{RaiseError} = $raise_error; + } + +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.39.5