bugzilla-4intranet/extensions/custis/code/install-update_db.pl

46 lines
1.2 KiB
Perl
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/perl
# ./checksetup'Ï×ÙÅ ÏÂÎÏ×ÌÅÎÉÑ ÂÁÚÙ
use strict;
use utf8;
use Encode;
use URI::Escape;
sub sure_utf8
{
my ($s) = @_;
$s = uri_unescape($s);
Encode::_utf8_on($s);
my $v = utf8::valid($s);
Encode::_utf8_off($s);
Encode::from_to($s, 'cp1251', 'utf8') unless $v;
$s = uri_escape($s);
return $s;
}
# ðÅÒÅËÏÄÉÒÏ×ËÁ ÐÁÒÁÍÅÔÒÏ× ÓÏÈÒÁΣÎÎÙÈ ÐÏÉÓËÏ× ÉÚ CP-1251 × UTF-8
print "Making sure saved queries are in UTF-8...\n";
my $dbh = Bugzilla->dbh;
my $nq = $dbh->selectall_arrayref("SELECT * FROM namedqueries WHERE query LIKE '%\\%%'", {Slice=>{}});
if ($nq)
{
my $q;
foreach (@$nq)
{
$q = $_->{query};
$q =~ s/(\%[0-9A-F]{2})+/sure_utf8($&)/iegso;
$dbh->do("UPDATE namedqueries SET query=? WHERE id=?", undef, $q, $_->{id}) if $q ne $_->{query};
}
}
# äÏÂÁ×ÌÑÅÍ ËÏÌÏÎËÕ wiki_url × ÐÒÏÄÕËÔÙ É ËÏÍÐÏÎÅÎÔÙ
if (!$dbh->bz_column_info('products', 'buglist'))
{
$dbh->bz_add_column('products', 'wiki_url', {TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"});
}
if (!$dbh->bz_column_info('components', 'buglist'))
{
$dbh->bz_add_column('components', 'wiki_url', {TYPE => 'varchar(255)', NOTNULL => 1, DEFAULT => "''"});
}