forked from GNUsocial/gnu-social
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,13 +328,18 @@ class StatusNetOAuthDataStore extends OAuthDataStore
|
||||
function add_avatar($profile, $url)
|
||||
{
|
||||
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
|
||||
copy($url, $temp_filename);
|
||||
$imagefile = new ImageFile($profile->id, $temp_filename);
|
||||
$filename = Avatar::filename($profile->id,
|
||||
image_type_to_extension($imagefile->type),
|
||||
null,
|
||||
common_timestamp());
|
||||
rename($temp_filename, Avatar::path($filename));
|
||||
try {
|
||||
copy($url, $temp_filename);
|
||||
$imagefile = new ImageFile($profile->id, $temp_filename);
|
||||
$filename = Avatar::filename($profile->id,
|
||||
image_type_to_extension($imagefile->type),
|
||||
null,
|
||||
common_timestamp());
|
||||
rename($temp_filename, Avatar::path($filename));
|
||||
} catch (Exception $e) {
|
||||
unlink($temp_filename);
|
||||
throw $e;
|
||||
}
|
||||
return $profile->setOriginal($filename);
|
||||
}
|
||||
|
||||
|
@ -1053,22 +1053,27 @@ 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');
|
||||
if (!copy($url, $temp_filename)) {
|
||||
throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
|
||||
}
|
||||
try {
|
||||
if (!copy($url, $temp_filename)) {
|
||||
throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
|
||||
}
|
||||
|
||||
if ($this->isGroup()) {
|
||||
$id = $this->group_id;
|
||||
} else {
|
||||
$id = $this->profile_id;
|
||||
if ($this->isGroup()) {
|
||||
$id = $this->group_id;
|
||||
} else {
|
||||
$id = $this->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;
|
||||
}
|
||||
// @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));
|
||||
// @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,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));
|
||||
try {
|
||||
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?
|
||||
|
||||
$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 = $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));
|
||||
$profile->setOriginal($filename);
|
||||
}
|
||||
}
|
||||
|
@ -436,18 +436,23 @@ 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');
|
||||
if (!copy($url, $temp_filename)) {
|
||||
throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
|
||||
}
|
||||
try {
|
||||
if (!copy($url, $temp_filename)) {
|
||||
throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
|
||||
}
|
||||
|
||||
$id = $dest->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));
|
||||
$id = $dest->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;
|
||||
}
|
||||
// @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