From 567bc422f215a8f9797925e8b41b732be10373e7 Mon Sep 17 00:00:00 2001 From: Blou Date: Fri, 27 Oct 2023 17:23:06 -0400 Subject: [PATCH] Bug 35250: modify scripts calling C4::Context::set_preference All the scripts using the call C4::Context->set_preference are edited to now use Koha::Config::SysPrefs->set_preference instead of C4::Context->set_preference() One call to delete_preference moved as well --- C4/UsageStats.pm | 4 ++-- Koha/SearchEngine/Elasticsearch/Indexer.pm | 2 +- admin/preferences.pl | 2 +- admin/share_content.pl | 10 +++++----- admin/systempreferences.pl | 7 ++++--- admin/usage_statistics.pl | 14 +++++++------- installer/data/mysql/updatedatabase.pl | 2 +- misc/admin/koha-preferences | 2 +- misc/cronjobs/share_usage_with_koha_community.pl | 2 +- svc/config/systempreferences | 4 ++-- tools/automatic_item_modification_by_age.pl | 2 +- 11 files changed, 26 insertions(+), 25 deletions(-) diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm index 56877dd8af..8b10039918 100644 --- a/C4/UsageStats.pm +++ b/C4/UsageStats.pm @@ -115,10 +115,10 @@ sub ReportToCommunity { ); my $content = decode_json( $res->decoded_content ); if ( $content->{koha_id} ) { - C4::Context->set_preference( 'UsageStatsID', $content->{koha_id} ); + Koha::Config::SysPrefs->set_preference( 'UsageStatsID', $content->{koha_id} ); } if ( $content->{id} ) { - C4::Context->set_preference( 'UsageStatsPublicID', $content->{id} ); + Koha::Config::SysPrefs->set_preference( 'UsageStatsPublicID', $content->{id} ); } } diff --git a/Koha/SearchEngine/Elasticsearch/Indexer.pm b/Koha/SearchEngine/Elasticsearch/Indexer.pm index 6101a3a372..e586152e87 100644 --- a/Koha/SearchEngine/Elasticsearch/Indexer.pm +++ b/Koha/SearchEngine/Elasticsearch/Indexer.pm @@ -245,7 +245,7 @@ sub index_status { ) { Koha::Exception->throw("Invalid index status: $status"); } - C4::Context->set_preference($key, $status); + Koha::Config::SysPrefs->set_preference($key, $status); return $status; } else { diff --git a/admin/preferences.pl b/admin/preferences.pl index 108aaf41d1..eabd223540 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -367,7 +367,7 @@ if ( $op eq 'save' ) { my $value = join( ',', $input->param( $param ) ); - C4::Context->set_preference( $pref, $value ); + Koha::Config::SysPrefs->set_preference( $pref, $value ); } print $input->redirect( '/cgi-bin/koha/admin/preferences.pl?tab=' . $tab ); diff --git a/admin/share_content.pl b/admin/share_content.pl index 89dd4e0cdb..27fa3951eb 100755 --- a/admin/share_content.pl +++ b/admin/share_content.pl @@ -50,17 +50,17 @@ if ( $op eq 'save' ) { my $auto_share = $query->param('autosharewithmana') || q{}; my $mana = $query->param('mana'); - C4::Context->set_preference('Mana', $mana); + Koha::Config::SysPrefs->set_preference('Mana', $mana); if ( $auto_share ne '' ) { - C4::Context->set_preference('AutoShareWithMana', 'subscription'); + Koha::Config::SysPrefs->set_preference('AutoShareWithMana', 'subscription'); } else { - C4::Context->set_preference('AutoShareWithMana', ''); + Koha::Config::SysPrefs->set_preference('AutoShareWithMana', ''); } } if ( $op eq 'reset' ) { - C4::Context->set_preference('ManaToken', ''); + Koha::Config::SysPrefs->set_preference('ManaToken', ''); } if ( $op eq 'send' && not $bad_url ) { @@ -78,7 +78,7 @@ if ( $op eq 'send' && not $bad_url ) { $template->param( result => $result ); if ( $result->{code} eq '201' && $result->{token} ) { - C4::Context->set_preference('ManaToken', $result->{token}); + Koha::Config::SysPrefs->set_preference('ManaToken', $result->{token}); } } diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl index d2d1369223..8b02c267ea 100755 --- a/admin/systempreferences.pl +++ b/admin/systempreferences.pl @@ -51,6 +51,7 @@ use C4::Languages qw( getTranslatedLanguages ); use C4::ClassSource qw( GetClassSources GetClassSource ); use C4::Output qw( output_html_with_http_headers output_and_exit_if_error ); use YAML::XS; +use Koha::Config::Sysprefs; my %tabsysprefs; #we do no longer need to keep track of a tab per pref (yaml) @@ -274,7 +275,7 @@ if ( $op eq 'update_and_reedit' ) { } } my $variable = $input->param('variable'); - C4::Context->set_preference($variable, $value); + Koha::Config::SysPrefs->set_preference($variable, $value); } ################## ADD_FORM ################################## @@ -334,7 +335,7 @@ if ( $op eq 'add_form' ) { $value = encode_base64($value); } - C4::Context->set_preference( $variable, $value, $expl, $type, $options ); + Koha::Config::SysPrefs->set_preference( $variable, $value, $expl, $type, $options ); print $input->redirect("/cgi-bin/koha/admin/systempreferences.pl?tab="); exit; ################## DELETE_CONFIRM ################################## @@ -351,7 +352,7 @@ if ( $op eq 'add_form' ) { # called by delete_confirm, used to effectively confirm deletion of data in DB } elsif ( $op eq 'delete_confirmed' ) { output_and_exit_if_error($input, $cookie, $template, { check => 'csrf_token' }); - C4::Context->delete_preference($searchfield); + Koha::Config::SysPrefs->delete_preference($searchfield); # END $OP eq DELETE_CONFIRMED ################## DEFAULT ################################## } else { # DEFAULT diff --git a/admin/usage_statistics.pl b/admin/usage_statistics.pl index 582e92aa1e..25ed5c4c60 100755 --- a/admin/usage_statistics.pl +++ b/admin/usage_statistics.pl @@ -43,13 +43,13 @@ if ( $op eq 'update' ) { my $UsageStatsLibraryUrl = $query->param('UsageStatsLibraryUrl'); my $UsageStatsLibrariesInfo = $query->param('UsageStatsLibrariesInfo'); my $UsageStatsGeolocation = $query->param('UsageStatsGeolocation'); - C4::Context->set_preference('UsageStats', $UsageStats); - C4::Context->set_preference('UsageStatsCountry', $UsageStatsCountry); - C4::Context->set_preference('UsageStatsLibraryName', $UsageStatsLibraryName); - C4::Context->set_preference('UsageStatsLibraryType', $UsageStatsLibraryType); - C4::Context->set_preference('UsageStatsLibraryUrl', $UsageStatsLibraryUrl); - C4::Context->set_preference('UsageStatsLibrariesInfo', $UsageStatsLibrariesInfo); - C4::Context->set_preference('UsageStatsGeolocation', $UsageStatsGeolocation); + Koha::Config::SysPrefs->set_preference('UsageStats', $UsageStats); + Koha::Config::SysPrefs->set_preference('UsageStatsCountry', $UsageStatsCountry); + Koha::Config::SysPrefs->set_preference('UsageStatsLibraryName', $UsageStatsLibraryName); + Koha::Config::SysPrefs->set_preference('UsageStatsLibraryType', $UsageStatsLibraryType); + Koha::Config::SysPrefs->set_preference('UsageStatsLibraryUrl', $UsageStatsLibraryUrl); + Koha::Config::SysPrefs->set_preference('UsageStatsLibrariesInfo', $UsageStatsLibrariesInfo); + Koha::Config::SysPrefs->set_preference('UsageStatsGeolocation', $UsageStatsGeolocation); my $libraries = Koha::Libraries->search; while ( my $library = $libraries->next ) { if ( my $latlng = $query->param('geolocation_' . $library->branchcode) ) { diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index b8f2babbdd..fabd50619e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -9651,7 +9651,7 @@ if ( CheckVersion($DBversion) ) { WHERE variable = 'UsageStatsLibraryType' "); if ( C4::Context->preference("UsageStatsLibraryType") eq "university" ) { - C4::Context->set_preference("UsageStatsLibraryType", "academic") + Koha::Config::SysPrefs->set_preference("UsageStatsLibraryType", "academic") } print "Upgrade to $DBversion done (Bug 13436: Add more options to UsageStatsLibraryType)\n"; SetVersion ($DBversion); diff --git a/misc/admin/koha-preferences b/misc/admin/koha-preferences index 5c07c2b8a7..f9c66a7556 100755 --- a/misc/admin/koha-preferences +++ b/misc/admin/koha-preferences @@ -64,7 +64,7 @@ sub _set_preference { $value = 0; } - C4::Context->set_preference( $preference->{variable}, $value ); + Koha::Config::SysPrefs->set_preference( $preference->{variable}, $value ); } sub GetPreferences { diff --git a/misc/cronjobs/share_usage_with_koha_community.pl b/misc/cronjobs/share_usage_with_koha_community.pl index 671bbe1a1a..28879fc772 100755 --- a/misc/cronjobs/share_usage_with_koha_community.pl +++ b/misc/cronjobs/share_usage_with_koha_community.pl @@ -46,7 +46,7 @@ if ($need_update) { say "Data need to be updated" if $verbose; my $report = C4::UsageStats::BuildReport(); C4::UsageStats::ReportToCommunity($report); - C4::Context->set_preference( 'UsageStatsLastUpdateTime', + Koha::Config::SysPrefs->set_preference( 'UsageStatsLastUpdateTime', strftime( "%s", localtime ) ); } elsif ($verbose) { diff --git a/svc/config/systempreferences b/svc/config/systempreferences index fd09218b6b..e5ddca1de3 100755 --- a/svc/config/systempreferences +++ b/svc/config/systempreferences @@ -72,7 +72,7 @@ sub set_preference { ); my $value = join( ',', $query->param( 'value' ) ); - C4::Context->set_preference( $preference, $value ); + Koha::Config::SysPrefs->set_preference( $preference, $value ); C4::Service->return_success( $response ); } @@ -143,7 +143,7 @@ sub set_preferences { my $value = join( ',', $query->multi_param( $param ) ); - C4::Context->set_preference( $pref, $value ); + Koha::Config::SysPrefs->set_preference( $pref, $value ); } C4::Service->return_success( $response ); diff --git a/tools/automatic_item_modification_by_age.pl b/tools/automatic_item_modification_by_age.pl index a3138091d3..cd432b28ff 100755 --- a/tools/automatic_item_modification_by_age.pl +++ b/tools/automatic_item_modification_by_age.pl @@ -93,7 +93,7 @@ if ( $op eq 'update' ) { push @rules, $rule; } my $syspref_content = to_json( \@rules ); - C4::Context->set_preference($syspref_name, $syspref_content); + Koha::Config::SysPrefs->set_preference($syspref_name, $syspref_content); $op = 'show'; } -- 2.34.1