diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2016-02-26 16:59:53 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2016-02-29 16:50:33 +0100 |
commit | 7189c72c33a03d57473f7e3443193d07bece7c15 (patch) | |
tree | 8b61c06e4006f2426037e92d1d65008d6976022c /apps/federation/lib | |
parent | eccd7cf6548e1ea639aea48cbf7e52e95dc98c11 (diff) | |
download | nextcloud-server-7189c72c33a03d57473f7e3443193d07bece7c15.tar.gz nextcloud-server-7189c72c33a03d57473f7e3443193d07bece7c15.zip |
remove remote address book if the admin removes the server from the trusted servers list
Diffstat (limited to 'apps/federation/lib')
-rw-r--r-- | apps/federation/lib/dbhandler.php | 22 | ||||
-rw-r--r-- | apps/federation/lib/trustedservers.php | 13 |
2 files changed, 34 insertions, 1 deletions
diff --git a/apps/federation/lib/dbhandler.php b/apps/federation/lib/dbhandler.php index df36228c760..8720560efc6 100644 --- a/apps/federation/lib/dbhandler.php +++ b/apps/federation/lib/dbhandler.php @@ -106,6 +106,28 @@ class DbHandler { } /** + * get trusted server with given ID + * + * @param int $id + * @return array + * @throws \Exception + */ + public function getServerById($id) { + $query = $this->connection->getQueryBuilder(); + $query->select('*')->from($this->dbTable) + ->where($query->expr()->eq('id', $query->createParameter('id'))) + ->setParameter('id', $id); + $query->execute(); + $result = $query->execute()->fetchAll(); + + if (empty($result)) { + throw new \Exception('No Server found with ID: ' . $id); + } + + return $result[0]; + } + + /** * get all trusted servers * * @return array diff --git a/apps/federation/lib/trustedservers.php b/apps/federation/lib/trustedservers.php index 340accfdbdf..fed6b0944a8 100644 --- a/apps/federation/lib/trustedservers.php +++ b/apps/federation/lib/trustedservers.php @@ -30,6 +30,8 @@ use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\ILogger; use OCP\Security\ISecureRandom; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; class TrustedServers { @@ -58,6 +60,9 @@ class TrustedServers { /** @var IConfig */ private $config; + /** @var EventDispatcherInterface */ + private $dispatcher; + /** * @param DbHandler $dbHandler * @param IClientService $httpClientService @@ -65,6 +70,7 @@ class TrustedServers { * @param IJobList $jobList * @param ISecureRandom $secureRandom * @param IConfig $config + * @param EventDispatcherInterface $dispatcher */ public function __construct( DbHandler $dbHandler, @@ -72,7 +78,8 @@ class TrustedServers { ILogger $logger, IJobList $jobList, ISecureRandom $secureRandom, - IConfig $config + IConfig $config, + EventDispatcherInterface $dispatcher ) { $this->dbHandler = $dbHandler; $this->httpClientService = $httpClientService; @@ -80,6 +87,7 @@ class TrustedServers { $this->jobList = $jobList; $this->secureRandom = $secureRandom; $this->config = $config; + $this->dispatcher = $dispatcher; } /** @@ -154,7 +162,10 @@ class TrustedServers { * @param int $id */ public function removeServer($id) { + $server = $this->dbHandler->getServerById($id); $this->dbHandler->removeServer($id); + $event = new GenericEvent($server['url_hash']); + $this->dispatcher->dispatch('OCP\Federation\TrustedServerEvent::remove', $event); } /** |