-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from WeareJH/lock-info
Display lock info and create command to list locks
- Loading branch information
Showing
9 changed files
with
241 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Jh\Import\Command; | ||
|
||
use Jh\Import\Config\Data; | ||
use Jh\Import\Locker\Locker; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ViewLocksCommand extends Command | ||
{ | ||
/** | ||
* @var Data | ||
*/ | ||
private $importConfig; | ||
|
||
/** | ||
* @var Locker | ||
*/ | ||
private $locker; | ||
|
||
public function __construct(Data $importConfig, Locker $locker) | ||
{ | ||
$this->importConfig = $importConfig; | ||
$this->locker = $locker; | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this->setName('jh-import:locks') | ||
->setDescription('Show current locks'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$locks = array_map( | ||
function (string $importName) { | ||
return [$importName]; | ||
}, | ||
array_filter( | ||
$this->importConfig->getAllImportNames(), | ||
function (string $importName) { | ||
return $this->locker->locked($importName); | ||
} | ||
) | ||
); | ||
|
||
if (empty($locks)) { | ||
$output->writeln(['', '<comment>No import is locked</comment>', '']); | ||
return; | ||
} | ||
|
||
$output->writeln(''); | ||
$output->writeln('<comment>All locked imports:</comment>'); | ||
$output->writeln(''); | ||
|
||
(new Table($output)) | ||
->setHeaders(['Locks']) | ||
->setRows($locks) | ||
->render(); | ||
|
||
$output->writeln(''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.