X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FConsole%2FContact.php;h=a80b88349a157bc99bfca55bbc720be1fbb74061;hb=d4a5a8051ad34a7be72238967afb3e6b140afdc8;hp=9dfcf1392555545137d4b2c8bf91f089661bbbc2;hpb=3ad6536fd076182611030a894bec5bd122949fdc;p=friendica.git diff --git a/src/Console/Contact.php b/src/Console/Contact.php index 9dfcf13925..a80b88349a 100644 --- a/src/Console/Contact.php +++ b/src/Console/Contact.php @@ -1,6 +1,6 @@ appMode = $appMode; } - protected function doExecute() + protected function doExecute(): int { if ($this->getOption('v')) { $this->out('Class: ' . __CLASS__); @@ -156,7 +157,7 @@ HELP; $url = Probe::cleanURI($url); - $contact = ContactModel::getByURLForUser($url, $user['uid']); + $contact = ContactModel::getByURL($url, null, [], $user['uid']); if (!empty($contact)) { throw new RuntimeException('Contact already exists'); } @@ -177,11 +178,12 @@ HELP; } /** - * Sends an unfriend message. Does not remove the contact + * Sends an unfriend message. * * @return bool True, if the command was successful + * @throws \Exception */ - private function terminateContact() + private function terminateContact(): bool { $cid = $this->getArgument(1); if (empty($cid)) { @@ -197,15 +199,24 @@ HELP; throw new RuntimeException('Contact not found'); } - $user = UserModel::getById($contact['uid']); + if (empty($contact['uid'])) { + throw new RuntimeException('Contact must be user-specific (uid != 0)'); + } + + try { + ContactModel::unfollow($contact); + + $this->out('Contact was successfully unfollowed'); - $result = ContactModel::terminateFriendship($user, $contact); + return true; + } catch (\Exception $e) { + DI::logger()->error($e->getMessage(), ['contact' => $contact]); + throw new RuntimeException('Unable to unfollow this contact, please check the log'); + } } /** * Marks a contact for removal - * - * @return bool True, if the command was successful */ private function removeContact() { @@ -218,7 +229,7 @@ HELP; } } - $result = ContactModel::remove($cid); + ContactModel::remove($cid); } /**