X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FFile.php;h=80fbdb181c72c3a313271f5d35c825d4602d0b98;hb=2892f70d18065e1478c729f2de96218c9500e2df;hp=f716a9d64cfa6eadcb18e81f3a39b9b03e8d23bd;hpb=9948523c33ea0d02681ff1e0cd4fcb839dc9df96;p=quix0rs-gnu-social.git diff --git a/classes/File.php b/classes/File.php index f716a9d64c..80fbdb181c 100644 --- a/classes/File.php +++ b/classes/File.php @@ -85,14 +85,22 @@ class File extends Managed_DataObject * @return File */ function saveNew(array $redir_data, $given_url) { - $x = new File; - $x->url = $given_url; - if (!empty($redir_data['protected'])) $x->protected = $redir_data['protected']; - if (!empty($redir_data['title'])) $x->title = $redir_data['title']; - if (!empty($redir_data['type'])) $x->mimetype = $redir_data['type']; - if (!empty($redir_data['size'])) $x->size = intval($redir_data['size']); - if (isset($redir_data['time']) && $redir_data['time'] > 0) $x->date = intval($redir_data['time']); - $file_id = $x->insert(); + + // I don't know why we have to keep doing this but I'm adding this last check to avoid + // uniqueness bugs. + + $x = File::staticGet('url', $given_url); + + if (empty($x)) { + $x = new File; + $x->url = $given_url; + if (!empty($redir_data['protected'])) $x->protected = $redir_data['protected']; + if (!empty($redir_data['title'])) $x->title = $redir_data['title']; + if (!empty($redir_data['type'])) $x->mimetype = $redir_data['type']; + if (!empty($redir_data['size'])) $x->size = intval($redir_data['size']); + if (isset($redir_data['time']) && $redir_data['time'] > 0) $x->date = intval($redir_data['time']); + $file_id = $x->insert(); + } $x->saveOembed($redir_data, $given_url); return $x; @@ -192,7 +200,7 @@ class File extends Managed_DataObject } if (empty($x)) { - $x = File::staticGet($file_id); + $x = File::staticGet('id', $file_id); if (empty($x)) { // @todo FIXME: This could possibly be a clearer message :) // TRANS: Server exception thrown when... Robin thinks something is impossible!