|
Lines 5343-5348
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
| 5343 |
SetVersion($DBversion); |
5343 |
SetVersion($DBversion); |
| 5344 |
} |
5344 |
} |
| 5345 |
|
5345 |
|
|
|
5346 |
$DBversion = "3.09.00.XXX"; |
| 5347 |
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { |
| 5348 |
$dbh->do('START TRANSACTION'); |
| 5349 |
$dbh->do('CREATE TABLE tmp_reserves AS SELECT * FROM old_reserves LIMIT 0'); |
| 5350 |
$dbh->do('ALTER TABLE tmp_reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); |
| 5351 |
$dbh->do(" |
| 5352 |
INSERT INTO tmp_reserves ( |
| 5353 |
borrowernumber, reservedate, biblionumber, |
| 5354 |
constrainttype, branchcode, notificationdate, |
| 5355 |
reminderdate, cancellationdate, reservenotes, |
| 5356 |
priority, found, timestamp, itemnumber, |
| 5357 |
waitingdate, expirationdate, lowestPriority |
| 5358 |
) SELECT |
| 5359 |
borrowernumber, reservedate, biblionumber, |
| 5360 |
constrainttype, branchcode, notificationdate, |
| 5361 |
reminderdate, cancellationdate, reservenotes, |
| 5362 |
priority, found, timestamp, itemnumber, |
| 5363 |
waitingdate, expirationdate, lowestPriority |
| 5364 |
FROM old_reserves ORDER BY reservedate |
| 5365 |
"); |
| 5366 |
$dbh->do('SET @ai = ( SELECT MAX( reserve_id ) FROM tmp_reserves )'); |
| 5367 |
$dbh->do('TRUNCATE old_reserves'); |
| 5368 |
$dbh->do('ALTER TABLE old_reserves ADD reserve_id INT( 11 ) NOT NULL PRIMARY KEY FIRST'); |
| 5369 |
$dbh->do('INSERT INTO old_reserves SELECT * FROM tmp_reserves WHERE reserve_id <= @ai'); |
| 5370 |
$dbh->do(" |
| 5371 |
INSERT INTO tmp_reserves ( |
| 5372 |
borrowernumber, reservedate, biblionumber, |
| 5373 |
constrainttype, branchcode, notificationdate, |
| 5374 |
reminderdate, cancellationdate, reservenotes, |
| 5375 |
priority, found, timestamp, itemnumber, |
| 5376 |
waitingdate, expirationdate, lowestPriority |
| 5377 |
) SELECT |
| 5378 |
borrowernumber, reservedate, biblionumber, |
| 5379 |
constrainttype, branchcode, notificationdate, |
| 5380 |
reminderdate, cancellationdate, reservenotes, |
| 5381 |
priority, found, timestamp, itemnumber, |
| 5382 |
waitingdate, expirationdate, lowestPriority |
| 5383 |
FROM reserves ORDER BY reservedate |
| 5384 |
"); |
| 5385 |
$dbh->do('TRUNCATE reserves'); |
| 5386 |
$dbh->do('ALTER TABLE reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); |
| 5387 |
$dbh->do('INSERT INTO reserves SELECT * FROM tmp_reserves WHERE reserve_id > @ai'); |
| 5388 |
$dbh->do('DROP TABLE tmp_reserves'); |
| 5389 |
$dbh->do('COMMIT'); |
| 5390 |
|
| 5391 |
my $sth = $dbh->prepare(" |
| 5392 |
SELECT COUNT( * ) AS count |
| 5393 |
FROM information_schema.COLUMNS |
| 5394 |
WHERE COLUMN_NAME = 'reserve_id' |
| 5395 |
AND ( |
| 5396 |
TABLE_NAME LIKE 'reserves' |
| 5397 |
OR |
| 5398 |
TABLE_NAME LIKE 'old_reserves' |
| 5399 |
) |
| 5400 |
"); |
| 5401 |
$sth->execute(); |
| 5402 |
my $row = $sth->fetchrow_hashref(); |
| 5403 |
die("Failed to add reserve_id to reserves tables, please refresh the page to try again.") unless ( $row->{'count'} ); |
| 5404 |
|
| 5405 |
print "Upgrade to $DBversion done (add reserve_id to reserves & old_reserves tables)\n"; |
| 5406 |
SetVersion($DBversion); |
| 5407 |
} |
| 5408 |
|
| 5346 |
=head1 FUNCTIONS |
5409 |
=head1 FUNCTIONS |
| 5347 |
|
5410 |
|
| 5348 |
=head2 TableExists($table) |
5411 |
=head2 TableExists($table) |
| 5349 |
- |
|
|