@@ -239,8 +239,10 @@ sub _delete($self, $wf) {
239239#
240240# ####################################
241241
242- sub _reconcile_source_id ( $stmt , $source_id , $book_todo , $book_done ) {
242+ sub _reconcile_source_id ( $stmt_todo , $idx , $source_id , $book_todo , $recon_done ) {
243+ my $stmt = $stmt_todo -> [$idx ];
243244 my $lc_source_id = lc ($source_id );
245+ print STDERR " source_id: $lc_source_id \n " ;
244246 my $candidates = [
245247 grep {
246248 lc ($book_todo -> [$_ ]-> {source }) eq $lc_source_id
@@ -249,12 +251,13 @@ sub _reconcile_source_id( $stmt, $source_id, $book_todo, $book_done ) {
249251 ];
250252
251253 return unless $candidates -> @*;
254+ print STDERR " Have candidates\n " ;
252255
253256 if (scalar ($candidates -> @*) == 1) {
254- my $found = splice $book_todo -> @*, $candidates -> [0], 1;
255- $found -> { recon_group } = $stmt -> { id };
256- $ stmt-> { recon_group } = $stmt -> { id };
257- push $book_done -> @*, $found ;
257+ push $recon_done -> @*, {
258+ book => [ splice $book_todo -> @*, $candidates -> [0], 1 ],
259+ stmt => [ splice $stmt_todo -> @*, $idx , 1 ],
260+ } ;
258261 return ;
259262 }
260263
@@ -268,55 +271,62 @@ sub _reconcile_source_id( $stmt, $source_id, $book_todo, $book_done ) {
268271
269272 return unless $candidates -> @*;
270273
271- my $found = splice $book_todo -> @*, $candidates -> [0], 1;
272- $found -> { recon_group } = $stmt -> { id };
273- $ stmt-> { recon_group } = $stmt -> { id };
274- push $book_done -> @*, $found ;
274+ push $recon_done -> @*, {
275+ book => [ splice $book_todo -> @*, $candidates -> [0], 1 ],
276+ stmt => [ splice $stmt_todo -> @*, $idx , 1 ],
277+ } ;
275278 return ;
276279}
277280
278- sub _reconcile_no_nource_id ($stmt , $prefix , $book_todo , $book_done ) {
281+ sub _reconcile_no_source_id ($stmt_todo , $idx , $prefix ,
282+ $book_todo , $recon_done ) {
283+ my $stmt = $stmt_todo -> [$idx ];
279284 my $candidates = [
280285 grep {
281286 $book_todo -> [$_ ]-> {amount } == $stmt -> {amount }
282287 and $book_todo -> [$_ ]-> {post_date } eq $stmt -> {post_date }
283- and $book_todo -> [$_ ]-> {source } !~ m / ^\Q $prefix \E /
288+ and (not $book_todo -> [$_ ]-> {source }
289+ or $book_todo -> [$_ ]-> {source } !~ m / ^\Q $prefix \E / )
284290 } 0..$book_todo -> $# *
285291 ];
286292
287293 return unless $candidates -> @*;
288294
289- my $found = splice $book_todo -> @*, $candidates -> [0], 1;
290- $found -> { recon_group } = $stmt -> { id };
291- $stmt -> { recon_group } = $stmt -> { id };
292- push $book_done -> @*, $found ;
293- return ;
295+ push $recon_done -> @*, {
296+ stmt => [ splice $book_todo -> @*, $candidates -> [0], 1 ],
297+ book => [ splice $stmt_todo -> @*, $idx , 1 ],
298+ } ;
299+ return 1 ;
294300}
295301
296302sub _reconcile ($self , $wf ) {
297303 my $stmt_todo = $wf -> context-> param( ' _stmt_todo' );
298304 my $book_todo = $wf -> context-> param( ' _book_todo' );
299- my $book_done = $wf -> context-> param( ' _book_done ' );
305+ my $recon_done = $wf -> context-> param( ' _recon_done ' );
300306 my $prefix = $wf -> context-> param( ' _prefix' );
301307
302- for my $ stmt ( $stmt_todo -> @*) {
308+ for my ( $idx , $ stmt) (indexed $stmt_todo -> @*) {
303309 my $source_id ;
304- if (defined $stmt -> {source_id }) {
305- if ($stmt -> {source_id } =~ m / ^[0-9] +$ / ) {
306- $source_id = $prefix . $stmt -> {source_id } ;
310+ if (defined $stmt -> {source }) {
311+ if ($stmt -> {source } =~ m / ^[0-9] +$ / ) {
312+ $source_id = " $prefix $stmt ->{source} " ;
307313 }
308- elsif ($stmt -> {source_id } ne ' ' ) {
309- $source_id = $stmt -> {source_id };
314+ elsif ($stmt -> {source } ne ' ' ) {
315+ $source_id = $stmt -> {source };
310316 }
311317 }
312318
313319 if (defined $source_id ) {
314- _reconcile_source_id( $stmt , $source_id , $book_todo , $book_done );
320+ _reconcile_source_id(
321+ $stmt_todo , $idx , $source_id , $book_todo , $recon_done );
315322 return ;
316323 }
317324
318- _reconcle_no_source_id( $stmt , $prefix , $book_todo , $book_done );
325+ _reconcile_no_source_id(
326+ $stmt_todo , $idx , $prefix , $book_todo , $recon_done );
319327 }
328+
329+ return ;
320330}
321331
322332# ####################################
0 commit comments