]> git.mxchange.org Git - friendica.git/blobdiff - src/Console/MoveToAvatarCache.php
update FR translations THX kalon33
[friendica.git] / src / Console / MoveToAvatarCache.php
index 1eb2d49e8365821ad863383622f932bf42a41af7..441dff682d9b57567d861ee7ede5c27c5b53e0a7 100644 (file)
@@ -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,19 +87,22 @@ 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 = ["NOT `self` AND `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);
                $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)) {
@@ -114,7 +118,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]) || Contact::isLocal($contact['url'])) {
                                continue;
                        }
                        $this->out(++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t", false);