<commit_before><?php

namespace Doctrine\ODM\MongoDB\Tools\Console\Command;

use Symfony\Components\Console\Command\Command;
use Symfony\Components\Console\Input;
use Symfony\Components\Console\Output;

/**
 * @author <NAME> <<EMAIL>>
 */
class IndexesCommand extends Command
{
    const CREATE  = 'ensure';
    const DROP    = 'delete';
    const REPLACE = 'replace';

    protected function configure()
    {
        $this
            ->setName('odm:mongodb:indexes')
            ->setDescription('Ensure all indexes for a document class')
            ->setDefinition(array(
                new Input\InputOption('mode', 'm', Input\InputOption::PARAMETER_REQUIRED, 'allows to \'' . self::CREATE . '\', \'' . self::DROP . '\', \'' . self::REPLACE . '\' all indexes for a document', self::CREATE),
                new Input\InputArgument('class', Input\InputArgument::REQUIRED, 'name of the class to ensure indexes for'),
            ))
        ;
    }

    protected function execute(Input\InputInterface $input, Output\OutputInterface $output)
    {
        $dm = $this->getDocumentManager();
        $className = $input->getArgument('class');
        $mode = $input->getOption('mode');
        $replace = false;
        $message = null;
        switch ($mode) {
            case self::REPLACE:
                $replace = true;
                $message = $message ?: 'Sucessfully replaced indexes for ' . $className;
            case self::DROP:
                $message = $message ?: 'Sucessfully deleted indexes for ' . $className;
                $dm->deleteDocumentIndexes($className);
                if ( ! $replace) {
                    break;
                }
            case self::CREATE:
                $message = $message ?: 'Sucessfully ensured indexes for ' . $className;
                $dm->ensureDocumentIndexes($className);
                break;
            default:
                throw new \InvalidArgumentException('Option \'mode\' must be one of \'' . self::CREATE . '\', \'' . self::DROP . '\' or \'' . self::REPLACE . '\'. \'' . $mode . '\' given.');
        }
        $output->write('<info>' . $message . '</info>');
    }
    /**
     * @return Doctrine\ODM\MongoDB\DocumentManager
     */
    protected function getDocumentManager() {
        return $this->getHelper('documentManager')->getDocumentManager();
    }
}<commit_msg>modified to allow index updates for all classes<commit_after><?php

namespace Doctrine\ODM\MongoDB\Tools\Console\Command;

use Symfony\Components\Console\Command\Command;
use Symfony\Components\Console\Input;
use Symfony\Components\Console\Output;

/**
 * @author <NAME> <<EMAIL>>
 */
class IndexesCommand extends Command
{
    const CREATE  = 'ensure';
    const DROP    = 'delete';
    const REPLACE = 'replace';

    protected function configure()
    {
        $this
            ->setName('odm:mongodb:indexes')
            ->setDescription('Ensure all indexes for a document class')
            ->setDefinition(array(
                new Input\InputOption('mode', 'm', Input\InputOption::PARAMETER_REQUIRED, 'allows to \'' . self::CREATE . '\', \'' . self::DROP . '\', \'' . self::REPLACE . '\' all indexes for a document', self::CREATE),
                new Input\InputOption('class', 'c', Input\InputOption::PARAMETER_OPTIONAL, 'the class name to ensure indexes for', null),
            ))
        ;
    }

    protected function execute(Input\InputInterface $input, Output\OutputInterface $output)
    {
        $mode = $input->getOption('mode');
		$classNames = array();

		if (null === ($className = $input->getOption('class'))) {
			foreach ($this->getMetadataFactory()->getAllMetadata() as $metadata) {
				$classNames[] = $metadata->name;
			}
		} else {
			$classNames[] = $className;
		}
		foreach ($classNames as $className) {
			try {
				$output->writeln('<info>' . $this->runIndexUpdatesForClass($className, $mode) . '</info>');
			} catch (\Exception $e) {
				$output->writeln('<error>' . $e->getMessage() . '</error>');
			}
		}
    }

	protected function runIndexUpdatesForClass($className, $mode)
	{
        $dm = $this->getDocumentManager();
        $replace = false;
        $message = null;
        switch ($mode) {
            case self::REPLACE:
                $replace = true;
                $message = $message ?: 'Sucessfully replaced indexes for ' . $className;
            case self::DROP:
                $message = $message ?: 'Sucessfully deleted indexes for ' . $className;
                $dm->deleteDocumentIndexes($className);
                if ( ! $replace) {
                    break;
                }
            case self::CREATE:
                $message = $message ?: 'Sucessfully ensured indexes for ' . $className;
                $dm->ensureDocumentIndexes($className);
                break;
            default:
                throw new \InvalidArgumentException('Option \'mode\' must be one of \'' . self::CREATE . '\', \'' . self::DROP . '\' or \'' . self::REPLACE . '\'. \'' . $mode . '\' given.');
        }
		return $message;
	}

	/**
     * @return Doctrine\ODM\MongoDB\DocumentManager
     */
    protected function getDocumentManager()
	{
        return $this->getHelper('documentManager')->getDocumentManager();
    }
	
	/**
	 * @return Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory
	 */
	protected function getMetadataFactory()
	{
		return $this->getDocumentManager()->getMetadataFactory();
	}
}
{'fraction_non_alphanumeric': 0.15177749125069073, 'fraction_numerical': 0.0, 'mean_word_length': 2.2949029126213594, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6614437', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1505, 'n_words': 330}