Skip to content

Commit 086876b

Browse files
Moved 'addCommandLocation' to 'Binary' class
1 parent d488478 commit 086876b

File tree

6 files changed

+71
-55
lines changed

6 files changed

+71
-55
lines changed

src/Backup/Cli/Binary.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ abstract class Binary
3131
*/
3232
protected $exec;
3333

34+
/**
35+
* Optional command locations
36+
*
37+
* @var array
38+
*/
39+
private static $optionalCommandLocations = array(
40+
'mongodump' => array(),
41+
'mysqldump' => array(
42+
'/usr/local/mysql/bin/mysqldump', // Mac OS X
43+
'/usr/mysql/bin/mysqldump', // Linux
44+
),
45+
'tar' => array(),
46+
);
47+
3448
/**
3549
* Executes the cli commands and handles compression
3650
*
@@ -156,4 +170,26 @@ protected function unlinkErrorFile($file)
156170
unlink($file);
157171
}
158172
}
173+
174+
/**
175+
* Adds a new 'path' to the list of optional command locations.
176+
*
177+
* @param string $command
178+
* @param string $path
179+
*/
180+
public static function addCommandLocation($command, $path)
181+
{
182+
self::$optionalCommandLocations[$command][] = $path;
183+
}
184+
185+
/**
186+
* Returns the list of optional 'mysqldump' locations.
187+
*
188+
* @param string $command
189+
* @return array
190+
*/
191+
public static function getCommandLocations($command)
192+
{
193+
return isset(self::$optionalCommandLocations[$command]) ? self::$optionalCommandLocations[$command] : array();
194+
}
159195
}

src/Backup/Source/Mongodump.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ public function setup(array $conf = array())
148148
protected function setupMongodump(array $conf)
149149
{
150150
if (empty($this->binary)) {
151-
$this->binary = Util\Cli::detectCmdLocation('mongodump', Util\Arr::getValue($conf, 'pathToMongodump'));
151+
$this->binary = Util\Cli::detectCmdLocation(
152+
'mongodump',
153+
Util\Arr::getValue($conf, 'pathToMongodump'),
154+
Binary::getCommandLocations('mongodump')
155+
);
152156
}
153157
}
154158

src/Backup/Source/Mysqldump.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,6 @@ class Mysqldump extends Binary implements Source
115115
*/
116116
private $validateConnection;
117117

118-
/**
119-
* Optional 'mysqldump' command locations
120-
*
121-
* @var array
122-
*/
123-
private static $optionalCommandLocations = array(
124-
'/usr/local/mysql/bin/mysqldump', // Mac OS X
125-
'/usr/mysql/bin/mysqldump', // Linux
126-
);
127-
128118
/**
129119
* Setup.
130120
*
@@ -158,7 +148,7 @@ protected function setupMysqldump(array $conf)
158148
$this->binary = Util\Cli::detectCmdLocation(
159149
'mysqldump',
160150
Util\Arr::getValue($conf, 'pathToMysqldump'),
161-
self::$optionalCommandLocations
151+
Binary::getCommandLocations('mysqldump')
162152
);
163153
}
164154
}
@@ -304,24 +294,4 @@ public function checkConnection($host, $user, $password, array $databases = arra
304294
unset($mysqli);
305295
}
306296
}
307-
308-
/**
309-
* Adds a new 'path' to the list of optional command locations.
310-
*
311-
* @param string $path
312-
*/
313-
public static function addCommandLocation($path)
314-
{
315-
self::$optionalCommandLocations[] = $path;
316-
}
317-
318-
/**
319-
* Returns the list of optional 'mysqldump' locations.
320-
*
321-
* @return array
322-
*/
323-
public static function getCommandLocations()
324-
{
325-
return self::$optionalCommandLocations;
326-
}
327297
}

src/Backup/Source/Tar.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ public function setup(array $conf = array())
7171
protected function setupTar(array $conf)
7272
{
7373
if (empty($this->binary)) {
74-
$this->binary = Util\Cli::detectCmdLocation('tar', Util\Arr::getValue($conf, 'pathToTar'));
74+
$this->binary = Util\Cli::detectCmdLocation(
75+
'tar',
76+
Util\Arr::getValue($conf, 'pathToTar'),
77+
Binary::getCommandLocations('tar')
78+
);
7579
}
7680
}
7781

tests/phpbu/Backup/Cli/BinaryTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ public function testExecuteCompressedOutputCompressorFail()
109109
$this->assertEquals(1, count($res->getOutput()));
110110
}
111111

112+
/**
113+
* Tests Binary::getCommandLocations
114+
*/
115+
public function testCommandLocationsDefault()
116+
{
117+
$list = Binary::getCommandLocations('tar');
118+
$this->assertEquals(0, count($list));
119+
120+
$list = Binary::getCommandLocations('mysqldump');
121+
$this->assertEquals(2, count($list));
122+
}
123+
124+
/**
125+
* Tests Binary::getCommandLocations
126+
*/
127+
public function testAddCommandLocations()
128+
{
129+
Binary::addCommandLocation('mongodump', '/foo/mongodump');
130+
$list = Binary::getCommandLocations('mongodump');
131+
132+
$this->assertEquals(1, count($list));
133+
$this->assertEquals('/foo/mongodump', $list[0]);
134+
}
135+
112136
/**
113137
* Create Target Mock.
114138
*

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -264,28 +264,6 @@ public function testBackupFail()
264264
$this->mysqldump->backup($target, $appResult);
265265
}
266266

267-
/**
268-
* Tests Mysqldump::getCommandLocations
269-
*/
270-
public function testCommandLocationsDefault()
271-
{
272-
$list = Mysqldump::getCommandLocations();
273-
274-
$this->assertEquals(2, count($list));
275-
}
276-
277-
/**
278-
* Tests Mysqldump::getCommandLocations
279-
*/
280-
public function testAddCommandLocations()
281-
{
282-
Mysqldump::addCommandLocation('/foo/mysql.exe');
283-
$list = Mysqldump::getCommandLocations();
284-
285-
$this->assertEquals(3, count($list));
286-
$this->assertEquals('/foo/mysql.exe', $list[2]);
287-
}
288-
289267
/**
290268
* Create Cli\Result mock.
291269
*

0 commit comments

Comments
 (0)