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

(-)a/Koha/REST/V1/Status.pm (+56 lines)
Line 0 Link Here
1
package Koha::REST::V1::Status;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Try::Tiny qw( catch try );
23
24
use Koha::Status;
25
26
=head1 NAME
27
28
Koha::REST::V1::Status - Controller library for status related API endpoints
29
30
=head1 API
31
32
=head2 Methods
33
34
=head3 version
35
36
Controller method that returns Koha version information
37
38
=cut
39
40
sub version {
41
    my $c = shift->openapi->valid_input or return;
42
43
    return try {
44
        my $status       = Koha::Status->new();
45
        my $version_info = $status->version();
46
47
        return $c->render(
48
            status  => 200,
49
            openapi => $version_info
50
        );
51
    } catch {
52
        $c->unhandled_exception($_);
53
    };
54
}
55
56
1;
(-)a/Koha/Status.pm (+85 lines)
Line 0 Link Here
1
package Koha::Status;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha;
21
22
=head1 NAME
23
24
Koha::Status - Koha instance status information
25
26
=head1 SYNOPSIS
27
28
    use Koha::Status;
29
30
    my $status = Koha::Status->new();
31
    my $version_info = $status->version();
32
33
=head1 DESCRIPTION
34
35
This class provides methods to retrieve status information about the Koha instance.
36
37
=head1 METHODS
38
39
=head2 new
40
41
    my $status = Koha::Status->new();
42
43
Constructor.
44
45
=cut
46
47
sub new {
48
    my ($class) = @_;
49
    return bless {}, $class;
50
}
51
52
=head2 version
53
54
    my $version_info = $status->version();
55
56
Returns version information in a structured format similar to
57
Koha::Template::Plugin::Koha->Version but with additional metadata.
58
59
Returns a hashref with the following structure:
60
- version: full version string
61
- major: major version number
62
- minor: minor version number
63
- release: major.minor version
64
- maintenance: major.minor.maintenance version
65
- development: development version (if applicable)
66
67
=cut
68
69
sub version {
70
    my ($self) = @_;
71
72
    my $version_string = Koha::version();
73
    my ( $major, $minor, $maintenance, $development ) = split( '\.', $version_string );
74
75
    return {
76
        version     => $version_string,
77
        major       => $major,
78
        minor       => $minor,
79
        release     => $major . "." . $minor,
80
        maintenance => $major . "." . $minor . "." . $maintenance,
81
        development => ( $development && $development ne '000' ) ? $development : undef,
82
    };
83
}
84
85
1;
(-)a/api/v1/swagger/definitions/koha_version.yaml (+30 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  version:
5
    type: string
6
    description: Full version string
7
    example: "25.06.00.029"
8
  major:
9
    type: string
10
    description: Major version number
11
    example: "25"
12
  minor:
13
    type: string
14
    description: Minor version number
15
    example: "06"
16
  release:
17
    type: string
18
    description: Release version (major.minor)
19
    example: "25.06"
20
  maintenance:
21
    type: string
22
    description: Maintenance version (major.minor.maintenance)
23
    example: "25.06.00"
24
  development:
25
    type: 
26
      - string
27
      - "null"
28
    description: Development version number (null if not a development version)
29
    example: "029"
30
additionalProperties: false
(-)a/api/v1/swagger/paths/status.yaml (+44 lines)
Line 0 Link Here
1
---
2
"/status/version":
3
  get:
4
    x-mojo-to: Status#version
5
    operationId: getStatusVersion
6
    tags:
7
      - status
8
    summary: Get Koha version information
9
    description: |
10
      Returns version information for this Koha instance including major, minor, 
11
      maintenance and development version numbers.
12
    produces:
13
      - application/json
14
    responses:
15
      "200":
16
        description: A suggestion
17
        schema:
18
          $ref: "../swagger.yaml#/definitions/koha_version"
19
      "400":
20
        description: Bad request
21
        schema:
22
          $ref: "../swagger.yaml#/definitions/error"
23
      "403":
24
        description: Access forbidden
25
        schema:
26
          $ref: "../swagger.yaml#/definitions/error"
27
      "404":
28
        description: Suggestion not found
29
        schema:
30
          $ref: "../swagger.yaml#/definitions/error"
31
      "500":
32
        description: |
33
          Internal server error. Possible `error_code` attribute values:
34
35
          * `internal_server_error`
36
        schema:
37
          $ref: "../swagger.yaml#/definitions/error"
38
      "503":
39
        description: Under maintenance
40
        schema:
41
          $ref: "../swagger.yaml#/definitions/error"
42
    x-koha-authorization:
43
      permissions:
44
        catalogue: 1
(-)a/api/v1/swagger/swagger.yaml (+7 lines)
Lines 124-129 definitions: Link Here
124
    $ref: ./definitions/import_batch_profiles.yaml
124
    $ref: ./definitions/import_batch_profiles.yaml
125
  import_record_match:
125
  import_record_match:
126
    $ref: ./definitions/import_record_match.yaml
126
    $ref: ./definitions/import_record_match.yaml
127
  koha_version:
128
    $ref: definitions/koha_version.yaml
127
  record_source:
129
  record_source:
128
    $ref: ./definitions/record_source.yaml
130
    $ref: ./definitions/record_source.yaml
129
  invoice:
131
  invoice:
Lines 609-614 paths: Link Here
609
    $ref: ./paths/transfer_limits.yaml#/~1transfer_limits~1batch
611
    $ref: ./paths/transfer_limits.yaml#/~1transfer_limits~1batch
610
  "/transfer_limits/{limit_id}":
612
  "/transfer_limits/{limit_id}":
611
    $ref: "./paths/transfer_limits.yaml#/~1transfer_limits~1{limit_id}"
613
    $ref: "./paths/transfer_limits.yaml#/~1transfer_limits~1{limit_id}"
614
  /status/version:
615
    $ref: ./paths/status.yaml#/~1status~1version
612
parameters:
616
parameters:
613
  advancededitormacro_id_pp:
617
  advancededitormacro_id_pp:
614
    description: Advanced editor macro internal identifier
618
    description: Advanced editor macro internal identifier
Lines 1345-1350 tags: Link Here
1345
  - description: "Manage file transport configurations\n"
1349
  - description: "Manage file transport configurations\n"
1346
    name: file_transports
1350
    name: file_transports
1347
    x-displayName: File transports
1351
    x-displayName: File transports
1352
  - description: "System status\n"
1353
    name: status
1354
    x-displayName: Status
1348
  - description: "Manage tickets\n"
1355
  - description: "Manage tickets\n"
1349
    name: tickets
1356
    name: tickets
1350
    x-displayName: Tickets
1357
    x-displayName: Tickets
(-)a/t/Koha/Status.t (+49 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 3;
21
use Test::NoWarnings;
22
23
use Koha::Status;
24
25
subtest 'new' => sub {
26
    plan tests => 1;
27
28
    my $status = Koha::Status->new();
29
    isa_ok( $status, 'Koha::Status', 'Constructor returns correct object type' );
30
};
31
32
subtest 'version' => sub {
33
    plan tests => 7;
34
35
    my $status       = Koha::Status->new();
36
    my $version_info = $status->version();
37
38
    is( ref($version_info), 'HASH', 'version() returns a hashref' );
39
40
    # Check required fields exist
41
    ok( exists $version_info->{version},     'version field exists' );
42
    ok( exists $version_info->{major},       'major field exists' );
43
    ok( exists $version_info->{minor},       'minor field exists' );
44
    ok( exists $version_info->{release},     'release field exists' );
45
    ok( exists $version_info->{maintenance}, 'maintenance field exists' );
46
47
    # Check version format and consistency
48
    like( $version_info->{version}, qr/^\d+\.\d+\.\d+\.\d+$/, 'version has correct format' );
49
};
(-)a/t/db_dependent/api/v1/status.t (-1 / +58 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::NoWarnings;
21
use Test::More tests => 2;
22
use Test::Mojo;
23
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
26
27
use Koha;
28
use Koha::Database;
29
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
my $t = Test::Mojo->new('Koha::REST::V1');
34
35
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
36
37
subtest 'version() tests' => sub {
38
39
    plan tests => 8;
40
41
    $schema->storage->txn_begin;
42
43
    my $librarian = $builder->build_object(
44
        {
45
            class => 'Koha::Patrons',
46
            value => { flags => 2**2 },    # catalogue flag = 2
47
        }
48
    );
49
    my $password = 'thePassword123';
50
    $librarian->set_password( { password => $password, skip_validation => 1 } );
51
    my $userid = $librarian->userid;
52
53
    $t->get_ok("//$userid:$password@/api/v1/status/version")->status_is(200)->json_is( '/version' => Koha::version() )
54
        ->json_has('/major')->json_has('/minor')->json_has('/release')->json_has('/maintenance')
55
        ->json_like( '/version' => qr/^\d+\.\d+\.\d+\.\d+$/ );
56
57
    $schema->storage->txn_rollback;
58
};

Return to bug 41107