1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Command; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Framework\Container; |
10
|
|
|
use Database; |
11
|
|
|
use Doctrine\ORM\EntityManager; |
12
|
|
|
use Notification; |
13
|
|
|
use Symfony\Component\Console\Command\Command; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
18
|
|
|
|
19
|
|
|
class SendNotificationsCommand extends Command |
20
|
|
|
{ |
21
|
|
|
protected static $defaultName = 'app:send-notifications'; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
private readonly EntityManager $em |
25
|
|
|
) { |
26
|
|
|
parent::__construct(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function configure(): void |
30
|
|
|
{ |
31
|
|
|
$this |
32
|
|
|
->setDescription('Send notifications') |
33
|
|
|
->addOption('debug', null, InputOption::VALUE_NONE, 'Enable debug mode') |
34
|
|
|
->setHelp('This command sends notifications using the Notification class.'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
38
|
|
|
{ |
39
|
|
|
Database::setManager($this->em); |
40
|
|
|
|
41
|
|
|
$container = $this->getApplication()->getKernel()->getContainer(); |
42
|
|
|
Container::setContainer($container); |
43
|
|
|
|
44
|
|
|
$io = new SymfonyStyle($input, $output); |
45
|
|
|
$debug = $input->getOption('debug'); |
46
|
|
|
|
47
|
|
|
if ($debug) { |
48
|
|
|
error_log('Debug mode activated'); |
49
|
|
|
$io->note('Debug mode activated'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$notification = new Notification(); |
53
|
|
|
$notification->send(); |
54
|
|
|
|
55
|
|
|
if ($debug) { |
56
|
|
|
error_log('Notifications have been sent.'); |
57
|
|
|
$io->success('Notifications have been sent successfully.'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return Command::SUCCESS; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|