Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
b03fc560
Commit
b03fc560
authored
Oct 03, 2008
by
mkanat%bugzilla.org
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 456919: Implement Bugzilla::Field::Choice->remove_from_db and have editvalues.cgi use it
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=bbaetz, a=mkanat
parent
fab5d3a3
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
53 deletions
+73
-53
Choice.pm
Bugzilla/Field/Choice.pm
+40
-0
Object.pm
Bugzilla/Object.pm
+15
-0
Status.pm
Bugzilla/Status.pm
+12
-0
editvalues.cgi
editvalues.cgi
+3
-51
user-error.html.tmpl
template/en/default/global/user-error.html.tmpl
+3
-2
No files found.
Bugzilla/Field/Choice.pm
View file @
b03fc560
...
...
@@ -170,12 +170,52 @@ sub update {
return
$changes
;
}
sub
remove_from_db
{
my
$self
=
shift
;
if
(
$self
->
is_default
)
{
ThrowUserError
(
'fieldvalue_is_default'
,
{
field
=>
$self
->
field
,
value
=>
$self
->
name
,
param_name
=>
$self
->
DEFAULT_MAP
->
{
$self
->
field
->
name
},
});
}
if
(
$self
->
is_static
)
{
ThrowUserError
(
'fieldvalue_not_deletable'
,
{
field
=>
$self
->
field
,
value
=>
$self
->
name
});
}
if
(
$self
->
bug_count
)
{
ThrowUserError
(
"fieldvalue_still_has_bugs"
,
{
field
=>
$self
->
field
,
value
=>
$self
->
name
,
count
=>
$self
->
bug_count
});
}
$self
->
SUPER::
remove_from_db
();
}
#############
# Accessors #
#############
sub
sortkey
{
return
$_
[
0
]
->
{
'sortkey'
};
}
sub
bug_count
{
my
$self
=
shift
;
return
$self
->
{
bug_count
}
if
defined
$self
->
{
bug_count
};
my
$dbh
=
Bugzilla
->
dbh
;
my
$fname
=
$self
->
field
->
name
;
my
$count
;
if
(
$self
->
field
->
type
==
FIELD_TYPE_MULTI_SELECT
)
{
$count
=
$dbh
->
selectrow_array
(
"SELECT COUNT(*) FROM bug_$fname
WHERE value = ?"
,
undef
,
$self
->
name
);
}
else
{
$count
=
$dbh
->
selectrow_array
(
"SELECT COUNT(*) FROM bugs
WHERE $fname = ?"
,
undef
,
$self
->
name
);
}
$self
->
{
bug_count
}
=
$count
;
return
$count
;
}
sub
field
{
my
$invocant
=
shift
;
my
$class
=
ref
$invocant
||
$invocant
;
...
...
Bugzilla/Object.pm
View file @
b03fc560
...
...
@@ -290,6 +290,15 @@ sub update {
return
\%
changes
;
}
sub
remove_from_db
{
my
$self
=
shift
;
my
$table
=
$self
->
DB_TABLE
;
my
$id_field
=
$self
->
ID_FIELD
;
Bugzilla
->
dbh
->
do
(
"DELETE FROM $table WHERE $id_field = ?"
,
undef
,
$self
->
id
);
undef
$self
;
}
###############################
#### Subroutines ######
###############################
...
...
@@ -726,6 +735,12 @@ C<update>.)
=back
=item C<remove_from_db>
Removes this object from the database. Will throw an error if you can't
remove it for some reason. The object will then be destroyed, as it is
not safe to use the object after it has been removed from the database.
=back
=head2 Subclass Helpers
...
...
Bugzilla/Status.pm
View file @
b03fc560
...
...
@@ -73,6 +73,18 @@ sub create {
return
$self
;
}
sub
remove_from_db
{
my
$self
=
shift
;
my
$dbh
=
Bugzilla
->
dbh
;
my
$id
=
$self
->
id
;
$dbh
->
bz_start_transaction
();
$self
->
SUPER::
remove_from_db
();
$dbh
->
do
(
'DELETE FROM status_workflow
WHERE old_status = ? OR new_status = ?'
,
undef
,
$id
,
$id
);
$dbh
->
bz_commit_transaction
();
}
###############################
##### Accessors ####
###############################
...
...
editvalues.cgi
View file @
b03fc560
...
...
@@ -265,58 +265,10 @@ if ($action eq 'del') {
#
if
(
$action
eq
'delete'
)
{
check_token_data
(
$token
,
'delete_field_value'
);
ValueMustExist
(
$field
,
$value
);
$vars
->
{
'value'
}
=
$value
;
$vars
->
{
'param_name'
}
=
$defaults
{
$field
};
if
(
defined
$defaults
{
$field
}
&&
(
$value
eq
Bugzilla
->
params
->
{
$defaults
{
$field
}}))
{
ThrowUserError
(
'fieldvalue_is_default'
,
$vars
);
}
# If the value cannot be deleted, throw an error.
if
(
lsearch
(
$static
{
$field
},
$value
)
>=
0
)
{
ThrowUserError
(
'fieldvalue_not_deletable'
,
$vars
);
}
trick_taint
(
$value
);
$dbh
->
bz_start_transaction
();
# Check if there are any bugs that still have this value.
my
$bug_count
;
if
(
$field_obj
->
type
!=
FIELD_TYPE_MULTI_SELECT
)
{
$bug_count
=
$dbh
->
selectrow_array
(
"SELECT COUNT(*) FROM bugs WHERE $field = ?"
,
undef
,
$value
);
}
else
{
$bug_count
=
$dbh
->
selectrow_array
(
"SELECT COUNT(*) FROM bug_$field WHERE value = ?"
,
undef
,
$value
);
}
if
(
$bug_count
)
{
# You tried to delete a field that bugs are still using.
# You can't just delete the bugs. That's ridiculous.
ThrowUserError
(
"fieldvalue_still_has_bugs"
,
{
field
=>
$field
,
value
=>
$value
,
count
=>
$bug_count
});
}
if
(
$field
eq
'bug_status'
)
{
my
$status_id
=
$dbh
->
selectrow_arrayref
(
'SELECT id FROM bug_status
WHERE value = ?'
,
undef
,
$value
);
$dbh
->
do
(
'DELETE FROM status_workflow
WHERE old_status = ? OR new_status = ?'
,
undef
,
(
$status_id
,
$status_id
));
}
$dbh
->
do
(
"DELETE FROM $field WHERE value = ?"
,
undef
,
$value
);
my
$value_obj
=
Bugzilla::Field::
Choice
->
type
(
$field
)
->
check
(
$value
);
$vars
->
{
'value'
}
=
$value_obj
->
name
;
$value_obj
->
remove_from_db
();
$dbh
->
bz_commit_transaction
();
delete_token
(
$token
);
$vars
->
{
'message'
}
=
'field_value_deleted'
;
...
...
template/en/default/global/user-error.html.tmpl
View file @
b03fc560
...
...
@@ -463,7 +463,8 @@
[% ELSIF error == "fieldvalue_not_deletable" %]
[% title = "Field Value Not Deletable" %]
The value '[% value FILTER html %]' cannot be removed because
it plays some special role for the '[% field.description FILTER html %]' field.
it plays some special role for the '[% field.description FILTER html %]'
field.
[% ELSIF error == "fieldvalue_not_specified" %]
[% title = "Field Value Not Specified" %]
...
...
@@ -484,7 +485,7 @@
[% ELSIF error == "fieldvalue_still_has_bugs" %]
[% title = "You Cannot Delete This Field Value" %]
You cannot delete the value '[% value FILTER html %]' from the
'[% field FILTER html %]'
field, because there are still
[% field.description FILTER html %]
field, because there are still
[%+ count FILTER html %] [%+ terms.bugs %] using it.
[% ELSIF error == "fieldvalue_undefined" %]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment