User:Victor Grousset - tuxayo/Development/Tools and operations
Jump to navigation
Jump to search
Run automated tests
One or just a few
prove t/db_dependent/Search.t
prove t/db_dependent/Search.t t/db_dependent/selenium/administration_tasks.t
# Cypress tests
time cypress run --config video=false --spec t/cypress/integration/ERM/Dialog_spec.ts
time cypress run --config video=false --spec "t/cypress/integration/ERM/Dialog_spec.ts,t/cypress/integration/ERM/Agreements_spec.ts"
All tests or all Cypress or all Selenium tests
Continuous_Integration#Run_automated_tests
Lighter restart in KTD (koha-testing-docker)
koha-plack --restart kohadev
Interactive Perl shell - REPL (Read–Eval–Print Loop) with Devel::REPL
Install and run
sudo apt install libdevel-repl-perl
re.pl
Usage examples
Connect to the database
my $dbh = DBI->connect('dbi:mysql:;host=db;port=3306', 'koha_kohadev', 'password');
Test number formatting
use Number::Format;
my $format = new Number::Format(-decimal_point => '.');
# $Number_Format1 = Number::Format=HASH(0x39cbf00);
$format->unformat_number("12345,89");
# 12345.89
# Caveat: don't use print if you want to see the value, otherwise you will get some kind of return value of print
$ print $format->unformat_number("12345,89");
# 1
Trigger the installer
echo "DROP DATABASE koha_kohadev; CREATE DATABASE koha_kohadev;" | koha-mysql kohadev ; restart_all
Install translations
update dababase
~/src/installer/data/mysql/updatedatabase.pl
Use yarn in KTD
# example with yarn install
sudo yarn install --modules-folder /kohadevbox/node_modules
Loop to create a lot of data in Perl
$ perl -MKoha::Database -e '
my $schema = Koha::Database->schema;
my $period = $schema->resultset("Aqbudgetperiod")->create({
budget_period_startdate => "2000-01-01",
budget_period_enddate => "2999-12-31"
});
$schema->resultset("Aqbudget")->create({
budget_owner_id => 1,
budget_period_id => $period->id
}) for (1..1000)
'
Restore backup in KTD (koha-testing-docker)
It's not clean, there are errors when running koha-remove so it's an incomplete removal. That's the best I've found for now.
docker exec -it koha-koha-1 bash
service koha-common stop
service apache2 stop
koha-remove kohadev
cd koha
koha-restore kohadev-2024-03-19.sql.gz kohadev-2024-03-19.tar.gz
restart_all
Reset DB with dump
If you don't have a devbox. Using BibLibre's tools (https://git.biblibre.com/biblibre/tools)
# memcached is flushed because if you switched to another version of the code, the old version will be in cache and the updatedatabase won't run
echo "flush_all" | nc -q 2 localhost 11211 && \
~/tools/sysop/db_replace.sh --confirm --dump ~/dumps/koha-sample.sql.gz && \
~/src/installer/data/mysql/updatedatabase.pl && \
~/tools/zebra/rebuild_full.sh -b -a
Use Elasticsearch
Switch the SearchEngine syspref
Index data
misc/search_tools/rebuild_elasticsearch.pl -v -d
Maybe also
# as root
koha-elasticsearch -v -p 5 --commit 1000 --rebuild kohadev
Test SIP with emulator
https://wiki.koha-community.org/wiki/Koha_SIP2_server_setup#Example
Run an old Koha
# Can go at least to 19.11
sudo apt install libyaml-syck-perl libtext-unaccent-perl libemail-valid-perl libcatmandu-marc-perl libcatmandu-store-elasticsearch-perl libextutils-pkgconfig-perl libwww-curl-perl libcurl4-gnutls-dev
sudo cpanm Search::Elasticsearch::Client::5_0::Direct
# you might need
sudo cpanm -i JSON::Validator::OpenAPI --force
# TODO try
sudo cpanm -i JSON::Validator
# you might need
sudo apt install libdbd-mock-perl
If the container has a too old Debian
# Somehow it needs elasticsearch, here opensearch works fine
KOHA_IMAGE=22.05-stretch bin/ktd --os1 up
# It works with the master branch of KTD repo. After trying,
# older branches don't help to simplify the operation.
# and **while** it's starting go into the container and edit the repositories
vim /etc/apt/sources.list
# replace "httpredir" with "archive" and remove the 2nd line.
# In the end the content should be
```
deb http://archive.debian.org/debian stretch main
```
# otherwise it will 404 when trying to install the cpanoutdated package and crash
Apply large patches without adding a git remote
wget -q -O- http://git.biblibre.com/biblibre/kohac/commit/457524cef965faf96a9516c17e9e0a8bbdec19aa.patch | git am -3 -
Generate test data
Many patrons
base:
SELECT surname, firstname, branchcode, categorycode
FROM
(
SELECT surname
FROM borrowers
ORDER BY rand()
) a,
(
SELECT firstname
FROM borrowers
ORDER BY rand() ) b,
(
SELECT branchcode
FROM borrowers
ORDER BY rand() ) c,
(
SELECT categorycode
FROM borrowers
ORDER BY rand() ) d
LIMIT 50000
Send emails
Setup email using your own SMTP server.
edit koha-conf.xml to add the following inside the <config> section
<smtp_server>
<host>yourSMTP.example.org</host>
<port>587</port>
<timeout>5</timeout>
<ssl_mode>STARTTLS</ssl_mode>
<user_name>youraddress@example.org</user_name>
<password>yourpassword</password>
<debug>1</debug>
</smtp_server>
A set KohaAdminEmailAddress to your address.
Test the REST API
$.ajax({
url: '/api/v1/biblios/55/items/117',
method: 'PUT',
data: JSON.stringify({
"collection_code": "COLLECTION1",
"external_id": "123test",
}),
contentType: 'application/json',
success: function(result) {
console.log('altered')
},
});
Switch Starman to deployment/production environment
To see the production error pages for example.
sudo vim /usr/sbin/koha-plack
See this section
if [ "$DEV_INSTALL" = "1" ]; then
# Maybe we should switch off debug_mode if DEV_INSTALL is not set?
environment="development"
fi
Replace "development" by "deployment"