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

(-)a/Koha/BiblioFramework.pm (+35 lines)
Lines 32-37 Koha::BiblioFramework - Koha BiblioFramework Object class Link Here
32
32
33
=cut
33
=cut
34
34
35
=head3 set_default
36
37
    $framework->set_default;
38
39
Set this framework as the new default, and unset whichever framework is currently the default.
40
41
=cut
42
43
sub set_default {
44
    my ( $self ) = @_;
45
46
    my $current_default = Koha::BiblioFrameworks->get_default;
47
    if ( defined $current_default ){
48
        $current_default->unset_default;
49
    }
50
51
    $self->update({ is_default => 1 })->store;
52
    return $self;
53
}
54
55
=head3 unset_default
56
57
    $framework->unset_default;
58
59
Unset this framework as the default.
60
61
=cut
62
63
sub unset_default {
64
    my ( $self ) = @_;
65
66
    $self->update({ is_default => 0 })->store;
67
    return $self;
68
}
69
35
=head3 type
70
=head3 type
36
71
37
=cut
72
=cut
(-)a/Koha/BiblioFrameworks.pm (+15 lines)
Lines 34-39 Koha::BiblioFrameworks - Koha BiblioFramework Object set class Link Here
34
34
35
=cut
35
=cut
36
36
37
=head3 get_default
38
39
    my $default_framework = Koha::BiblioFrameworks->get_default;
40
41
Get the allocated default framework.
42
If returned undefined, then the current default framework is the Default framework (framework with no frameworkcode).
43
44
=cut
45
46
sub get_default {
47
    my ( $self ) = @_;
48
49
    return $self->find({ is_default => 1 });
50
}
51
37
=head3 type
52
=head3 type
38
53
39
=cut
54
=cut
(-)a/admin/biblio_framework.pl (+3 lines)
Lines 52-62 if ( $op eq 'add_form' ) { Link Here
52
} elsif ( $op eq 'add_validate' ) {
52
} elsif ( $op eq 'add_validate' ) {
53
    my $frameworkcode = $input->param('frameworkcode');
53
    my $frameworkcode = $input->param('frameworkcode');
54
    my $frameworktext = $input->param('frameworktext');
54
    my $frameworktext = $input->param('frameworktext');
55
    my $is_default    = $input->param('is_default');
55
    my $is_a_modif    = $input->param('is_a_modif');
56
    my $is_a_modif    = $input->param('is_a_modif');
56
57
57
    if ($is_a_modif) {
58
    if ($is_a_modif) {
58
        my $framework = Koha::BiblioFrameworks->find($frameworkcode);
59
        my $framework = Koha::BiblioFrameworks->find($frameworkcode);
59
        $framework->frameworktext($frameworktext);
60
        $framework->frameworktext($frameworktext);
61
        $is_default ? $framework->set_default : $framework->unset_default;
60
        eval { $framework->store; };
62
        eval { $framework->store; };
61
        if ($@) {
63
        if ($@) {
62
            push @messages, { type => 'error', code => 'error_on_update' };
64
            push @messages, { type => 'error', code => 'error_on_update' };
Lines 69-74 if ( $op eq 'add_form' ) { Link Here
69
                frameworktext => $frameworktext,
71
                frameworktext => $frameworktext,
70
            }
72
            }
71
        );
73
        );
74
        $is_default ? $framework->set_default : $framework->unset_default;
72
        eval { $framework->store; };
75
        eval { $framework->store; };
73
        if ($@) {
76
        if ($@) {
74
            push @messages, { type => 'error', code => 'error_on_insert' };
77
            push @messages, { type => 'error', code => 'error_on_insert' };
(-)a/cataloguing/addbiblio.pl (+6 lines)
Lines 1016-1021 if ( $record ne '-1' ) { Link Here
1016
    my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
1016
    my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
1017
    $template->param( title => $title );
1017
    $template->param( title => $title );
1018
}
1018
}
1019
my $default_framework = Koha::BiblioFrameworks->get_default;
1020
if ( defined $default_framework
1021
    && defined $frameworkcode
1022
    && $frameworkcode eq '' ){
1023
    $frameworkcode = $default_framework->frameworkcode;
1024
}
1019
$template->param(
1025
$template->param(
1020
    popup => $mode,
1026
    popup => $mode,
1021
    frameworkcode => $frameworkcode,
1027
    frameworkcode => $frameworkcode,
(-)a/cataloguing/addbooks.pl (+5 lines)
Lines 135-139 $template->param( Link Here
135
    z3950_search_params => C4::Search::z3950_search_args($query),
135
    z3950_search_params => C4::Search::z3950_search_args($query),
136
);
136
);
137
137
138
my $default_framework = Koha::BiblioFrameworks->get_default;
139
if ( $default_framework ){
140
    $template->param( default_frameworkcode => $default_framework->frameworkcode );
141
}
142
138
output_html_with_http_headers $input, $cookie, $template->output;
143
output_html_with_http_headers $input, $cookie, $template->output;
139
144
(-)a/installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.pl (+16 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "23111",
5
    description => "Add is_default column to biblio_framework table",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        if( !column_exists( 'biblio_framework', 'is_default' ) ) {
11
          $dbh->do(q{
12
              ALTER TABLE biblio_framework ADD is_default TINYINT(1) DEFAULT 0 NOT NULL AFTER `frameworktext`
13
          });
14
        }
15
    },
16
};
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1034-1039 DROP TABLE IF EXISTS `biblio_framework`; Link Here
1034
CREATE TABLE `biblio_framework` (
1034
CREATE TABLE `biblio_framework` (
1035
  `frameworkcode` varchar(4) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the unique code assigned to the framework',
1035
  `frameworkcode` varchar(4) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the unique code assigned to the framework',
1036
  `frameworktext` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the description/name given to the framework',
1036
  `frameworktext` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the description/name given to the framework',
1037
  `is_default` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'indicates whether this framework is the default to be used when importing records or editing records with no framework mapped',
1037
  PRIMARY KEY (`frameworkcode`)
1038
  PRIMARY KEY (`frameworkcode`)
1038
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1039
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1039
/*!40101 SET character_set_client = @saved_cs_client */;
1040
/*!40101 SET character_set_client = @saved_cs_client */;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/biblio_framework.tt (+8 lines)
Lines 126-131 MARC frameworks › Administration › Koha Link Here
126
                    <input type="text" name="frameworktext" id="description" size="40" maxlength="80" value="[% framework.frameworktext | html %]" required="required" class="required" />
126
                    <input type="text" name="frameworktext" id="description" size="40" maxlength="80" value="[% framework.frameworktext | html %]" required="required" class="required" />
127
                    <span class="required">Required</span>
127
                    <span class="required">Required</span>
128
                </li>
128
                </li>
129
                <li>
130
                    <label for="default">Set as default: </label>
131
                    [% IF framework.is_default %]
132
                        <input type="checkbox" name="is_default" id="is_default" value="1" checked="checked">
133
                    [% ELSE %]
134
                        <input type="checkbox" name="is_default" id="is_default" value="1">
135
                    [% END %]
136
                </li>
129
            </ol>
137
            </ol>
130
        </fieldset>
138
        </fieldset>
131
        <fieldset class="action">
139
        <fieldset class="action">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt (-1 / +5 lines)
Lines 283-289 Link Here
283
            });
283
            });
284
284
285
            $("#z3950search").click(function(){
285
            $("#z3950search").click(function(){
286
                PopupZ3950("Default");
286
                [% IF default_frameworkcode %]
287
                    PopupZ3950('[% default_frameworkcode | html %]');
288
                [% ELSE %]
289
                    PopupZ3950("Default");
290
                [% END %]
287
                return false;
291
                return false;
288
            });
292
            });
289
293
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (-1 / +5 lines)
Lines 268-274 Link Here
268
                                            <select name="framework" id="frameworks">
268
                                            <select name="framework" id="frameworks">
269
                                                <option value="">Default</option>
269
                                                <option value="">Default</option>
270
                                                [% FOREACH framework IN frameworks %]
270
                                                [% FOREACH framework IN frameworks %]
271
                                                    <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
271
                                                    [% IF framework.is_default %]
272
                                                        <option value="[% framework.frameworkcode | html %]" selected="selected">[% framework.frameworktext | html %]</option>
273
                                                    [% ELSE %]
274
                                                        <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
275
                                                    [% END %]
272
                                                [% END %]
276
                                                [% END %]
273
                                            </select>
277
                                            </select>
274
                                        [% END %]
278
                                        [% END %]
(-)a/t/db_dependent/Koha/BiblioFrameworks.t (-2 / +17 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 3;
21
use Test::More tests => 7;
22
use Koha::BiblioFramework;
22
use Koha::BiblioFramework;
23
use Koha::BiblioFrameworks;
23
use Koha::BiblioFrameworks;
24
24
Lines 40-45 is( Koha::BiblioFrameworks->search->count, $nb_of_frameworks + 2, 'The 2 biblio Link Here
40
my $retrieved_framework_1 = Koha::BiblioFrameworks->find( $new_framework_1->frameworkcode );
40
my $retrieved_framework_1 = Koha::BiblioFrameworks->find( $new_framework_1->frameworkcode );
41
is( $retrieved_framework_1->frameworktext, $new_framework_1->frameworktext, 'Find a biblio framework by frameworkcode should return the correct framework' );
41
is( $retrieved_framework_1->frameworktext, $new_framework_1->frameworktext, 'Find a biblio framework by frameworkcode should return the correct framework' );
42
42
43
# testing of default frameworks
44
$new_framework_1->set_default;
45
my $default_framework = Koha::BiblioFrameworks->get_default;
46
is( $default_framework->frameworkcode, $new_framework_1->frameworkcode, 'Successfully identified default framework' );
47
48
$new_framework_2->set_default;
49
$default_framework = Koha::BiblioFrameworks->get_default;
50
is( $default_framework->frameworkcode, $new_framework_2->frameworkcode, 'Successfully changed default framework' );
51
$new_framework_1 = Koha::BiblioFrameworks->find( $new_framework_1->frameworkcode );
52
is( $new_framework_1->is_default, 0, 'Old default framework has been unset' );
53
54
$default_framework->unset_default;
55
my $nb_of_defaults = Koha::BiblioFrameworks->search({ is_default => 1 })->count;
56
is( $nb_of_defaults, 0, 'No default framework is set' );
57
# end of default frameworks testing
58
43
$retrieved_framework_1->delete;
59
$retrieved_framework_1->delete;
44
is( Koha::BiblioFrameworks->search->count, $nb_of_frameworks + 1, 'Delete should have deleted the biblio framework' );
60
is( Koha::BiblioFrameworks->search->count, $nb_of_frameworks + 1, 'Delete should have deleted the biblio framework' );
45
$schema->storage->txn_rollback;
61
$schema->storage->txn_rollback;
46
- 

Return to bug 23111