Commit 159e5e2 1 parent 69be2be commit 159e5e2 Copy full SHA for 159e5e2
File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1
1
package MusicBrainz::Server::Controller::Admin::Attributes ;
2
2
use Moose;
3
3
4
+ use MusicBrainz::Server::Translation qw( l ln ) ;
5
+
4
6
no if $] >= 5.018, warnings => " experimental::smartmatch" ;
5
7
6
8
BEGIN { extends ' MusicBrainz::Server::Controller' };
@@ -125,9 +127,18 @@ sub delete : Chained('attribute_base') Args(1) RequireAuth(account_admin) Secure
125
127
126
128
$c -> detach;
127
129
}
130
+
131
+ if ($c -> model($model )-> has_children($id )) {
132
+ my $error_message = l(' You cannot remove the attribute “{name}” because it is the parent of other attributes.' , { name => $attr -> name });
133
+
134
+ $c -> stash(
135
+ current_view => ' Node' ,
136
+ component_path => ' admin/attributes/CannotRemoveAttribute' ,
137
+ component_props => {message => $error_message }
138
+ );
139
+
128
140
$c -> detach;
129
141
}
130
-
131
142
if ($c -> form_posted_and_valid($form )) {
132
143
$c -> model(' MB' )-> with_transaction(sub {
133
144
$c -> model($model )-> delete ($id );
Original file line number Diff line number Diff line change @@ -19,6 +19,13 @@ sub _column_mapping {
19
19
};
20
20
}
21
21
22
+ sub has_children {
23
+ my ($self , $id ) = @_ ;
24
+ return $self -> sql-> select_single_value(
25
+ ' SELECT 1 FROM ' . $self -> _table . ' WHERE parent = ? LIMIT 1' ,
26
+ $id );
27
+ }
28
+
22
29
no Moose;
23
30
1;
24
31
You can’t perform that action at this time.
0 commit comments