summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Install/DB.pm
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@gmail.com>2012-01-24 23:21:43 +0100
committerFrédéric Buclin <LpSolit@gmail.com>2012-01-24 23:21:43 +0100
commite8aa4f8c87f0bd8c54e03ce551ad76362780a9a3 (patch)
tree7544067fb166a7dbf38f908947ea8859a3dba153 /Bugzilla/Install/DB.pm
parente2a95ffbe2beb52bf3e69102b4646ddf5793d8df (diff)
downloadbugzilla-e8aa4f8c87f0bd8c54e03ce551ad76362780a9a3.tar.gz
bugzilla-e8aa4f8c87f0bd8c54e03ce551ad76362780a9a3.tar.xz
Bug 718183: Rename duplicated series names before inserting the new index in the series table
r=dkl a=LpSolit
Diffstat (limited to 'Bugzilla/Install/DB.pm')
-rw-r--r--Bugzilla/Install/DB.pm31
1 files changed, 31 insertions, 0 deletions
diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm
index adff55915..44646962b 100644
--- a/Bugzilla/Install/DB.pm
+++ b/Bugzilla/Install/DB.pm
@@ -3480,6 +3480,37 @@ sub _fix_series_indexes {
return if $dbh->bz_index_info('series', 'series_category_idx');
$dbh->bz_drop_index('series', 'series_creator_idx');
+
+ # Fix duplicated names under the same category/subcategory before
+ # adding the more restrictive index.
+ my $duplicated_series = $dbh->selectall_arrayref(
+ 'SELECT s1.series_id, s1.category, s1.subcategory, s1.name
+ FROM series AS s1
+ INNER JOIN series AS s2
+ ON s1.category = s2.category
+ AND s1.subcategory = s2.subcategory
+ AND s1.name = s2.name
+ WHERE s1.series_id != s2.series_id');
+ my $sth_series_update = $dbh->prepare('UPDATE series SET name = ? WHERE series_id = ?');
+ my $sth_series_query = $dbh->prepare('SELECT 1 FROM series WHERE name = ?
+ AND category = ? AND subcategory = ?');
+
+ my %renamed_series;
+ foreach my $series (@$duplicated_series) {
+ my ($series_id, $category, $subcategory, $name) = @$series;
+ # Leave the first series alone, then rename duplicated ones.
+ if ($renamed_series{"${category}_${subcategory}_${name}"}++) {
+ print "Renaming series ${category}/${subcategory}/${name}...\n";
+ my $c = 0;
+ my $exists = 1;
+ while ($exists) {
+ $sth_series_query->execute($name . ++$c, $category, $subcategory);
+ $exists = $sth_series_query->fetchrow_array;
+ }
+ $sth_series_update->execute($name . $c, $series_id);
+ }
+ }
+
$dbh->bz_add_index('series', 'series_creator_idx', ['creator']);
$dbh->bz_add_index('series', 'series_category_idx',
{FIELDS => [qw(category subcategory name)], TYPE => 'UNIQUE'});