Skip to content

Commit 1c7f620

Browse files
authored
Merge pull request #7328 from christianbeeznest/rna-23159
Internal: Skip gradebook attendances in migrations + fast SQL attendance migration - refs BT#23159
2 parents 7062b31 + f3ecce2 commit 1c7f620

5 files changed

Lines changed: 687 additions & 54 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 Symfony\Component\Console\Command\Command;
10+
use Symfony\Component\Console\Input\ArrayInput;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Input\InputOption;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
final class DoctrineMigrationsMigrateCommandDecorator extends Command
16+
{
17+
public const SKIP_ATTENDANCES_FLAG = 'CHAMILO_MIGRATION_SKIP_ATTENDANCES';
18+
19+
public function __construct(private readonly Command $inner)
20+
{
21+
parent::__construct($inner->getName() ?: 'doctrine:migrations:migrate');
22+
}
23+
24+
protected function configure(): void
25+
{
26+
$this->setName($this->inner->getName() ?: 'doctrine:migrations:migrate');
27+
$this->setDescription((string) $this->inner->getDescription());
28+
$this->setHelp((string) $this->inner->getHelp());
29+
30+
$definition = clone $this->inner->getDefinition();
31+
$this->setDefinition($definition);
32+
33+
$this->addOption(
34+
'skip-attendances',
35+
null,
36+
InputOption::VALUE_NONE,
37+
'When enabled, only migrate attendances linked to gradebook (type=7). Others will be skipped.'
38+
);
39+
}
40+
41+
protected function execute(InputInterface $input, OutputInterface $output): int
42+
{
43+
$skipAttendances = (bool) $input->getOption('skip-attendances');
44+
45+
if ($skipAttendances) {
46+
$_SERVER[self::SKIP_ATTENDANCES_FLAG] = '1';
47+
$_ENV[self::SKIP_ATTENDANCES_FLAG] = '1';
48+
putenv(self::SKIP_ATTENDANCES_FLAG.'=1');
49+
}
50+
51+
try {
52+
$innerDefinition = $this->inner->getDefinition();
53+
$data = [];
54+
55+
foreach ($innerDefinition->getArguments() as $name => $argument) {
56+
$value = $input->getArgument($name);
57+
if (null !== $value) {
58+
$data[$name] = $value;
59+
}
60+
}
61+
62+
foreach ($innerDefinition->getOptions() as $name => $option) {
63+
$value = $input->getOption($name);
64+
65+
if ($option->acceptValue()) {
66+
if (null !== $value) {
67+
$data['--'.$name] = $value;
68+
}
69+
} else {
70+
if (true === $value) {
71+
$data['--'.$name] = true;
72+
}
73+
}
74+
}
75+
76+
$innerInput = new ArrayInput($data, $innerDefinition);
77+
$innerInput->setInteractive($input->isInteractive());
78+
79+
return $this->inner->run($innerInput, $output);
80+
} finally {
81+
unset($_SERVER[self::SKIP_ATTENDANCES_FLAG], $_ENV[self::SKIP_ATTENDANCES_FLAG]);
82+
putenv(self::SKIP_ATTENDANCES_FLAG);
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)