- Timestamp:
- Oct 25, 2017, 10:55:05 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php
r841 r852 42 42 } 43 43 44 $this->Database->query('BEGIN'); 45 44 $Queries = array(); 46 45 foreach($Interfaces as $Index => $Interface) 47 46 { 48 47 // Update last online time if still online 49 48 if($Interface['NewOnline']) 50 $ DbResult = $this->Database->update('NetworkInterface', '`Id` = "'.$Interface['Id'].'"',49 $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = "'.$Interface['Id'].'"', 51 50 array('LastOnline' => TimeToMysqlDateTime($StartTime))); 52 51 … … 54 53 { 55 54 // Online state changed 56 $ DbResult = $this->Database->query('INSERT INTO `NetworkInterfaceUpDown` (`Interface`,55 $Queries[] = 'INSERT INTO `NetworkInterfaceUpDown` (`Interface`, 57 56 `State`, `Time`, `Duration`) VALUES ('.$Interface['Id'].', '.$Interface['NewOnline'].', "'. 58 TimeToMysqlDateTime($StartTime).'", NULL)' );57 TimeToMysqlDateTime($StartTime).'", NULL)'; 59 58 // Update previous record duration in UpDown table 60 $ this->Database->query('UPDATE `NetworkInterfaceUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '.59 $Queries[] = 'UPDATE `NetworkInterfaceUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '. 61 60 '`TM`.`Time`, (SELECT `Time` FROM (SELECT * FROM `NetworkInterfaceUpDown`) AS `TA` WHERE (`TA`.`Time` > `TM`.`Time`) '. 62 61 'AND (`TA`.`Interface`=`TM`.`Interface`) ORDER BY `TA`.`Time` ASC LIMIT 1)) '. 63 'WHERE (`TM`.`Duration` IS NULL) AND (`TM`.`Interface` ='.$Interface['Id'].')' );64 $ this->Database->update('NetworkInterface', '`Id` = "'.$Interface['Id'].'"',62 'WHERE (`TM`.`Duration` IS NULL) AND (`TM`.`Interface` ='.$Interface['Id'].')'; 63 $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = "'.$Interface['Id'].'"', 65 64 array('Online' => $Interface['NewOnline'])); 66 65 } 67 66 } 67 $this->Database->Transaction($Queries); 68 68 69 69 // Set offline all interfaces which were not updated as online … … 81 81 } 82 82 83 $Queries = array(); 83 84 // Update device online state 84 85 $DbResult = $this->Database->select('NetworkInterface', '`Device`, SUM(`Online`) AS `SumOnline`', '`Online` = 1 GROUP BY `Device`'); … … 86 87 { 87 88 if($Device['SumOnline'] > 0) 88 $ this->Database->update('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime), 'Online' => 1));89 $Queries[] = $this->Database->GetUpdate('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime), 'Online' => 1)); 89 90 } 90 $this->Database->update('NetworkDevice', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0)); 91 92 $this->Database->query('COMMIT'); 91 $Queries[] = $this->Database->GetUpdate('NetworkDevice', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0)); 92 $this->Database->Transaction($Queries); 93 93 } 94 94
Note:
See TracChangeset
for help on using the changeset viewer.