diff options
author | Brion Vibber <brion@pobox.com> | 2010-10-13 11:04:41 -0700 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-10-13 11:10:04 -0700 |
commit | bca215563ff7aaee5c253b3a55cadc3b02116ef9 (patch) | |
tree | 9368ba6a3a4c350180b8dcf798367a1b1f9f13d7 /plugins/WikiHowProfile | |
parent | 2291d68e7019d04ae57f8cb408c42fc775a9a9ff (diff) |
Clean up remote avatar temporary files if we fail before saving them into avatars directory (OMB core, OStatus, WikiHowProfile, YammerImport)
Diffstat (limited to 'plugins/WikiHowProfile')
-rw-r--r-- | plugins/WikiHowProfile/WikiHowProfilePlugin.php | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/plugins/WikiHowProfile/WikiHowProfilePlugin.php b/plugins/WikiHowProfile/WikiHowProfilePlugin.php index fa683c483..753dff5a3 100644 --- a/plugins/WikiHowProfile/WikiHowProfilePlugin.php +++ b/plugins/WikiHowProfile/WikiHowProfilePlugin.php @@ -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); } } |