Merge sjc04p1fviap02.teslamotors.com:ZoneMinder into storageareas

This commit is contained in:
Isaac Connor 2017-10-10 13:41:32 -04:00
commit 9cbcc43e3d
4 changed files with 22 additions and 11 deletions

View File

@ -1,7 +1,7 @@
<?php
class Event {
public function __construct( $IdOrRow ) {
public function __construct( $IdOrRow = null ) {
$row = NULL;
if ( $IdOrRow ) {
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
@ -19,15 +19,18 @@ class Event {
Error("Unknown argument passed to Event Constructor ($IdOrRow)");
return;
}
} # end if isset($IdOrRow)
if ( $row ) {
foreach ($row as $k => $v) {
$this->{$k} = $v;
}
} else {
Error('No row for Event ' . $IdOrRow );
$backTrace = debug_backtrace();
$file = $backTrace[1]['file'];
$line = $backTrace[1]['line'];
Error('No row for Event ' . $IdOrRow . " from $file:$line");
}
} # end if isset($IdOrRow)
} // end function __construct
public function Storage() {
@ -163,11 +166,11 @@ class Event {
} // end function getStreamSrc
function DiskSpace() {
if ( null == $this{'DiskSpace'} ) {
$this{'DiskSpace'} = folder_size( $this->Path() );
if ( null == $this->{'DiskSpace'} ) {
$this->{'DiskSpace'} = folder_size( $this->Path() );
dbQuery( 'UPDATE Events SET DiskSpace=? WHERE Id=?', array( $this->{'DiskSpace'}, $this->{'Id'} ) );
}
return $this{'DiskSpace'};
return $this->{'DiskSpace'};
}
function createListThumbnail( $overwrite=false ) {

View File

@ -1,14 +1,21 @@
<?php
require_once( 'database.php' );
$storage_cache = array();
class Storage {
public function __construct( $IdOrRow = NULL ) {
$row = NULL;
if ( $IdOrRow ) {
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
if ( isset( $storage_cache[$IdOrRow] ) ) {
return $storage_cache[$IdOrRow];
} else {
$row = dbFetchOne( 'SELECT * FROM Storage WHERE Id=?', NULL, array( $IdOrRow ) );
if ( ! $row ) {
Error("Unable to load Storage record for Id=" . $IdOrRow );
}
}
} elseif ( is_array( $IdOrRow ) ) {
$row = $IdOrRow;
}
@ -17,6 +24,7 @@ class Storage {
foreach ($row as $k => $v) {
$this->{$k} = $v;
}
$storage_cache[$IdOrRow] = $this;
} else {
$this->{'Name'} = '';
$this->{'Path'} = '';

View File

@ -127,10 +127,10 @@ function dbQuery( $sql, $params=NULL ) {
} else {
$result = $dbConn->query( $sql );
}
//if ( $params )
//Warning("SQL: $sql" . implode(',',$params));
//else
//Warning("SQL: $sql" );
if ( $params )
Warning("SQL: $sql" . implode(',',$params));
else
Warning("SQL: $sql" );
} catch(PDOException $e) {
Fatal( "SQL-ERR '".$e->getMessage()."', statement was '".$sql."'" );
}

View File

@ -2197,7 +2197,7 @@ function getStreamMode( ) {
function folder_size($dir) {
$size = 0;
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
$size += is_file($each) ? filesize($each) : folderSize($each);
$size += is_file($each) ? filesize($each) : folder_size($each);
}
return $size;
} // end function folder_size