Changeset 773 for trunk/cgi-bin
- Timestamp:
- 09/09/15 18:03:23 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r768 r773 479 479 480 480 } # 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 487 sub _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() 481 509 482 510 … … 2072 2100 my $delfbsth = $dbh->prepare("DELETE FROM freeblocks WHERE parent_id = ? AND cidr <<= ?"); 2073 2101 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 allocations2089 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 2098 2102 my @ret; 2099 2103 my @newfreelist; … … 2114 2118 # the block we're munging 2115 2119 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); 2117 2121 2118 2122 foreach my $goner (@clist) {
Note:
See TracChangeset
for help on using the changeset viewer.