From eade5316b981be26cacccc2ff29e2f897b0fc30e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 20 Mar 2018 12:18:07 -0700 Subject: [PATCH] Move Monitor delete logic to the object. Don't fixSequences when deleting monitors --- web/includes/Monitor.php | 31 +++++++++++++++++++++++++++++++ web/includes/actions.php | 37 ++++++++----------------------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php index 52031824c..b3c47350d 100644 --- a/web/includes/Monitor.php +++ b/web/includes/Monitor.php @@ -405,5 +405,36 @@ Logger::Debug("sending command to $url"); } return $this->{'GroupIds'}; } + public function delete() { + $this->zmaControl('stop'); + $this->zmcControl('stop'); + + // If fast deletes are on, then zmaudit will clean everything else up later + // If fast deletes are off and there are lots of events then this step may + // well time out before completing, in which case zmaudit will still tidy up + if ( !ZM_OPT_FAST_DELETE ) { + $markEids = dbFetchAll('SELECT Id FROM Events WHERE MonitorId=?', 'Id', array($markMid)); + foreach($markEids as $markEid) + deleteEvent( $markEid ); + + deletePath(ZM_DIR_EVENTS.'/'.basename($this->{'Name'})); + deletePath(ZM_DIR_EVENTS.'/'.$this->{'Id'}); + $Storage = $this->Storage(); + if ( $Storage->Path() != ZM_DIR_EVENTS ) { + deletePath($Storage>Path().'/'.basename($this->{'Name'})); + deletePath($Storage->Path().'/'.$this->{'Id'}); + } + } // end if ZM_OPT_FAST_DELETE + + // This is the important stuff + dbQuery('DELETE FROM Zones WHERE MonitorId = ?', array($this->{'Id'})); + if ( ZM_OPT_X10 ) + dbQuery('DELETE FROM TriggersX10 WHERE MonitorId=?', array($this->{'Id'})); + dbQuery('DELETE FROM Monitors WHERE Id = ?', array($this->{'Id'})); + + // Deleting a Monitor does not affect the order, just creates a gap in the sequence. Who cares? + // fixSequences(); + + } // end function delete } // end class Monitor ?> diff --git a/web/includes/actions.php b/web/includes/actions.php index 02c0592ae..51737a67b 100644 --- a/web/includes/actions.php +++ b/web/includes/actions.php @@ -195,7 +195,6 @@ if ( canView( 'Events' ) ) { $_REQUEST['Id'] = dbInsertId(); } if ( $action == 'execute' ) { -session_write_close(); executeFilter( $tempFilterName ); } @@ -618,35 +617,14 @@ if ( canEdit( 'Monitors' ) ) { $view = 'none'; } elseif ( $action == 'delete' ) { if ( isset($_REQUEST['markMids']) && !$user['MonitorIds'] ) { + require_once( 'Monitor.php' ); foreach( $_REQUEST['markMids'] as $markMid ) { - if ( canEdit( 'Monitors', $markMid ) ) { + if ( canEdit('Monitors', $markMid) ) { + // This could be faster as a select all if ( $monitor = dbFetchOne( 'SELECT * FROM Monitors WHERE Id = ?', NULL, array($markMid) ) ) { - if ( daemonCheck() ) { - zmaControl( $monitor, 'stop' ); - zmcControl( $monitor, 'stop' ); - } - - // If fast deletes are on, then zmaudit will clean everything else up later - // If fast deletes are off and there are lots of events then this step may - // well time out before completing, in which case zmaudit will still tidy up - if ( !ZM_OPT_FAST_DELETE ) { - $markEids = dbFetchAll( 'SELECT Id FROM Events WHERE MonitorId=?', 'Id', array($markMid) ); - foreach( $markEids as $markEid ) - deleteEvent( $markEid ); - - deletePath( ZM_DIR_EVENTS.'/'.basename($monitor['Name']) ); - deletePath( ZM_DIR_EVENTS.'/'.$monitor['Id'] ); // I'm trusting the Id. - } // end if ZM_OPT_FAST_DELETE - - // This is the important stuff - dbQuery( 'DELETE FROM Zones WHERE MonitorId = ?', array($markMid) ); - if ( ZM_OPT_X10 ) - dbQuery( 'DELETE FROM TriggersX10 WHERE MonitorId=?', array($markMid) ); - dbQuery( 'DELETE FROM Monitors WHERE Id = ?', array($markMid) ); - - fixSequences(); - - } // end if found the monitor in the db + $Monitor = new Monitor($monitor); + $Monitor->delete(); + } // end if monitor found in db } // end if canedit this monitor } // end foreach monitor in MarkMid } // markMids is set and we aren't limited to specific monitors @@ -993,9 +971,10 @@ if ( canEdit( 'System' ) ) { } if ( $action == 'reset' ) { + session_start(); $_SESSION['zmEventResetTime'] = strftime( STRF_FMT_DATETIME_DB ); setcookie( 'zmEventResetTime', $_SESSION['zmEventResetTime'], time()+3600*24*30*12*10 ); - //if ( $cookies ) session_write_close(); + session_write_close(); } ?>