Doctrine\ODM\CouchDB\Tools\Console\Command\UpdateDesignDocCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $dm = $this->getHelper('couchdb')->getDocumentManager();
        $couchDbClient = $dm->getCouchDBClient();
        $config = $dm->getConfiguration();
        //If a docname is provided update only that document,
        //otherwise update all modified/new docs.
        if (is_string($inputDoc = $input->getArgument('docname'))) {
            $designDocNames = array($inputDoc);
        } else {
            $designDocNames = $config->getDesignDocumentNames();
        }
        $foundChanges = false;
        foreach ($designDocNames as $docName) {
            $designDocData = $config->getDesignDocument($docName);
            $localDesignDoc = new $designDocData['className']($designDocData['options']);
            $localDocBody = $localDesignDoc->getData();
            $remoteDocBody = $couchDbClient->findDocument('_design/' . $docName)->body;
            if ($this->isMissingOrDifferent($localDocBody, $remoteDocBody)) {
                $response = $couchDbClient->createDesignDocument($docName, $localDesignDoc);
                $foundChanges = true;
                if ($response->status < 300) {
                    $output->writeln("Succesfully updated: " . $docName);
                } else {
                    $output->writeln("Error updating {$docName}: {$response->body['reason']}");
                }
            }
        }
        if (!$foundChanges) {
            $output->writeln("No changes found; nothing to do.");
        }
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     DoctrineCommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm') ?: 'default');
     return parent::execute($input, $output);
 }