add fileSize to the api, and use it to add remote fileSize reporting in includes/Event
This commit is contained in:
parent
e7bd5900bc
commit
62edca6dcb
|
@ -126,6 +126,7 @@ class EventsController extends AppController {
|
||||||
$event['Event']['Prev'] = $event_neighbors['prev']['Event']['Id'];
|
$event['Event']['Prev'] = $event_neighbors['prev']['Event']['Id'];
|
||||||
|
|
||||||
$event['Event']['fileExists'] = $this->Event->fileExists($event['Event']);
|
$event['Event']['fileExists'] = $this->Event->fileExists($event['Event']);
|
||||||
|
$event['Event']['fileSize'] = $this->Event->fileSize($event['Event']);
|
||||||
|
|
||||||
# Also get the previous and next events for the same monitor
|
# Also get the previous and next events for the same monitor
|
||||||
$event_monitor_neighbors = $this->Event->find('neighbors', array(
|
$event_monitor_neighbors = $this->Event->find('neighbors', array(
|
||||||
|
|
|
@ -115,13 +115,13 @@ class Event extends AppModel {
|
||||||
} // end function Relative_Path()
|
} // end function Relative_Path()
|
||||||
|
|
||||||
|
|
||||||
public function fileExists( $event ) {
|
public function fileExists($event) {
|
||||||
//$data = $this->findById($id);
|
//$data = $this->findById($id);
|
||||||
//return $data['Event']['dataset_filename'];
|
//return $data['Event']['dataset_filename'];
|
||||||
$storage = $this->Storage->findById( $event['StorageId'] );
|
$storage = $this->Storage->findById($event['StorageId']);
|
||||||
|
|
||||||
if ( $event['DefaultVideo'] ) {
|
if ( $event['DefaultVideo'] ) {
|
||||||
if ( file_exists( $storage['Storage']['Path'].'/'.$this->Relative_Path($event).'/'.$event['DefaultVideo'] ) ) {
|
if ( file_exists($storage['Storage']['Path'].'/'.$this->Relative_Path($event).'/'.$event['DefaultVideo']) ) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
Logger::Debug("FIle does not exist at " . $storage['Storage']['Path'].'/'.$this->Relative_Path($event).'/'.$event['DefaultVideo'] );
|
Logger::Debug("FIle does not exist at " . $storage['Storage']['Path'].'/'.$this->Relative_Path($event).'/'.$event['DefaultVideo'] );
|
||||||
|
@ -130,5 +130,10 @@ class Event extends AppModel {
|
||||||
Logger::Debug("No DefaultVideo in Event" . $this->Event);
|
Logger::Debug("No DefaultVideo in Event" . $this->Event);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
} // end function fileExists($event)
|
||||||
|
|
||||||
|
public function fileSize($event) {
|
||||||
|
$storage = $this->Storage->findById($event['StorageId']);
|
||||||
|
return filesize($storage['Storage']['Path'].'/'.$this->Relative_Path($event).'/'.$event['DefaultVideo']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit c3976f1478c681b0bbc132ec3a3e82c3984eeed5
|
Subproject commit 0bd63fb464957080ead342db58ca9e01532cf1ef
|
|
@ -566,6 +566,50 @@ class Event {
|
||||||
return false;
|
return false;
|
||||||
} # end public function file_exists()
|
} # end public function file_exists()
|
||||||
|
|
||||||
|
public function file_size() {
|
||||||
|
if ( file_exists($this->Path().'/'.$this->DefaultVideo()) ) {
|
||||||
|
return filesize($this->Path().'/'.$this->DefaultVideo());
|
||||||
|
}
|
||||||
|
$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']['fileSize'];
|
||||||
|
} catch ( Exception $e ) {
|
||||||
|
Error("Except $e thrown trying to get event data");
|
||||||
|
}
|
||||||
|
} # end if not local
|
||||||
|
return 0;
|
||||||
|
} # end public function file_size()
|
||||||
|
|
||||||
} # end class
|
} # end class
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -105,7 +105,7 @@ while( $event = $result->fetch(PDO::FETCH_ASSOC) ) {
|
||||||
} # end if has previous events
|
} # end if has previous events
|
||||||
if ( ! $Event->file_exists() ) {
|
if ( ! $Event->file_exists() ) {
|
||||||
$EventsByMonitor[$event['MonitorId']]['FileMissing'][] = $Event;
|
$EventsByMonitor[$event['MonitorId']]['FileMissing'][] = $Event;
|
||||||
} else if ( ! filesize( $Event->Path().'/'.$Event->DefaultVideo() ) ) {
|
} else if ( ! $Event->file_size() ) {
|
||||||
$EventsByMonitor[$event['MonitorId']]['ZeroSize'][] = $Event;
|
$EventsByMonitor[$event['MonitorId']]['ZeroSize'][] = $Event;
|
||||||
}
|
}
|
||||||
$EventsByMonitor[$event['MonitorId']]['Events'][] = $Event;
|
$EventsByMonitor[$event['MonitorId']]['Events'][] = $Event;
|
||||||
|
|
Loading…
Reference in New Issue