3 namespace Wallabag\CoreBundle\Command
;
5 use Doctrine\ORM\NoResultException
;
6 use Symfony\Component\Console\Input\InputArgument
;
7 use Symfony\Component\Console\Input\InputInterface
;
8 use Symfony\Component\Console\Output\OutputInterface
;
9 use Wallabag\CoreBundle\Entity\Notification
;
10 use Wallabag\CoreBundle\Notifications\Action
;
11 use Wallabag\UserBundle\Entity\User
;
13 class ReleaseNotificationCommand
extends AbstractNotificationCommand
15 /** @var OutputInterface */
18 protected function configure()
21 ->setName('wallabag:notification:release')
22 ->setDescription('Emits a notification to all users to let them know of a new release')
23 ->setHelp('This command helps you send a release notification to all of the users instance, or just for one user.')
26 InputArgument
::OPTIONAL
,
27 'A link to display with the notification'
33 protected function execute(InputInterface
$input, OutputInterface
$output)
35 $this->output
= $output;
37 $username = $input->getArgument('username');
39 $link = $input->getArgument('link');
43 $user = $this->getUser($username);
44 $this->sendNotification($user, $link);
45 } catch (NoResultException
$e) {
46 $output->writeln(sprintf('<error>User "%s" not found.</error>', $username));
51 $users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll();
53 $output->writeln(sprintf('Sending notifications to %d user accounts. This can take some time.', count($users)));
55 foreach ($users as $user) {
56 $output->writeln(sprintf('Processing user %s', $user->getUsername()));
57 $this->sendNotification($user, $link);
59 $output->writeln('Finished sending notifications.');
68 private function sendNotification(User
$user, $link)
70 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
72 $notification = new Notification($user);
73 $notification->setTitle('notifications.release.title')
74 ->addParameter('%version%', $this->getContainer()->getParameter('wallabag_core.version'))
75 ->setType(Notification
::TYPE_RELEASE
);
77 $details = new Action();
78 $details->setType(Action
::TYPE_INFO
)
79 ->setLabel('notifications.release.details')
81 $notification->addAction($details);
83 $em->persist($notification);
86 $this->output
->writeln(sprintf('Sent notification for user %s', $user->getUserName()));