Skip to content

Commit

Permalink
Fix metaData revisionDates that were left as 0 from upgrades. Thanks …
Browse files Browse the repository at this point in the history
…to Dale Trexe for the script which inspired this upgrade sub. Fixes bug #12339.
  • Loading branch information
perlDreamer committed Aug 30, 2012
1 parent 93f583d commit 4f74c4c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -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.
Expand Down
56 changes: 56 additions & 0 deletions docs/upgrades/upgrade_7.10.26-7.10.27.pl
Expand Up @@ -31,10 +31,66 @@ BEGIN
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 {
Expand Down

0 comments on commit 4f74c4c

Please sign in to comment.