| 1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
| 2 |
# Last-Modified: <Fri Aug 8 13:56:31 2008> |
# Last-Modified: <Sun Aug 10 10:31:57 2008> |
| 3 |
|
|
| 4 |
use strict; |
use strict; |
| 5 |
use warnings; |
use warnings; |
| 17 |
use Debbugs::Status qw{read_bug get_bug_status bug_presence}; |
use Debbugs::Status qw{read_bug get_bug_status bug_presence}; |
| 18 |
use Debbugs::Packages qw{binarytosource}; |
use Debbugs::Packages qw{binarytosource}; |
| 19 |
use Debbugs::Config qw{:globals}; |
use Debbugs::Config qw{:globals}; |
| 20 |
use Debbugs::User qw{read_usertags}; |
use Debbugs::User; |
| 21 |
|
#use Debbugs::User qw{read_usertags}; |
| 22 |
|
|
| 23 |
$YAML::Syck::ImplicitTyping = 1; |
$YAML::Syck::ImplicitTyping = 1; |
| 24 |
|
|
| 102 |
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname"); |
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname"); |
| 103 |
# We want to commit the transaction as a hole at the end |
# We want to commit the transaction as a hole at the end |
| 104 |
$dbh->{AutoCommit} = 0; |
$dbh->{AutoCommit} = 0; |
| 105 |
|
my $timing = 1; |
| 106 |
|
my $t; |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
$t = time(); |
| 110 |
# Free usertags table |
# Free usertags table |
| 111 |
$dbh->prepare("DELETE FROM bug_user_tags")->execute() or die |
$dbh->prepare("DELETE FROM bug_user_tags")->execute() or die |
| 112 |
"Couldn't empty bug_user_tags: $!"; |
"Couldn't empty bug_user_tags: $!"; |
| 113 |
|
print "Deleting usertags: ",(time() - $t),"s\n" if $timing; |
| 114 |
|
$t = time(); |
| 115 |
# read and insert user tags |
# read and insert user tags |
| 116 |
my @users = get_bugs_users(); |
my @users = get_bugs_users(); |
| 117 |
foreach my $user (@users) { |
foreach my $user (@users) { |
| 118 |
my %tags = (); |
#read_usertags(\%tags, $user); |
| 119 |
read_usertags(\%tags, $user); |
my $u = Debbugs::User->new($user); |
| 120 |
|
my %tags = %{$u->{tags}}; |
| 121 |
$user = $dbh->quote($user); |
$user = $dbh->quote($user); |
| 122 |
foreach my $tag (keys %tags) { |
foreach my $tag (keys %tags) { |
| 123 |
my $qtag = $dbh->quote($tag); |
my $qtag = $dbh->quote($tag); |
| 124 |
map { $dbh->prepare("INSERT INTO bug_user_tags VALUES ($user, $qtag, $_)")->execute() or die $! } @{$tags{$tag}}; |
map { $dbh->prepare("INSERT INTO bug_user_tags VALUES ($user, $qtag, $_)")->execute() or die $! } @{$tags{$tag}}; |
| 125 |
} |
} |
| 126 |
} |
} |
| 127 |
|
print "Inserting usertags: ",(time() - $t),"s\n" if $timing; |
| 128 |
####### XXX EXPERIMENT |
$t = time(); |
|
####### XXX What to do with bugs both archived and unarchived |
|
|
#my $max_last_modified = get_db_max_last_modified($dbh); |
|
|
#my @modified_bugs; |
|
|
#if($max_last_modified) { |
|
|
# @modified_bugs = @{get_modified_bugs($max_last_modified)}; |
|
|
# Delete modified bugs |
|
|
# for my $bug (@modified_bugs) { |
|
|
# map { |
|
|
# $dbh->prepare("DELETE FROM $_ WHERE id = $bug")->execute() |
|
|
# } qw{bugs bug_merged_with bug_found_in bug_fixed_in}; |
|
|
# } |
|
|
#} else { |
|
|
# @modified_bugs = get_bugs(archive => 'both'); |
|
|
#} |
|
|
#@modified_bugs = without_duplicates(@modified_bugs); |
|
| 129 |
my @modified_bugs; |
my @modified_bugs; |
| 130 |
if($src_config{archived}) { |
if($src_config{archived}) { |
| 131 |
@modified_bugs = get_bugs(archive => 1); |
@modified_bugs = get_bugs(archive => 1); |
| 133 |
@modified_bugs = get_bugs(); |
@modified_bugs = get_bugs(); |
| 134 |
} |
} |
| 135 |
|
|
| 136 |
print scalar(@modified_bugs), " modified bugs\n"; |
print "Fetching list of ",scalar(@modified_bugs), " bugs to insert: ",(time() - $t),"s\n" if $timing; |
| 137 |
####### XXX EXPERIMENT |
$t = time(); |
| 138 |
|
|
| 139 |
# Get the bugs we want to import |
# Get the bugs we want to import |
| 140 |
# my @bugs = $src_config{archived} ? get_bugs(archive => 1) : get_bugs(); |
# my @bugs = $src_config{archived} ? get_bugs(archive => 1) : get_bugs(); |
| 141 |
|
|
| 142 |
# Delete all bugs we are going to import |
# Delete all bugs we are going to import |
| 143 |
for my $bug (@modified_bugs) { |
my $modbugs = join(", ", @modified_bugs); |
| 144 |
map { |
for my $table qw{bugs_archived bugs bug_merged_with bug_found_in bug_fixed_in bug_tags} { |
| 145 |
$dbh->prepare("DELETE FROM $_ WHERE id = $bug")->execute() or die $! |
$dbh->prepare("DELETE FROM $table WHERE id IN ($modbugs)")->execute() or die $! |
|
} qw{bugs_archived bugs_unarchived bug_merged_with bug_found_in bug_fixed_in bug_tags}; |
|
| 146 |
} |
} |
| 147 |
print "Bugs deleted\n"; |
print "Deleting bugs: ",(time() - $t),"s\n" if $timing; |
| 148 |
|
$t = time(); |
| 149 |
|
|
| 150 |
# Used to chache binary to source mappings |
# Used to chache binary to source mappings |
| 151 |
my %binarytosource = (); |
my %binarytosource = (); |
|
|
|
| 152 |
# XXX What if a bug is in location 'db' (which currently doesn't exist) |
# XXX What if a bug is in location 'db' (which currently doesn't exist) |
| 153 |
my $location = $src_config{archived} ? 'archive' : 'db_h'; |
my $location = $src_config{archived} ? 'archive' : 'db_h'; |
| 154 |
my $table = $src_config{archived} ? 'bugs_archived' : 'bugs_unarchived'; |
my $table = $src_config{archived} ? 'bugs_archived' : 'bugs'; |
| 155 |
# Read all bugs |
# Read all bugs |
| 156 |
foreach my $bug_nr (@modified_bugs) { |
foreach my $bug_nr (@modified_bugs) { |
| 157 |
# Fetch bug using Debbugs |
# Fetch bug using Debbugs |
| 184 |
my $source = $binarytosource{$bug{package}}; |
my $source = $binarytosource{$bug{package}}; |
| 185 |
|
|
| 186 |
if(not defined $source) { |
if(not defined $source) { |
| 187 |
$source = 'NULL'; |
# if source is not defined, then we $bug{package} is likely to |
| 188 |
|
# be a source package name (or the source package has the same |
| 189 |
|
# name as the binary package). See #480818 for ex. |
| 190 |
|
$source = $dbh->quote($bug{package}); |
| 191 |
} else { |
} else { |
| 192 |
$source = $dbh->quote($source); |
$source = $dbh->quote($source); |
| 193 |
} |
} |
| 221 |
$present_in_unstable = 'TRUE'; |
$present_in_unstable = 'TRUE'; |
| 222 |
} |
} |
| 223 |
|
|
|
|
|
| 224 |
# Insert data into bugs table |
# Insert data into bugs table |
| 225 |
my $query = "INSERT INTO $table VALUES ($bug_nr, '$bug{package}', $source, $bug{date}, \ |
my $query = "INSERT INTO $table VALUES ($bug_nr, '$bug{package}', $source, $bug{date}, \ |
| 226 |
E$bug{pending}, '$bug{severity}', E$bug{originator}, E$bug{owner}, \ |
E$bug{pending}, '$bug{severity}', E$bug{originator}, E$bug{owner}, \ |
| 249 |
} |
} |
| 250 |
} |
} |
| 251 |
|
|
| 252 |
|
print "Inserting bugs: ",(time() - $t),"s\n" if $timing; |
| 253 |
|
$t = time(); |
| 254 |
$dbh->commit(); |
$dbh->commit(); |
| 255 |
|
print "Committing bugs: ",(time() - $t),"s\n" if $timing; |
| 256 |
} |
} |
| 257 |
|
|
| 258 |
main(); |
main(); |