]> git.mxchange.org Git - friendica.git/blobdiff - src/Console/MoveToAvatarCache.php
Merge pull request #13724 from Raroun/Fix-for-Issue-#13637---Photo-caption-prevents...
[friendica.git] / src / Console / MoveToAvatarCache.php
index a10997620b93251789179f54e5318021d9645fe0..055b0c2c0d52c95ce31506d7768d3857e1ec63ff 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -46,7 +46,7 @@ class MoveToAvatarCache extends \Asika\SimpleConsole\Console
        /**
         * @var $baseurl Friendica\App\BaseURL
         */
-       private $baseurl;
+       private $baseUrl;
 
        /**
         * @var L10n
@@ -75,17 +75,17 @@ HELP;
                return $help;
        }
 
-       public function __construct(\Friendica\Database\Database $dba, BaseURL $baseurl, L10n $l10n, IManageConfigValues $config, array $argv = null)
+       public function __construct(\Friendica\Database\Database $dba, BaseURL $baseUrl, L10n $l10n, IManageConfigValues $config, array $argv = null)
        {
                parent::__construct($argv);
 
                $this->dba     = $dba;
-               $this->baseurl = $baseurl;
+               $this->baseUrl = $baseUrl;
                $this->l10n    = $l10n;
                $this->config = $config;
        }
 
-       protected function doExecute()
+       protected function doExecute(): int
        {
                if (!$this->config->get('system', 'avatar_cache')) {
                        $this->err($this->l10n->t('The avatar cache needs to be enabled to use this command.'));
@@ -93,13 +93,16 @@ HELP;
                }
 
                $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];
+               $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', $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)) {
@@ -115,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) || in_array($contact['network'], [Protocol::MAIL, Protocol::FEED])) {
+                       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);