Skip to content

Instantly share code, notes, and snippets.

@SebLours
Last active August 24, 2016 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SebLours/b905a6c98e06f392d741d808cd15c5b5 to your computer and use it in GitHub Desktop.
Save SebLours/b905a6c98e06f392d741d808cd15c5b5 to your computer and use it in GitHub Desktop.
Show all softdeleteable entities class name (not for annotation config)
<?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));
}
}
}
}
@SebLours
Copy link
Author

I use a yaml config mapping. For annotation config just configure the Doctrine AnnotationReader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment