Last active
August 24, 2016 12:54
-
-
Save SebLours/b905a6c98e06f392d741d808cd15c5b5 to your computer and use it in GitHub Desktop.
Show all softdeleteable entities class name (not for annotation config)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Command; | |
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper; | |
use Gedmo\Mapping\ExtensionMetadataFactory; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
/** | |
* SoftDeleteableShowCommand | |
*/ | |
class SoftDeleteableEnabledCommand extends Command | |
{ | |
protected function configure() | |
{ | |
$this | |
->setName('app:softdeleteable:enabled') | |
->setDescription('Show all softdeleteable enabled entities') | |
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command'); | |
; | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em')); | |
$entityManager = $this->getHelper('em')->getEntityManager(); | |
$entityClassNames = $entityManager->getConfiguration() | |
->getMetadataDriverImpl() | |
->getAllClassNames() | |
; | |
$extensionMetadataFactory = new ExtensionMetadataFactory( | |
$entityManager, | |
'Gedmo\SoftDeleteable', | |
new \Doctrine\Common\Annotations\AnnotationReader() | |
); | |
foreach ($entityClassNames as $entityClassName) { | |
$classMetadata = $entityManager->getClassMetadata($entityClassName); | |
$config = $extensionMetadataFactory->getExtensionMetadata($classMetadata); | |
if ($config && $config['softDeleteable']) { | |
$output->writeLn(sprintf('enable for <info>%s</info>', $entityClassName)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use a yaml config mapping. For annotation config just configure the
Doctrine AnnotationReader