update importation command: add option --file
This commit is contained in:
parent
54772127a4
commit
7c1c2a7233
11
README.md
11
README.md
|
@ -84,12 +84,19 @@ Finally, create a script run in a cron:
|
|||
cd "/path/to/app"
|
||||
|
||||
find /var/lib/mailrss -name "foobar-*" | while read MAIL_FILE; do
|
||||
cat "MAIL_FILE" | php bin/console mail:import xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
MAILING_ID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
rm "MAIL_FILE"
|
||||
php bin/console mail:import "$MAILING_ID" -f "$MAIL_FILE" && rm "$MAIL_FILE"
|
||||
done
|
||||
```
|
||||
|
||||
You also can import a mail using stdin:
|
||||
|
||||
```
|
||||
$ php bin/console mail:import "$MAILING_ID" < "$MAIL_FILE"
|
||||
$ command | php bin/console mail:import "$MAILING_ID"
|
||||
```
|
||||
|
||||
If you wan create another feed then:
|
||||
|
||||
* Create an aliase
|
||||
|
|
|
@ -39,6 +39,7 @@ class MailImportCommand extends Command
|
|||
{
|
||||
$this
|
||||
->setDescription('Import a mail into a mailing')
|
||||
->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'File')
|
||||
->addArgument('mailing_id', InputArgument::OPTIONAL, 'ID of the mailing')
|
||||
;
|
||||
}
|
||||
|
@ -47,6 +48,7 @@ class MailImportCommand extends Command
|
|||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$mailingId = $input->getArgument('mailing_id');
|
||||
$file = $input->getOption('file');
|
||||
|
||||
$mailing = $this->mailingRepo->find(['id' => $mailingId]);
|
||||
|
||||
|
@ -56,16 +58,32 @@ class MailImportCommand extends Command
|
|||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$stdIn = file_get_contents('php://stdin');
|
||||
if (empty($file)) {
|
||||
$file = 'php://stdin';
|
||||
|
||||
if (empty($stdIn)) {
|
||||
$content = trim(file_get_contents($file));
|
||||
|
||||
if (empty($content)) {
|
||||
$io->error('Standard input is empty');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
} elseif (file_exists($file) && is_readable($file) && is_file($file)) {
|
||||
$content = trim(file_get_contents($file));
|
||||
|
||||
if (empty($content)) {
|
||||
$io->error('File is empty');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
} else {
|
||||
$io->error('No such file or is not readable');
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$parser = new Parser();
|
||||
$parser->setText($stdIn);
|
||||
$parser->setText($content);
|
||||
|
||||
$subject = $parser->getHeader('subject');
|
||||
$date = $parser->getHeader('date');
|
||||
|
|
Loading…
Reference in a new issue