Lines 13-50
if( CheckVersion( $DBversion ) ) {
Link Here
|
13 |
$dbh->do( q| ALTER TABLE old_issues ADD CONSTRAINT `old_issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE | ); |
13 |
$dbh->do( q| ALTER TABLE old_issues ADD CONSTRAINT `old_issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE | ); |
14 |
} |
14 |
} |
15 |
|
15 |
|
16 |
# Now attempt to migrate previously action logged issues into issues.issuer |
|
|
17 |
# We assume that an item issued to a borrower on the same day is the same issue |
18 |
# |
19 |
# Get existing action logs |
20 |
# - user = issuer |
21 |
# - object = borrowernumber |
22 |
# - info = itemnumber |
23 |
my $action_logs = $dbh->selectall_arrayref("SELECT DATE(timestamp) AS dt, user, object, info FROM action_logs WHERE module='CIRCULATION' and action='ISSUE'", { Slice => {} }); |
24 |
|
25 |
foreach my $log( @{$action_logs} ) { |
26 |
# Look for an issue of this item, to this borrower, on this day |
27 |
# We're doing DATE comparison in the database to avoid invoking |
28 |
# DateTime and it's performance sapping ways... |
29 |
# |
30 |
# If we're dealing with an actual borrower |
31 |
if ($log->{user} != 0) { |
32 |
my $done_issue = $dbh->do( |
33 |
"UPDATE issues SET issuer = ? WHERE DATE(timestamp) = ? AND borrowernumber = ? AND itemnumber = ?", |
34 |
undef, |
35 |
( $log->{user}, $log->{dt}, $log->{object}, $log->{info} ) |
36 |
); |
37 |
# If we didn't find the issue in 'issues', look in 'old_issues' |
38 |
if (!$done_issue) { |
39 |
$dbh->do( |
40 |
"UPDATE old_issues SET issuer = ? WHERE DATE(timestamp) = ? AND borrowernumber = ? AND itemnumber = ?", |
41 |
undef, |
42 |
( $log->{user}, $log->{dt}, $log->{object}, $log->{info} ) |
43 |
); |
44 |
} |
45 |
} |
46 |
} |
47 |
|
48 |
SetVersion( $DBversion ); |
16 |
SetVersion( $DBversion ); |
49 |
print "Upgrade to $DBversion done (Bug 23916 - Add issues.issuer)\n"; |
17 |
print "Upgrade to $DBversion done (Bug 23916 - Add issues.issuer)\n"; |
50 |
} |
18 |
} |
51 |
- |
|
|