]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/WikiHowProfile/WikiHowProfilePlugin.php
Clean up remote avatar temporary files if we fail before saving them into avatars...
[quix0rs-gnu-social.git] / plugins / WikiHowProfile / WikiHowProfilePlugin.php
index fa683c4836e7dc643246c43cd11acac2bd9df7a3..753dff5a375e65453b666cb6c4297e0279c32c48 100644 (file)
@@ -174,20 +174,25 @@ class WikiHowProfilePlugin extends Plugin
         // @fixme this should be better encapsulated
         // ripped from OStatus via oauthstore.php (for old OMB client)
         $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
-        if (!copy($url, $temp_filename)) {
-            throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
-        }
-
-        $profile = $user->getProfile();
-        $id = $profile->id;
-        // @fixme should we be using different ids?
+        try {
+            if (!copy($url, $temp_filename)) {
+                throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
+            }
 
-        $imagefile = new ImageFile($id, $temp_filename);
-        $filename = Avatar::filename($id,
-                                     image_type_to_extension($imagefile->type),
-                                     null,
-                                     common_timestamp());
-        rename($temp_filename, Avatar::path($filename));
+            $profile = $user->getProfile();
+            $id = $profile->id;
+            // @fixme should we be using different ids?
+
+            $imagefile = new ImageFile($id, $temp_filename);
+            $filename = Avatar::filename($id,
+                                         image_type_to_extension($imagefile->type),
+                                         null,
+                                         common_timestamp());
+            rename($temp_filename, Avatar::path($filename));
+        } catch (Exception $e) {
+            unlink($temp_filename);
+            throw $e;
+        }
         $profile->setOriginal($filename);
     }
 }