diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5f128ac07..056929591 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,8 @@ - fixed #12379: userImport documentation error - fixed #12382: WebGUI::Crud does not work with all form types - fixed: Threads with no posts return the wrong lastReply data. + - fixed #12339: Upgrade to 7.10 causes metadata values to "disappear" (Dale Trexel) + 7.10.26 - fixed: Template diagnostics when called without a session asset. diff --git a/docs/upgrades/upgrade_7.10.26-7.10.27.pl b/docs/upgrades/upgrade_7.10.26-7.10.27.pl index 5a4c222be..cc499a350 100644 --- a/docs/upgrades/upgrade_7.10.26-7.10.27.pl +++ b/docs/upgrades/upgrade_7.10.26-7.10.27.pl @@ -31,10 +31,66 @@ my $quiet; # this line required my $session = start(); # this line required # upgrade functions go here +fixMetaDataRevisionDates($session); finish($session); # this line required +#---------------------------------------------------------------------------- +# Describe what our function does +sub fixMetaDataRevisionDates { + my $session = shift; + print "\tCheck to see if metaData has bad revision dates... " unless $quiet; + my $getMeta0 = $session->db->read( + 'SELECT fieldId, assetId, value from metaData_values where revisionDate=0' + ); + my $getRevisionDates = $session->db->prepare( + 'select revisionDate from assetData where assetId=? order by revisionDate' + ); + my $getMetaValue = $session->db->prepare( + 'select value from metaData_values where assetId=? and fieldId=? and revisionDate=?' + ); + my $updateMetaValue = $session->db->prepare( + 'UPDATE metaData_values set value=? where assetId=? AND fieldId=? and revisionDate=?' + ); + my $insertMetaValue = $session->db->prepare( + 'INSERT INTO metaData_values (assetId, fieldId, value, revisionDate) VALUES (?,?,?,?)' + ); + ##Get each metaData_value entry + METAENTRY: while (my $metaEntry = $getMeta0->hashRef) { + $getRevisionDates->execute([$metaEntry->{assetId}]); + ##Get all revisionDates for the asset in that entry + REVISIONDATE: while (my ($revisionDate) = $getRevisionDates->array) { + ##Find the metaData value for that revisionDate + $getMetaValue->execute([$metaEntry->{assetId}, $metaEntry->{fieldId}, $revisionDate, ]); + my ($metaValue) = $getMetaValue->array; + ##If that matches the current entry, we're done with this revisionDate + next REVISIONDATE if $metaValue eq $metaEntry->{value}; + ##It doesn't match, so we have to fix it. + ##Update a bad entry + if (defined $metaValue) { + $updateMetaValue->execute([ + @{$metaEntry}{qw/value assetId fieldId/}, $revisionDate, + ]); + } + ##Insert a new one + else { + $insertMetaValue->execute([ + @{$metaEntry}{qw/assetId fieldId value/}, $revisionDate, + ]); + } + } + } + $getMeta0->finish; + $getRevisionDates->finish; + $getMetaValue->finish; + $insertMetaValue->finish; + $updateMetaValue->finish; + $session->db->write('delete from metaData_values where revisionDate=0'); + print "DONE!\n" unless $quiet; +} + + #---------------------------------------------------------------------------- # Describe what our function does #sub exampleFunction {