+ $filepath = File::path($this->filename);
+ if (!empty($this->filename) && $this->filehash === null) {
+ // Calculate if we have an older upload method somewhere (Qvitter) that
+ // doesn't do this before calling new MediaFile on its local files...
+ $this->filehash = hash_file(File::FILEHASH_ALG, $filepath);
+ if ($this->filehash === false) {
+ throw new ServerException('Could not read file for hashing');
+ }
+ }
+
+ try {
+ $file = File::getByHash($this->filehash);
+ // We're done here. Yes. Already. We assume sha256 won't collide on us anytime soon.
+ return $file;
+ } catch (NoResultException $e) {
+ // Well, let's just continue below.
+ }
+