Clean up remote avatar temporary files if we fail before saving them into avatars directory (OMB core, OStatus, WikiHowProfile, YammerImport)
This commit is contained in:
parent
2291d68e70
commit
bca215563f
|
@ -328,6 +328,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
|
|||
function add_avatar($profile, $url)
|
||||
{
|
||||
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
|
||||
try {
|
||||
copy($url, $temp_filename);
|
||||
$imagefile = new ImageFile($profile->id, $temp_filename);
|
||||
$filename = Avatar::filename($profile->id,
|
||||
|
@ -335,6 +336,10 @@ class StatusNetOAuthDataStore extends OAuthDataStore
|
|||
null,
|
||||
common_timestamp());
|
||||
rename($temp_filename, Avatar::path($filename));
|
||||
} catch (Exception $e) {
|
||||
unlink($temp_filename);
|
||||
throw $e;
|
||||
}
|
||||
return $profile->setOriginal($filename);
|
||||
}
|
||||
|
||||
|
|
|
@ -1053,6 +1053,7 @@ class Ostatus_profile extends Memcached_DataObject
|
|||
// @fixme this should be better encapsulated
|
||||
// ripped from oauthstore.php (for old OMB client)
|
||||
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
|
||||
try {
|
||||
if (!copy($url, $temp_filename)) {
|
||||
throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
|
||||
}
|
||||
|
@ -1069,6 +1070,10 @@ class Ostatus_profile extends Memcached_DataObject
|
|||
null,
|
||||
common_timestamp());
|
||||
rename($temp_filename, Avatar::path($filename));
|
||||
} catch (Exception $e) {
|
||||
unlink($temp_filename);
|
||||
throw $e;
|
||||
}
|
||||
// @fixme hardcoded chmod is lame, but seems to be necessary to
|
||||
// keep from accidentally saving images from command-line (queues)
|
||||
// that can't be read from web server, which causes hard-to-notice
|
||||
|
|
|
@ -174,6 +174,7 @@ 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');
|
||||
try {
|
||||
if (!copy($url, $temp_filename)) {
|
||||
throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
|
||||
}
|
||||
|
@ -188,6 +189,10 @@ class WikiHowProfilePlugin extends Plugin
|
|||
null,
|
||||
common_timestamp());
|
||||
rename($temp_filename, Avatar::path($filename));
|
||||
} catch (Exception $e) {
|
||||
unlink($temp_filename);
|
||||
throw $e;
|
||||
}
|
||||
$profile->setOriginal($filename);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -436,6 +436,7 @@ class YammerImporter
|
|||
// @fixme this should be better encapsulated
|
||||
// ripped from oauthstore.php (for old OMB client)
|
||||
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
|
||||
try {
|
||||
if (!copy($url, $temp_filename)) {
|
||||
throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
|
||||
}
|
||||
|
@ -448,6 +449,10 @@ class YammerImporter
|
|||
null,
|
||||
common_timestamp());
|
||||
rename($temp_filename, Avatar::path($filename));
|
||||
} catch (Exception $e) {
|
||||
unlink($temp_filename);
|
||||
throw $e;
|
||||
}
|
||||
// @fixme hardcoded chmod is lame, but seems to be necessary to
|
||||
// keep from accidentally saving images from command-line (queues)
|
||||
// that can't be read from web server, which causes hard-to-notice
|
||||
|
|
Loading…
Reference in New Issue
Block a user