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

(-)a/Koha/BiblioFramework.pm (+36 lines)
Lines 32-37 Koha::BiblioFramework - Koha BiblioFramework Object class Link Here
32
32
33
=cut
33
=cut
34
34
35
36
=head3 set_default
37
38
    $framework->set_default;
39
40
Set this framework as the new default, and unset whichever framework is currently the default.
41
42
=cut
43
44
sub set_default {
45
    my ($self) = @_;
46
47
    my $current_default = Koha::BiblioFrameworks->get_default;
48
    if ( defined $current_default ) {
49
        $current_default->unset_default;
50
    }
51
52
    $self->update( { is_default => 1 } )->store;
53
    return $self;
54
}
55
56
=head3 unset_default
57
58
    $framework->unset_default;
59
60
Unset this framework as the default.
61
62
=cut
63
64
sub unset_default {
65
    my ($self) = @_;
66
67
    $self->update( { is_default => 0 } )->store;
68
    return $self;
69
}
70
35
=head3 type
71
=head3 type
36
72
37
=cut
73
=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 (+7 lines)
Lines 807-812 if ( $record ne '-1' ) { Link Here
807
    my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
807
    my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title;
808
    $template->param( title => $title );
808
    $template->param( title => $title );
809
}
809
}
810
my $default_framework = Koha::BiblioFrameworks->get_default;
811
if (   defined $default_framework
812
    && defined $frameworkcode
813
    && $frameworkcode eq '' )
814
{
815
    $frameworkcode = $default_framework->frameworkcode;
816
}
810
$template->param(
817
$template->param(
811
    popup => $mode,
818
    popup => $mode,
812
    frameworkcode => $frameworkcode,
819
    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 (+17 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(
12
                q{ ALTER TABLE biblio_framework ADD is_default TINYINT(1) DEFAULT 0 NOT NULL AFTER `frameworktext` });
13
14
            say $out "Added column 'biblio_framework.is_default'";
15
        }
16
    },
17
};
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1117-1122 DROP TABLE IF EXISTS `biblio_framework`; Link Here
1117
CREATE TABLE `biblio_framework` (
1117
CREATE TABLE `biblio_framework` (
1118
  `frameworkcode` varchar(4) NOT NULL DEFAULT '' COMMENT 'the unique code assigned to the framework',
1118
  `frameworkcode` varchar(4) NOT NULL DEFAULT '' COMMENT 'the unique code assigned to the framework',
1119
  `frameworktext` varchar(255) NOT NULL DEFAULT '' COMMENT 'the description/name given to the framework',
1119
  `frameworktext` varchar(255) NOT NULL DEFAULT '' COMMENT 'the description/name given to the framework',
1120
  `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',
1120
  PRIMARY KEY (`frameworkcode`)
1121
  PRIMARY KEY (`frameworkcode`)
1121
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1122
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1122
/*!40101 SET character_set_client = @saved_cs_client */;
1123
/*!40101 SET character_set_client = @saved_cs_client */;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/biblio_framework.tt (+8 lines)
Lines 135-140 Link Here
135
                    <input type="text" name="frameworktext" id="description" size="40" maxlength="80" value="[% framework.frameworktext | html %]" required="required" class="required" />
135
                    <input type="text" name="frameworktext" id="description" size="40" maxlength="80" value="[% framework.frameworktext | html %]" required="required" class="required" />
136
                    <span class="required">Required</span>
136
                    <span class="required">Required</span>
137
                </li>
137
                </li>
138
                <li>
139
                    <label for="default">Set as default: </label>
140
                    [% IF framework.is_default %]
141
                        <input type="checkbox" name="is_default" id="is_default" value="1" checked="checked">
142
                    [% ELSE %]
143
                        <input type="checkbox" name="is_default" id="is_default" value="1">
144
                    [% END %]
145
                </li>
138
            </ol>
146
            </ol>
139
        </fieldset>
147
        </fieldset>
140
        <fieldset class="action">
148
        <fieldset class="action">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt (-1 / +5 lines)
Lines 290-296 Link Here
290
            });
290
            });
291
291
292
            $("#z3950search").click(function(){
292
            $("#z3950search").click(function(){
293
                PopupZ3950("Default");
293
                [% IF default_frameworkcode %]
294
                    PopupZ3950('[% default_frameworkcode | html %]');
295
                [% ELSE %]
296
                    PopupZ3950("Default");
297
                [% END %]
294
                return false;
298
                return false;
295
            });
299
            });
296
300
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (-1 / +5 lines)
Lines 265-271 Link Here
265
                                                    <select name="framework" id="frameworks">
265
                                                    <select name="framework" id="frameworks">
266
                                                        <option value="">Default</option>
266
                                                        <option value="">Default</option>
267
                                                        [% FOREACH framework IN frameworks %]
267
                                                        [% FOREACH framework IN frameworks %]
268
                                                            <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
268
                                                            [% IF framework.is_default %]
269
                                                                <option value="[% framework.frameworkcode | html %]" selected="selected">[% framework.frameworktext | html %]</option>
270
                                                            [% ELSE %]
271
                                                                <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
272
                                                            [% END %]
269
                                                        [% END %]
273
                                                        [% END %]
270
                                                    </select>
274
                                                    </select>
271
                                                    <div class="hint">New bibliographic records will use this framework</div>
275
                                                    <div class="hint">New bibliographic records will use this framework</div>
(-)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