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

(-)a/Koha/Schema/Component/Localization.pm (-34 / +44 lines)
Lines 98-122 use Carp; Link Here
98
98
99
use base qw(DBIx::Class);
99
use base qw(DBIx::Class);
100
100
101
=head2 localization_add_relationships
102
103
Add relationships to the localization table
104
105
=cut
106
101
sub localization_add_relationships {
107
sub localization_add_relationships {
102
    my ($class, $rel_name, $fk_column, $pk_column, @properties) = @_;
108
    my ($class, $pk_column, @properties) = @_;
103
109
104
    my $rel_info = $class->relationship_info($rel_name);
110
    my $rel_class = 'Koha::Schema::Result::Localization';
105
    unless ($rel_info) {
111
    my $source_name = $class =~ s/.*:://r;
106
        confess "Unknown relation '$rel_name'";
107
    }
108
112
109
    $class->has_many(
113
    $class->has_many(
110
        'localizations',
114
        'localizations',
111
        $rel_info->{class},
115
        $rel_class,
112
        { "foreign.$fk_column" => "self.$pk_column" },
116
        sub {
113
        { cascade_copy => 0, cascade_delete => 0, cascade_update => 0 },
117
            my ($args) = @_;
118
119
            return (
120
                {
121
                    "$args->{foreign_alias}.code"   => { -ident => "$args->{self_alias}.$pk_column" },
122
                    "$args->{foreign_alias}.entity" => $source_name,
123
                },
124
                !$args->{self_result_object} ? () : {
125
                    "$args->{foreign_alias}.code"   => $args->{self_result_object}->get_column($pk_column),
126
                    "$args->{foreign_alias}.entity" => $source_name,
127
                },
128
            );
129
        },
130
        { cascade_copy => 0, cascade_delete => 1, cascade_update => 0 },
114
    );
131
    );
115
132
116
    foreach my $property (@properties) {
133
    foreach my $property (@properties) {
117
        $class->might_have(
134
        $class->might_have(
118
            $property . "_localization",
135
            $property . '_localization',
119
            $rel_info->{class},
136
            $rel_class,
120
            sub {
137
            sub {
121
                my ($args) = @_;
138
                my ($args) = @_;
122
139
Lines 127-144 sub localization_add_relationships { Link Here
127
144
128
                return (
145
                return (
129
                    {
146
                    {
130
                        "$args->{foreign_alias}.$fk_column" => { -ident => "$args->{self_alias}.$pk_column" },
147
                        "$args->{foreign_alias}.code"     => { -ident => "$args->{self_alias}.$pk_column" },
131
                        "$args->{foreign_alias}.property"   => $property,
148
                        "$args->{foreign_alias}.entity"   => $source_name,
132
                        "$args->{foreign_alias}.lang"       => $lang,
149
                        "$args->{foreign_alias}.property" => $property,
150
                        "$args->{foreign_alias}.lang"     => $lang,
133
                    },
151
                    },
134
                    !$args->{self_result_object} ? () : {
152
                    !$args->{self_result_object} ? () : {
135
                        "$args->{foreign_alias}.$fk_column" => $args->{self_result_object}->get_column($pk_column),
153
                        "$args->{foreign_alias}.code"     => $args->{self_result_object}->get_column($pk_column),
136
                        "$args->{foreign_alias}.property"   => $property,
154
                        "$args->{foreign_alias}.entity"   => $source_name,
137
                        "$args->{foreign_alias}.lang"       => $lang,
155
                        "$args->{foreign_alias}.property" => $property,
156
                        "$args->{foreign_alias}.lang"     => $lang,
138
                    },
157
                    },
139
                    !$args->{foreign_values} ? () : {
140
                        "$args->{foreign_alias}.$fk_column" => $args->{foreign_values}->{$pk_column},
141
                    }
142
                );
158
                );
143
            },
159
            },
144
            { cascade_copy => 0, cascade_delete => 0, cascade_update => 0 },
160
            { cascade_copy => 0, cascade_delete => 0, cascade_update => 0 },
Lines 146-167 sub localization_add_relationships { Link Here
146
162
147
        $class->has_many(
163
        $class->has_many(
148
            $property . '_localizations',
164
            $property . '_localizations',
149
            $rel_info->{class},
165
            $rel_class,
150
            sub {
166
            sub {
151
                my ($args) = @_;
167
                my ($args) = @_;
152
168
153
                return (
169
                return (
154
                    {
170
                    {
155
                        "$args->{foreign_alias}.$fk_column" => { -ident => "$args->{self_alias}.$pk_column" },
171
                        "$args->{foreign_alias}.code"     => { -ident => "$args->{self_alias}.$pk_column" },
156
                        "$args->{foreign_alias}.property"   => $property,
172
                        "$args->{foreign_alias}.entity"   => $source_name,
173
                        "$args->{foreign_alias}.property" => $property,
157
                    },
174
                    },
158
                    !$args->{self_result_object} ? () : {
175
                    !$args->{self_result_object} ? () : {
159
                        "$args->{foreign_alias}.$fk_column" => $args->{self_result_object}->get_column($pk_column),
176
                        "$args->{foreign_alias}.code"     => $args->{self_result_object}->get_column($pk_column),
160
                        "$args->{foreign_alias}.property"   => $property,
177
                        "$args->{foreign_alias}.entity"   => $source_name,
178
                        "$args->{foreign_alias}.property" => $property,
161
                    },
179
                    },
162
                    !$args->{foreign_values} ? () : {
163
                        "$args->{foreign_alias}.$fk_column" => $args->{foreign_values}->{$pk_column},
164
                    }
165
                );
180
                );
166
            },
181
            },
167
            { cascade_copy => 0, cascade_delete => 0, cascade_update => 0 },
182
            { cascade_copy => 0, cascade_delete => 0, cascade_update => 0 },
Lines 180-193 sub localization { Link Here
180
    unless ($localizations_map) {
195
    unless ($localizations_map) {
181
        $localizations_map = {};
196
        $localizations_map = {};
182
197
183
        my $rel_info = $self->relationship_info('localizations');
198
        my $localizations = $result_source->schema->resultset('Localization')->search({ lang => $lang });
184
        my $rel_source = $rel_info->{class} =~ s/.*:://r;
185
186
        my ($fk_column) = map { s/^foreign\.//r } keys %{ $rel_info->{cond} };
187
188
        my $localizations = $result_source->schema->resultset($rel_source)->search({ lang => $lang });
189
        while (my $localization = $localizations->next) {
199
        while (my $localization = $localizations->next) {
190
            my $fk = $localization->get_column($fk_column);
200
            my $fk = $localization->get_column('code');
191
            my $localization_key = sprintf('%s:%s', $fk, $localization->property);
201
            my $localization_key = sprintf('%s:%s', $fk, $localization->property);
192
            $localizations_map->{$localization_key} = $localization->translation;
202
            $localizations_map->{$localization_key} = $localization->translation;
193
        }
203
        }
(-)a/Koha/Schema/Result/Itemtype.pm (-22 / +3 lines)
Lines 293-313 __PACKAGE__->has_many( Link Here
293
  { cascade_copy => 0, cascade_delete => 0 },
293
  { cascade_copy => 0, cascade_delete => 0 },
294
);
294
);
295
295
296
=head2 itemtypes_localizations
297
298
Type: has_many
299
300
Related object: L<Koha::Schema::Result::ItemtypesLocalization>
301
302
=cut
303
304
__PACKAGE__->has_many(
305
  "itemtypes_localizations",
306
  "Koha::Schema::Result::ItemtypesLocalization",
307
  { "foreign.itemtype" => "self.itemtype" },
308
  { cascade_copy => 0, cascade_delete => 0 },
309
);
310
311
=head2 old_reserves
296
=head2 old_reserves
312
297
313
Type: has_many
298
Type: has_many
Lines 359-366 __PACKAGE__->has_many( Link Here
359
);
344
);
360
345
361
346
362
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-10-25 13:25:14
347
# Created by DBIx::Class::Schema::Loader v0.07052 @ 2024-12-03 14:37:10
363
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jd0dYE700dpg1IiRnfbcEg
348
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:l3ycM1L5bmCeM0Pby8GceA
364
349
365
__PACKAGE__->add_columns(
350
__PACKAGE__->add_columns(
366
    '+automatic_checkin'            => { is_boolean => 1 },
351
    '+automatic_checkin'            => { is_boolean => 1 },
Lines 372-382 __PACKAGE__->add_columns( Link Here
372
);
357
);
373
358
374
__PACKAGE__->load_components('+Koha::Schema::Component::Localization');
359
__PACKAGE__->load_components('+Koha::Schema::Component::Localization');
375
__PACKAGE__->localization_add_relationships(
360
__PACKAGE__->localization_add_relationships('itemtype', 'description');
376
    'itemtypes_localizations',
377
    'itemtype' => 'itemtype',
378
    'description'
379
);
380
361
381
sub koha_object_class {
362
sub koha_object_class {
382
    'Koha::ItemType';
363
    'Koha::ItemType';
(-)a/installer/data/mysql/atomicupdate/bug-38136.pl (-23 / +9 lines)
Lines 3-36 use Koha::Installer::Output qw(say_warning say_failure say_success say_info); Link Here
3
3
4
return {
4
return {
5
    bug_number  => '38136',
5
    bug_number  => '38136',
6
    description => 'Add itemtypes_localizations table',
6
    description => 'Add localization.property',
7
    up          => sub {
7
    up          => sub {
8
        my ($args) = @_;
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
10
11
        unless ( TableExists('itemtypes_localizations') ) {
11
        unless (column_exists('localization', 'property')) {
12
            $dbh->do( "
12
            $dbh->do("alter table `localization` add `property` varchar(100) null after `code`");
13
                CREATE TABLE `itemtypes_localizations` (
13
            $dbh->do("update `localization` set `property` = 'description', entity = 'Itemtype'");
14
                  `itemtypes_localizations_id` int(11) NOT NULL AUTO_INCREMENT,
14
            $dbh->do("alter table `localization` modify `property` varchar(100) not null");
15
                  `itemtype` varchar(10) NOT NULL,
15
            $dbh->do("alter table `localization` drop key `entity_code_lang`");
16
                  `property` varchar(100) NOT NULL,
16
            $dbh->do("alter table `localization` add unique key `entity_code_property_lang` (`entity`, `code`, `property`, `lang`)");
17
                  `lang` varchar(25) NOT NULL,
18
                  `translation` mediumtext DEFAULT NULL,
19
                  PRIMARY KEY (`itemtypes_localizations_id`),
20
                  UNIQUE KEY `itemtype_property_lang` (`itemtype`, `property`, `lang`),
21
                  CONSTRAINT `itemtypes_localizations_itemtype_fk`
22
                    FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
23
                    ON DELETE CASCADE ON UPDATE CASCADE
24
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
25
            " );
26
17
27
            if ( TableExists('localization') ) {
18
            say_success($out, 'Added column localization.property and updated localization.entity values');
28
                $dbh->do( "
29
                    INSERT INTO `itemtypes_localizations` (`itemtype`, `property`, `lang`, `translation`)
30
                    SELECT `code`, 'description', `lang`, `translation` FROM `localization` WHERE `entity` = 'itemtypes'
31
                " );
32
                $dbh->do('DROP TABLE localization');
33
            }
34
        }
19
        }
20
35
    },
21
    },
36
};
22
};
(-)a/installer/data/mysql/kohastructure.sql (-18 / +2 lines)
Lines 4180-4202 CREATE TABLE `itemtypes_branches` ( Link Here
4180
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4180
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4181
/*!40101 SET character_set_client = @saved_cs_client */;
4181
/*!40101 SET character_set_client = @saved_cs_client */;
4182
4182
4183
--
4184
-- Table structure for table `itemtypes_localizations`
4185
--
4186
4187
CREATE TABLE `itemtypes_localizations` (
4188
  `itemtypes_localizations_id` int(11) NOT NULL AUTO_INCREMENT,
4189
  `itemtype` varchar(10) NOT NULL,
4190
  `property` varchar(100) NOT NULL,
4191
  `lang` varchar(25) NOT NULL,
4192
  `translation` mediumtext DEFAULT NULL,
4193
  PRIMARY KEY (`itemtypes_localizations_id`),
4194
  UNIQUE KEY `itemtype_property_lang` (`itemtype`, `property`, `lang`),
4195
  CONSTRAINT `itemtypes_localizations_itemtype_fk`
4196
    FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
4197
    ON DELETE CASCADE ON UPDATE CASCADE
4198
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4199
4200
--
4183
--
4201
-- Table structure for table `keyboard_shortcuts`
4184
-- Table structure for table `keyboard_shortcuts`
4202
--
4185
--
Lines 4423-4432 CREATE TABLE `localization` ( Link Here
4423
  `localization_id` int(11) NOT NULL AUTO_INCREMENT,
4406
  `localization_id` int(11) NOT NULL AUTO_INCREMENT,
4424
  `entity` varchar(16) NOT NULL,
4407
  `entity` varchar(16) NOT NULL,
4425
  `code` varchar(64) NOT NULL,
4408
  `code` varchar(64) NOT NULL,
4409
  `property` varchar(100) NOT NULL,
4426
  `lang` varchar(25) NOT NULL COMMENT 'could be a foreign key',
4410
  `lang` varchar(25) NOT NULL COMMENT 'could be a foreign key',
4427
  `translation` mediumtext DEFAULT NULL,
4411
  `translation` mediumtext DEFAULT NULL,
4428
  PRIMARY KEY (`localization_id`),
4412
  PRIMARY KEY (`localization_id`),
4429
  UNIQUE KEY `entity_code_lang` (`entity`,`code`,`lang`)
4413
  UNIQUE KEY `entity_code_property_lang` (`entity`,`code`,`property`,`lang`)
4430
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4414
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4431
/*!40101 SET character_set_client = @saved_cs_client */;
4415
/*!40101 SET character_set_client = @saved_cs_client */;
4432
4416
(-)a/svc/localization (-1 / +1 lines)
Lines 60-65 sub add_translation { Link Here
60
        my $localization = $row->create_related(
60
        my $localization = $row->create_related(
61
            "${property}_localizations",
61
            "${property}_localizations",
62
            {
62
            {
63
                entity => $source,
63
                lang => $lang,
64
                lang => $lang,
64
                translation => $translation,
65
                translation => $translation,
65
            }
66
            }
66
- 

Return to bug 38136