getKV doesn't throw exception

This commit is contained in:
hannes 2016-02-16 19:16:05 +00:00
parent f708a5b016
commit 501d081d3b

View File

@ -170,19 +170,22 @@ class File_redirection extends Managed_DataObject
try { try {
$r = File_redirection::getByUrl($in_url); $r = File_redirection::getByUrl($in_url);
try {
$f = File::getKV('id',$r->file_id); $f = File::getKV('id',$r->file_id);
if($file instanceof File) {
$r->file = $f; $r->file = $f;
$r->redir_url = $f->url; $r->redir_url = $f->url;
} catch (NoResultException $e) { } else {
// Invalid entry, delete and run again // Invalid entry, delete and run again
common_log(LOG_ERR, "Could not find File with id=".$r->file_id." referenced in File_redirection, deleting File redirection entry and and trying again..."); common_log(LOG_ERR, "Could not find File with id=".$r->file_id." referenced in File_redirection, deleting File redirection entry and and trying again...");
$r->delete(); $r->delete();
return self::where($in_url); return self::where($in_url);
} }
// File_redirecion and File record found, return both // File_redirecion and File record found, return both
return $r; return $r;
} catch (NoResultException $e) { } catch (NoResultException $e) {
// File_redirecion record not found, but this might be a direct link to a file // File_redirecion record not found, but this might be a direct link to a file
try { try {
@ -207,15 +210,17 @@ class File_redirection extends Managed_DataObject
// in that case we have the file id already // in that case we have the file id already
try { try {
$r = File_redirection::getByUrl($redir_info['url']); $r = File_redirection::getByUrl($redir_info['url']);
try {
$f = File::getKV('id',$r->file_id); $f = File::getKV('id',$r->file_id);
if($f instanceof File) {
$redir->file = $f; $redir->file = $f;
$redir->redir_url = $f->url; $redir->redir_url = $f->url;
} catch (NoResultException $e) { } else {
// Invalid entry in File_redirection, delete and run again // Invalid entry in File_redirection, delete and run again
common_log(LOG_ERR, "Could not find File with id=".$r->file_id." referenced in File_redirection, deleting File_redirection entry and trying again..."); common_log(LOG_ERR, "Could not find File with id=".$r->file_id." referenced in File_redirection, deleting File_redirection entry and trying again...");
$r->delete(); $r->delete();
return self::where($in_url); return self::where($in_url);
} }
} catch (NoResultException $e) { } catch (NoResultException $e) {
// save the file now when we know that we don't have it in File_redirection // save the file now when we know that we don't have it in File_redirection