Skip to content

Commit 4f74c4c

Browse files
committedAug 30, 2012
Fix metaData revisionDates that were left as 0 from upgrades. Thanks to Dale Trexe for the script which inspired this upgrade sub. Fixes bug #12339.
1 parent 93f583d commit 4f74c4c

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
 

‎docs/changelog/7.x.x.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
- fixed #12379: userImport documentation error
33
- fixed #12382: WebGUI::Crud does not work with all form types
44
- fixed: Threads with no posts return the wrong lastReply data.
5+
- fixed #12339: Upgrade to 7.10 causes metadata values to "disappear" (Dale Trexel)
6+
57

68
7.10.26
79
- fixed: Template diagnostics when called without a session asset.

‎docs/upgrades/upgrade_7.10.26-7.10.27.pl

+56
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,66 @@ BEGIN
3131
my $session = start(); # this line required
3232

3333
# upgrade functions go here
34+
fixMetaDataRevisionDates($session);
3435

3536
finish($session); # this line required
3637

3738

39+
#----------------------------------------------------------------------------
40+
# Describe what our function does
41+
sub fixMetaDataRevisionDates {
42+
my $session = shift;
43+
print "\tCheck to see if metaData has bad revision dates... " unless $quiet;
44+
my $getMeta0 = $session->db->read(
45+
'SELECT fieldId, assetId, value from metaData_values where revisionDate=0'
46+
);
47+
my $getRevisionDates = $session->db->prepare(
48+
'select revisionDate from assetData where assetId=? order by revisionDate'
49+
);
50+
my $getMetaValue = $session->db->prepare(
51+
'select value from metaData_values where assetId=? and fieldId=? and revisionDate=?'
52+
);
53+
my $updateMetaValue = $session->db->prepare(
54+
'UPDATE metaData_values set value=? where assetId=? AND fieldId=? and revisionDate=?'
55+
);
56+
my $insertMetaValue = $session->db->prepare(
57+
'INSERT INTO metaData_values (assetId, fieldId, value, revisionDate) VALUES (?,?,?,?)'
58+
);
59+
##Get each metaData_value entry
60+
METAENTRY: while (my $metaEntry = $getMeta0->hashRef) {
61+
$getRevisionDates->execute([$metaEntry->{assetId}]);
62+
##Get all revisionDates for the asset in that entry
63+
REVISIONDATE: while (my ($revisionDate) = $getRevisionDates->array) {
64+
##Find the metaData value for that revisionDate
65+
$getMetaValue->execute([$metaEntry->{assetId}, $metaEntry->{fieldId}, $revisionDate, ]);
66+
my ($metaValue) = $getMetaValue->array;
67+
##If that matches the current entry, we're done with this revisionDate
68+
next REVISIONDATE if $metaValue eq $metaEntry->{value};
69+
##It doesn't match, so we have to fix it.
70+
##Update a bad entry
71+
if (defined $metaValue) {
72+
$updateMetaValue->execute([
73+
@{$metaEntry}{qw/value assetId fieldId/}, $revisionDate,
74+
]);
75+
}
76+
##Insert a new one
77+
else {
78+
$insertMetaValue->execute([
79+
@{$metaEntry}{qw/assetId fieldId value/}, $revisionDate,
80+
]);
81+
}
82+
}
83+
}
84+
$getMeta0->finish;
85+
$getRevisionDates->finish;
86+
$getMetaValue->finish;
87+
$insertMetaValue->finish;
88+
$updateMetaValue->finish;
89+
$session->db->write('delete from metaData_values where revisionDate=0');
90+
print "DONE!\n" unless $quiet;
91+
}
92+
93+
3894
#----------------------------------------------------------------------------
3995
# Describe what our function does
4096
#sub exampleFunction {

0 commit comments

Comments
 (0)
Please sign in to comment.