Skip to content

Commit 832d570

Browse files
gbprodruflin
authored andcommitted
Fix PHP notice on getAliases if index has no aliases (#1080)
A php notice is triggered in `\Elastica\Index::getAliases()` if index has no aliases. Only happens if php `error_reporting` setting is set to `-1`. Closes #1078
1 parent 9240104 commit 832d570

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file based on the
66
### Backward Compatibility Breaks
77

88
### Bugfixes
9+
- Fix php notice on `\Elastica\Index::getAliases()` if index has no aliases #1078
910

1011
### Added
1112

lib/Elastica/Index.php

+4
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ public function getAliases()
434434
{
435435
$responseData = $this->request('_alias/*', \Elastica\Request::GET)->getData();
436436

437+
if (!isset($responseData[$this->getName()])) {
438+
return array();
439+
}
440+
437441
$data = $responseData[$this->getName()];
438442
if (!empty($data['aliases'])) {
439443
return array_keys($data['aliases']);

test/lib/Elastica/Test/IndexTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -941,4 +941,22 @@ public function testConvertScalarsToString()
941941
$this->assertEquals('1', $index->getName());
942942
$this->assertInternalType('string', $index->getName());
943943
}
944+
945+
/**
946+
* @group functional
947+
*/
948+
public function testGetEmptyAliases()
949+
{
950+
$indexName = 'test-getaliases';
951+
952+
$client = $this->_getClient();
953+
$index = $client->getIndex($indexName);
954+
955+
$index->create(array(), true);
956+
$this->_waitForAllocation($index);
957+
$index->refresh();
958+
$index->optimize();
959+
960+
$this->assertEquals(array(), $index->getAliases());
961+
}
944962
}

0 commit comments

Comments
 (0)