Revision 6b9b1781
Von Sven Schöling vor mehr als 1 Jahr hinzugefügt
SL/DB/Helper/RecordLink.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
use parent qw(Exporter); |
5 | 5 |
|
6 |
use Carp qw(croak); |
|
7 |
|
|
8 |
use SL::MoreCommon qw(listify); |
|
9 |
|
|
6 | 10 |
use constant RECORD_ID => 'converted_from_record_id'; |
7 | 11 |
use constant RECORD_TYPE_REF => 'converted_from_record_type_ref'; |
8 | 12 |
use constant RECORD_ITEM_ID => 'converted_from_record_item_id'; |
... | ... | |
12 | 16 |
|
13 | 17 |
|
14 | 18 |
sub link_records { |
15 |
my ($self, $allowed_linked_records, $allowed_linked_record_items) = @_; |
|
19 |
my ($self, $allowed_linked_records, $allowed_linked_record_items, %flags) = @_;
|
|
16 | 20 |
|
17 | 21 |
my %allowed_linked_records = map {$_ => 1} @$allowed_linked_records; |
18 | 22 |
my %allowed_linked_record_items = map {$_ => 1} @$allowed_linked_record_items; |
19 | 23 |
|
20 |
return 1 unless my $from_record_id = $self->{RECORD_ID()}; |
|
24 |
return 1 unless my $from_record_ids = $self->{RECORD_ID()};
|
|
21 | 25 |
|
22 | 26 |
my $from_record_type = $self->{RECORD_TYPE_REF()}; |
23 | 27 |
unless ($allowed_linked_records{$from_record_type}) { |
24 | 28 |
croak("Not allowed @{[ RECORD_TYPE_REF ]}: $from_record_type"); |
25 | 29 |
} |
26 | 30 |
|
27 |
$from_record_type->new(id => $from_record_id)->load |
|
28 |
->link_to_record($self); |
|
31 |
for my $id (listify($from_record_ids)) { |
|
32 |
my $from_record = $from_record_type->new(id => $id)->load; |
|
33 |
$from_record->link_to_record($self); |
|
34 |
|
|
35 |
close_quotations($from_record, %flags); |
|
36 |
} |
|
29 | 37 |
|
30 | 38 |
#clear converted_from; |
31 | 39 |
delete $self->{$_} for RECORD_ID, RECORD_TYPE_REF; |
... | ... | |
54 | 62 |
delete $record_item->{$_} for RECORD_ITEM_ID, RECORD_ITEM_TYPE_REF; |
55 | 63 |
} |
56 | 64 |
|
65 |
|
|
66 |
sub close_quotations { |
|
67 |
my ($from_record, %flags) = @_; |
|
68 |
|
|
69 |
return unless $flags{close_source_quotations}; |
|
70 |
return unless 'SL::DB::Order' eq ref $from_record; |
|
71 |
return unless $from_record->type =~ /quotation/; |
|
72 |
|
|
73 |
$from_record->update_attributes(closed => 1); |
|
74 |
} |
|
75 |
|
|
76 |
|
|
57 | 77 |
1; |
58 | 78 |
|
59 | 79 |
__END__ |
Auch abrufbar als: Unified diff
RecordLink: support für mehrere ids und close_quotations