X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FConsole%2FMoveToAvatarCache.php;h=055b0c2c0d52c95ce31506d7768d3857e1ec63ff;hb=d27576059670faf87f80eaae2b4560f85b5310fc;hp=08c30c21530646804195436d90445e11b0a7edb8;hpb=1d29025091f44e8079d4f50ed27f7e727dc81ac3;p=friendica.git diff --git a/src/Console/MoveToAvatarCache.php b/src/Console/MoveToAvatarCache.php index 08c30c2153..055b0c2c0d 100644 --- a/src/Console/MoveToAvatarCache.php +++ b/src/Console/MoveToAvatarCache.php @@ -1,6 +1,6 @@ dba = $dba; - $this->baseurl = $baseurl; + $this->baseUrl = $baseUrl; $this->l10n = $l10n; + $this->config = $config; } - protected function doExecute() + protected function doExecute(): int { - $condition = ["`avatar` != ? AND `photo` LIKE ? AND `uid` = ? AND `uri-id` != ? AND NOT `uri-id` IS NULL", - '', $this->baseurl->get() . '/photo/%', 0, 0]; + 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', 'network']; + $condition = ["NOT `self` AND `avatar` != ? AND `photo` LIKE ? AND `uid` = ? AND `uri-id` != ? AND NOT `uri-id` IS NULL AND NOT `network` IN (?, ?)", + '', $this->baseUrl . '/photo/%', 0, 0, Protocol::MAIL, Protocol::FEED]; $count = 0; $total = $this->dba->count('contact', $condition); - $contacts = $this->dba->select('contact', ['id', 'avatar', 'photo', 'uri-id', 'url', 'avatar'], $condition, ['order' => ['id']]); + $contacts = $this->dba->select('contact', $fields, $condition, ['order' => ['id']]); while ($contact = $this->dba->fetch($contacts)) { + if (Contact::isLocal($contact['url'])) { + continue; + } $this->out(++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t", false); $resourceid = Photo::ridFromURI($contact['photo']); if (empty($resourceid)) { @@ -100,8 +117,8 @@ HELP; $total = $this->dba->fetch($totals)['total'] ?? 0; $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'], ['id', 'avatar', 'photo', 'uri-id', 'url', 'avatar']); - if (empty($contact)) { + $contact = Contact::getById($photo['contact-id'], $fields); + if (empty($contact) || in_array($contact['network'], [Protocol::MAIL, Protocol::FEED]) || Contact::isLocal($contact['url'])) { continue; } $this->out(++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t", false);