Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 96670fe8

Von Moritz Bunkus vor etwa 8 Jahren hinzugefügt

  • ID 96670fe82a38116ac10592a6ccbd34800f8ad9f8
  • Vorgänger e5a76ed1
  • Nachfolger 0b84f51f

»with_transaction« anstelle von »do_transaction« verwenden

Es sollte so selten wie möglich »do_transaction« verwndet werden, damit
man sich immer angewöhnt, »with_transaction« zu nutzen.

Hintergründe und Unterschiede zwischen den beiden Funktionen sind in der
Dokumentation von SL/DB.pm beschrieben.

Unterschiede anzeigen:

SL/Controller/Taxzones.pm
72 72
  # allow deletion of unused tax zones. Will fail, due to database
73 73
  # constraints, if tax zone is used anywhere
74 74

  
75
  my $db = $self->{config}->db;
76
  $db->do_transaction(sub {
77
        my $taxzone_charts = SL::DB::Manager::TaxzoneChart->get_all(where => [ taxzone_id => $self->config->id ]);
78
        foreach my $taxzonechart ( @{$taxzone_charts} ) { $taxzonechart->delete };
79
        $self->config->delete();
80
        flash_later('info',  $::locale->text('The tax zone has been deleted.'));
75
  $self->{config}->db->with_transaction(sub {
76
    my $taxzone_charts = SL::DB::Manager::TaxzoneChart->get_all(where => [ taxzone_id => $self->config->id ]);
77
    foreach my $taxzonechart ( @{$taxzone_charts} ) { $taxzonechart->delete };
78
    $self->config->delete();
79
    flash_later('info',  $::locale->text('The tax zone has been deleted.'));
80

  
81
    1;
81 82
  }) || flash_later('error', $::locale->text('The tax zone is in use and cannot be deleted.'));
82 83

  
83 84
  $self->redirect_to(action => 'list');
......
121 122
  my @errors;
122 123

  
123 124
  my $db = $self->config->db;
124
  $db->do_transaction( sub {
125
  if (!$db->with_transaction(sub {
125 126

  
126 127
    # always allow editing of description and obsolete
127 128
    $self->config->assign_attributes( %{$params} ) ;
......
160 161
        $taxzone_chart->save;
161 162
      }
162 163
    }
163
  } ) || die @errors ? join("\n", @errors) . "\n" : $db->error . "\n";
164
         # die with rollback of taxzone save if saving of any of the taxzone_charts fails
165
         # only show the $db->error if we haven't already identified the likely error ourselves
164

  
165
    1;
166
  })) {
167
    die @errors ? join("\n", @errors) . "\n" : $db->error . "\n";
168
    # die with rollback of taxzone save if saving of any of the taxzone_charts fails
169
    # only show the $db->error if we haven't already identified the likely error ourselves
170
  }
166 171

  
167 172
  flash_later('info', $is_new ? t8('The taxzone has been created.') : t8('The taxzone has been saved.'));
168 173
  $self->redirect_to(action => 'list');

Auch abrufbar als: Unified diff