View | Details | Raw Unified | Return to bug 7793
Collapse All | Expand All

(-)a/Koha/Schema/Result/MessageQueue.pm (-11 / +8 lines)
Lines 1-21 Link Here
1
use utf8;
2
package Koha::Schema::Result::MessageQueue;
1
package Koha::Schema::Result::MessageQueue;
3
2
4
# Created by DBIx::Class::Schema::Loader
3
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
5
7
=head1 NAME
8
9
Koha::Schema::Result::MessageQueue
10
11
=cut
12
13
use strict;
6
use strict;
14
use warnings;
7
use warnings;
15
8
16
use base 'DBIx::Class::Core';
9
use base 'DBIx::Class::Core';
17
10
18
=head1 TABLE: C<message_queue>
11
12
=head1 NAME
13
14
Koha::Schema::Result::MessageQueue
19
15
20
=cut
16
=cut
21
17
Lines 130-135 __PACKAGE__->add_columns( Link Here
130
  "content_type",
126
  "content_type",
131
  { data_type => "text", is_nullable => 1 },
127
  { data_type => "text", is_nullable => 1 },
132
);
128
);
129
__PACKAGE__->set_primary_key("message_id");
133
130
134
=head1 RELATIONS
131
=head1 RELATIONS
135
132
Lines 165-176 __PACKAGE__->belongs_to( Link Here
165
  "message_transport_type",
162
  "message_transport_type",
166
  "Koha::Schema::Result::MessageTransportType",
163
  "Koha::Schema::Result::MessageTransportType",
167
  { message_transport_type => "message_transport_type" },
164
  { message_transport_type => "message_transport_type" },
168
  { is_deferrable => 1, on_delete => "RESTRICT", on_update => "CASCADE" },
165
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
169
);
166
);
170
167
171
168
172
# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-07-11 09:26:55
169
# Created by DBIx::Class::Schema::Loader v0.07010 @ 2015-02-24 18:59:44
173
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YWxM2O2W/h34qqIOIpzOtw
170
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:v+Th3wvct4LBCEp+fRlMBw
174
171
175
172
176
# You can replace this text with custom content, and it will be preserved on regeneration
173
# You can replace this text with custom content, and it will be preserved on regeneration
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 2574-2580 CREATE TABLE `message_queue` ( Link Here
2574
  `to_address` mediumtext,
2574
  `to_address` mediumtext,
2575
  `from_address` mediumtext,
2575
  `from_address` mediumtext,
2576
  `content_type` text,
2576
  `content_type` text,
2577
  KEY `message_id` (`message_id`),
2577
  PRIMARY KEY `message_id` (`message_id`),
2578
  KEY `borrowernumber` (`borrowernumber`),
2578
  KEY `borrowernumber` (`borrowernumber`),
2579
  KEY `message_transport_type` (`message_transport_type`),
2579
  KEY `message_transport_type` (`message_transport_type`),
2580
  CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2580
  CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +37 lines)
Lines 6715-6720 if ( CheckVersion($DBversion) ) { Link Here
6715
    SetVersion ($DBversion);
6715
    SetVersion ($DBversion);
6716
}
6716
}
6717
6717
6718
$DBversion = "3.19.00.XXX";
6719
if ( CheckVersion($DBversion) ) {
6720
6721
    #First make sure that there are no duplicate message_id's which might be quite impossible thanks to the AUTO_INCREMENT.
6722
    #If duplicates exists, find the next free message_id and UPDATE the duplicate message_queues with the new biggest id's.
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
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";
6752
    SetVersion ($DBversion);
6753
}
6754
6718
$DBversion = "3.11.00.113";
6755
$DBversion = "3.11.00.113";
6719
if ( CheckVersion($DBversion) ) {
6756
if ( CheckVersion($DBversion) ) {
6720
    $dbh->do(q{
6757
    $dbh->do(q{
6721
- 

Return to bug 7793