I like to throw exceptions instead of using if statements.
This commit is contained in:
parent
06b25f384a
commit
979c525124
@ -194,10 +194,14 @@ class File extends Managed_DataObject
|
||||
}
|
||||
|
||||
$redir = File_redirection::where($given_url);
|
||||
try {
|
||||
$file = $redir->getFile();
|
||||
|
||||
if (!$file instanceof File || empty($file->id)) {
|
||||
} catch (EmptyPkeyValueException $e) {
|
||||
common_log(LOG_ERR, 'File_redirection::where gave object with empty file_id for given_url '._ve($given_url));
|
||||
throw new ServerException('URL processing failed without new File object');
|
||||
} catch (NoResultException $e) {
|
||||
// This should not happen
|
||||
common_log(LOG_ERR, 'File_redirection after discovery could still not return a File object.');
|
||||
throw new ServerException('URL processing failed without new File object');
|
||||
}
|
||||
|
||||
|
@ -445,8 +445,8 @@ class File_redirection extends Managed_DataObject
|
||||
}
|
||||
|
||||
public function getFile() {
|
||||
if(empty($this->file) && $this->file_id) {
|
||||
$this->file = File::getKV('id', $this->file_id);
|
||||
if (!$this->file instanceof File) {
|
||||
$this->file = File::getByID($this->file_id);
|
||||
}
|
||||
|
||||
return $this->file;
|
||||
|
Loading…
Reference in New Issue
Block a user