X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FConsole%2FContact.php;h=37f3f056e4f755da410df6b52419f702c53ef090;hb=1810b32c26683bb94fee10de2ffe18de1a7e85bf;hp=55fd5024ca266e66c1804c3e58780164ecb80c54;hpb=315dddbcb9232fea105d2da53ad2ba0e143bd7e4;p=friendica.git diff --git a/src/Console/Contact.php b/src/Console/Contact.php index 55fd5024ca..37f3f056e4 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__); @@ -153,6 +155,8 @@ HELP; } } + $url = Probe::cleanURI($url); + $contact = ContactModel::getByURLForUser($url, $user['uid']); if (!empty($contact)) { throw new RuntimeException('Contact already exists'); @@ -164,7 +168,7 @@ HELP; $network = CliPrompt::prompt(); } - $result = ContactModel::createFromProbe($user, $url, false, $network); + $result = ContactModel::createFromProbeForUser($user['uid'], $url, $network); if ($result['success']) { $this->out('User ' . $user['nickname'] . ' now connected to ' . $url . ', contact ID ' . $result['cid']); @@ -174,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)) { @@ -194,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() { @@ -215,7 +229,7 @@ HELP; } } - $result = ContactModel::remove($cid); + ContactModel::remove($cid); } /**