Lines 5212-5217
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
5212 |
SetVersion($DBversion); |
5212 |
SetVersion($DBversion); |
5213 |
} |
5213 |
} |
5214 |
|
5214 |
|
|
|
5215 |
$DBversion = "3.08.00.XXX"; |
5216 |
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { |
5217 |
$dbh->do('START TRANSACTION'); |
5218 |
$dbh->do('CREATE TABLE tmp_reserves AS SELECT * FROM reserves LIMIT 0'); |
5219 |
$dbh->do('ALTER TABLE tmp_reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); |
5220 |
$dbh->do(" |
5221 |
INSERT INTO tmp_reserves ( |
5222 |
borrowernumber, reservedate, biblionumber, |
5223 |
constrainttype, branchcode, notificationdate, |
5224 |
reminderdate, cancellationdate, reservenotes, |
5225 |
priority, found, timestamp, itemnumber, |
5226 |
waitingdate, expirationdate, lowestPriority |
5227 |
) SELECT |
5228 |
borrowernumber, reservedate, biblionumber, |
5229 |
constrainttype, branchcode, notificationdate, |
5230 |
reminderdate, cancellationdate, reservenotes, |
5231 |
priority, found, timestamp, itemnumber, |
5232 |
waitingdate, expirationdate, lowestPriority |
5233 |
FROM old_reserves ORDER BY reservedate |
5234 |
"); |
5235 |
$dbh->do('SET @ai = ( SELECT MAX( reserve_id ) FROM tmp_reserves )'); |
5236 |
$dbh->do('TRUNCATE old_reserves'); |
5237 |
$dbh->do('ALTER TABLE old_reserves ADD reserve_id INT( 11 ) NOT NULL PRIMARY KEY FIRST'); |
5238 |
$dbh->do('INSERT INTO old_reserves SELECT * FROM tmp_reserves WHERE reserve_id <= @ai'); |
5239 |
$dbh->do(" |
5240 |
INSERT INTO tmp_reserves ( |
5241 |
borrowernumber, reservedate, biblionumber, |
5242 |
constrainttype, branchcode, notificationdate, |
5243 |
reminderdate, cancellationdate, reservenotes, |
5244 |
priority, found, timestamp, itemnumber, |
5245 |
waitingdate, expirationdate, lowestPriority |
5246 |
) SELECT |
5247 |
borrowernumber, reservedate, biblionumber, |
5248 |
constrainttype, branchcode, notificationdate, |
5249 |
reminderdate, cancellationdate, reservenotes, |
5250 |
priority, found, timestamp, itemnumber, |
5251 |
waitingdate, expirationdate, lowestPriority |
5252 |
FROM reserves ORDER BY reservedate |
5253 |
"); |
5254 |
$dbh->do('TRUNCATE reserves'); |
5255 |
$dbh->do('ALTER TABLE reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'); |
5256 |
$dbh->do('INSERT INTO reserves SELECT * FROM tmp_reserves WHERE reserve_id > @ai'); |
5257 |
$dbh->do('DROP TABLE tmp_reserves'); |
5258 |
$dbh->do('COMMIT'); |
5259 |
|
5260 |
my $sth = $dbh->prepare(" |
5261 |
SELECT COUNT( * ) AS count |
5262 |
FROM information_schema.COLUMNS |
5263 |
WHERE COLUMN_NAME = 'reserve_id' |
5264 |
AND ( |
5265 |
TABLE_NAME LIKE 'reserves' |
5266 |
OR |
5267 |
TABLE_NAME LIKE 'old_reserves' |
5268 |
) |
5269 |
"); |
5270 |
$sth->execute(); |
5271 |
my $row = $sth->fetchrow_hashref(); |
5272 |
die("Failed to add reserve_id to reserves tables, please refresh the page to try again.") unless ( $row->{'count'} ); |
5273 |
|
5274 |
print "Upgrade to $DBversion done (add reserve_id to reserves & old_reserves tables)\n"; |
5275 |
SetVersion($DBversion); |
5276 |
} |
5277 |
|
5215 |
=head1 FUNCTIONS |
5278 |
=head1 FUNCTIONS |
5216 |
|
5279 |
|
5217 |
=head2 TableExists($table) |
5280 |
=head2 TableExists($table) |
5218 |
- |
|
|