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

(-)a/Koha/Plugins.pm (-2 / +2 lines)
Lines 26-33 use C4::Context; Link Here
26
use C4::Output;
26
use C4::Output;
27
27
28
BEGIN {
28
BEGIN {
29
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") );
30
31
    push @INC, C4::Context->config("pluginsdir");
29
    push @INC, C4::Context->config("pluginsdir");
32
}
30
}
33
31
Lines 40-45 Koha::Plugins - Module for loading and managing plugins. Link Here
40
sub new {
38
sub new {
41
    my ( $class, $args ) = @_;
39
    my ( $class, $args ) = @_;
42
40
41
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
42
43
    $args->{'pluginsdir'} = C4::Context->config("pluginsdir");
43
    $args->{'pluginsdir'} = C4::Context->config("pluginsdir");
44
44
45
    return bless( $args, $class );
45
    return bless( $args, $class );
(-)a/Koha/Plugins/Base.pm (-2 / +2 lines)
Lines 27-34 use C4::Context; Link Here
27
use C4::Auth;
27
use C4::Auth;
28
28
29
BEGIN {
29
BEGIN {
30
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") );
31
32
    push @INC, C4::Context->config("pluginsdir");
30
    push @INC, C4::Context->config("pluginsdir");
33
}
31
}
34
32
Lines 41-46 C4::Plugins::Base - Base Module for plugins Link Here
41
sub new {
39
sub new {
42
    my ( $class, $args ) = @_;
40
    my ( $class, $args ) = @_;
43
41
42
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
43
44
    $args->{'class'} = $class;
44
    $args->{'class'} = $class;
45
    $args->{'template'} = Template->new( { ABSOLUTE => 1 } );
45
    $args->{'template'} = Template->new( { ABSOLUTE => 1 } );
46
46
(-)a/Koha/Plugins/Handler.pm (-2 / +3 lines)
Lines 26-33 use Module::Load::Conditional qw(can_load); Link Here
26
use C4::Context;
26
use C4::Context;
27
27
28
BEGIN {
28
BEGIN {
29
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") );
30
31
    push @INC, C4::Context->config("pluginsdir");
29
    push @INC, C4::Context->config("pluginsdir");
32
}
30
}
33
31
Lines 52-57 Runs a plugin Link Here
52
50
53
sub run {
51
sub run {
54
    my ( $class, $args ) = @_;
52
    my ( $class, $args ) = @_;
53
54
    die('Plugins not enabled in config') unless ( C4::Context->config("enable_plugins") || $args->{'enable_plugins'} );
55
55
    my $plugin_class  = $args->{'class'};
56
    my $plugin_class  = $args->{'class'};
56
    my $plugin_method = $args->{'method'};
57
    my $plugin_method = $args->{'method'};
57
    my $cgi           = $args->{'cgi'};
58
    my $cgi           = $args->{'cgi'};
(-)a/t/Koha/Plugin/Test.pm (+53 lines)
Line 0 Link Here
1
package Koha::Plugin::Test;
2
3
## It's good practive to use Modern::Perl
4
use Modern::Perl;
5
6
## Required for all plugins
7
use base qw(Koha::Plugins::Base);
8
9
our $VERSION = 1.01;
10
our $metadata = {
11
    name            => 'Test Plugin',
12
    author          => 'Kyle M Hall',
13
    description     => 'Test plugin',
14
    date_authored   => '2013-01-14',
15
    date_updated    => '2013-01-14',
16
    minimum_version => '3.11',
17
    maximum_version => undef,
18
    version         => $VERSION,
19
};
20
21
## This is the minimum code required for a plugin's 'new' method
22
## More can be added, but none should be removed
23
sub new {
24
    my ( $class, $args ) = @_;
25
    $args->{'metadata'} = $metadata;
26
    my $self = $class->SUPER::new($args);
27
    return $self;
28
}
29
30
sub report {
31
    my ( $self, $args ) = @_;
32
    return 1;
33
}
34
35
sub tool {
36
    my ( $self, $args ) = @_;
37
    return 1;
38
}
39
40
sub configure {
41
    my ( $self, $args ) = @_;
42
    return 1;
43
}
44
45
sub install {
46
    my ( $self, $args ) = @_;
47
    return 1;
48
}
49
50
sub uninstall {
51
    my ( $self, $args ) = @_;
52
    return 1;
53
}
(-)a/t/db_dependent/Plugins.t (-1 / +39 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
6
use Test::More tests => 15;
7
use File::Basename;
8
9
use Module::Load::Conditional qw(can_load);
10
11
use C4::Context;
12
13
BEGIN {
14
    push( @INC, dirname(__FILE__) . '/..' );
15
16
    use_ok('Koha::Plugins');
17
    use_ok('Koha::Plugins::Handler');
18
    use_ok('Koha::Plugins::Base');
19
    use_ok('Koha::Plugin::Test');
20
}
21
22
ok( can_load( modules => { "Koha::Plugin::Test" => undef } ), 'Test can_load' );
23
24
my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1});
25
26
isa_ok( $plugin, "Koha::Plugin::Test", 'Test plugin class' );
27
isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' );
28
29
ok( $plugin->can('report'), 'Test plugin can report' );
30
ok( $plugin->can('tool'), 'Test plugin can tool' );
31
ok( $plugin->can('configure'), 'Test plugin can configure' );
32
ok( $plugin->can('install'), 'Test plugin can install' );
33
ok( $plugin->can('uninstall'), 'Test plugin can install' );
34
35
my $metadata = $plugin->get_metadata();
36
ok( $metadata->{'name'} eq 'Test Plugin', 'Test $plugin->get_metadata()' );
37
38
ok( $plugin->get_qualified_table_name('mytable') eq 'koha_plugin_test_mytable', 'Test $plugin->get_qualified_table_name()' );
39
ok( $plugin->get_plugin_http_path() eq '/plugin/Koha/Plugin/Test', 'Test $plugin->get_plugin_http_path()' );

Return to bug 7804