]> git.mxchange.org Git - friendica.git/commitdiff
Delete invalid photo data
authorMichael <heluecht@pirati.ca>
Tue, 24 May 2022 17:49:29 +0000 (17:49 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 24 May 2022 17:49:29 +0000 (17:49 +0000)
src/Console/MoveToAvatarCache.php

index 2d14f405fe2b4ebbd15ff423515bcf3f722ef06b..b4684859713daeeea81a435a03be4ae22d6945b8 100644 (file)
@@ -86,34 +86,48 @@ HELP;
                $total    = $this->dba->count('contact', $condition);
                $contacts = $this->dba->select('contact', ['id', 'avatar', 'photo', 'uri-id', 'url', 'avatar'], $condition, ['order' => ['id']]);
                while ($contact = $this->dba->fetch($contacts)) {
+                       $valid = true;
                        echo ++$count . '/' . $total . "\t" . $contact['id'] . "\t" . $contact['url'] . "\t";
                        $resourceid = Photo::ridFromURI($contact['photo']);
                        if (empty($resourceid)) {
                                echo $this->l10n->t('no resource in photo %s', $contact['photo']) . "\n";
-                               continue;
+                               $valid = false;
                        }
-                       echo '1';
-                       $photo = Photo::selectFirst([], ['resource-id' => $resourceid], ['order' => ['scale']]);
-                       if (empty($photo)) {
-                               echo ' ' . $this->l10n->t('no photo with id %s', $resourceid) . "\n";
-                               continue;
+
+                       if ($valid) {
+                               echo '1';
+                               $photo = Photo::selectFirst([], ['resource-id' => $resourceid], ['order' => ['scale']]);
+                               if (empty($photo)) {
+                                       echo ' ' . $this->l10n->t('no photo with id %s', $resourceid) . "\n";
+                                       $valid = false;
+                               }
+                       }
+
+                       if ($valid) {
+                               echo '2';
+                               $imgdata = Photo::getImageDataForPhoto($photo);
+                               if (empty($imgdata)) {
+                                       echo ' ' . $this->l10n->t('no image data for photo with id %s', $resourceid) . "\n";
+                                       $valid = false;
+                               }
                        }
 
-                       echo '2';
-                       $imgdata = Photo::getImageDataForPhoto($photo);
-                       if (empty($imgdata)) {
-                               echo ' ' . $this->l10n->t('no image data for photo with id %s', $resourceid) . "\n";
-                               continue;
+                       if ($valid) {
+                               echo '3';
+                               $image = new Image($imgdata, Images::getMimeTypeByData($imgdata));
+                               if (!$image->isValid()) {
+                                       echo ' ' . $this->l10n->t('invalid image for id %s', $resourceid) . "\n";
+                                       $valid = false;
+                               }
                        }
-                       echo '3';
-                       $image = new Image($imgdata, Images::getMimeTypeByData($imgdata));
-                       if (!$image->isValid()) {
-                               echo ' ' . $this->l10n->t('invalid image for id %s', $resourceid) . "\n";
-                               continue;
+
+                       if ($valid) {
+                               echo '4';
+                               $fields = Avatar::storeAvatarByImage($contact, $image);
+                       } else {
+                               $fields = ['photo' => '', 'thumb' => '', 'micro' => ''];
                        }
 
-                       echo '4';
-                       $fields = Avatar::storeAvatarByImage($contact, $image);
                        echo '5';
                        Contact::update($fields, ['uri-id' => $contact['uri-id']]);
                        echo '6';