|
Lines 5246-5251
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
| 5246 |
SetVersion($DBversion); |
5246 |
SetVersion($DBversion); |
| 5247 |
} |
5247 |
} |
| 5248 |
|
5248 |
|
|
|
5249 |
$DBversion = "3.09.00.XXX"; |
| 5250 |
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { |
| 5251 |
$dbh->do('START TRANSACTION'); |
| 5252 |
$dbh->do('CREATE TABLE tmp_reserves AS SELECT * FROM reserves LIMIT 0'); |
| 5253 |
$dbh->do('ALTER TABLE tmp_reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); |
| 5254 |
$dbh->do(" |
| 5255 |
INSERT INTO tmp_reserves ( |
| 5256 |
borrowernumber, reservedate, biblionumber, |
| 5257 |
constrainttype, branchcode, notificationdate, |
| 5258 |
reminderdate, cancellationdate, reservenotes, |
| 5259 |
priority, found, timestamp, itemnumber, |
| 5260 |
waitingdate, expirationdate, lowestPriority |
| 5261 |
) SELECT |
| 5262 |
borrowernumber, reservedate, biblionumber, |
| 5263 |
constrainttype, branchcode, notificationdate, |
| 5264 |
reminderdate, cancellationdate, reservenotes, |
| 5265 |
priority, found, timestamp, itemnumber, |
| 5266 |
waitingdate, expirationdate, lowestPriority |
| 5267 |
FROM old_reserves ORDER BY reservedate |
| 5268 |
"); |
| 5269 |
$dbh->do('SET @ai = ( SELECT MAX( reserve_id ) FROM tmp_reserves )'); |
| 5270 |
$dbh->do('TRUNCATE old_reserves'); |
| 5271 |
$dbh->do('ALTER TABLE old_reserves ADD reserve_id INT( 11 ) NOT NULL PRIMARY KEY FIRST'); |
| 5272 |
$dbh->do('INSERT INTO old_reserves SELECT * FROM tmp_reserves WHERE reserve_id <= @ai'); |
| 5273 |
$dbh->do(" |
| 5274 |
INSERT INTO tmp_reserves ( |
| 5275 |
borrowernumber, reservedate, biblionumber, |
| 5276 |
constrainttype, branchcode, notificationdate, |
| 5277 |
reminderdate, cancellationdate, reservenotes, |
| 5278 |
priority, found, timestamp, itemnumber, |
| 5279 |
waitingdate, expirationdate, lowestPriority |
| 5280 |
) SELECT |
| 5281 |
borrowernumber, reservedate, biblionumber, |
| 5282 |
constrainttype, branchcode, notificationdate, |
| 5283 |
reminderdate, cancellationdate, reservenotes, |
| 5284 |
priority, found, timestamp, itemnumber, |
| 5285 |
waitingdate, expirationdate, lowestPriority |
| 5286 |
FROM reserves ORDER BY reservedate |
| 5287 |
"); |
| 5288 |
$dbh->do('TRUNCATE reserves'); |
| 5289 |
$dbh->do('ALTER TABLE reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); |
| 5290 |
$dbh->do('INSERT INTO reserves SELECT * FROM tmp_reserves WHERE reserve_id > @ai'); |
| 5291 |
$dbh->do('DROP TABLE tmp_reserves'); |
| 5292 |
$dbh->do('COMMIT'); |
| 5293 |
|
| 5294 |
my $sth = $dbh->prepare(" |
| 5295 |
SELECT COUNT( * ) AS count |
| 5296 |
FROM information_schema.COLUMNS |
| 5297 |
WHERE COLUMN_NAME = 'reserve_id' |
| 5298 |
AND ( |
| 5299 |
TABLE_NAME LIKE 'reserves' |
| 5300 |
OR |
| 5301 |
TABLE_NAME LIKE 'old_reserves' |
| 5302 |
) |
| 5303 |
"); |
| 5304 |
$sth->execute(); |
| 5305 |
my $row = $sth->fetchrow_hashref(); |
| 5306 |
die("Failed to add reserve_id to reserves tables, please refresh the page to try again.") unless ( $row->{'count'} ); |
| 5307 |
|
| 5308 |
print "Upgrade to $DBversion done (add reserve_id to reserves & old_reserves tables)\n"; |
| 5309 |
SetVersion($DBversion); |
| 5310 |
} |
| 5311 |
|
| 5249 |
=head1 FUNCTIONS |
5312 |
=head1 FUNCTIONS |
| 5250 |
|
5313 |
|
| 5251 |
=head2 TableExists($table) |
5314 |
=head2 TableExists($table) |
| 5252 |
- |
|
|