|
Lines 10462-10467
if ( CheckVersion($DBversion) ) {
Link Here
|
| 10462 |
SetVersion ($DBversion); |
10462 |
SetVersion ($DBversion); |
| 10463 |
} |
10463 |
} |
| 10464 |
|
10464 |
|
|
|
10465 |
$DBversion = "3.21.00.XXX"; |
| 10466 |
if ( CheckVersion($DBversion) ) { |
| 10467 |
|
| 10468 |
#First make sure that there are no duplicate message_id's which might be quite impossible thanks to the AUTO_INCREMENT. |
| 10469 |
#If duplicates exists, find the next free message_id and UPDATE the duplicate message_queues with the new biggest id's. |
| 10470 |
my $sthGetDuplicatePKs = $dbh->prepare("SELECT count(message_id) as duplicate_pks, message_id ". |
| 10471 |
"FROM message_queue GROUP BY message_id HAVING duplicate_pks > 1;"); |
| 10472 |
#USE THIS TO TEST "FROM message_queue GROUP BY message_id HAVING duplicate_pks > 0;"); |
| 10473 |
my $sthGetMessage_queues = $dbh->prepare("SELECT * FROM message_queue WHERE message_id = ?"); |
| 10474 |
my $sthGetBiggestMessageId = $dbh->prepare("SELECT max(message_id) as message_id FROM message_queue;"); |
| 10475 |
my $sthUpdateMessageQueue = $dbh->prepare("UPDATE message_queue SET message_id = ? WHERE message_id = ? AND borrowernumber = ? AND time_queued = ? AND content = ?;"); |
| 10476 |
|
| 10477 |
#Get duplicate message_ids |
| 10478 |
$sthGetDuplicatePKs->execute; |
| 10479 |
my $message_ids = $sthGetDuplicatePKs->fetchall_arrayref({}); |
| 10480 |
foreach my $mi (@$message_ids) { |
| 10481 |
if ($mi->{duplicate_pks} > 1) { #Making sure there are multiple usages of this id |
| 10482 |
#USE TO TEST if ($mi->{duplicate_pks} > 0) { #Making sure we trigger this repair routine for messages with no duplicates, just to test. |
| 10483 |
$sthGetMessage_queues->execute($mi->{message_id}); #Get all the message_queues sharing the same id. |
| 10484 |
my $duplicates = $sthGetMessage_queues->fetchall_arrayref({}); |
| 10485 |
my $firstRun = 1; #On the first replace run for this set of duplicates, preserve the original id. |
| 10486 |
foreach my $duplicate (@$duplicates) { |
| 10487 |
next if $firstRun-- == 1; #Preserve the original id for the first conflicting message_queue-row |
| 10488 |
$sthGetBiggestMessageId->execute(); |
| 10489 |
my $max_message_id = $sthGetBiggestMessageId->fetchrow(); |
| 10490 |
$max_message_id++; |
| 10491 |
$sthUpdateMessageQueue->execute( $max_message_id, $duplicate->{message_id}, $duplicate->{borrowernumber}, $duplicate->{time_queued}, $duplicate->{content} ); |
| 10492 |
} |
| 10493 |
} |
| 10494 |
} |
| 10495 |
|
| 10496 |
#Finally add the PRIMARY KEY |
| 10497 |
$dbh->do( "ALTER TABLE message_queue DROP KEY message_id, ADD CONSTRAINT PRIMARY KEY (message_id);" ); |
| 10498 |
print "Upgrade to $DBversion done (Bug 7793 - redefine the field message_id as PRIMARY KEY of message_queue)\n"; |
| 10499 |
SetVersion ($DBversion); |
| 10500 |
} |
| 10501 |
|
| 10465 |
# DEVELOPER PROCESS, search for anything to execute in the db_update directory |
10502 |
# DEVELOPER PROCESS, search for anything to execute in the db_update directory |
| 10466 |
# SEE bug 13068 |
10503 |
# SEE bug 13068 |
| 10467 |
# if there is anything in the atomicupdate, read and execute it. |
10504 |
# if there is anything in the atomicupdate, read and execute it. |
| 10468 |
- |
|
|