Lines 5369-5374
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
5369 |
SetVersion($DBversion); |
5369 |
SetVersion($DBversion); |
5370 |
} |
5370 |
} |
5371 |
|
5371 |
|
|
|
5372 |
$DBversion = "3.09.00.XXX"; |
5373 |
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { |
5374 |
$dbh->do('START TRANSACTION'); |
5375 |
$dbh->do('CREATE TABLE tmp_reserves AS SELECT * FROM old_reserves LIMIT 0'); |
5376 |
$dbh->do('ALTER TABLE tmp_reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); |
5377 |
$dbh->do(" |
5378 |
INSERT INTO tmp_reserves ( |
5379 |
borrowernumber, reservedate, biblionumber, |
5380 |
constrainttype, branchcode, notificationdate, |
5381 |
reminderdate, cancellationdate, reservenotes, |
5382 |
priority, found, timestamp, itemnumber, |
5383 |
waitingdate, expirationdate, lowestPriority |
5384 |
) SELECT |
5385 |
borrowernumber, reservedate, biblionumber, |
5386 |
constrainttype, branchcode, notificationdate, |
5387 |
reminderdate, cancellationdate, reservenotes, |
5388 |
priority, found, timestamp, itemnumber, |
5389 |
waitingdate, expirationdate, lowestPriority |
5390 |
FROM old_reserves ORDER BY reservedate |
5391 |
"); |
5392 |
$dbh->do('SET @ai = ( SELECT MAX( reserve_id ) FROM tmp_reserves )'); |
5393 |
$dbh->do('TRUNCATE old_reserves'); |
5394 |
$dbh->do('ALTER TABLE old_reserves ADD reserve_id INT( 11 ) NOT NULL PRIMARY KEY FIRST'); |
5395 |
$dbh->do('INSERT INTO old_reserves SELECT * FROM tmp_reserves WHERE reserve_id <= @ai'); |
5396 |
$dbh->do(" |
5397 |
INSERT INTO tmp_reserves ( |
5398 |
borrowernumber, reservedate, biblionumber, |
5399 |
constrainttype, branchcode, notificationdate, |
5400 |
reminderdate, cancellationdate, reservenotes, |
5401 |
priority, found, timestamp, itemnumber, |
5402 |
waitingdate, expirationdate, lowestPriority |
5403 |
) SELECT |
5404 |
borrowernumber, reservedate, biblionumber, |
5405 |
constrainttype, branchcode, notificationdate, |
5406 |
reminderdate, cancellationdate, reservenotes, |
5407 |
priority, found, timestamp, itemnumber, |
5408 |
waitingdate, expirationdate, lowestPriority |
5409 |
FROM reserves ORDER BY reservedate |
5410 |
"); |
5411 |
$dbh->do('TRUNCATE reserves'); |
5412 |
$dbh->do('ALTER TABLE reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); |
5413 |
$dbh->do('INSERT INTO reserves SELECT * FROM tmp_reserves WHERE reserve_id > @ai'); |
5414 |
$dbh->do('DROP TABLE tmp_reserves'); |
5415 |
$dbh->do('COMMIT'); |
5416 |
|
5417 |
my $sth = $dbh->prepare(" |
5418 |
SELECT COUNT( * ) AS count |
5419 |
FROM information_schema.COLUMNS |
5420 |
WHERE COLUMN_NAME = 'reserve_id' |
5421 |
AND ( |
5422 |
TABLE_NAME LIKE 'reserves' |
5423 |
OR |
5424 |
TABLE_NAME LIKE 'old_reserves' |
5425 |
) |
5426 |
"); |
5427 |
$sth->execute(); |
5428 |
my $row = $sth->fetchrow_hashref(); |
5429 |
die("Failed to add reserve_id to reserves tables, please refresh the page to try again.") unless ( $row->{'count'} ); |
5430 |
|
5431 |
print "Upgrade to $DBversion done (add reserve_id to reserves & old_reserves tables)\n"; |
5432 |
SetVersion($DBversion); |
5433 |
} |
5434 |
|
5372 |
|
5435 |
|
5373 |
=head1 FUNCTIONS |
5436 |
=head1 FUNCTIONS |
5374 |
|
5437 |
|
5375 |
- |
|
|