+ if ($discover) {
+ $redir_info = File_redirection::lookupWhere($in_url);
+ if(is_string($redir_info)) {
+ $redir_info = array('url' => $redir_info);
+ }
+
+ // Save the file if we don't have it already
+ $redir->file = File::saveNew($redir_info,$redir_info['url']);
+
+ // If this is a redirection, save it
+ // (if it hasn't been saved yet by some other process while we we
+ // were running lookupWhere())
+ if($redir_info['url'] != $in_url) {
+ try {
+ $file_redir = File_redirection::getByUrl($in_url);
+ } catch (NoResultException $e) {
+ $file_redir = new File_redirection();
+ $file_redir->urlhash = File::hashurl($in_url);
+ $file_redir->url = $in_url;
+ $file_redir->file_id = $redir->file->getID();
+ $file_redir->insert();
+ $file_redir->redir_url = $redir->file->url;
+ }
+
+ $file_redir->file = $redir->file;
+ return $file_redir;
+ }