Skip to content

Commit

Permalink
moved DocumentMigrateClassCommand to PHPCR ODM
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Feb 4, 2014
1 parent c51cc09 commit a4bc86d
Showing 1 changed file with 7 additions and 46 deletions.
53 changes: 7 additions & 46 deletions OptionalCommand/ODM/DocumentMigrateClassCommand.php
Expand Up @@ -20,81 +20,42 @@

namespace Doctrine\Bundle\PHPCRBundle\OptionalCommand\ODM;

use PHPCR\Util\Console\Command\NodesUpdateCommand;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ODM\PHPCR\Tools\Console\Command\DocumentMigrateClassCommand as BaseDocumentMigrateClassCommand;
use Doctrine\Bundle\PHPCRBundle\Command\DoctrineCommandHelper;

/**
* @author Daniel Leech <daniel@dantleech.com>
*/
class DocumentMigrateClassCommand extends NodesUpdateCommand
class DocumentMigrateClassCommand extends BaseDocumentMigrateClassCommand
{
/**
* {@inheritDoc}
*/
protected function configure()
{
$this
->setName('doctrine:phpcr:document:migrate-class')
->addOption(
parent::configure();

$this->addOption(
'session', null,
InputOption::VALUE_OPTIONAL,
'The session to use for this command'
)
->setDescription('Command to migrate document classes.')

->addArgument('classname', InputArgument::REQUIRED, 'Old class name (does not need to exist in current codebase')
->addArgument('new-classname', InputArgument::REQUIRED, 'New class name (must exist in current codebase')
->setHelp(<<<HERE
The <info>doctrine:phpcr:docment:migrate-class</info> command migrates document classes matching the given old class name to given new class name.
<info>$ php ./app/console/phpcr doctrine:phpcr:document:migrate-class "Old\\ClassName" "New\\ClassName"</info>
HERE
);
);
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// we do not want to expose the parent options, but use the arguments and
// options to pass information to the parent.
parent::configure();

DoctrineCommandHelper::setApplicationPHPCRSession(
$this->getApplication(),
$input->getOption('session')
);

$classname = $input->getArgument('classname');
$newClassname = $input->getArgument('new-classname');

if (!class_exists($newClassname)) {
throw new \Exception(sprintf('New class name "%s" does not exist.',
$newClassname
));
}

$classParents = array_reverse(class_parents($newClassname));

$input->setOption('query', sprintf(
'SELECT * FROM [nt:base] WHERE [phpcr:class] = "%s"',
$classname
));

$input->setOption('apply-closure', array(
function ($session, $node) use ($newClassname, $classParents) {
$node->setProperty('phpcr:class', $newClassname);
$node->setProperty('phpcr:classparents', $classParents);
}
));

parent::execute($input, $output);
return parent::execute($input, $output);
}
}

0 comments on commit a4bc86d

Please sign in to comment.