You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

111 lines
2.5 KiB

<?php
use Spip\Cli\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressHelper;
class MailsubscriberSubscribe extends Command {
protected function configure() {
$this
->setName('mailsubscriber:subscribe')
->setDescription('Inscrire un email a des listes de diffusion')
->addOption(
'email',
null,
InputOption::VALUE_REQUIRED,
'email a inscrire',
null
)
->addOption(
'nom',
null,
InputOption::VALUE_OPTIONAL,
'Nom de la personne inscrite',
''
)
->addOption(
'listes',
null,
InputOption::VALUE_OPTIONAL,
'Listes (separées par des virgules si plusieurs)',
null
)
->addOption(
'lang',
null,
InputOption::VALUE_OPTIONAL,
'Lang de l\'inscrit',
null
)
->addOption(
'force',
null,
InputOption::VALUE_OPTIONAL,
'permet de forcer une inscription sans doubleoptin',
null
)
->addOption(
'graceful',
null,
InputOption::VALUE_OPTIONAL,
'permet de ne pas reinscrire quelqu\'un qui s\'est desabonne',
true
)
->addOption(
'notify',
null,
InputOption::VALUE_OPTIONAL,
'indique si on veut ou non notifier par email',
true
)
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
include_spip('inc/filtres');
$email = $input->getOption('email');
if (!$email) {
$output->writeln("<error>Indiquez un email</error>");
return self::FAILURE;
}
if (!$email = email_valide($email)) {
$output->writeln("<error>Indiquez un email valide</error>");
return self::FAILURE;
}
$options = array();
foreach (array('nom', 'lang', 'force', 'graceful', 'notify') as $o) {
if (!is_null($value= $input->getOption($o))) {
if (in_array($o, ['force', 'graceful', 'notify'])) {
if ($value === 'false') {
$value = false;
}
if ($value === 'true') {
$value = true;
}
}
$options[$o] = $value;
}
}
$listes = $input->getOption('listes');
if (!is_null($listes)) {
$options['listes'] = explode(',', $listes);
}
$subscribe = charger_fonction('subscribe', 'newsletter');
$subscribe($email, $options);
$subscriber = charger_fonction('subscriber', 'newsletter');
$infos = $subscriber($email);
$output->writeln(var_export($infos, true));
return self::SUCCESS;
}
}