Merge pull request #11563 from annando/avatar-error

Issue-11560: Fix error when creating avatar cache file
This commit is contained in:
Hypolite Petovan 2022-05-26 18:58:49 -04:00 committed by GitHub
commit d4631176b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 18 deletions

View file

@ -28,6 +28,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Core\Config\Capability\IManageConfigValues;
/** /**
* tool to move cached avatars to the avatar file cache. * tool to move cached avatars to the avatar file cache.
@ -51,6 +52,11 @@ class MoveToAvatarCache extends \Asika\SimpleConsole\Console
*/ */
private $l10n; private $l10n;
/**
* @var IManageConfigValues
*/
private $config;
protected function getHelp() protected function getHelp()
{ {
$help = <<<HELP $help = <<<HELP
@ -68,23 +74,30 @@ HELP;
return $help; return $help;
} }
public function __construct(\Friendica\Database\Database $dba, BaseURL $baseurl, L10n $l10n, array $argv = null) public function __construct(\Friendica\Database\Database $dba, BaseURL $baseurl, L10n $l10n, IManageConfigValues $config, array $argv = null)
{ {
parent::__construct($argv); parent::__construct($argv);
$this->dba = $dba; $this->dba = $dba;
$this->baseurl = $baseurl; $this->baseurl = $baseurl;
$this->l10n = $l10n; $this->l10n = $l10n;
$this->config = $config;
} }
protected function doExecute() protected function doExecute()
{ {
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", $condition = ["`avatar` != ? AND `photo` LIKE ? AND `uid` = ? AND `uri-id` != ? AND NOT `uri-id` IS NULL",
'', $this->baseurl->get() . '/photo/%', 0, 0]; '', $this->baseurl->get() . '/photo/%', 0, 0];
$count = 0; $count = 0;
$total = $this->dba->count('contact', $condition); $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)) { while ($contact = $this->dba->fetch($contacts)) {
$this->out(++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t", false); $this->out(++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t", false);
$resourceid = Photo::ridFromURI($contact['photo']); $resourceid = Photo::ridFromURI($contact['photo']);
@ -100,7 +113,7 @@ HELP;
$total = $this->dba->fetch($totals)['total'] ?? 0; $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); $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)) { while ($photo = $this->dba->fetch($photos)) {
$contact = Contact::getById($photo['contact-id'], ['id', 'avatar', 'photo', 'uri-id', 'url', 'avatar']); $contact = Contact::getById($photo['contact-id'], $fields);
if (empty($contact)) { if (empty($contact)) {
continue; continue;
} }

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2022.05-rc\n" "Project-Id-Version: 2022.05-rc\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-05-24 20:12+0000\n" "POT-Creation-Date: 2022-05-26 20:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -1641,27 +1641,31 @@ msgstr ""
msgid "The contact has been blocked from the node" msgid "The contact has been blocked from the node"
msgstr "" msgstr ""
#: src/Console/MoveToAvatarCache.php:92 #: src/Console/MoveToAvatarCache.php:90
msgid "The avatar cache needs to be enabled to use this command."
msgstr ""
#: src/Console/MoveToAvatarCache.php:105
#, php-format #, php-format
msgid "no resource in photo %s" msgid "no resource in photo %s"
msgstr "" msgstr ""
#: src/Console/MoveToAvatarCache.php:118 #: src/Console/MoveToAvatarCache.php:133
#, php-format #, php-format
msgid "no photo with id %s" msgid "no photo with id %s"
msgstr "" msgstr ""
#: src/Console/MoveToAvatarCache.php:127 #: src/Console/MoveToAvatarCache.php:142
#, php-format #, php-format
msgid "no image data for photo with id %s" msgid "no image data for photo with id %s"
msgstr "" msgstr ""
#: src/Console/MoveToAvatarCache.php:136 #: src/Console/MoveToAvatarCache.php:151
#, php-format #, php-format
msgid "invalid image for id %s" msgid "invalid image for id %s"
msgstr "" msgstr ""
#: src/Console/MoveToAvatarCache.php:149 #: src/Console/MoveToAvatarCache.php:164
#, php-format #, php-format
msgid "Quit on invalid photo %s" msgid "Quit on invalid photo %s"
msgstr "" msgstr ""
@ -3579,45 +3583,45 @@ msgid ""
"credentials in your Settings -> Social Networks page." "credentials in your Settings -> Social Networks page."
msgstr "" msgstr ""
#: src/Model/Contact.php:2572 #: src/Model/Contact.php:2577
msgid "The profile address specified does not provide adequate information." msgid "The profile address specified does not provide adequate information."
msgstr "" msgstr ""
#: src/Model/Contact.php:2574 #: src/Model/Contact.php:2579
msgid "No compatible communication protocols or feeds were discovered." msgid "No compatible communication protocols or feeds were discovered."
msgstr "" msgstr ""
#: src/Model/Contact.php:2577 #: src/Model/Contact.php:2582
msgid "An author or name was not found." msgid "An author or name was not found."
msgstr "" msgstr ""
#: src/Model/Contact.php:2580 #: src/Model/Contact.php:2585
msgid "No browser URL could be matched to this address." msgid "No browser URL could be matched to this address."
msgstr "" msgstr ""
#: src/Model/Contact.php:2583 #: src/Model/Contact.php:2588
msgid "" msgid ""
"Unable to match @-style Identity Address with a known protocol or email " "Unable to match @-style Identity Address with a known protocol or email "
"contact." "contact."
msgstr "" msgstr ""
#: src/Model/Contact.php:2584 #: src/Model/Contact.php:2589
msgid "Use mailto: in front of address to force email check." msgid "Use mailto: in front of address to force email check."
msgstr "" msgstr ""
#: src/Model/Contact.php:2590 #: src/Model/Contact.php:2595
msgid "" msgid ""
"The profile address specified belongs to a network which has been disabled " "The profile address specified belongs to a network which has been disabled "
"on this site." "on this site."
msgstr "" msgstr ""
#: src/Model/Contact.php:2595 #: src/Model/Contact.php:2600
msgid "" msgid ""
"Limited profile. This person will be unable to receive direct/personal " "Limited profile. This person will be unable to receive direct/personal "
"notifications from you." "notifications from you."
msgstr "" msgstr ""
#: src/Model/Contact.php:2654 #: src/Model/Contact.php:2659
msgid "Unable to retrieve contact information." msgid "Unable to retrieve contact information."
msgstr "" msgstr ""