summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2006-08-04 09:40:49 +0200
committermkanat%bugzilla.org <>2006-08-04 09:40:49 +0200
commite68208dd74f630691a541c6dba5783ccbe0f0b40 (patch)
treec2978bdc53ee5b0b441ee972b58b4953b395e296 /Bugzilla
parent4883aac15d2f621818f18d6b07dc98175eb12695 (diff)
downloadbugzilla-e68208dd74f630691a541c6dba5783ccbe0f0b40.tar.gz
bugzilla-e68208dd74f630691a541c6dba5783ccbe0f0b40.tar.xz
Bug 347116: Move field-definition code from checksetup.pl into a module
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=myk
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Field.pm160
-rw-r--r--Bugzilla/Install/DB.pm8
2 files changed, 160 insertions, 8 deletions
diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm
index 87c799234..ba939036c 100644
--- a/Bugzilla/Field.pm
+++ b/Bugzilla/Field.pm
@@ -80,6 +80,10 @@ use Bugzilla::Util;
use Bugzilla::Constants;
use Bugzilla::Error;
+###############################
+#### Initialization ####
+###############################
+
use constant DB_TABLE => 'fielddefs';
use constant LIST_ORDER => 'sortkey, name';
@@ -100,6 +104,66 @@ use constant SQL_DEFINITIONS => {
FIELD_TYPE_FREETEXT, { TYPE => 'varchar(255)' },
};
+# Field definitions for the fields that ship with Bugzilla.
+# These are used by populate_field_definitions to populate
+# the fielddefs table.
+use constant DEFAULT_FIELDS => (
+ {name => 'bug_id', desc => 'Bug #', in_new_bugmail => 1},
+ {name => 'short_desc', desc => 'Summary', in_new_bugmail => 1},
+ {name => 'classification', desc => 'Classification', in_new_bugmail => 1},
+ {name => 'product', desc => 'Product', in_new_bugmail => 1},
+ {name => 'version', desc => 'Version', in_new_bugmail => 1},
+ {name => 'rep_platform', desc => 'Platform', in_new_bugmail => 1},
+ {name => 'bug_file_loc', desc => 'URL', in_new_bugmail => 1},
+ {name => 'op_sys', desc => 'OS/Version', in_new_bugmail => 1},
+ {name => 'bug_status', desc => 'Status', in_new_bugmail => 1},
+ {name => 'status_whiteboard', desc => 'Status Whiteboard',
+ in_new_bugmail => 1},
+ {name => 'keywords', desc => 'Keywords', in_new_bugmail => 1},
+ {name => 'resolution', desc => 'Resolution'},
+ {name => 'bug_severity', desc => 'Severity', in_new_bugmail => 1},
+ {name => 'priority', desc => 'Priority', in_new_bugmail => 1},
+ {name => 'component', desc => 'Component', in_new_bugmail => 1},
+ {name => 'assigned_to', desc => 'AssignedTo', in_new_bugmail => 1},
+ {name => 'reporter', desc => 'ReportedBy', in_new_bugmail => 1},
+ {name => 'votes', desc => 'Votes'},
+ {name => 'qa_contact', desc => 'QAContact', in_new_bugmail => 1},
+ {name => 'cc', desc => 'CC', in_new_bugmail => 1},
+ {name => 'dependson', desc => 'BugsThisDependsOn', in_new_bugmail => 1},
+ {name => 'blocked', desc => 'OtherBugsDependingOnThis',
+ in_new_bugmail => 1},
+
+ {name => 'attachments.description', desc => 'Attachment description'},
+ {name => 'attachments.filename', desc => 'Attachment filename'},
+ {name => 'attachments.mimetype', desc => 'Attachment mime type'},
+ {name => 'attachments.ispatch', desc => 'Attachment is patch'},
+ {name => 'attachments.isobsolete', desc => 'Attachment is obsolete'},
+ {name => 'attachments.isprivate', desc => 'Attachment is private'},
+
+ {name => 'target_milestone', desc => 'Target Milestone'},
+ {name => 'creation_ts', desc => 'Creation date', in_new_bugmail => 1},
+ {name => 'delta_ts', desc => 'Last changed date', in_new_bugmail => 1},
+ {name => 'longdesc', desc => 'Comment'},
+ {name => 'alias', desc => 'Alias'},
+ {name => 'everconfirmed', desc => 'Ever Confirmed'},
+ {name => 'reporter_accessible', desc => 'Reporter Accessible'},
+ {name => 'cclist_accessible', desc => 'CC Accessible'},
+ {name => 'bug_group', desc => 'Group'},
+ {name => 'estimated_time', desc => 'Estimated Hours', in_new_bugmail => 1},
+ {name => 'remaining_time', desc => 'Remaining Hours'},
+ {name => 'deadline', desc => 'Deadline', in_new_bugmail => 1},
+ {name => 'commenter', desc => 'Commenter'},
+ {name => 'flagtypes.name', desc => 'Flag'},
+ {name => 'requestees.login_name', desc => 'Flag Requestee'},
+ {name => 'setters.login_name', desc => 'Flag Setter'},
+ {name => 'work_time', desc => 'Hours Worked'},
+ {name => 'percentage_complete', desc => 'Percentage Complete'},
+ {name => 'content', desc => 'Content'},
+ {name => 'attach_data.thedata', desc => 'Attachment data'},
+ {name => 'attachments.isurl', desc => 'Attachment is a URL'},
+ {name => "owner_idle_time", desc => "Time Since Assignee Touched"},
+);
+
=pod
=head2 Instance Properties
@@ -318,8 +382,102 @@ sub get_legal_field_values {
return $result_ref;
}
+=item C<populate_field_definitions()>
+
+Description: Populates the fielddefs table during an installation
+ or upgrade.
+
+Params: none
+
+Returns: nothing
+
+=cut
+
+sub populate_field_definitions {
+ my $dbh = Bugzilla->dbh;
+
+ # ADD and UPDATE field definitions
+ foreach my $definition (DEFAULT_FIELDS) {
+ create_or_update($definition);
+ }
+
+ # DELETE fields which were added only accidentally, or which
+ # were never tracked in bugs_activity. Note that you can never
+ # delete fields which are used by bugs_activity.
+
+ # Oops. Bug 163299
+ $dbh->do("DELETE FROM fielddefs WHERE name='cc_accessible'");
+ # Oops. Bug 215319
+ $dbh->do("DELETE FROM fielddefs WHERE name='requesters.login_name'");
+ # This field was never tracked in bugs_activity, so it's safe to delete.
+ $dbh->do("DELETE FROM fielddefs WHERE name='attachments.thedata'");
+
+ # MODIFY old field definitions
+
+ # 2005-11-13 LpSolit@gmail.com - Bug 302599
+ # One of the field names was a fragment of SQL code, which is DB dependent.
+ # We have to rename it to a real name, which is DB independent.
+ my $new_field_name = 'days_elapsed';
+ my $field_description = 'Days since bug changed';
+
+ my ($old_field_id, $old_field_name) =
+ $dbh->selectrow_array('SELECT id, name FROM fielddefs
+ WHERE description = ?',
+ undef, $field_description);
+
+ if ($old_field_id && ($old_field_name ne $new_field_name)) {
+ print "SQL fragment found in the 'fielddefs' table...\n";
+ print "Old field name: " . $old_field_name . "\n";
+ # We have to fix saved searches first. Queries have been escaped
+ # before being saved. We have to do the same here to find them.
+ $old_field_name = url_quote($old_field_name);
+ my $broken_named_queries =
+ $dbh->selectall_arrayref('SELECT userid, name, query
+ FROM namedqueries WHERE ' .
+ $dbh->sql_istrcmp('query', '?', 'LIKE'),
+ undef, "%=$old_field_name%");
+
+ my $sth_UpdateQueries = $dbh->prepare('UPDATE namedqueries SET query = ?
+ WHERE userid = ? AND name = ?');
+
+ print "Fixing saved searches...\n" if scalar(@$broken_named_queries);
+ foreach my $named_query (@$broken_named_queries) {
+ my ($userid, $name, $query) = @$named_query;
+ $query =~ s/=\Q$old_field_name\E(&|$)/=$new_field_name$1/gi;
+ $sth_UpdateQueries->execute($query, $userid, $name);
+ }
+
+ # We now do the same with saved chart series.
+ my $broken_series =
+ $dbh->selectall_arrayref('SELECT series_id, query
+ FROM series WHERE ' .
+ $dbh->sql_istrcmp('query', '?', 'LIKE'),
+ undef, "%=$old_field_name%");
+
+ my $sth_UpdateSeries = $dbh->prepare('UPDATE series SET query = ?
+ WHERE series_id = ?');
+
+ print "Fixing saved chart series...\n" if scalar(@$broken_series);
+ foreach my $series (@$broken_series) {
+ my ($series_id, $query) = @$series;
+ $query =~ s/=\Q$old_field_name\E(&|$)/=$new_field_name$1/gi;
+ $sth_UpdateSeries->execute($query, $series_id);
+ }
+ # Now that saved searches have been fixed, we can fix the field name.
+ print "Fixing the 'fielddefs' table...\n";
+ print "New field name: " . $new_field_name . "\n";
+ $dbh->do('UPDATE fielddefs SET name = ? WHERE id = ?',
+ undef, ($new_field_name, $old_field_id));
+}
+
+ # This field has to be created separately, or the above upgrade code
+ # might not run properly.
+ Bugzilla::Field::create_or_update(
+ {name => $new_field_name, desc => $field_description});
+
+}
+
-=pod
=head2 Data Validation
diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm
index 1e8dcb693..46e9b5c5a 100644
--- a/Bugzilla/Install/DB.pm
+++ b/Bugzilla/Install/DB.pm
@@ -23,7 +23,6 @@ use strict;
use Bugzilla::Bug qw(is_open_state);
use Bugzilla::Constants;
-use Bugzilla::Field;
use Bugzilla::Util;
use Bugzilla::Series;
@@ -280,9 +279,6 @@ sub update_table_definitions {
_remove_user_series_map();
_copy_old_charts_into_database();
- Bugzilla::Field::create_or_update(
- {name => "owner_idle_time", desc => "Time Since Assignee Touched"});
-
_add_user_group_map_grant_type();
_add_group_group_map_grant_type();
@@ -1376,9 +1372,7 @@ sub _convert_groups_system_from_groupset {
}
}
# Replace old activity log groupset records with lists of names
- # of groups. Start by defining the bug_group field and getting its id.
- Bugzilla::Field::create_or_update(
- {name => "bug_group", desc => "Group"});
+ # of groups.
$sth = $dbh->prepare("SELECT id FROM fielddefs
WHERE name = " . $dbh->quote('bug_group'));
$sth->execute();