Browse Source

update importation command: add option --file

develop
Simon Vieille 6 months ago
parent
commit
7c1c2a7233
Signed by: deblan GPG Key ID: 03383D15A1D31745
  1. 13
      README.md
  2. 26
      src/Command/MailImportCommand.php

13
README.md

@ -76,7 +76,7 @@ In case of you want to delete the mailing:
$ php bin/console mailing:delete xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```
Finally, create a script run in a cron:
Finally, create a script run in a cron:
```
#!/bin/sh
@ -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

26
src/Command/MailImportCommand.php

@ -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)) {
$io->error('Standard input is empty');
$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…
Cancel
Save