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

(-)a/installer/data/mysql/kohastructure.sql (-12 / +12 lines)
Lines 1421-1428 CREATE TABLE `borrowers` ( Link Here
1421
  `B_email` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the patron/borrower''s alternate email address',
1421
  `B_email` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the patron/borrower''s alternate email address',
1422
  `B_phone` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the patron/borrower''s alternate phone number',
1422
  `B_phone` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'the patron/borrower''s alternate phone number',
1423
  `dateofbirth` date DEFAULT NULL COMMENT 'the patron/borrower''s date of birth (YYYY-MM-DD)',
1423
  `dateofbirth` date DEFAULT NULL COMMENT 'the patron/borrower''s date of birth (YYYY-MM-DD)',
1424
  `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'foreign key from the branches table, includes the code of the patron/borrower''s home branch',
1424
  `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'foreign key from the branches table, includes the code of the patron/borrower''s home branch',
1425
  `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'foreign key from the categories table, includes the code of the patron category',
1425
  `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'foreign key from the categories table, includes the code of the patron category',
1426
  `dateenrolled` date DEFAULT NULL COMMENT 'date the patron was added to Koha (YYYY-MM-DD)',
1426
  `dateenrolled` date DEFAULT NULL COMMENT 'date the patron was added to Koha (YYYY-MM-DD)',
1427
  `dateexpiry` date DEFAULT NULL COMMENT 'date the patron/borrower''s card is set to expire (YYYY-MM-DD)',
1427
  `dateexpiry` date DEFAULT NULL COMMENT 'date the patron/borrower''s card is set to expire (YYYY-MM-DD)',
1428
  `password_expiration_date` date DEFAULT NULL COMMENT 'date the patron/borrower''s password is set to expire (YYYY-MM-DD)',
1428
  `password_expiration_date` date DEFAULT NULL COMMENT 'date the patron/borrower''s password is set to expire (YYYY-MM-DD)',
Lines 1478-1485 CREATE TABLE `borrowers` ( Link Here
1478
  KEY `firstname_idx` (`firstname`(191)),
1478
  KEY `firstname_idx` (`firstname`(191)),
1479
  KEY `othernames_idx` (`othernames`(191)),
1479
  KEY `othernames_idx` (`othernames`(191)),
1480
  KEY `sms_provider_id` (`sms_provider_id`),
1480
  KEY `sms_provider_id` (`sms_provider_id`),
1481
  CONSTRAINT `borrowers_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`),
1481
  CONSTRAINT `borrowers_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE SET NULL ON UPDATE CASCADE,
1482
  CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`),
1482
  CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
1483
  CONSTRAINT `borrowers_ibfk_3` FOREIGN KEY (`sms_provider_id`) REFERENCES `sms_providers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
1483
  CONSTRAINT `borrowers_ibfk_3` FOREIGN KEY (`sms_provider_id`) REFERENCES `sms_providers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
1484
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1484
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1485
/*!40101 SET character_set_client = @saved_cs_client */;
1485
/*!40101 SET character_set_client = @saved_cs_client */;
Lines 1561-1573 DROP TABLE IF EXISTS `branchtransfers`; Link Here
1561
/*!40101 SET character_set_client = utf8 */;
1561
/*!40101 SET character_set_client = utf8 */;
1562
CREATE TABLE `branchtransfers` (
1562
CREATE TABLE `branchtransfers` (
1563
  `branchtransfer_id` int(12) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
1563
  `branchtransfer_id` int(12) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
1564
  `itemnumber` int(11) NOT NULL DEFAULT 0 COMMENT 'the itemnumber that it is in transit (items.itemnumber)',
1564
  `itemnumber` int(11) NOT NULL COMMENT 'the itemnumber that it is in transit (items.itemnumber)',
1565
  `daterequested` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date the transfer was requested',
1565
  `daterequested` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date the transfer was requested',
1566
  `datesent` datetime DEFAULT NULL COMMENT 'the date the transfer was initialized',
1566
  `datesent` datetime DEFAULT NULL COMMENT 'the date the transfer was initialized',
1567
  `frombranch` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the branch the transfer is coming from',
1567
  `frombranch` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the branch the transfer is coming from',
1568
  `datearrived` datetime DEFAULT NULL COMMENT 'the date the transfer arrived at its destination',
1568
  `datearrived` datetime DEFAULT NULL COMMENT 'the date the transfer arrived at its destination',
1569
  `datecancelled` datetime DEFAULT NULL COMMENT 'the date the transfer was cancelled',
1569
  `datecancelled` datetime DEFAULT NULL COMMENT 'the date the transfer was cancelled',
1570
  `tobranch` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the branch the transfer was going to',
1570
  `tobranch` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the branch the transfer was going to',
1571
  `comments` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any comments related to the transfer',
1571
  `comments` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'any comments related to the transfer',
1572
  `reason` ENUM('Manual','StockrotationAdvance','StockrotationRepatriation','ReturnToHome','ReturnToHolding','RotatingCollection','Reserve','LostReserve','CancelReserve','TransferCancellation','Recall','RecallCancellation') COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'what triggered the transfer',
1572
  `reason` ENUM('Manual','StockrotationAdvance','StockrotationRepatriation','ReturnToHome','ReturnToHolding','RotatingCollection','Reserve','LostReserve','CancelReserve','TransferCancellation','Recall','RecallCancellation') COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'what triggered the transfer',
1573
  `cancellation_reason` enum('Manual','StockrotationAdvance','StockrotationRepatriation','ReturnToHome','ReturnToHolding','RotatingCollection','Reserve','LostReserve','CancelReserve','ItemLost','WrongTransfer','CancelRecall') COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'what triggered the transfer cancellation',
1573
  `cancellation_reason` enum('Manual','StockrotationAdvance','StockrotationRepatriation','ReturnToHome','ReturnToHolding','RotatingCollection','Reserve','LostReserve','CancelReserve','ItemLost','WrongTransfer','CancelRecall') COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'what triggered the transfer cancellation',
Lines 3053-3061 DROP TABLE IF EXISTS `issues`; Link Here
3053
/*!40101 SET character_set_client = utf8 */;
3053
/*!40101 SET character_set_client = utf8 */;
3054
CREATE TABLE `issues` (
3054
CREATE TABLE `issues` (
3055
  `issue_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key for issues table',
3055
  `issue_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key for issues table',
3056
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the borrowers table for the patron this item was checked out to',
3056
  `borrowernumber` int(11) NOT NULL COMMENT 'foreign key, linking this to the borrowers table for the patron this item was checked out to',
3057
  `issuer_id` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the borrowers table for the user who checked out this item',
3057
  `issuer_id` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the borrowers table for the user who checked out this item',
3058
  `itemnumber` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the items table for the item that was checked out',
3058
  `itemnumber` int(11) NOT NULL COMMENT 'foreign key, linking this to the items table for the item that was checked out',
3059
  `date_due` datetime DEFAULT NULL COMMENT 'datetime the item is due (yyyy-mm-dd hh:mm::ss)',
3059
  `date_due` datetime DEFAULT NULL COMMENT 'datetime the item is due (yyyy-mm-dd hh:mm::ss)',
3060
  `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key, linking to the branches table for the location the item was checked out',
3060
  `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key, linking to the branches table for the location the item was checked out',
3061
  `returndate` datetime DEFAULT NULL COMMENT 'date the item was returned, will be NULL until moved to old_issues',
3061
  `returndate` datetime DEFAULT NULL COMMENT 'date the item was returned, will be NULL until moved to old_issues',
Lines 3077-3084 CREATE TABLE `issues` ( Link Here
3077
  KEY `branchcode_idx` (`branchcode`),
3077
  KEY `branchcode_idx` (`branchcode`),
3078
  KEY `bordate` (`borrowernumber`,`timestamp`),
3078
  KEY `bordate` (`borrowernumber`,`timestamp`),
3079
  KEY `issues_ibfk_borrowers_borrowernumber` (`issuer_id`),
3079
  KEY `issues_ibfk_borrowers_borrowernumber` (`issuer_id`),
3080
  CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON UPDATE CASCADE,
3080
  CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3081
  CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON UPDATE CASCADE,
3081
  CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
3082
  CONSTRAINT `issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
3082
  CONSTRAINT `issues_ibfk_borrowers_borrowernumber` FOREIGN KEY (`issuer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
3083
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3083
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
3084
/*!40101 SET character_set_client = @saved_cs_client */;
3084
/*!40101 SET character_set_client = @saved_cs_client */;
Lines 3951-3957 DROP TABLE IF EXISTS `old_issues`; Link Here
3951
/*!40101 SET @saved_cs_client     = @@character_set_client */;
3951
/*!40101 SET @saved_cs_client     = @@character_set_client */;
3952
/*!40101 SET character_set_client = utf8 */;
3952
/*!40101 SET character_set_client = utf8 */;
3953
CREATE TABLE `old_issues` (
3953
CREATE TABLE `old_issues` (
3954
  `issue_id` int(11) NOT NULL COMMENT 'primary key for issues table',
3954
  `issue_id` int(11) DEFAULT NULL COMMENT 'primary key for issues table',
3955
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the borrowers table for the patron this item was checked out to',
3955
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the borrowers table for the patron this item was checked out to',
3956
  `issuer_id` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the borrowers table for the user who checked out this item',
3956
  `issuer_id` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the borrowers table for the user who checked out this item',
3957
  `itemnumber` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the items table for the item that was checked out',
3957
  `itemnumber` int(11) DEFAULT NULL COMMENT 'foreign key, linking this to the items table for the item that was checked out',
(-)a/t/lib/TestBuilder.pm (-6 / +16 lines)
Lines 27-32 sub new { Link Here
27
27
28
    $self->{gen_type} = _gen_type();
28
    $self->{gen_type} = _gen_type();
29
    $self->{default_values} = _gen_default_values();
29
    $self->{default_values} = _gen_default_values();
30
30
    return $self;
31
    return $self;
31
}
32
}
32
33
Lines 70-75 sub build_object { Link Here
70
    my $class = $params->{class};
71
    my $class = $params->{class};
71
    my $value = $params->{value};
72
    my $value = $params->{value};
72
73
74
    my $depth = delete $params->{depth} || 0;
75
73
    if ( not defined $class ) {
76
    if ( not defined $class ) {
74
        carp "Missing class param";
77
        carp "Missing class param";
75
        return;
78
        return;
Lines 81-87 sub build_object { Link Here
81
    load $class;
84
    load $class;
82
    my $source = $class->_type;
85
    my $source = $class->_type;
83
86
84
    my $hashref = $self->build({ source => $source, value => $value });
87
    my $hashref = $self->build({ source => $source, value => $value, depth => $depth });
85
    my $object;
88
    my $object;
86
    if ( $class eq 'Koha::Old::Patrons' ) {
89
    if ( $class eq 'Koha::Old::Patrons' ) {
87
        $object = $class->search({ borrowernumber => $hashref->{borrowernumber} })->next;
90
        $object = $class->search({ borrowernumber => $hashref->{borrowernumber} })->next;
Lines 111-116 sub build { Link Here
111
    }
114
    }
112
    my $value   = $params->{value};
115
    my $value   = $params->{value};
113
116
117
    my $depth = delete $params->{depth} || 0;
118
    $depth++;
119
114
    my @unknowns = grep( !/^(source|value)$/, keys %{ $params });
120
    my @unknowns = grep( !/^(source|value)$/, keys %{ $params });
115
    carp "Unknown parameter(s): ", join( ', ', @unknowns ) if scalar @unknowns;
121
    carp "Unknown parameter(s): ", join( ', ', @unknowns ) if scalar @unknowns;
116
122
Lines 122-134 sub build { Link Here
122
128
123
    # loop thru all fk and create linked records if needed
129
    # loop thru all fk and create linked records if needed
124
    # fills remaining entries in $col_values
130
    # fills remaining entries in $col_values
125
    my $foreign_keys = $self->_getForeignKeys( { source => $source } );
131
    my $foreign_keys = $self->_getForeignKeys( { source => $source, depth => $depth } );
126
    for my $fk ( @$foreign_keys ) {
132
    for my $fk ( @$foreign_keys ) {
127
        # skip when FK points to itself: e.g. borrowers:guarantorid
133
        # skip when FK points to itself: e.g. borrowers:guarantorid
128
        next if $fk->{source} eq $source;
134
        next if $fk->{source} eq $source;
129
        my $keys = $fk->{keys};
135
        my $keys = $fk->{keys};
130
        my $tbl = $fk->{source};
136
        my $tbl = $fk->{source};
131
        my $res = $self->_create_links( $tbl, $keys, $col_values, $value );
137
        my $res = $self->_create_links( $tbl, $keys, $col_values, $value, $depth );
132
        return if !$res; # failed: no need to go further
138
        return if !$res; # failed: no need to go further
133
        foreach( keys %$res ) { # save new values
139
        foreach( keys %$res ) { # save new values
134
            $col_values->{$_} = $res->{$_};
140
            $col_values->{$_} = $res->{$_};
Lines 205-211 sub build_sample_item { Link Here
205
sub _create_links {
211
sub _create_links {
206
# returns undef for failure to create linked records
212
# returns undef for failure to create linked records
207
# otherwise returns hashref containing new column values for parent record
213
# otherwise returns hashref containing new column values for parent record
208
    my ( $self, $linked_tbl, $keys, $col_values, $value ) = @_;
214
    my ( $self, $linked_tbl, $keys, $col_values, $value, $depth ) = @_;
209
215
210
    my $fk_value = {};
216
    my $fk_value = {};
211
    my ( $cnt_scalar, $cnt_null ) = ( 0, 0 );
217
    my ( $cnt_scalar, $cnt_null ) = ( 0, 0 );
Lines 241-247 sub _create_links { Link Here
241
        return {} if $self->schema->resultset($linked_tbl)->find( \%fk_pk_value );
247
        return {} if $self->schema->resultset($linked_tbl)->find( \%fk_pk_value );
242
    }
248
    }
243
    # create record with a recursive build call
249
    # create record with a recursive build call
244
    my $row = $self->build({ source => $linked_tbl, value => $fk_value });
250
    my $row = $self->build({ source => $linked_tbl, value => $fk_value, depth => $depth });
245
    return if !$row; # failure
251
    return if !$row; # failure
246
252
247
    # Finally, only return the new values
253
    # Finally, only return the new values
Lines 343-348 sub _getForeignKeys { Link Here
343
            my @keys;
349
            my @keys;
344
            while( my ($col_fk_name, $col_name) = each(%{$rel_info->{cond}}) ) {
350
            while( my ($col_fk_name, $col_name) = each(%{$rel_info->{cond}}) ) {
345
                $col_name    =~ s|self.(\w+)|$1|;
351
                $col_name    =~ s|self.(\w+)|$1|;
352
353
                next
354
                  if $params->{depth} > 1
355
                  && $source->columns_info->{$col_name}->{is_nullable};
356
346
                $col_fk_name =~ s|foreign.(\w+)|$1|;
357
                $col_fk_name =~ s|foreign.(\w+)|$1|;
347
                push @keys, {
358
                push @keys, {
348
                    col_name    => $col_name,
359
                    col_name    => $col_name,
349
- 

Return to bug 31142