mirror of
https://github.com/friendica/friendica
synced 2024-12-23 04:40:15 +00:00
Merge pull request #11565 from annando/force-avatar-update
Pass the "force" parameter to the avatar update
This commit is contained in:
commit
d3624af1b6
3 changed files with 12 additions and 10 deletions
|
@ -29,6 +29,7 @@ use Friendica\Model\Photo;
|
|||
use Friendica\Util\Images;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Protocol;
|
||||
|
||||
/**
|
||||
* tool to move cached avatars to the avatar file cache.
|
||||
|
@ -86,14 +87,14 @@ HELP;
|
|||
|
||||
protected function doExecute()
|
||||
{
|
||||
if ($this->config->get('system', 'avatar_cache')) {
|
||||
if (!$this->config->get('system', 'avatar_cache')) {
|
||||
$this->err($this->l10n->t('The avatar cache needs to be enabled to use this command.'));
|
||||
return 2;
|
||||
}
|
||||
|
||||
$fields = ['id', 'avatar', 'photo', 'thumb', 'micro', 'uri-id', 'url', 'avatar'];
|
||||
$condition = ["`avatar` != ? AND `photo` LIKE ? AND `uid` = ? AND `uri-id` != ? AND NOT `uri-id` IS NULL",
|
||||
'', $this->baseurl->get() . '/photo/%', 0, 0];
|
||||
$fields = ['id', 'avatar', 'photo', 'thumb', 'micro', 'uri-id', 'url', 'avatar', 'network'];
|
||||
$condition = ["`avatar` != ? AND `photo` LIKE ? AND `uid` = ? AND `uri-id` != ? AND NOT `uri-id` IS NULL AND NOT `network` IN (?, ?)",
|
||||
'', $this->baseurl->get() . '/photo/%', 0, 0, Protocol::MAIL, Protocol::FEED];
|
||||
|
||||
$count = 0;
|
||||
$total = $this->dba->count('contact', $condition);
|
||||
|
@ -114,7 +115,7 @@ HELP;
|
|||
$photos = $this->dba->p("SELECT `resource-id`, MAX(`contact-id`) AS `contact-id` FROM `photo` WHERE `contact-id` != ? AND `photo-type` = ? GROUP BY `resource-id`;", 0, Photo::CONTACT_AVATAR);
|
||||
while ($photo = $this->dba->fetch($photos)) {
|
||||
$contact = Contact::getById($photo['contact-id'], $fields);
|
||||
if (empty($contact)) {
|
||||
if (empty($contact) || in_array($contact['network'], [Protocol::MAIL, Protocol::FEED])) {
|
||||
continue;
|
||||
}
|
||||
$this->out(++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t", false);
|
||||
|
|
|
@ -44,11 +44,12 @@ class Avatar
|
|||
/**
|
||||
* Returns a field array with locally cached avatar pictures
|
||||
*
|
||||
* @param array $contact
|
||||
* @param string $avatar
|
||||
* @param array $contact Contact array
|
||||
* @param string $avatar Link to avatar picture
|
||||
* @param bool $force force picture update
|
||||
* @return array
|
||||
*/
|
||||
public static function fetchAvatarContact(array $contact, string $avatar): array
|
||||
public static function fetchAvatarContact(array $contact, string $avatar, bool $force = false): array
|
||||
{
|
||||
$fields = ['avatar' => $avatar, 'avatar-date' => DateTimeFormat::utcNow(), 'photo' => '', 'thumb' => '', 'micro' => ''];
|
||||
|
||||
|
@ -61,7 +62,7 @@ class Avatar
|
|||
return $fields;
|
||||
}
|
||||
|
||||
if ($avatar != $contact['avatar']) {
|
||||
if (($avatar != $contact['avatar']) || $force) {
|
||||
self::deleteCache($contact);
|
||||
Logger::debug('Avatar file name changed', ['new' => $avatar, 'old' => $contact['avatar']]);
|
||||
} elseif (self::isCacheFile($contact['photo']) && self::isCacheFile($contact['thumb']) && self::isCacheFile($contact['micro'])) {
|
||||
|
|
|
@ -2049,7 +2049,7 @@ class Contact
|
|||
}
|
||||
} else {
|
||||
Photo::delete(['uid' => $uid, 'contact-id' => $cid, 'photo-type' => Photo::CONTACT_AVATAR]);
|
||||
$fields = Avatar::fetchAvatarContact($contact, $avatar);
|
||||
$fields = Avatar::fetchAvatarContact($contact, $avatar, $force);
|
||||
$update = ($avatar . $fields['photo'] . $fields['thumb'] . $fields['micro'] != $contact['avatar'] . $contact['photo'] . $contact['thumb'] . $contact['micro']) || $force;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue