Bugzilla – Attachment 192288 Details for
Bug 41746
Add a dev script to insert a new syspref
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41746: Move to Koha::Devel::Sysprefs
165a11a.patch (text/plain), 6.23 KB, created by
Jonathan Druart
on 2026-02-02 11:12:00 UTC
(
hide
)
Description:
Bug 41746: Move to Koha::Devel::Sysprefs
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2026-02-02 11:12:00 UTC
Size:
6.23 KB
patch
obsolete
>From 165a11a90d7805b8a8af52b801630bf121b75be6 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 26 Jan 2026 16:03:27 +0100 >Subject: [PATCH] Bug 41746: Move to Koha::Devel::Sysprefs > >--- > Koha/Devel/Sysprefs.pm | 97 +++++++++++++++++++++++++++++++++ > t/db_dependent/check_sysprefs.t | 68 ++--------------------- > 2 files changed, 103 insertions(+), 62 deletions(-) > create mode 100644 Koha/Devel/Sysprefs.pm > >diff --git a/Koha/Devel/Sysprefs.pm b/Koha/Devel/Sysprefs.pm >new file mode 100644 >index 00000000000..cf550cf1a58 >--- /dev/null >+++ b/Koha/Devel/Sysprefs.pm >@@ -0,0 +1,97 @@ >+package Koha::Devel::Sysprefs; >+ >+use Modern::Perl; >+use File::Slurp qw(read_file); >+ >+=head1 NAME >+ >+Koha::Devel::Sysprefs >+ >+=head1 DESCRIPTION >+ >+Handle system preferences operations for developers. >+ >+=cut >+ >+=head1 API >+ >+=cut >+ >+=head2 new >+ >+my $syspref_handler = Koha::Devel::Sysprefs->new(); >+ >+Constructor >+ >+=cut >+ >+sub new { >+ my ( $class, $args ) = @_; >+ $args ||= {}; >+ >+ unless ( $args->{filepath} ) { >+ $args->{filepath} = sprintf "%s/installer/data/mysql/mandatory/sysprefs.sql", >+ C4::Context->config('intranetdir'); >+ } >+ my $self = bless $args, $class; >+ return $self; >+} >+ >+=head2 get_sysprefs_from_file >+ >+my @sysprefs = $syspref_handler->get_sysprefs_from_file(); >+ >+Return an array of sysprefs from the SQL file used to populate the system preferences DB table. >+ >+=cut >+ >+sub get_sysprefs_from_file { >+ my ($self) = @_; >+ my @sysprefs; >+ my @lines = read_file( $self->{filepath} ) or die "Can't open $self->{filepath}: $!"; >+ for my $line (@lines) { >+ chomp $line; >+ next if $line =~ /^INSERT INTO /; # first line >+ next if $line =~ /^;$/; # last line >+ next if $line =~ /^--/; # Comment line >+ if ( >+ $line =~ m/ >+ '(?<variable>[^'\\]*(?:\\.[^'\\]*)*)',\s* >+ '(?<value>[^'\\]*(?:\\.[^'\\]*)*)',\s* >+ (?<options>NULL|'(?<options_content>[^'\\]*(?:\\.[^'\\]*)*)'),\s* >+ (?<explanation>NULL|'(?<explanation_content>[^'\\]*(?:\\.[^'\\]*)*)'),\s* >+ (?<type>NULL|'(?<type_content>[^'\\]*(?:\\.[^'\\]*)*)') >+ /xms >+ ) >+ { >+ my $variable = $+{variable}; >+ my $value = $+{value}; >+ my $options = $+{options_content}; >+ my $explanation = $+{explanation_content}; >+ my $type = $+{type_content}; >+ >+ if ($options) { >+ $options =~ s/\\'/'/g; >+ $options =~ s/\\\\/\\/g; >+ } >+ if ($explanation) { >+ $explanation =~ s/\\'/'/g; >+ $explanation =~ s/\\n/\n/g; >+ } >+ >+ # FIXME Explode if already exists? >+ push @sysprefs, { >+ variable => $variable, >+ value => $value, >+ options => $options, >+ explanation => $explanation, >+ type => $type, >+ }; >+ } else { >+ die "$line does not match"; >+ } >+ } >+ return @sysprefs; >+} >+ >+1; >diff --git a/t/db_dependent/check_sysprefs.t b/t/db_dependent/check_sysprefs.t >index afe4eccc504..0d3a82c4bc9 100755 >--- a/t/db_dependent/check_sysprefs.t >+++ b/t/db_dependent/check_sysprefs.t >@@ -19,20 +19,19 @@ > > use Modern::Perl; > >-use File::Slurp qw(read_file); >-use C4::Context; > use Array::Utils qw(array_minus); > > use Test::NoWarnings; > use Test::More tests => 3; > >+use C4::Context; >+ >+use Koha::Devel::Sysprefs; >+ > our $dbh = C4::Context->dbh; >-my $intranetdir = C4::Context->config('intranetdir'); >-my $root_dir = $intranetdir . '/installer/data/mysql/mandatory'; >-my $syspref_filepath = "$root_dir/sysprefs.sql"; >+my $intranetdir = C4::Context->config('intranetdir'); > >-my @lines = read_file($syspref_filepath) or die "Can't open $syspref_filepath: $!"; >-my @sysprefs_in_file = get_sysprefs_from_file(@lines); >+my @sysprefs_in_file = Koha::Devel::Sysprefs->new->get_sysprefs_from_file(); > > subtest 'Compare database with sysprefs.sql file' => sub { > ok( scalar(@sysprefs_in_file), "Found sysprefs" ); >@@ -70,61 +69,6 @@ subtest 'Compare sysprefs.sql with YAML files' => sub { > } > }; > >-# Get sysprefs from SQL file populating sysprefs table with INSERT statement. >-# >-# Example: >-# INSERT INTO `systempreferences` (variable,value,explanation,options,type) >-# VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services', >-# 'US|CA|DE|FR|JP|UK','Choice') >-# >-sub get_sysprefs_from_file { >- my @lines = @_; >- my @sysprefs; >- for my $line (@lines) { >- chomp $line; >- next if $line =~ /^INSERT INTO /; # first line >- next if $line =~ /^;$/; # last line >- next if $line =~ /^--/; # Comment line >- if ( >- $line =~ m/ >- '(?<variable>[^'\\]*(?:\\.[^'\\]*)*)',\s* >- '(?<value>[^'\\]*(?:\\.[^'\\]*)*)',\s* >- (?<options>NULL|'(?<options_content>[^'\\]*(?:\\.[^'\\]*)*)'),\s* >- (?<explanation>NULL|'(?<explanation_content>[^'\\]*(?:\\.[^'\\]*)*)'),\s* >- (?<type>NULL|'(?<type_content>[^'\\]*(?:\\.[^'\\]*)*)') >- /xms >- ) >- { >- my $variable = $+{variable}; >- my $value = $+{value}; >- my $options = $+{options_content}; >- my $explanation = $+{explanation_content}; >- my $type = $+{type_content}; >- >- if ($options) { >- $options =~ s/\\'/'/g; >- $options =~ s/\\\\/\\/g; >- } >- if ($explanation) { >- $explanation =~ s/\\'/'/g; >- $explanation =~ s/\\n/\n/g; >- } >- >- # FIXME Explode if already exists? >- push @sysprefs, { >- variable => $variable, >- value => $value, >- options => $options, >- explanation => $explanation, >- type => $type, >- }; >- } else { >- die "$line does not match"; >- } >- } >- return @sysprefs; >-} >- > # Get system preferences from YAML files > sub get_syspref_from_yaml { > my @prefs; >-- >2.43.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41746
: 192288 |
192289
|
192290
|
192291
|
192292