<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Console_Table;
use Friendica\App;
+use Friendica\DI;
use Friendica\Model\Contact as ContactModel;
use Friendica\Model\User as UserModel;
use Friendica\Network\Probe;
$this->appMode = $appMode;
}
- protected function doExecute()
+ protected function doExecute(): int
{
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
}
/**
- * 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)) {
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()
{
}
}
- $result = ContactModel::remove($cid);
+ ContactModel::remove($cid);
}
/**