Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1282 from mariansollmann/issue-1282
Browse files Browse the repository at this point in the history
Add delete command to index cli
  • Loading branch information
Marian Sollmann committed Jun 12, 2014
2 parents e68727d + bed4a5d commit 59d8369
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions library/CM/Elasticsearch/Index/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CM_Elasticsearch_Index_Cli extends CM_Cli_Runnable_Abstract {
* @param string|null $indexName
*/
public function create($indexName = null) {
if ($indexName) {
if (null !== $indexName) {
$indexes = array($this->_getIndex($indexName));
} else {
$indexes = $this->_getIndexes();
Expand All @@ -20,14 +20,14 @@ public function create($indexName = null) {

/**
* @param string|CM_Elasticsearch_Type_Abstract|null $indexName
* @param string|null $host Elasticsearch host
* @param int|null $port Elasticsearch port
* @param string|null $host Elasticsearch host
* @param int|null $port Elasticsearch port
* @throws CM_Exception_Invalid
*/
public function update($indexName = null, $host = null, $port = null) {
if ($indexName instanceof CM_Elasticsearch_Type_Abstract) {
$indexes = array($indexName);
} elseif ($indexName) {
} elseif (null !== $indexName) {
$indexes = array($this->_getIndex($indexName, $host, $port));
} else {
$indexes = $this->_getIndexes($host, $port);
Expand Down Expand Up @@ -55,6 +55,20 @@ public function update($indexName = null, $host = null, $port = null) {
}
}

/**
* @param string|null $indexName
*/
public function delete($indexName = null) {
if (null !== $indexName) {
$indexes = array($this->_getIndex($indexName));
} else {
$indexes = $this->_getIndexes();
}
foreach ($indexes as $index) {
$index->getIndex()->delete();
}
}

public function optimize() {
$servers = CM_Config::get()->CM_Elasticsearch_Client->servers;
foreach ($servers as $server) {
Expand Down

0 comments on commit 59d8369

Please sign in to comment.