Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d0779d01

Von Moritz Bunkus vor etwa 17 Jahren hinzugefügt

  • ID d0779d015d862645b9f63140f7e7af2596238c8e
  • Vorgänger e549422f
  • Nachfolger 87dbaf3c

Den Test, ob ein Artikel noch nicht benutzt wurde und deshalb gelöscht werden kann, auf weitere Tabellen ausgedehnt.

Unterschiede anzeigen:

SL/IC.pm
203 203
  $sth->finish;
204 204

  
205 205
  # is it an orphan
206
  $query =
207
    qq|SELECT i.parts_id
208
       FROM invoice i
209
       WHERE (i.parts_id = ?)
210

  
211
       UNION
212

  
213
       SELECT o.parts_id
214
       FROM orderitems o
215
       WHERE (o.parts_id = ?)
206
  my @referencing_tables = qw(invoice orderitems invoice inventory rmaitems);
207
  my %column_map         = ( );
208
  my $parts_id           = conv_i($form->{id});
216 209

  
217
       UNION
210
  $form->{orphaned}      = 1;
218 211

  
219
       SELECT a.parts_id
220
       FROM assembly a
221
       WHERE (a.parts_id = ?)|;
222
  @values = (conv_i($form->{id}), conv_i($form->{id}), conv_i($form->{id}));
223
  ($form->{orphaned}) = selectrow_query($form, $dbh, $query, @values);
224
  $form->{orphaned} = !$form->{orphaned};
212
  foreach my $table (@referencing_tables) {
213
    my $column  = $column_map{$table} || 'parts_id';
214
    $query      = qq|SELECT $column FROM $table WHERE $column = ? LIMIT 1|;
215
    my ($found) = selectrow_query($form, $dbh, $query, $parts_id);
225 216

  
226
  $form->{"unit_changeable"} = 1;
227
  foreach my $table (qw(invoice assembly orderitems inventory license)) {
228
    $query = qq|SELECT COUNT(*) FROM $table WHERE parts_id = ?|;
229
    my ($count) = selectrow_query($form, $dbh, $query, conv_i($form->{"id"}));
230

  
231
    if ($count) {
232
      $form->{"unit_changeable"} = 0;
217
    if ($found) {
218
      $form->{orphaned} = 0;
233 219
      last;
234 220
    }
235 221
  }
236 222

  
223
  $form->{"unit_changeable"} = $form->{orphaned};
224

  
237 225
  $dbh->disconnect;
238 226

  
239 227
  $main::lxdebug->leave_sub();
......
724 712
  # connect to database, turn off AutoCommit
725 713
  my $dbh = $form->dbconnect_noauto($myconfig);
726 714

  
727
  my %columns = ( "assembly" => "id", "alternate" => "id", "parts" => "id" );
715
  my %columns = ( "assembly" => "id", "parts" => "id" );
728 716

  
729
  for my $table (qw(prices partstax makemodel inventory assembly parts)) {
717
  for my $table (qw(prices partstax makemodel inventory assembly license translation parts)) {
730 718
    my $column = defined($columns{$table}) ? $columns{$table} : "parts_id";
731 719
    do_query($form, $dbh, qq|DELETE FROM $table WHERE $column = ?|, @values);
732 720
  }

Auch abrufbar als: Unified diff