Browse Source

Don't update the last change date so much.

Joe Clarke 4 years ago
parent
commit
1c7e146034
1 changed files with 16 additions and 18 deletions
  1. 16 18
      www/logicsw.php

+ 16 - 18
www/logicsw.php

@@ -55,7 +55,6 @@ if (isset($_SERVER['REMOTE_USER'])) {
     $ruser = $_SERVER['REMOTE_USER'];
 }
 
-$errors = array();
 if (isset($_REQUEST['submit_top']) || isset($_REQUEST['submit_bottom'])) {
     $pia = $_REQUEST['prev_ip_address'];
     $ppid = $_REQUEST['prev_pid'];
@@ -68,8 +67,10 @@ if (isset($_REQUEST['submit_top']) || isset($_REQUEST['submit_bottom'])) {
     $exp = $_REQUEST['exception'];
     $idf = (isset($_REQUEST['is_idf'])) ? $_REQUEST['is_idf'] : array();
     $d = (isset($_REQUEST['delete'])) ? $_REQUEST['delete'] : array();
+    $made_change = false;
     foreach ($pia as $sname => $value) {
         $curr_del = (isset($d[$sname])) ? $d[$sname] : 0;
+        $errors = array();
         if ($curr_del == 1) {
             if ($ia[$sname] !== null && $ia[$sname] != '') {
                 $sql = 'UPDATE ADDRESSES SET used=? WHERE address=?';
@@ -95,6 +96,7 @@ if (isset($_REQUEST['submit_top']) || isset($_REQUEST['submit_bottom'])) {
                 array_push($errors, "Failed to delete {$sname}: {$e->getMessage()}");
             }
             if (count($errors) == 0) {
+                $made_change = true;
                 @unlink(PORT_TMPL_DIR.'/devices/'."{$sname}-ports.tmpl");
             }
             continue;
@@ -158,6 +160,7 @@ if (isset($_REQUEST['submit_top']) || isset($_REQUEST['submit_bottom'])) {
             }
         }
         if (count($errors) == 0) {
+            $made_change = true;
             if ($pexp[$sname] != $exp[$sname]) {
                 if ($exp[$sname] != '__BOGUS__') {
                     @symlink(PORT_PROFILE_DIR.'/'.$exp[$sname], PORT_TMPL_DIR.'/devices/'."{$sname}-ports.tmpl");
@@ -165,16 +168,18 @@ if (isset($_REQUEST['submit_top']) || isset($_REQUEST['submit_bottom'])) {
                     @unlink(PORT_TMPL_DIR.'/devices/'."{$sname}-ports.tmpl");
                 }
             }
-            $now = time();
-            $sql = 'UPDATE SYS_PROPERTIES SET value=? WHERE name=?';
-            try {
-                $sth = $dbh->prepare($sql);
-                $sth->execute([$now, 'last_logic_update']);
-                $sth->closeCursor();
-                $logger->info("User {$ruser} updated the last logic date");
-            } catch (PDOException $e) {
-                array_push($errors, "Failed to update the last logic update date: '{$e->getMessage()}'");
-            }
+        }
+    }
+    if ($made_change) {
+        $now = time();
+        $sql = 'UPDATE SYS_PROPERTIES SET value=? WHERE name=?';
+        try {
+            $sth = $dbh->prepare($sql);
+            $sth->execute([$now, 'last_logic_update']);
+            $sth->closeCursor();
+            $logger->info("User {$ruser} updated the last logic date");
+        } catch (PDOException $e) {
+            array_push($errors, "Failed to update the last logic update date: '{$e->getMessage()}'");
         }
     }
 }
@@ -338,7 +343,6 @@ foreach ($MDFS as $m) {
     ?>
                <option value="<?=$_SERVER['PHP_SELF']?>?filter=<?=$m?>" <?=($filter == $m) ? 'selected' : ''?>><?=$m?></option>
 <?php
-
 }
 ?>
                <option value="<?=$_SERVER['PHP_SELF']?>?filter=u" <?=($filter == 'u') ? 'selected' : ''?>>No IP Assigned</option>
@@ -347,7 +351,6 @@ foreach ($ZTP_PIDS as $spid) {
     $selected = ($filter == "pid:$spid") ? 'selected' : ''; ?>
                <option value="<?=$_SERVER['PHP_SELF']?>?filter=pid:<?=$spid?>" <?=$selected?>><?=$spid?></option>
 <?php
-
 }
 ?>
            </select></td>
@@ -373,7 +376,6 @@ foreach ($ZTP_PIDS as $spid) {
             ?>
           <input type="hidden" name="<?=$name?>" value="<?=$value?>">
 <?php
-
         }
     }
 ?>
@@ -392,7 +394,6 @@ foreach ($errors as $error) {
     ?>
           <p class="error"><?=$error?></p>
 <?php
-
 }
 ?>
         </div>
@@ -434,12 +435,10 @@ foreach ($switches as $row) {
             ?>
               <option value="__BOGUS__" <?=$selected?>>--Please Select--</option>
 <?php
-
         } else {
             ?>
               <option value="<?=$p?>" <?=$selected?>><?=$p?></option>
 <?php
-
         }
     } ?>
             </select></td>
@@ -468,7 +467,6 @@ foreach ($switches as $row) {
         } ?>
               <option value="<?=$path?>" <?=$selected?>><?=$exname?></option>
 <?php
-
     } ?>
         </select>&nbsp;<a href="#" onClick='var pp = document.getElementById("exception_<?=$name?>"); if (pp.value == "__BOGUS__") { alert("There is no port profile associated to this logical switch."); return false; } else { window.open("<?=$base?>/show_config.php?type=profile&cfg=" + pp.value + "&dname=<?=$name?>", "Config for profile " + pp.value, "height=650,width=980"); return false; }'><img src="/images/mag.gif" border="0" title="View port profile"></td>
           </tr>