Changeset 531 for trunk/cgi-bin/IPDB.pm
- Timestamp:
- 10/29/12 18:09:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r530 r531 30 30 &getTypeList 31 31 &getParent &getRoutedCity 32 &allocateBlock & deleteBlock &getBlockData32 &allocateBlock &updateBlock &deleteBlock &getBlockData 33 33 &getNodeList &getNodeName &getNodeInfo 34 34 &mailNotify … … 44 44 &getTypeList 45 45 &getParent &getRoutedCity 46 &allocateBlock & deleteBlock &getBlockData46 &allocateBlock &updateBlock &deleteBlock &getBlockData 47 47 &getNodeList &getNodeName &getNodeInfo 48 48 &mailNotify … … 826 826 827 827 828 ## IPDB::updateBlock() 829 # Update an allocation 830 # Takes all allocation fields in a hash 831 sub updateBlock { 832 my $dbh = shift; 833 my %args = @_; 834 835 return ('FAIL', 'Missing block to update') if !$args{block}; 836 837 # do it all in a transaction 838 local $dbh->{AutoCommit} = 0; 839 local $dbh->{RaiseError} = 1; 840 841 my @fieldlist; 842 my @vallist; 843 foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata') { 844 if ($args{$_}) { 845 push @fieldlist, $_; 846 push @vallist, $args{$_}; 847 } 848 } 849 850 my $updtable = 'allocations'; 851 my $keyfield = 'cidr'; 852 if ($args{alloctype} =~ /^(.)i$/) { 853 $updtable = 'poolips'; 854 $keyfield = 'ip'; 855 } else { 856 ## fixme: there's got to be a better way... 857 if ($args{swip}) { 858 if ($args{swip} eq 'on' || $args{swip} eq '1' || $args{swip} eq 'y') { 859 $args{swip} = 'y'; 860 } else { 861 $args{swip} = 'n'; 862 } 863 } 864 foreach ('type', 'swip') { 865 if ($args{$_}) { 866 push @fieldlist, $_; 867 push @vallist, $args{$_}; 868 } 869 } 870 } 871 872 return ('FAIL', 'No fields to update') if !@fieldlist; 873 874 push @vallist, $args{block}; 875 my $sql = "UPDATE $updtable SET "; 876 $sql .= join " = ?, ", @fieldlist; 877 $sql .= " = ? WHERE $keyfield = ?"; 878 879 eval { 880 # do the update 881 $dbh->do($sql, undef, @vallist); 882 883 if ($args{node}) { 884 # done with delete/insert so we don't have to worry about funkyness updating a node ref that isn't there 885 $dbh->do("DELETE FROM noderef WHERE block = ?", undef, ($args{block}) ); 886 $dbh->do("INSERT INTO noderef (block,node_id) VALUES (?,?)", undef, ($args{block}, $args{node}) ); 887 } 888 889 $dbh->commit; 890 }; 891 if ($@) { 892 my $msg = $@; 893 $dbh->rollback; 894 return ('FAIL', $msg); 895 } 896 return 0; 897 } # end updateBlock() 898 899 828 900 ## IPDB::deleteBlock() 829 901 # Removes an allocation from the database, including deleting IPs
Note:
See TracChangeset
for help on using the changeset viewer.