Skip to content

Commit df385cc

Browse files
Merge pull request #400 from erkiaas/main
Add limit option to Elasticdump
2 parents 8409853 + 7778b81 commit df385cc

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

src/Backup/Source/Elasticdump.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ class Elasticdump extends SimulatorExecutable implements Simulator
6464
*/
6565
private $type;
6666

67+
/**
68+
* Number of documents to dump.
69+
* --limit
70+
*
71+
* @var string
72+
*/
73+
private $limit;
74+
6775
/**
6876
* Setup
6977
*
@@ -89,6 +97,7 @@ protected function setupSourceData(array $conf)
8997
{
9098
$this->index = Util\Arr::getValue($conf, 'index', '');
9199
$this->type = Util\Arr::getValue($conf, 'type', '');
100+
$this->limit = Util\Arr::getValue($conf, 'limit', '');
92101
}
93102

94103
/**
@@ -126,6 +135,7 @@ protected function createExecutable(Target $target) : Executable
126135
->credentials($this->user, $this->password)
127136
->dumpIndex($this->index)
128137
->dumpType($this->type)
138+
->limit($this->limit)
129139
->dumpTo($target->getPathnamePlain());
130140
return $executable;
131141
}

src/Cli/Executable/Elasticdump.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class Elasticdump extends Abstraction
6565
*/
6666
private $dumpPathname;
6767

68+
/**
69+
* Number of documents to dump.
70+
* --limit
71+
*
72+
* @var string
73+
*/
74+
private $limit;
75+
6876
/**
6977
* Constructor.
7078
*
@@ -124,6 +132,18 @@ public function dumpTo($pathname)
124132
return $this;
125133
}
126134

135+
/**
136+
* Set limit of documents to dump.
137+
*
138+
* @param string $limit
139+
* @return \phpbu\App\Cli\Executable\Elasticdump
140+
*/
141+
public function limit($limit)
142+
{
143+
$this->limit = $limit;
144+
return $this;
145+
}
146+
127147
/**
128148
* Set elastic credentials.
129149
*
@@ -159,6 +179,7 @@ protected function createCommandLine() : CommandLine
159179

160180
$cmd->addOption('--input', $this->generateNodeUrl($this->host, $this->user, $this->password, $this->index));
161181
$cmd->addOptionIfNotEmpty('--type', $this->type);
182+
$cmd->addOptionIfNotEmpty('--limit', $this->limit);
162183
$cmd->addOption('--output', $this->dumpPathname);
163184

164185
return $process;

tests/phpbu/Backup/Source/ElasticdumpTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ public function testUser()
5252
$this->assertEquals('"' . PHPBU_TEST_BIN . '/' . $expected, $executable->getCommand());
5353
}
5454

55+
/**
56+
* Tests Elasticdump::getExecutable
57+
*/
58+
public function testLimit()
59+
{
60+
$target = $this->createTargetMock('backup.json');
61+
$elasticdump = new Elasticdump();
62+
$elasticdump->setup(['pathToElasticdump' => PHPBU_TEST_BIN, 'limit' => '100']);
63+
64+
$executable = $elasticdump->getExecutable($target);
65+
$expected = 'elasticdump" --input=\'http://localhost:9200/\' --limit=\'100\' --output=\'backup.json\'';
66+
67+
$this->assertEquals('"' . PHPBU_TEST_BIN . '/' . $expected, $executable->getCommand());
68+
}
69+
5570
/**
5671
* Tests Elasticdump::backup
5772
*/

tests/phpbu/Cli/Executable/ElasticdumpTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ public function testType()
7777
$this->assertEquals('"' . PHPBU_TEST_BIN . '/' . $expected, $elastic->getCommand());
7878
}
7979

80+
/**
81+
* Tests Elasticdump::createCommand
82+
*/
83+
public function testLimit()
84+
{
85+
$expected = 'elasticdump" --input=\'http://localhost:9200/\' --limit=\'500\' --output=\'./foo.json\'';
86+
$elastic = new Elasticdump(PHPBU_TEST_BIN);
87+
$elastic->useHost('localhost:9200')->limit('500')->dumpTo('./foo.json');
88+
89+
$this->assertEquals('"' . PHPBU_TEST_BIN . '/' . $expected, $elastic->getCommand());
90+
}
91+
8092
/**
8193
* Tests Elasticdump::createCommandLine
8294
*/

0 commit comments

Comments
 (0)