diff -r 99c15cfe420b -r b435f8055cb4 Command/SyncDocumentsCommand.php --- a/Command/SyncDocumentsCommand.php Fri Oct 28 14:57:11 2011 +0200 +++ b/Command/SyncDocumentsCommand.php Fri Nov 04 11:56:59 2011 +0100 @@ -27,13 +27,12 @@ $this ->setName('wikitag:sync-doc') ->setDescription('Synchronize and index document class') - ->addArgument('class', InputArgument::REQUIRED, 'The document class') ->addOption('clear', 'c', InputOption::VALUE_NONE, "clear all docs"); } protected function execute(InputInterface $input, OutputInterface $output) { - $class = $input->getArgument('class'); + $class = $this->getContainer()->getParameter('wiki_tag.document_class'); $clear = $input->getOption('clear'); @@ -52,25 +51,14 @@ //TODO : write progress $doclist = $rep->findAll(); foreach ($doclist as $doc) { - $output->writeln("TITLE : ".$doc->getTitle()); - $docrep->writeDocument($doc); + $docrep->writeDocument($doc, $this->getContainer()->getParameter('wiki_tag.document_id_column'), $this->getContainer()->getParameter('wiki_tag.fields')); } $doctrine->getEntityManager()->flush(); if($clear) { - $req_ids = $doctrine->getEntityManager()->createQuery("SELECT partial doc.{id} FROM $class doc"); - $doc_ids = array(); - foreach($req_ids->getResult(Query::HYDRATE_SCALAR) as $doc_id) { - $doc_ids[] = strval($doc_id['doc_id']); - } - - $req = $doctrine->getEntityManager()->createQuery("SELECT wtdoc FROM WikiTagBundle:Document wtdoc WHERE wtdoc.externalId NOT IN (:doc_ids)"); - $req->setParameter('doc_ids', $doc_ids); - foreach ($req->getResult() as $wtdoc) { - $output->writeln("DELETE : ".$wtdoc->getId()); - $doctrine->getEntityManager()->remove($wtdoc); - } + $req = $doctrine->getEntityManager()->createQuery("DELETE WikiTagBundle:Document wtdoc WHERE wtdoc.externalId NOT IN (SELECT doc FROM $class doc)"); + $req->getResult(); $doctrine->getEntityManager()->flush(); }