From 4dfa7f374aa7c71b2db47015ea979ffaa37b19a0 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Tue, 4 Aug 2020 13:03:33 +0100 Subject: [PATCH] [TheFreeNetwork][fix_duplicates.php] Don't die because you couldn't federate an undo follow --- .../TheFreeNetwork/scripts/fix_duplicates.php | 46 ++++++++++++------- plugins/OStatus/OStatusPlugin.php | 4 +- plugins/OStatus/classes/Ostatus_profile.php | 2 +- plugins/OStatus/lib/salmon.php | 13 ++++-- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/modules/TheFreeNetwork/scripts/fix_duplicates.php b/modules/TheFreeNetwork/scripts/fix_duplicates.php index 5c9905b3c1..9c145baf53 100644 --- a/modules/TheFreeNetwork/scripts/fix_duplicates.php +++ b/modules/TheFreeNetwork/scripts/fix_duplicates.php @@ -80,25 +80,35 @@ function fix_duplicates(string $profile_class, array &$seen): void // Have we seen this profile before? if (array_key_exists($uri, $seen)) { - // Was it on a previous protocol? Keep the highest preference protocol's one - if ($seen[$uri] !== $id) { - printfnq("Deleting Profile with id = {$id}\n"); - $profile = Profile::getByID($id); - $profile->delete(); - } else { - printfnq("Deleting {$profile_class} with id = {$id}\n"); - $protocol_profile->delete(); + try { + // Was it on a previous protocol? Keep the highest preference protocol's one + if ($seen[$uri] !== $id) { + printfnq("Deleting Profile with id = {$id}\n"); + $profile = Profile::getByID($id); + $profile->delete(); + } else { + printfnq("Deleting {$profile_class} with id = {$id}\n"); + $protocol_profile->delete(); + } + } catch (Exception $e) { + // Let it go + printfnq('FWIW: ' . $e->getMessage() . "\n"); } } elseif (array_key_exists($uri, $seen_local)) { - // Was it in this protocol? Delete the older record. - if ($seen_local[$uri] !== $id) { - printfnq("Deleting Profile with id = {$seen_local[$uri]}\n"); - $profile = Profile::getByID($seen_local[$uri]); - $profile->delete(); - } else { - printfnq("Deleting {$profile_class} with id = {$seen_local[$uri]}\n"); - $profile = $profile_class::getKV('profile_id', $seen_local[$uri]); - $profile->delete(); + try { + // Was it in this protocol? Delete the older record. + if ($seen_local[$uri] !== $id) { + printfnq("Deleting Profile with id = {$seen_local[$uri]}\n"); + $profile = Profile::getByID($seen_local[$uri]); + $profile->delete(); + } else { + printfnq("Deleting {$profile_class} with id = {$seen_local[$uri]}\n"); + $profile = $profile_class::getKV('profile_id', $seen_local[$uri]); + $profile->delete(); + } + } catch (Exception $e) { + // Let it go + printfnq('FWIW: ' . $e->getMessage() . "\n"); } // Update the profile id for this URI. $seen_local[$uri] = $id; @@ -107,6 +117,8 @@ function fix_duplicates(string $profile_class, array &$seen): void $seen_local[$uri] = $id; } } + $protocol_profile->free(); + unset($protocol_profile); // Merge the findings inside this protocol with the global seen to be used on the next protocol of the list. $seen = array_merge($seen, $seen_local); diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index bcc98b941b..149d22fa52 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -710,7 +710,7 @@ class OStatusPlugin extends Plugin * @param Profile $profile subscriber * @param Profile $other subscribee * - * @return hook return code + * @return bool hook return code * * @throws Exception */ @@ -735,7 +735,7 @@ class OStatusPlugin extends Plugin * @param Profile $profile subscriber * @param Profile $other subscribee * - * @return hook return code + * @return bool hook return code * * @throws Exception */ diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 14ad1cb82c..833fe456d8 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -385,7 +385,7 @@ class Ostatus_profile extends Managed_DataObject * * @param mixed $entry XML string, Notice, or Activity * @param Profile $actor - * @return boolean success + * @return bool success */ public function notifyActivity($entry, Profile $actor) { diff --git a/plugins/OStatus/lib/salmon.php b/plugins/OStatus/lib/salmon.php index 27aad3a43d..134fa3c475 100644 --- a/plugins/OStatus/lib/salmon.php +++ b/plugins/OStatus/lib/salmon.php @@ -43,11 +43,16 @@ class Salmon * * @param string $endpoint_uri * @param string $xml string representation of payload - * @param Profile $user profile whose keys we sign with (must be a local user) - * @return boolean success + * @param Profile $actor profile whose keys we sign with (must be a local user) + * @param Profile|null $target + * @return bool success */ - public static function post($endpoint_uri, $xml, Profile $actor, Profile $target=null) - { + public static function post( + $endpoint_uri, + $xml, + Profile $actor, + ?Profile $target = null + ) { if (empty($endpoint_uri)) { common_debug('No endpoint URI for Salmon post to '.$actor->getUri()); return false;