Lines 6718-6753
if ( CheckVersion($DBversion) ) {
Link Here
|
6718 |
$DBversion = "3.19.00.XXX"; |
6718 |
$DBversion = "3.19.00.XXX"; |
6719 |
if ( CheckVersion($DBversion) ) { |
6719 |
if ( CheckVersion($DBversion) ) { |
6720 |
|
6720 |
|
6721 |
#First make sure that there are no duplicate message_id's which might be quite impossible thanks to the AUTO_INCREMENT. |
6721 |
$dbh->do("ALTER TABLE message_queue DROP message_id" ); |
6722 |
#If duplicates exists, find the next free message_id and UPDATE the duplicate message_queues with the new biggest id's. |
6722 |
$dbh->do("ALTER TABLE message_queue ADD message_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST"); |
6723 |
my $sthGetDuplicatePKs = $dbh->prepare("SELECT count(message_id) as duplicate_pks, message_id ". |
|
|
6724 |
"FROM message_queue GROUP BY message_id HAVING duplicate_pks > 1;"); |
6725 |
#USE THIS TO TEST "FROM message_queue GROUP BY message_id HAVING duplicate_pks > 0;"); |
6726 |
my $sthGetMessage_queues = $dbh->prepare("SELECT * FROM message_queue WHERE message_id = ?"); |
6727 |
my $sthGetBiggestMessageId = $dbh->prepare("SELECT max(message_id) as message_id FROM message_queue;"); |
6728 |
my $sthUpdateMessageQueue = $dbh->prepare("UPDATE message_queue SET message_id = ? WHERE message_id = ? AND borrowernumber = ? AND time_queued = ? AND content = ?;"); |
6729 |
|
6730 |
#Get duplicate message_ids |
6731 |
$sthGetDuplicatePKs->execute; |
6732 |
my $message_ids = $sthGetDuplicatePKs->fetchall_arrayref({}); |
6733 |
foreach my $mi (@$message_ids) { |
6734 |
if ($mi->{duplicate_pks} > 1) { #Making sure there are multiple usages of this id |
6735 |
#USE TO TEST if ($mi->{duplicate_pks} > 0) { #Making sure we trigger this repair routine for messages with no duplicates, just to test. |
6736 |
$sthGetMessage_queues->execute($mi->{message_id}); #Get all the message_queues sharing the same id. |
6737 |
my $duplicates = $sthGetMessage_queues->fetchall_arrayref({}); |
6738 |
my $firstRun = 1; #On the first replace run for this set of duplicates, preserve the original id. |
6739 |
foreach my $duplicate (@$duplicates) { |
6740 |
next if $firstRun-- == 1; #Preserve the original id for the first conflicting message_queue-row |
6741 |
$sthGetBiggestMessageId->execute(); |
6742 |
my $max_message_id = $sthGetBiggestMessageId->fetchrow(); |
6743 |
$max_message_id++; |
6744 |
$sthUpdateMessageQueue->execute( $max_message_id, $duplicate->{message_id}, $duplicate->{borrowernumber}, $duplicate->{time_queued}, $duplicate->{content} ); |
6745 |
} |
6746 |
} |
6747 |
} |
6748 |
|
6723 |
|
6749 |
#Finally add the PRIMARY KEY |
|
|
6750 |
$dbh->do( "ALTER TABLE message_queue DROP KEY message_id, ADD CONSTRAINT PRIMARY KEY (message_id);" ); |
6751 |
print "Upgrade to $DBversion done (Bug 7793 - redefine the field message_id as PRIMARY KEY of message_queue)\n"; |
6724 |
print "Upgrade to $DBversion done (Bug 7793 - redefine the field message_id as PRIMARY KEY of message_queue)\n"; |
6752 |
SetVersion ($DBversion); |
6725 |
SetVersion ($DBversion); |
6753 |
} |
6726 |
} |
6754 |
- |
|
|