Revision 1f6662b4
Von Sven Schöling vor etwa 15 Jahren hinzugefügt
SL/RecordLinks.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use SL::Common; |
4 | 4 |
use SL::DBUtils; |
5 |
use Data::Dumper; |
|
6 |
use List::Util qw(reduce); |
|
5 | 7 |
|
6 | 8 |
sub create_links { |
7 | 9 |
$main::lxdebug->enter_sub(); |
... | ... | |
130 | 132 |
my $myconfig = \%main::myconfig; |
131 | 133 |
my $form = $main::form; |
132 | 134 |
|
133 |
my $last_hop = shift @hops; |
|
134 |
my @links = undef;
|
|
135 |
my $last_hop = shift @hops;
|
|
136 |
my @links; |
|
135 | 137 |
for my $hop (@hops) { |
136 | 138 |
|
137 | 139 |
my @temp_links = $self->get_links( |
... | ... | |
141 | 143 |
to_id => $hop->{id}, |
142 | 144 |
); |
143 | 145 |
|
144 |
if (@links) { |
|
145 |
@links = grep { $_ } |
|
146 |
cross { |
|
147 |
if ( $a->{to_table} eq $b->{from_table} |
|
148 |
&& $a->{to_id} eq $b->{from_id} ) { |
|
149 |
+{ $a->{from_table}, $a->{from_id}, |
|
150 |
$b->{to_table}, $b->{to_table} } |
|
151 |
} |
|
152 |
} @links, @temp_links; |
|
153 |
} else { |
|
154 |
@links = @temp_links; |
|
155 |
} |
|
146 |
# short circuit if any of these are empty |
|
147 |
return wantarray ? () : [] unless scalar @temp_links; |
|
156 | 148 |
|
157 |
$last_hop = $hop; |
|
149 |
push @links, \@temp_links; |
|
150 |
$last_hop = $hop; |
|
158 | 151 |
} |
159 | 152 |
|
153 |
my $result = reduce { |
|
154 |
[ |
|
155 |
grep { $_ } |
|
156 |
cross { |
|
157 |
if ( $a->{to_table} eq $b->{from_table} |
|
158 |
&& $a->{to_id} eq $b->{from_id} ) { |
|
159 |
+{ from_table => $a->{from_table}, |
|
160 |
from_id => $a->{from_id}, |
|
161 |
to_table => $b->{to_table}, |
|
162 |
to_id => $b->{to_id} } |
|
163 |
} |
|
164 |
} @{ $a }, @{ $b } |
|
165 |
] |
|
166 |
} @links; |
|
167 |
|
|
160 | 168 |
$main::lxdebug->leave_sub(); |
161 | 169 |
|
162 |
return wantarray ? @links : \@links;
|
|
170 |
return wantarray ? @{ $result } : $result;
|
|
163 | 171 |
} |
164 | 172 |
|
165 | 173 |
1; |
Auch abrufbar als: Unified diff
Bugfix: get_links_via behandelt jetzt korrekt, wenn der erste hop leer
ist.
Conflicts: