forked from GNUsocial/gnu-social
Refactor on File::processNew
The code was so involved there was even a comment asking for a refactor. Now, File_redirection::where always returns a nice File_redirection object instead of an array or string or nothing. The object is either one which already existed or else a new, unsaved object. Instead of duplicating "does it exist" checks everywhere, do it in File_redirection::where. You either get what exists or something to save. An unsaved File_redirection may be paired with an unsaved File. You will want to save the File first (using ->saveFile()) and put the id in File_redirection#file_id before saving.
This commit is contained in:
@@ -128,12 +128,12 @@ class File_oembed extends Managed_DataObject
|
||||
if ($file instanceof File) {
|
||||
$file_oembed->mimetype = $file->mimetype;
|
||||
} else {
|
||||
$file_redir = File_redirection::getKV('url', $given_url);
|
||||
if (empty($file_redir)) {
|
||||
$redir_data = File_redirection::where($given_url);
|
||||
$file_oembed->mimetype = $redir_data['type'];
|
||||
$redir = File_redirection::where($given_url);
|
||||
if (empty($redir->file_id)) {
|
||||
$f = $redir->getFile();
|
||||
$file_oembed->mimetype = $f->mimetype;
|
||||
} else {
|
||||
$file_id = $file_redir->file_id;
|
||||
$file_id = $redir->file_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user