Skip to content

Commit ea39a7e

Browse files
author
roger
committed
First additions to the plugin.
1 parent 7117dac commit ea39a7e

File tree

4 files changed

+426
-0
lines changed

4 files changed

+426
-0
lines changed

.github/workflows/main.yml

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- 'v*.*.*'
8+
jobs:
9+
unit_tests:
10+
name: Run unit tests
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
koha-version: [main, stable, oldstable]
16+
17+
steps:
18+
19+
- name: Is a tag?
20+
run: |
21+
echo "${{ startsWith(github.ref, 'refs/tags/v') }}"
22+
23+
- name: GitHub Ref 1
24+
run: |
25+
echo "${GITHUB_REF##*/}"
26+
27+
- name: GitHub Ref 2
28+
run: |
29+
echo "${{ github.event.ref }}"
30+
31+
- name: GitHub Ref 3
32+
run: |
33+
echo "${{ github.ref }}"
34+
35+
- name: Dump env
36+
run: env | sort
37+
38+
- name: Dump GitHub context
39+
env:
40+
GITHUB_CONTEXT: ${{ toJson(github) }}
41+
run: echo "$GITHUB_CONTEXT"
42+
43+
- uses: actions/checkout@v1
44+
45+
- name: Get Koha Version Branch Name
46+
id: koha-version
47+
uses: "bywatersolutions/github-action-koha-get-version-by-label@master"
48+
with:
49+
version-label: "${{ matrix.koha-version }}"
50+
51+
- name: Check out Koha
52+
run: |
53+
cd ..
54+
git clone --branch ${{ steps.koha-version.outputs.current-branch-name }} --single-branch --depth 1 https://github.com/Koha-Community/Koha.git kohaclone
55+
56+
- name: Export additional variables needed by koha-testing-docker
57+
run: |
58+
cd ..
59+
pwd
60+
ls -alh
61+
IFS='/' read -r -a parts <<< "$GITHUB_REPOSITORY"
62+
export GITHUB_REPO="${parts[1]}"
63+
export ROOT_DIR="$(pwd)"
64+
export LOCAL_USER_ID="$(id -u)" # Needed for koha-testing-docker
65+
export SYNC_REPO="$ROOT_DIR/kohaclone"
66+
export KOHA_INTRANET_URL="http://127.0.0.1:8081"
67+
export KOHA_MARC_FLAVOUR="marc21"
68+
echo "GITHUB_REPO=$GITHUB_REPO" >> $GITHUB_ENV
69+
echo "ROOT_DIR=$ROOT_DIR" >> $GITHUB_ENV
70+
echo "LOCAL_USER_ID=$LOCAL_USER_ID" >> $GITHUB_ENV
71+
echo "SYNC_REPO=$SYNC_REPO" >> $GITHUB_ENV
72+
echo "KOHA_INTRANET_URL=$KOHA_INTRANET_URL" >> $GITHUB_ENV
73+
echo "KOHA_MARC_FLAVOUR=$KOHA_MARC_FLAVOUR" >> $GITHUB_ENV
74+
echo "RUN_TESTS_AND_EXIT=no" >> $GITHUB_ENV
75+
echo "KOHA_IMAGE=main" >> $GITHUB_ENV
76+
echo "GITHUB REPO: $GITHUB_REPO"
77+
echo "ROOT DIR: $ROOT_DIR"
78+
echo "SYNC_REPO: $SYNC_REPO"
79+
ls -alh $SYNC_REPO
80+
81+
- name: Set up koha-testing-docker
82+
run: |
83+
sudo sysctl -w vm.max_map_count=262144
84+
wget -O docker-compose.yml https://gitlab.com/koha-community/koha-testing-docker/raw/main/docker-compose.yml
85+
mkdir -p env
86+
wget -O env/defaults.env https://gitlab.com/koha-community/koha-testing-docker/raw/main/env/defaults.env
87+
cp env/defaults.env .env
88+
docker compose pull
89+
# - name: Setup Debug Session
90+
# uses: csexton/debugger-action@master
91+
92+
#- name: Run tests
93+
#run: |
94+
#pwd
95+
#ls -alh
96+
#docker compose -f docker-compose.yml -p koha up --detach
97+
#cd ..
98+
#pwd
99+
#ls -alh
100+
#echo "`date`: Installing YAML::Syck, needed for Koha 20.11 and earlier"
101+
#docker exec koha-koha-1 apt-get install -y libyaml-syck-perl libemail-valid-perl libmojo-jwt-perl
102+
#while [ $? -ne 0 ]; do echo "INSTALL YAML::Syck" && docker exec koha-koha-1 apt-get install -y libyaml-syck-perl libemail-valid-perl; done
103+
#echo "SLEEPING 3 MINUTES"
104+
#sleep 60
105+
#echo "1 MINUTE DONE"
106+
#sleep 60
107+
#echo "2 MINUTES DONE"
108+
#sleep 60
109+
#echo "3 MINUTES DONE"
110+
#echo "WAKING UP"
111+
#echo "DOCKER LOGS"
112+
#docker logs koha-koha-1 2>&1
113+
#echo "/DOCKER LOGS"
114+
#docker cp $GITHUB_REPO/. koha-koha-1:/var/lib/koha/kohadev/plugins
115+
#docker exec koha-koha-1 bash -c 'prove /var/lib/koha/kohadev/plugins/t'
116+
117+
- name: Post test cleanup
118+
run: |
119+
docker compose down
120+
docker volume prune -f
121+
docker image prune -f
122+
rm docker-compose.yml
123+
rm -rf env .env
124+
125+
release:
126+
name: Build & Release
127+
runs-on: ubuntu-latest
128+
if: startsWith(github.ref, 'refs/tags/v')
129+
needs: unit_tests
130+
strategy:
131+
fail-fast: false
132+
steps:
133+
- uses: actions/checkout@v1
134+
135+
- name: Parse out and store the GitHub repository name
136+
id: myvars
137+
run: |
138+
IFS='/' read -r -a parts <<< "$GITHUB_REPOSITORY"
139+
GITHUB_REPO="${parts[1]}"
140+
echo ::set-output name=github_repo::$GITHUB_REPO
141+
echo "GITHUB REPO: $GITHUB_REPO"
142+
143+
TAG_VERSION="${GITHUB_REF##*/}"
144+
echo "TAG VERSION: $TAG_VERSION"
145+
TAG_VERSION="${TAG_VERSION:1}"
146+
echo "TAG VERSION 2: $TAG_VERSION"
147+
echo ::set-output name=tag_version::$TAG_VERSION
148+
149+
- name: Get Koha Version Branch Name
150+
id: koha-version-oldstable
151+
uses: "bywatersolutions/github-action-koha-get-version-by-label@master"
152+
with:
153+
version-label: "oldstable"
154+
155+
- name: Print minimum version
156+
run: |
157+
echo "Current oldstable version: ${{ steps.koha-version-oldstable.outputs.version-major-minor }}"
158+
159+
- name: Dump myvars outputs
160+
env:
161+
GITHUB_CONTEXT: ${{ toJson(steps.myvars.outputs) }}
162+
run: echo "$GITHUB_CONTEXT"
163+
164+
- name: Build Koha Plugin kpz artifact
165+
id: kpz
166+
uses: "bywatersolutions/github-action-koha-plugin-create-kpz@master"
167+
with:
168+
release-version: ${{ steps.myvars.outputs.tag_version }}
169+
release-name: ${{ steps.myvars.outputs.github_repo }}
170+
minimum-version: ${{ steps.koha-version-oldstable.outputs.version-major-minor }}
171+
plugin-module: "Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm"
172+
173+
- name: See if kpz was created
174+
run: |
175+
echo "FILENAME: ${{ steps.kpz.outputs.filename }}"
176+
ls -alh
177+
178+
- name: Release
179+
uses: softprops/action-gh-release@v1
180+
if: startsWith(github.ref, 'refs/tags/')
181+
with:
182+
files: |
183+
${{ steps.kpz.outputs.filename }}
184+
CHANGELOG.md
185+
env:
186+
GITHUB_TOKEN: ${{ secrets.PAT }}
187+
188+
keepalive:
189+
name: Keep Alive
190+
runs-on: ubuntu-latest
191+
steps:
192+
- uses: actions/checkout@v3
193+
- name: Check age and push commit if needed
194+
run: |
195+
LAST_COMMIT=$( git --no-pager log -1 --format=%ct )
196+
NOW=$(date +%s)
197+
DIFF=$(($NOW-$LAST_COMMIT))
198+
DAYS=$(($DIFF/86400))
199+
git config --global user.email kyle@bywatersolutions.com
200+
git config --global user.name "Kyle M Hall"
201+
git commit --allow-empty -m "Automated commit from keep alive workflow"
202+
if [ "$DAYS" -gt "50" ]; then git push; fi
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package Koha::Plugin::Com::LMSCloud::LatePaymentClaiming;
2+
3+
# Koha is free software; you can redistribute it and/or modify it
4+
# under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# Koha is distributed in the hope that it will be useful, but
9+
# WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with Koha; if not, see <http://www.gnu.org/licenses>.
15+
16+
use Modern::Perl;
17+
18+
use base qw(Koha::Plugins::Base);
19+
use utf8;
20+
use JSON qw( decode_json );
21+
use Try::Tiny;
22+
use Cwd qw(abs_path);
23+
24+
use C4::Context;
25+
use C4::Auth qw( get_template_and_user );
26+
27+
use Koha::DateUtils qw( dt_from_string output_pref );
28+
use Koha::Patrons;
29+
30+
our $VERSION = "0.1.0";
31+
our $MINIMUM_VERSION = "22.11";
32+
33+
our $metadata = {
34+
name => 'Late Payment Claiming',
35+
author => 'LMSCloud GmbH',
36+
date_authored => '2026-02-15',
37+
date_updated => "2026-01-19",
38+
minimum_version => $MINIMUM_VERSION,
39+
maximum_version => undef,
40+
version => $VERSION,
41+
description => 'Koha plugin to claim outstanding fees with claim messages or and configurable actions',
42+
};
43+
44+
sub new {
45+
my ( $class, $args ) = @_;
46+
47+
$args->{'metadata'} = $metadata;
48+
$args->{'metadata'}->{'class'} = $class;
49+
50+
my $self = $class->SUPER::new($args);
51+
52+
$self->{cgi} = CGI->new();
53+
54+
return $self;
55+
}
56+
57+
sub configure {
58+
my ( $self, $args ) = @_;
59+
my $cgi = $self->{'cgi'};
60+
61+
unless ( $cgi->param('save') ) {
62+
my $template = $self->get_template({ file => 'configure.tt' });
63+
64+
$template->param(
65+
claim_config => $self->retrieve_data('claim_config'),
66+
batch_active => $self->retrieve_data('batch_active'),
67+
last_upgraded => $self->retrieve_data('last_upgraded'),
68+
);
69+
70+
$self->output_html( $template->output() );
71+
exit;
72+
}
73+
$self->store_data(
74+
{
75+
claim_config => scalar $cgi->param('claim_config'),
76+
batch_active => scalar $cgi->param('batch_active'),
77+
}
78+
);
79+
$self->go_home();
80+
exit;
81+
}
82+
83+
## This is the 'install' method. Any database tables or other setup that should
84+
## be done when the plugin if first installed should be executed in this method.
85+
## The installation method should always return true if the installation succeeded
86+
## or false if it failed.
87+
sub install() {
88+
my ( $self, $args ) = @_;
89+
90+
# my $table = $self->get_qualified_table_name('configuration');
91+
#
92+
# return C4::Context->dbh->do( "
93+
# CREATE TABLE IF NOT EXISTS $table (
94+
# `apikey` VARCHAR( 255 ) NOT NULL DEFAULT ''
95+
# ) ENGINE = INNODB;
96+
# " );
97+
98+
my $dt = dt_from_string();
99+
$self->store_data( { last_upgraded => $dt->ymd('-') . ' ' . $dt->hms(':') } );
100+
101+
return 1;
102+
}
103+
104+
## This is the 'upgrade' method. It will be triggered when a newer version of a
105+
## plugin is installed over an existing older version of a plugin
106+
sub upgrade {
107+
my ( $self, $args ) = @_;
108+
109+
my $dt = dt_from_string();
110+
$self->store_data( { last_upgraded => $dt->ymd('-') . ' ' . $dt->hms(':') } );
111+
112+
return 1;
113+
}
114+
115+
## This method will be run just before the plugin files are deleted
116+
## when a plugin is uninstalled. It is good practice to clean up
117+
## after ourselves!
118+
sub uninstall() {
119+
my ( $self, $args ) = @_;
120+
121+
# my $table = $self->get_qualified_table_name('configuration');
122+
#
123+
# return C4::Context->dbh->do("DROP TABLE IF EXISTS $table");
124+
}
125+
126+
sub api_namespace {
127+
my ($self) = @_;
128+
129+
return 'latepaymentclaiming';
130+
}
131+
132+
1;

0 commit comments

Comments
 (0)