dba = $dba; $this->baseUrl = $baseUrl; $this->l10n = $l10n; $this->config = $config; } protected function doExecute(): int { if ($this->config->get('system', 'avatar_cache')) { $this->err($this->l10n->t('The avatar cache needs to be disabled in local.config.php to use this command.')); return 2; } // Contacts (but not self contacts) with cached avatars. $condition = ["NOT `self` AND (`photo` != ? OR `thumb` != ? OR `micro` != ?)", '', '', '']; $total = $this->dba->count('contact', $condition); $count = 0; $contacts = $this->dba->select('contact', ['id', 'uri-id', 'url', 'uid', 'photo', 'thumb', 'micro'], $condition); while ($contact = $this->dba->fetch($contacts)) { if (Avatar::deleteCache($contact) || $this->isAvatarCache($contact)) { Contact::update(['photo' => '', 'thumb' => '', 'micro' => ''], ['id' => $contact['id']]); } $this->out(++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t" . $contact['photo']); } $this->dba->close($contacts); return 0; } private function isAvatarCache(array $contact): bool { if (!empty($contact['photo']) && strpos($contact['photo'], Avatar::baseUrl()) === 0) { return true; } if (!empty($contact['thumb']) && strpos($contact['thumb'], Avatar::baseUrl()) === 0) { return true; } if (!empty($contact['micro']) && strpos($contact['micro'], Avatar::baseUrl()) === 0) { return true; } return false; } }