r4157 executeAutoPorts(): don't return result
authorDenis Ovsienko <infrastation@yandex.ru>
Thu, 27 Jan 2011 09:51:11 +0000 (09:51 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Thu, 27 Jan 2011 09:51:11 +0000 (09:51 +0000)
commitAddPort(): don't return result, use exceptions
addPortForObject(): update respectively
addMultiPorts(): idem
addBulkPorts(): idem
executeAutoPorts(): idem
doSwitchSNMPmining(): idem
generatePortsForCatModule(): idem

inc/database.php
inc/ophandlers.php
inc/snmp.php

index 5deb941..146ea7d 100644 (file)
@@ -908,7 +908,7 @@ function commitAddPort ($object_id = 0, $port_name, $port_type_id, $port_label,
        if (alreadyUsedL2Address ($db_l2address, $object_id))
        {
                $dbxlink->exec ('UNLOCK TABLES');
-               return "address ${db_l2address} belongs to another object";
+               throw new InvalidRequestArgException ('port_l2address', $port_l2address, 'address belongs to another object');
        }
        $matches = array();
        switch (1)
@@ -923,7 +923,7 @@ function commitAddPort ($object_id = 0, $port_name, $port_type_id, $port_label,
                break;
        default:
                $dbxlink->exec ('UNLOCK TABLES');
-               return "invalid port type id '${port_type_id}'";
+               throw new InvalidArgException ('port_type_id', $port_type_id, 'format error');
        }
        $result = usePreparedInsertBlade
        (
@@ -939,10 +939,6 @@ function commitAddPort ($object_id = 0, $port_name, $port_type_id, $port_label,
                )
        );
        $dbxlink->exec ('UNLOCK TABLES');
-       if ($result)
-               return '';
-       else
-               return 'SQL query failed';
 }
 
 // The fifth argument may be either explicit 'NULL' or some (already quoted by the upper layer)
@@ -2809,10 +2805,8 @@ function executeAutoPorts ($object_id = 0, $type_id = 0)
                throw new InvalidArgException ('$object_id', $object_id);
        if ($type_id == 0)
                throw new InvalidArgException ('$type_id', $type_id);
-       $ret = TRUE;
        foreach (getAutoPorts ($type_id) as $autoport)
-               $ret = $ret and '' == commitAddPort ($object_id, $autoport['name'], $autoport['type'], '', '');
-       return $ret;
+               commitAddPort ($object_id, $autoport['name'], $autoport['type'], '', '');
 }
 
 // Return only implicitly listed tags, the rest of the chain will be
index 80ed6c1..2facbc8 100644 (file)
@@ -504,13 +504,12 @@ function updPortForwarding ()
 }
 
 $msgcode['addPortForObject']['OK'] = 48;
-$msgcode['addPortForObject']['ERR2'] = 100;
 function addPortForObject ()
 {
        assertStringArg ('port_name', TRUE);
        genericAssertion ('port_l2address', 'l2address0');
        genericAssertion ('port_name', 'string');
-       $error = commitAddPort
+       commitAddPort
        (
                $_REQUEST['object_id'],
                trim ($_REQUEST['port_name']),
@@ -518,10 +517,7 @@ function addPortForObject ()
                trim ($_REQUEST['port_label']),
                trim ($_REQUEST['port_l2address'])
        );
-       if ($error != '')
-               return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
-       else
-               return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
+       return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
 }
 
 $msgcode['editPortForObject']['OK'] = 7;
@@ -660,19 +656,13 @@ http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a008
                $port_ids = getPortIDs ($object_id, $port['name']);
                if (!count ($port_ids))
                {
-                       $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
-                       if ($result == '')
-                               $added_count++;
-                       else
-                               $error_count++;
+                       commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
+                       $added_count++;
                }
                elseif (count ($port_ids) == 1) // update only single-socket ports
                {
-                       $result = commitUpdatePort ($object_id, $port_ids[0], $port['name'], $port_type, $port['label'], $port['l2address']);
-                       if ($result == '')
-                               $updated_count++;
-                       else
-                               $error_count++;
+                       commitUpdatePort ($object_id, $port_ids[0], $port['name'], $port_type, $port['label'], $port['l2address']);
+                       $updated_count++;
                }
        }
        return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $updated_count, $error_count));
@@ -699,11 +689,8 @@ function addBulkPorts ()
                $port_name .= '%u';
        for ($i=0,$c=$port_numbering_start; $i<$port_numbering_count; $i++,$c++)
        {
-               $result = commitAddPort ($object_id, @sprintf($port_name,$c), $port_type_id, @sprintf($port_label,$c), '');
-               if ($result == '')
-                       $added_count++;
-               else
-                       $error_count++;
+               commitAddPort ($object_id, @sprintf($port_name,$c), $port_type_id, @sprintf($port_label,$c), '');
+               $added_count++;
        }
        return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $error_count));
 }
index 676f179..a5fe3cc 100644 (file)
@@ -1195,10 +1195,7 @@ function doSwitchSNMPmining ($objectInfo, $device)
                                continue; // try next processor on current port
                        $newlabel = preg_replace ($iftable_processors[$processor_name]['pattern'], $iftable_processors[$processor_name]['label'], $iface['ifDescr'], 1, $count);
                        checkPIC ($iftable_processors[$processor_name]['dict_key']);
-                       $msg = commitAddPort ($objectInfo['id'], $newname, $iftable_processors[$processor_name]['dict_key'], $newlabel, $iface['ifPhysAddress']);
-                       if (!empty($msg)) {
-                               $log = mergeLogs($log, oneLiner(100, array("Error adding port " . $iface['ifDescr'] . ": $processor_name: $msg")));
-                       }
+                       commitAddPort ($objectInfo['id'], $newname, $iftable_processors[$processor_name]['dict_key'], $newlabel, $iface['ifPhysAddress']);
                        if (!$iftable_processors[$processor_name]['try_next_proc']) // done with this port
                                continue 2;
                }
@@ -1402,11 +1399,7 @@ function generatePortsForCatModule ($object_id, $slotno = 1, $mtype = 'X6748', $
                $dbxlink->beginTransaction();
                for ($i = 1; $i <= 48; $i++)
                {
-                       if ('' != commitAddPort ($object_id, "gi${slotno}/${i}", '1-24', "slot ${slotno} port ${i}", $mac_address))
-                       {
-                               $dbxlink->rollBack();
-                               break 2;
-                       }
+                       commitAddPort ($object_id, "gi${slotno}/${i}", '1-24', "slot ${slotno} port ${i}", $mac_address);
                        $mac_address = nextMACAddress ($mac_address);
                }
                $dbxlink->commit();