/
RefreshEntitiesCommand.php
53 lines (44 loc) · 1.74 KB
/
RefreshEntitiesCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Concrete\Core\Console\Command;
use Concrete\Core\Console\Command;
use Concrete\Core\Database\DatabaseStructureManager;
use Concrete\Core\Package\Event\PackageEntities;
use Concrete\Core\Support\Facade\Application;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class RefreshEntitiesCommand extends Command
{
protected function configure()
{
$errExitCode = static::RETURN_CODE_ON_FAILURE;
$this
->setName('c5:entities:refresh')
->setDescription('Refresh the Doctrine database entities')
->addEnvOption()
->setCanRunAsRoot(false)
->setHelp(<<<EOT
This command will refresh the Doctrine database entities and set the following return codes
0 operation completed successfully
{$errExitCode} errors occurred
EOT
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$app = Application::getFacadeApplication();
$pev = new PackageEntities();
$app->make(EventDispatcherInterface::class)->dispatch('on_refresh_package_entities', $pev);
$entityManagers = array_merge([$app->make(EntityManagerInterface::class)], $pev->getEntityManagers());
foreach ($entityManagers as $em) {
$manager = new DatabaseStructureManager($em);
$manager->refreshEntities();
}
if ($output->getVerbosity() >= $output::VERBOSITY_NORMAL) {
$output->writeln('Doctrine cache cleared, proxy classes regenerated, entity database table schema updated.');
}
return 0;
}
}