Bugzilla – Attachment 77035 Details for
Bug 21079
Unify metadata schema across backends
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21079: Unify metadata schema across backends
Bug-21079-Unify-metadata-schema-across-backends.patch (text/plain), 5.36 KB, created by
Andrew Isherwood
on 2018-07-17 14:02:55 UTC
(
hide
)
Description:
Bug 21079: Unify metadata schema across backends
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2018-07-17 14:02:55 UTC
Size:
5.36 KB
patch
obsolete
>From becdcd244737002a68aecb918b7fe65e4364e3ce Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Tue, 17 Jul 2018 14:49:47 +0100 >Subject: [PATCH] Bug 21079: Unify metadata schema across backends > >This patch contains a database upgrade that takes appropriate metadata >properties relating to articles in the FreeForm backend and creates >metadata that corresponds with the metadata being created by the BLDSS >backend. This enables us to create templates that can display metadata >equally across any backends that contain this metadata; > >To test: >- Ensure you have at least one article request created with the FreeForm backend >- Check the metadata for the request: > => TEST: You should have properties such as 'article_title', 'article_author' populated > => TEST: You should NOT have properties such as 'container_title' & > 'pages' >- Run the upgrade > => TEST: For the same requests you should now have the following > properties: > - container_title (this should correspond with 'title') > - title (this should correspond with 'article_title') > - pages (this should correspond with 'article_pages') > - author (this should correspond with 'article_author') >--- > .../bug_21079_map_illrequestattributes.perl | 94 ++++++++++++++++++++++ > 1 file changed, 94 insertions(+) > create mode 100644 installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl > >diff --git a/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl b/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl >new file mode 100644 >index 0000000000..0ff1b4b21d >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_21079_map_illrequestattributes.perl >@@ -0,0 +1,94 @@ >+use Try::Tiny; >+$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_temp r, illrequestattributes_temp 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) { >+ $dbh->{AutoCommit} = 0; >+ $dbh->{RaiseError} = 1; >+ try { >+ my $del = $dbh->do( >+ "DELETE FROM illrequestattributes_temp ". >+ "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_temp '. >+ '(illrequest_id, type, value, readonly) '. >+ 'VALUES '. >+ '(?, ?, ?, ?)' >+ ); >+ $sth->execute( >+ $reqid, >+ $key, >+ $attr->{$key}, >+ 0 >+ ); >+ } >+ } >+ $dbh->commit; >+ } catch { >+ warn "Upgrade to $DBversion failed: $_"; >+ eval { $dbh->rollback }; >+ }; >+ } >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 21079 - Unify metadata schema across backends)\n"; >+} >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21079
:
77035
|
77036
|
79720
|
79725
|
80288
|
81740
|
82092