Ensure non-NULL values in $data array in Contact::updateAvatar
- Throw Exception instead of returning false if contact doesn't exist - Address https://github.com/friendica/friendica/issues/7998#issuecomment-596271239
This commit is contained in:
parent
2702732308
commit
89534b5be3
1 changed files with 9 additions and 3 deletions
|
@ -1913,17 +1913,23 @@ class Contact
|
||||||
*
|
*
|
||||||
* @return array Returns array of the different avatar sizes
|
* @return array Returns array of the different avatar sizes
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
|
* @throws HTTPException\NotFoundException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function updateAvatar($avatar, $uid, $cid, $force = false)
|
public static function updateAvatar($avatar, $uid, $cid, $force = false)
|
||||||
{
|
{
|
||||||
$contact = DBA::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid, 'self' => false]);
|
$contact = DBA::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid, 'self' => false]);
|
||||||
if (!DBA::isResult($contact)) {
|
if (!DBA::isResult($contact)) {
|
||||||
return false;
|
Logger::error('Contact not found', ['cid' => $cid]);
|
||||||
} else {
|
throw new HTTPException\NotFoundException('Contact not found');
|
||||||
$data = [$contact["photo"], $contact["thumb"], $contact["micro"]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
$contact['photo'] ?? '',
|
||||||
|
$contact['thumb'] ?? '',
|
||||||
|
$contact['micro'] ?? '',
|
||||||
|
];
|
||||||
|
|
||||||
foreach ($data as $image_uri) {
|
foreach ($data as $image_uri) {
|
||||||
$image_rid = Photo::ridFromURI($image_uri);
|
$image_rid = Photo::ridFromURI($image_uri);
|
||||||
if ($image_rid && !Photo::exists(['resource-id' => $image_rid, 'uid' => $uid])) {
|
if ($image_rid && !Photo::exists(['resource-id' => $image_rid, 'uid' => $uid])) {
|
||||||
|
|
Loading…
Reference in a new issue