diff --git a/src/Commands/ClearOpCache.php b/src/Commands/ClearOpCache.php index 4e836c3..9d43b63 100644 --- a/src/Commands/ClearOpCache.php +++ b/src/Commands/ClearOpCache.php @@ -23,6 +23,6 @@ public function digipolisClearOpCache( 'host' => null, ] ) { - $this->taskClearOpCache($environment, $opts['host'])->run(); + return $this->taskClearOpCache($environment, $opts['host'])->run(); } } diff --git a/src/Commands/PartialCleanDirs.php b/src/Commands/PartialCleanDirs.php index c26f6ab..ede97db 100644 --- a/src/Commands/PartialCleanDirs.php +++ b/src/Commands/PartialCleanDirs.php @@ -30,7 +30,7 @@ public function digipolisCleanDir($dirs, $opts = ['sort' => PartialCleanDirsTask } $dirsArg[] = $dirParts[0]; } - $this->taskPartialCleanDirs($dirsArg) + return $this->taskPartialCleanDirs($dirsArg) ->sortBy($opts['sort']) ->run(); } diff --git a/src/Commands/PushPackage.php b/src/Commands/PushPackage.php index 906261a..8e61fbf 100644 --- a/src/Commands/PushPackage.php +++ b/src/Commands/PushPackage.php @@ -38,7 +38,7 @@ public function digipolisPushPackage( $auth = $opts['key-file'] ? new KeyFile($user, $opts['key-file'], $opts['password']) : new Password($user, $opts['password']); - $this->taskPushPackage($host, $auth) + return $this->taskPushPackage($host, $auth) ->port($opts['port']) ->timeout($opts['timeout']) ->destinationFolder($destination) diff --git a/src/PartialCleanDirs.php b/src/PartialCleanDirs.php index f9938bb..5ce20c3 100644 --- a/src/PartialCleanDirs.php +++ b/src/PartialCleanDirs.php @@ -240,11 +240,12 @@ protected function cleanDir($dir, $keep) $finder->sort($this->sort); break; } - foreach ($finder as $item) { - if ($keep) { - $keep--; - continue; - } + $items = iterator_to_array($finder->getIterator()); + if ($keep) { + array_splice($items, -$keep); + } + foreach ($items as $item) { + $this->fs->chmod($item, 0777, 0000, true); $this->fs->remove($item); } } diff --git a/tests/PartialCleanDirsTest.php b/tests/PartialCleanDirsTest.php index c481b15..37cfe40 100644 --- a/tests/PartialCleanDirsTest.php +++ b/tests/PartialCleanDirsTest.php @@ -75,54 +75,99 @@ public function testRun() { ->getMock(); $fs->expects($this->at(0)) - ->method('remove') - ->with('dir6'); + ->method('chmod') + ->with('dir1', 0777, 0000, true); $fs->expects($this->at(1)) ->method('remove') - ->with('dir7'); + ->with('dir1'); $fs->expects($this->at(2)) - ->method('remove') - ->with('dir8'); + ->method('chmod') + ->with('dir2', 0777, 0000, true); $fs->expects($this->at(3)) ->method('remove') - ->with('dir9'); + ->with('dir2'); $fs->expects($this->at(4)) - ->method('remove') - ->with('dir10'); + ->method('chmod') + ->with('dir3', 0777, 0000, true); $fs->expects($this->at(5)) ->method('remove') - ->with('dir11'); - - // Delete items in path/to/dir2. + ->with('dir3'); $fs->expects($this->at(6)) - ->method('remove') - ->with('dir4'); + ->method('chmod') + ->with('dir4', 0777, 0000, true); $fs->expects($this->at(7)) ->method('remove') - ->with('dir5'); + ->with('dir4'); $fs->expects($this->at(8)) - ->method('remove') - ->with('dir6'); + ->method('chmod') + ->with('dir5', 0777, 0000, true); $fs->expects($this->at(9)) ->method('remove') - ->with('dir7'); + ->with('dir5'); $fs->expects($this->at(10)) - ->method('remove') - ->with('dir8'); + ->method('chmod') + ->with('dir6', 0777, 0000, true); $fs->expects($this->at(11)) ->method('remove') - ->with('dir9'); + ->with('dir6'); + + // Delete items in path/to/dir2. $fs->expects($this->at(12)) - ->method('remove') - ->with('dir10'); + ->method('chmod') + ->with('dir1', 0777, 0000, true); $fs->expects($this->at(13)) ->method('remove') - ->with('dir11'); + ->with('dir1'); + $fs->expects($this->at(14)) + ->method('chmod') + ->with('dir2', 0777, 0000, true); + $fs->expects($this->at(15)) + ->method('remove') + ->with('dir2'); + $fs->expects($this->at(16)) + ->method('chmod') + ->with('dir3', 0777, 0000, true); + $fs->expects($this->at(17)) + ->method('remove') + ->with('dir3'); + $fs->expects($this->at(18)) + ->method('chmod') + ->with('dir4', 0777, 0000, true); + $fs->expects($this->at(19)) + ->method('remove') + ->with('dir4'); + $fs->expects($this->at(20)) + ->method('chmod') + ->with('dir5', 0777, 0000, true); + $fs->expects($this->at(21)) + ->method('remove') + ->with('dir5'); + $fs->expects($this->at(22)) + ->method('chmod') + ->with('dir6', 0777, 0000, true); + $fs->expects($this->at(23)) + ->method('remove') + ->with('dir6'); + $fs->expects($this->at(24)) + ->method('chmod') + ->with('dir7', 0777, 0000, true); + $fs->expects($this->at(25)) + ->method('remove') + ->with('dir7'); + $fs->expects($this->at(26)) + ->method('chmod') + ->with('dir8', 0777, 0000, true); + $fs->expects($this->at(27)) + ->method('remove') + ->with('dir8'); // Delete items in path/to/dir3. - $fs->expects($this->at(14)) + $fs->expects($this->at(28)) + ->method('chmod') + ->with('dir1', 0777, 0000, true); + $fs->expects($this->at(29)) ->method('remove') - ->with('dir11'); + ->with('dir1'); $result = $this->taskPartialCleanDirs($dirs, $finder, $fs) ->run();