From 9127eb63dc6c8ef2ddb1bbedc0a6de92d6c1cf2b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 7 May 2018 14:07:30 -0700 Subject: [PATCH] Implement file_exists function to determine either locally or through remote api calls whether the file for an event exists. --- web/includes/Event.php | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/web/includes/Event.php b/web/includes/Event.php index dbf7f00ff..db55506fe 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -522,6 +522,50 @@ class Event { return ''.$text.''; } + public function file_exists() { + if ( file_exists( $this->Path().'/'.$this->DefaultVideo() ) ) { + return true; + } + $Storage= $this->Storage(); + $Server = $Storage->ServerId() ? $Storage->Server() : $this->Monitor()->Server(); + if ( $Server->Id() != ZM_SERVER_ID ) { + + $url = $Server->Url() . '/zm/api/events/'.$this->{'Id'}.'.json'; + if ( ZM_OPT_USE_AUTH ) { + if ( ZM_AUTH_RELAY == 'hashed' ) { + $url .= '?auth='.generateAuthHash( ZM_AUTH_HASH_IPS ); + } elseif ( ZM_AUTH_RELAY == 'plain' ) { + $url = '?user='.$_SESSION['username']; + $url = '?pass='.$_SESSION['password']; + } elseif ( ZM_AUTH_RELAY == 'none' ) { + $url = '?user='.$_SESSION['username']; + } + } + Logger::Debug("sending command to $url"); + // use key 'http' even if you send the request to https://... + $options = array( + 'http' => array( + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", + 'method' => 'GET', + 'content' => '' + ) + ); + $context = stream_context_create($options); + try { + $result = file_get_contents($url, false, $context); + if ($result === FALSE) { /* Handle error */ + Error("Error restarting zmc using $url"); + } + $event_data = json_decode($result,true); + Logger::Debug(print_r($event_data['event']['Event'],1)); + return $event_data['event']['Event']['fileExists']; + } catch ( Exception $e ) { + Error("Except $e thrown trying to get event data"); + } + } # end if not local + return false; + } # end public function file_exists() + } # end class ?>