From ab1f86dbb8c3e9bd3f6105041fa1b23e0d2759fc Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Sat, 29 Mar 2014 18:23:19 -0400 Subject: [PATCH] Bug 11393 - Untested patch for doing the human intervention part. This is intentionally going to be obsoleted, but attached to the bug so it could be referenced, if needed. File::Copy is already a dependency, and File::Find is a core module as far as I can tell. --- installer/data/mysql/updatedatabase.pl | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 062ecc1..85e053f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -32,6 +32,8 @@ use warnings; # CPAN modules use DBI; +use File::Find; +use File::Copy; use Getopt::Long; # Koha modules use C4::Context; @@ -8083,6 +8085,92 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.15.00.XXX"; +if ( CheckVersion($DBversion) ) { + my $sth = $dbh->prepare( q{ SELECT value FROM systempreferences + WHERE variable='language' } ); + $sth->execute(); + my $StaffLanguage = $sth->fetchrow; + $sth = $dbh->prepare( q{ SELECT value FROM systempreferences + WHERE variable='opaclanguages' } ); + $sth->execute(); + my $OpacLanguage = $sth->fetchrow; + + my $action = 'Nothing'; + + if ( $StaffLanguage =~ /th-THA/ ) { + $StaffLanguage = s/th-THA//g; + if ( $StaffLanguage =~ /th-TH/ ) { + $StaffLanguage = s/,,/,/g; + $action = 'Remove'; + } + else { + $StaffLanguage = s/,,/,th-TH,/g; + $action = 'Replace'; + } + $sth = $dbh->prepare( q{ UPDATE systempreferences + SET value=? + WHERE variable='language' } ); + $sth->execute($StaffLanguage); + } + + if ( $OpacLanguage =~ /th-THA/ ) { + $OpacLanguage = s/th-THA//g; + if ( $OpacLanguage =~ /th-TH/ ) { + $OpacLanguage = s/,,/,/g; + $action = 'Remove'; + } + else { + $OpacLanguage = s/,,/,th-TH,/g; + $action = 'Replace'; + } + $sth = $dbh->prepare( q{ UPDATE systempreferences + SET value=? + WHERE variable='opaclanguages' } ); + $sth->execute($OpacLanguage); + } + + my %DirList; + my @StaffLang; + my @OpacLang; + + find ( sub { $DirList{$File::Find::dir} = 1; }, + C4::Context->config('opachtdocs') ); + find ( sub { $DirList{$File::Find::dir} = 1; }, + C4::Context->config('intrahtdocs') ); + foreach my $DirName (sort keys %DirList) { + if ($DirName =~ /th-TH$/ || $DirName =~ /th-THA$/ ) { + if ($DirName =~ /intranet/) { + push @StaffLang, $DirName; + } + else { + push @OpacLang, $DirName; + } + } + } + + if ( $action eq 'Remove' ) { + foreach my $DirName (@StaffLang @OpacLang) { + remove_tree($DirName); + } + } + elsif ( $action eq 'Replace' ) { + foreach my $DirName (@StaffLang @OpacLang) { + my $destdir = $DirName; + $destdir = s/th-THA/th-TH/g; + move($DirName, $destdir); + } + } + + if ( $action eq 'Nothing' ) { + print "Upgrade to $DBversion done (Not applicable)\n"; + } + else { + print "Upgrade to $DBversion done (Bug 11393: Language menu not show up as name for Thai (th-THA was shown) )\n"; + } + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) -- 1.7.9.5