Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow string argument in AbstractUpdateAction::setRefresh #1791

Merged
merged 2 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
* Ability to specify the type of authentication manually by the `auth_type` parameter (in the client class config) was added (allowed values are `basic, digest, gssnegotiate, ntlm`)
### Changed

* Allow `string` such as `wait_for` to be passed to `AbstractUpdateAction::setRefresh` [#1791](https://github.com/ruflin/Elastica/pull/1791)
* Changed the return type of `AbstractUpdateAction::getRefresh` to `boolean|string` [#1791](https://github.com/ruflin/Elastica/pull/1791)
### Deprecated
### Removed
### Fixed
Expand Down
16 changes: 12 additions & 4 deletions src/AbstractUpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,29 @@ public function hasRetryOnConflict()
}

/**
* @param bool $refresh
* @param bool|string $refresh
*
* @return $this
*/
public function setRefresh($refresh = true)
{
return $this->setParam('refresh', (bool) $refresh ? 'true' : 'false');
\is_bool($refresh) && $refresh = $refresh
? Reindex::REFRESH_TRUE
: Reindex::REFRESH_FALSE;

return $this->setParam(Reindex::REFRESH, $refresh);
}

/**
* @return bool
* @return bool|string
*/
public function getRefresh()
{
return 'true' === $this->getParam('refresh');
$refresh = $this->getParam('refresh');

return \in_array($refresh, [Reindex::REFRESH_TRUE, Reindex::REFRESH_FALSE])
? Reindex::REFRESH_TRUE === $refresh
: $refresh;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Elastica\Document;
use Elastica\Exception\InvalidException;
use Elastica\Index;
use Elastica\Reindex;
use Elastica\Test\Base as BaseTest;

/**
Expand Down Expand Up @@ -118,6 +119,10 @@ public function testGetSetHasRefresh(): void
$document->setRefresh(true);
$this->assertTrue($document->hasRefresh());
$this->assertTrue($document->getRefresh());

$document->setRefresh(Reindex::REFRESH_WAIT_FOR);
$this->assertTrue($document->hasRefresh());
$this->assertEquals(Reindex::REFRESH_WAIT_FOR, $document->getRefresh());
}

/**
Expand Down