Skip to content

Commit

Permalink
Merge pull request #3 from Padam87/feature/path
Browse files Browse the repository at this point in the history
Feature/path
  • Loading branch information
Padam87 committed Jan 14, 2016
2 parents bcf1b00 + 41669c2 commit cde208e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
16 changes: 13 additions & 3 deletions Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DumpCommand extends ConfigurationAwareCommand
protected function configure()
{
parent::configure();

$this
->setName('cron:dump')
->setDescription('Dumps jobs to a crontab file')
Expand All @@ -29,12 +29,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);

$group = $input->getOption('group');
$this->dump($input);
}

/**
* @param InputInterface $input
*
* @return string
*/
protected function dump(InputInterface $input)
{
$reader = new AnnotationReader();
$helper = new Helper($this->getApplication(), $reader);

$tab = $helper->read($input, $group);
$tab = $helper->read($input, $input->getOption('group'), $this->getConfiguration());

$path = strtolower(
sprintf(
Expand All @@ -43,5 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
)
);
file_put_contents($path, (string) $tab);

return $path;
}
}
21 changes: 5 additions & 16 deletions Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

class ImportCommand extends ConfigurationAwareCommand
class ImportCommand extends DumpCommand
{
/**
* {@inheritdoc}
Expand All @@ -32,22 +32,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);

$user = $input->getOption('user');
$group = $input->getOption('group');

$reader = new AnnotationReader();
$helper = new Helper($this->getApplication(), $reader);
$path = $this->dump($input);

$path = strtolower(
sprintf(
'%s/%s-%s.crontab',
sys_get_temp_dir(),
$this->getApplication()->getName(),
time()
)
);
$content = $helper->read($input, $group);
file_put_contents($path, (string) $content);
$user = $input->getOption('user');

$command = sprintf(
'crontab%s %s',
Expand All @@ -63,6 +50,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln($process->getErrorOutput());
}

unlink($path);

return $process->getExitCode();
}
}
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function getConfigTreeBuilder()
->defaultValue('')
->info('Cron log directory')
->end()
->scalarNode('path')
->defaultValue(null)
->info('Cron path variable')
->end()
->end()
;

Expand Down
9 changes: 7 additions & 2 deletions Util/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public function __construct(Application $application, AnnotationReader $annotati

/**
* @param InputInterface $input
* @param null $group
* @param string|null $group
* @param array|null $config
*
* @return Tab
*/
public function read(InputInterface $input = null, $group = null)
public function read(InputInterface $input = null, $group = null, array $config = null)
{
$tab = new Tab();

Expand Down Expand Up @@ -68,6 +69,10 @@ public function read(InputInterface $input = null, $group = null)
$vars['SYMFONY_ENV'] = $input->getOption('env');
$vars['MAILTO'] = $input->getOption('mailto');

if ($config != null && isset($config['path']) && $config['path'] != null) {
$vars['PATH'] = $config['path'];
}

return $tab;
}
}

0 comments on commit cde208e

Please sign in to comment.