Revision f3aa6818
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/Controller/RequirementSpec.pm | ||
---|---|---|
185 | 185 |
|
186 | 186 |
my $versioned_copy = SL::DB::RequirementSpec->new(id => $::form->{versioned_copy_id})->load; |
187 | 187 |
|
188 |
$self->requirement_spec->delete_items; |
|
189 | 188 |
$self->requirement_spec->copy_from( |
190 | 189 |
$versioned_copy, |
191 | 190 |
version_id => $versioned_copy->version_id, |
SL/DB/RequirementSpec.pm | ||
---|---|---|
156 | 156 |
return $self; |
157 | 157 |
} |
158 | 158 |
|
159 |
sub delete_items { |
|
160 |
my ($self) = @_; |
|
161 |
|
|
162 |
my $worker = sub { |
|
163 |
# First convert all items to sections so that deleting won't |
|
164 |
# violate foreign key constraints on parent_id. |
|
165 |
SL::DB::Manager::RequirementSpecItem->update_all( |
|
166 |
set => { parent_id => undef, item_type => 'section' }, |
|
167 |
where => [ |
|
168 |
requirement_spec_id => $self->id, |
|
169 |
'!parent_id' => undef, |
|
170 |
]); |
|
171 |
|
|
172 |
# Now delete all items in one go. |
|
173 |
SL::DB::Manager::RequirementSpecItem->delete_all(where => [ requirement_spec_id => $self->id ]); |
|
174 |
|
|
175 |
# Last clear values in ourself. |
|
176 |
$self->items([]); |
|
177 |
}; |
|
178 |
|
|
179 |
return $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); |
|
180 |
} |
|
181 |
|
|
182 | 159 |
sub previous_version { |
183 | 160 |
my ($self) = @_; |
184 | 161 |
|
Auch abrufbar als: Unified diff
Refactoring: explizites $rspec->delete_items vor ->copy_from inzwischen unnötig
...seitdem die BEFORE-DELETE-Trigger für die Items richtig funktionieren.