mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 18:22:41 +01:00
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
This commit is contained in:
parent
c22693ff29
commit
c40be811ea
1 changed files with 5 additions and 21 deletions
|
@ -16,6 +16,9 @@ class PhabricatorSearchService
|
||||||
const STATUS_OKAY = 'okay';
|
const STATUS_OKAY = 'okay';
|
||||||
const STATUS_FAIL = 'fail';
|
const STATUS_FAIL = 'fail';
|
||||||
|
|
||||||
|
const ROLE_WRITE = 'write';
|
||||||
|
const ROLE_READ = 'read';
|
||||||
|
|
||||||
public function __construct(PhabricatorFulltextStorageEngine $engine) {
|
public function __construct(PhabricatorFulltextStorageEngine $engine) {
|
||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
$this->hostType = $engine->getHostType();
|
$this->hostType = $engine->getHostType();
|
||||||
|
@ -84,30 +87,11 @@ class PhabricatorSearchService
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isWritable() {
|
public function isWritable() {
|
||||||
return $this->hasRole('write');
|
return (bool)$this->getAllHostsForRole(self::ROLE_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isReadable() {
|
public function isReadable() {
|
||||||
return $this->hasRole('read');
|
return (bool)$this->getAllHostsForRole(self::ROLE_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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPort() {
|
public function getPort() {
|
||||||
|
|
Loading…
Reference in a new issue