| | 561 | |
|---|
| | 562 | ############################################################################### |
|---|
| | 563 | # GetPathDepth |
|---|
| | 564 | ############################################################################### |
|---|
| | 565 | sub GetPathDepth { |
|---|
| | 566 | my($row) = @_; |
|---|
| | 567 | |
|---|
| | 568 | # If we've already worked out the depth of this row, return it immediately |
|---|
| | 569 | if ($row->{parentdata} > 1) { |
|---|
| | 570 | return $row->{parentdata}; |
|---|
| | 571 | } |
|---|
| | 572 | |
|---|
| | 573 | my($maxParentDepth, $depth, $parents, $parent); |
|---|
| | 574 | |
|---|
| | 575 | # Get the row(s) corresponding to the parent(s) of this row, and work out |
|---|
| | 576 | # the maximum depth |
|---|
| | 577 | |
|---|
| | 578 | my $sql = <<"EOSQL"; |
|---|
| | 579 | SELECT |
|---|
| | 580 | * |
|---|
| | 581 | FROM |
|---|
| | 582 | PhysicalAction |
|---|
| | 583 | WHERE |
|---|
| | 584 | parentdata > 0 |
|---|
| | 585 | AND physname = ? |
|---|
| | 586 | AND actiontype = ? |
|---|
| | 587 | EOSQL |
|---|
| | 588 | |
|---|
| | 589 | my $sth = $gCfg{dbh}->prepare($sql); |
|---|
| | 590 | $sth->execute( @{ $row }{qw(parentphys actiontype)} ); |
|---|
| | 591 | |
|---|
| | 592 | $parents = $sth->fetchall_arrayref( {} ); |
|---|
| | 593 | $maxParentDepth = 0; |
|---|
| | 594 | foreach $parent (@$parents) { |
|---|
| | 595 | $depth = &GetPathDepth($parent); |
|---|
| | 596 | $maxParentDepth = ($depth > $maxParentDepth) ? $depth : $maxParentDepth; |
|---|
| | 597 | } |
|---|
| | 598 | |
|---|
| | 599 | # Depth of this path becomes one more than the maximum parent depth |
|---|
| | 600 | $depth = $maxParentDepth + 1; |
|---|
| | 601 | |
|---|
| | 602 | # Update the row for this record |
|---|
| | 603 | &UpdateDepth($row, $depth); |
|---|
| | 604 | |
|---|
| | 605 | return $depth; |
|---|
| | 606 | } # End GetPathDepth |
|---|
| | 607 | |
|---|
| | 608 | ############################################################################### |
|---|
| | 609 | # UpdateDepth |
|---|
| | 610 | ############################################################################### |
|---|
| | 611 | sub UpdateDepth { |
|---|
| | 612 | my($row, $depth) = @_; |
|---|
| | 613 | |
|---|
| | 614 | my $sql = <<"EOSQL"; |
|---|
| | 615 | UPDATE |
|---|
| | 616 | PhysicalAction |
|---|
| | 617 | SET |
|---|
| | 618 | parentdata = ? |
|---|
| | 619 | WHERE |
|---|
| | 620 | action_id = ? |
|---|
| | 621 | EOSQL |
|---|
| | 622 | |
|---|
| | 623 | my $sth = $gCfg{dbh}->prepare($sql); |
|---|
| | 624 | $sth->execute( $depth, $row->{action_id} ); |
|---|
| | 625 | |
|---|
| | 626 | } # End UpdateParentRec |
|---|