Changeset 773 for trunk


Ignore:
Timestamp:
09/09/15 18:03:23 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Factor getChildren() minisub out of shrinkBlock() so we can call it
from splitBlock as well

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r768 r773  
    479479
    480480} # end _deleteCascade()
     481
     482
     483## IPDB::_getChildren()
     484# Recursive sub to retrieve a flat list of suballocations
     485# Takes the root parent ID, master ID, reference to push results into, and the CIDR
     486# range to restrict results to
     487sub _getChildren {
     488  my $dbh = shift;
     489  my $id = shift;
     490  my $master = shift;
     491  my $retlist = shift;  # better than trying to return complex structures recursively. Ow.
     492  my $cidr = shift;
     493
     494  if (!$cidr) {
     495    my $bd = getBlockData($dbh, $id);
     496    $cidr = $bd->{cidr};
     497  }
     498
     499  my $sth = $dbh->prepare(q(
     500        SELECT id,cidr,type FROM allocations
     501        WHERE parent_id = ? AND master_id = ? AND cidr <<= ?
     502        ) );
     503  $sth->execute($id, $master, $cidr);
     504  while (my $row = $sth->fetchrow_hashref) {
     505    push @$retlist, $row;
     506    _getChildren($dbh, $row->{id}, $master, $retlist, $cidr);
     507  }
     508} # end _getChildren()
    481509
    482510
     
    20722100  my $delfbsth = $dbh->prepare("DELETE FROM freeblocks WHERE parent_id = ? AND cidr <<= ?");
    20732101
    2074 ##fixme:  turn this into a public/top-level sub?
    2075   sub getchildren {
    2076     my $dbh = shift;
    2077     my $id = shift;
    2078     my $master = shift;
    2079     my $retlist = shift;  # better than trying to return complex structures recursively. Ow.
    2080     my $cidr = shift;
    2081 
    2082     if (!$cidr) {
    2083       my $bd = getBlockData($dbh, $id);
    2084       $cidr = $bd->{cidr};
    2085     }
    2086 
    2087     my $sth = $dbh->prepare(q(
    2088         SELECT id,cidr,type FROM allocations
    2089         WHERE parent_id = ? AND master_id = ? AND cidr <<= ?
    2090         ) );
    2091     $sth->execute($id, $master, $cidr);
    2092     while (my $row = $sth->fetchrow_hashref) {
    2093       push @$retlist, $row;
    2094       getchildren($dbh, $row->{id}, $master, $retlist, $cidr);
    2095     }
    2096   }
    2097 
    20982102  my @ret;
    20992103  my @newfreelist;
     
    21142118      # the block we're munging
    21152119      push @clist, { id => $id, type => $binfo->{type}, cidr => $binfo->{block} };
    2116       getchildren($dbh, $id, $binfo->{master_id}, \@clist, $newfree);
     2120      _getChildren($dbh, $id, $binfo->{master_id}, \@clist, $newfree);
    21172121
    21182122      foreach my $goner (@clist) {
Note: See TracChangeset for help on using the changeset viewer.