]> git.mxchange.org Git - friendica.git/commitdiff
Throw exception when a few keys are missing from probe data array in Repository\Diasp...
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 8 Dec 2022 14:40:35 +0000 (09:40 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 10 Dec 2022 16:42:04 +0000 (11:42 -0500)
- Address part of https://github.com/friendica/friendica/issues/11993#issuecomment-1338134893

src/Model/Contact.php
src/Protocol/Diaspora/Repository/DiasporaContact.php

index 873de08906f26d00d90c638f6e3950917b600295..79ddae713a435f162e7eab5d213f51f706c2cbfa 100644 (file)
@@ -1395,9 +1395,17 @@ class Contact
                }
 
                if ($data['network'] == Protocol::DIASPORA) {
-                       DI::dsprContact()->updateFromProbeArray($data);
+                       try {
+                               DI::dsprContact()->updateFromProbeArray($data);
+                       } catch (\InvalidArgumentException $e) {
+                               Logger::error($e->getMessage(), ['url' => $url, 'data' => $data]);
+                       }
                } elseif (!empty($data['networks'][Protocol::DIASPORA])) {
-                       DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]);
+                       try {
+                               DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]);
+                       } catch (\InvalidArgumentException $e) {
+                               Logger::error($e->getMessage(), ['url' => $url, 'data' => $data['networks'][Protocol::DIASPORA]]);
+                       }
                }
 
                self::updateFromProbeArray($contact_id, $data);
@@ -2485,15 +2493,23 @@ class Contact
                        return false;
                }
 
-               $ret = Probe::uri($contact['url'], $network, $contact['uid']);
+               $data = Probe::uri($contact['url'], $network, $contact['uid']);
 
-               if ($ret['network'] == Protocol::DIASPORA) {
-                       DI::dsprContact()->updateFromProbeArray($ret);
-               } elseif (!empty($ret['networks'][Protocol::DIASPORA])) {
-                       DI::dsprContact()->updateFromProbeArray($ret['networks'][Protocol::DIASPORA]);
+               if ($data['network'] == Protocol::DIASPORA) {
+                       try {
+                               DI::dsprContact()->updateFromProbeArray($data);
+                       } catch (\InvalidArgumentException $e) {
+                               Logger::error($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]);
+                       }
+               } elseif (!empty($data['networks'][Protocol::DIASPORA])) {
+                       try {
+                               DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]);
+                       } catch (\InvalidArgumentException $e) {
+                               Logger::error($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]);
+                       }
                }
 
-               return self::updateFromProbeArray($id, $ret);
+               return self::updateFromProbeArray($id, $data);
        }
 
        /**
index ac8d200aa8058ff99bdf32462f3928a98b13c125..1669707b922e3bc6202ed075bc3dd509f407bfba 100644 (file)
@@ -234,6 +234,18 @@ class DiasporaContact extends BaseRepository
         */
        public function updateFromProbeArray(array $data): Entity\DiasporaContact
        {
+               if (empty($data['url'])) {
+                       throw new \InvalidArgumentException('Missing url key in Diaspora probe data array');
+               }
+
+               if (empty($data['guid'])) {
+                       throw new \InvalidArgumentException('Missing guid key in Diaspora probe data array');
+               }
+
+               if (empty($data['pubkey'])) {
+                       throw new \InvalidArgumentException('Missing pubkey key in Diaspora probe data array');
+               }
+
                $uriId = ItemURI::insert(['uri' => $data['url'], 'guid' => $data['guid']]);
 
                $contact   = Contact::getByUriId($uriId, ['id', 'created']);