- $redir_data = File_redirection::where($long_url);
- if (is_array($redir_data)) {
- // We haven't seen the target URL before.
- // Save file and embedding data about it!
- $file = File::saveNew($redir_data, $long_url);
- $file_id = $file->getID();
- } else if (is_string($redir_data)) {
- // The file is a known redirect target.
- $file = File::getKV('url', $redir_data);
- if (empty($file)) {
- // @fixme should we save a new one?
- // this case was triggering sometimes for redirects
- // with unresolvable targets; found while fixing
- // "can't linkify" bugs with shortened links to
- // SSL sites with cert issues.
- return null;
- }
- $file_id = $file->getID();
+ $redir = File_redirection::where($long_url);
+ $file = $redir->getFile();
+ if (empty($file->id)) {
+ $file->saveFile();