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:
Stephen Paul Weber
2015-11-02 05:15:08 +00:00
parent 2c8536dbf0
commit a9b1b60a97
6 changed files with 96 additions and 143 deletions

View File

@@ -987,20 +987,9 @@ function common_linkify($url) {
$canon = "mailto:$url";
$longurl = "mailto:$url";
} else {
$canon = File_redirection::_canonUrl($url);
$longurl_data = File_redirection::where($canon, common_config('attachments', 'process_links'));
if (is_array($longurl_data)) {
$longurl = $longurl_data['url'];
} elseif (is_string($longurl_data)) {
$longurl = $longurl_data;
} else {
// Unable to reach the server to verify contents, etc
// Just pass the link on through for now.
common_log(LOG_ERR, "Can't linkify url '$url'");
$longurl = $url;
}
$longurl = $longurl_data->url;
}
$attrs = array('href' => $canon, 'title' => $longurl);