From c40be811ea9b2419335fce7fe16096a16e7d6b04 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 28 Mar 2017 12:47:56 -0700 Subject: [PATCH] Fix isReadable() and isWritable() in SearchService Summary: Ref T12450. Minor cleanup: - setRoles() has no callers. - getRoles() has no callers (these two methods are leftovers from an earlier iteration of the change). - The `hasRole()` logic doesn't work since nothing calls `setRole()`. - `hasRole()` has only `isreadable/iswritable` as callers. - The `isReadable()/isWritable()` logic doesn't work since `hasRole()` doesn't work. Instead, just check if there are any readable/writable hosts. `Host` already inherits its config from `Service` so this gets the same answer without any fuss. Also add some read/write constants to make grepping this stuff a little easier. Test Plan: - Grepped for all removed symbols, saw only newer-generation calls in `Host`. - See next diff for use of `isWritable()`. Reviewers: chad, 20after4 Reviewed By: 20after4 Maniphest Tasks: T12450 Differential Revision: https://secure.phabricator.com/D17571 --- .../search/PhabricatorSearchService.php | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/infrastructure/cluster/search/PhabricatorSearchService.php b/src/infrastructure/cluster/search/PhabricatorSearchService.php index 0a563207b1..b4f6b76aec 100644 --- a/src/infrastructure/cluster/search/PhabricatorSearchService.php +++ b/src/infrastructure/cluster/search/PhabricatorSearchService.php @@ -16,6 +16,9 @@ class PhabricatorSearchService const STATUS_OKAY = 'okay'; const STATUS_FAIL = 'fail'; + const ROLE_WRITE = 'write'; + const ROLE_READ = 'read'; + public function __construct(PhabricatorFulltextStorageEngine $engine) { $this->engine = $engine; $this->hostType = $engine->getHostType(); @@ -84,30 +87,11 @@ class PhabricatorSearchService } public function isWritable() { - return $this->hasRole('write'); + return (bool)$this->getAllHostsForRole(self::ROLE_WRITE); } public function isReadable() { - return $this->hasRole('read'); - } - - public function hasRole($role) { - return isset($this->roles[$role]) && $this->roles[$role] !== false; - } - - public function setRoles(array $roles) { - foreach ($roles as $role => $val) { - if ($val === false && isset($this->roles[$role])) { - unset($this->roles[$role]); - } else { - $this->roles[$role] = $val; - } - } - return $this; - } - - public function getRoles() { - return $this->roles; + return (bool)$this->getAllHostsForRole(self::ROLE_READ); } public function getPort() {