Add defaults to Server, getting rid of error log when loading the default non existent storage area
This commit is contained in:
parent
246b50be9c
commit
5dc852132e
|
@ -3,15 +3,27 @@ require_once('database.php');
|
||||||
|
|
||||||
$storage_cache = array();
|
$storage_cache = array();
|
||||||
class Storage {
|
class Storage {
|
||||||
|
private $defaults = array(
|
||||||
|
'Id' => null,
|
||||||
|
'Path' => '',
|
||||||
|
'Name' => '',
|
||||||
|
'Type' => 'local',
|
||||||
|
'Url' => '',
|
||||||
|
'DiskSpace' => null,
|
||||||
|
'Scheme' => 'Medium',
|
||||||
|
'ServerId' => 0,
|
||||||
|
'DoDelete' => 1,
|
||||||
|
);
|
||||||
|
|
||||||
public function __construct( $IdOrRow = NULL ) {
|
public function __construct( $IdOrRow = NULL ) {
|
||||||
global $storage_cache;
|
global $storage_cache;
|
||||||
|
|
||||||
$row = NULL;
|
$row = NULL;
|
||||||
if ( $IdOrRow ) {
|
if ( $IdOrRow ) {
|
||||||
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
|
if ( is_integer($IdOrRow) or is_numeric($IdOrRow) ) {
|
||||||
$row = dbFetchOne( 'SELECT * FROM Storage WHERE Id=?', NULL, array( $IdOrRow ) );
|
$row = dbFetchOne('SELECT * FROM Storage WHERE Id=?', NULL, array($IdOrRow));
|
||||||
if ( ! $row ) {
|
if ( ! $row ) {
|
||||||
Error("Unable to load Storage record for Id=" . $IdOrRow );
|
Error('Unable to load Storage record for Id=' . $IdOrRow);
|
||||||
}
|
}
|
||||||
} else if ( is_array($IdOrRow) ) {
|
} else if ( is_array($IdOrRow) ) {
|
||||||
$row = $IdOrRow;
|
$row = $IdOrRow;
|
||||||
|
@ -59,7 +71,13 @@ class Storage {
|
||||||
if ( array_key_exists($fn, $this) )
|
if ( array_key_exists($fn, $this) )
|
||||||
return $this->{$fn};
|
return $this->{$fn};
|
||||||
|
|
||||||
|
if ( array_key_exists( $fn, $this->defaults ) )
|
||||||
|
return $this->defaults{$fn};
|
||||||
|
|
||||||
$backTrace = debug_backtrace();
|
$backTrace = debug_backtrace();
|
||||||
|
$file = $backTrace[0]['file'];
|
||||||
|
$line = $backTrace[0]['line'];
|
||||||
|
Warning("Unknown function call Storage->$fn from $file:$line");
|
||||||
$file = $backTrace[1]['file'];
|
$file = $backTrace[1]['file'];
|
||||||
$line = $backTrace[1]['line'];
|
$line = $backTrace[1]['line'];
|
||||||
Warning("Unknown function call Storage->$fn from $file:$line");
|
Warning("Unknown function call Storage->$fn from $file:$line");
|
||||||
|
@ -73,6 +91,7 @@ class Storage {
|
||||||
isset($storage_cache[$parameters['Id']]) ) {
|
isset($storage_cache[$parameters['Id']]) ) {
|
||||||
return $storage_cache[$parameters['Id']];
|
return $storage_cache[$parameters['Id']];
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = Storage::find($parameters, $options);
|
$results = Storage::find($parameters, $options);
|
||||||
if ( count($results) > 1 ) {
|
if ( count($results) > 1 ) {
|
||||||
Error("Storage Returned more than 1");
|
Error("Storage Returned more than 1");
|
||||||
|
@ -111,12 +130,12 @@ class Storage {
|
||||||
} # end if options
|
} # end if options
|
||||||
if ( isset($options['limit']) ) {
|
if ( isset($options['limit']) ) {
|
||||||
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
||||||
$sql .= ' LIMIT ' . $limit;
|
$sql .= ' LIMIT ' . $option['limit'];
|
||||||
} else {
|
} else {
|
||||||
$backTrace = debug_backtrace();
|
$backTrace = debug_backtrace();
|
||||||
$file = $backTrace[1]['file'];
|
$file = $backTrace[1]['file'];
|
||||||
$line = $backTrace[1]['line'];
|
$line = $backTrace[1]['line'];
|
||||||
Error("Invalid value for limit($limit) passed to Control::find from $file:$line");
|
Error("Invalid value for limit(".$options['limit'].") passed to Control::find from $file:$line");
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
} # end if limit
|
} # end if limit
|
||||||
|
@ -124,9 +143,9 @@ class Storage {
|
||||||
$storage_areas = array();
|
$storage_areas = array();
|
||||||
$result = dbQuery($sql, $values);
|
$result = dbQuery($sql, $values);
|
||||||
if ( $result ) {
|
if ( $result ) {
|
||||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Storage');
|
$results = $result->fetchALL();
|
||||||
foreach ( $results as $row => $obj ) {
|
foreach ( $results as $row ) {
|
||||||
$storage_areas[] = $obj;
|
$storage_areas[] = new Storage($row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $storage_areas;
|
return $storage_areas;
|
||||||
|
|
Loading…
Reference in New Issue