# HG changeset patch # User ymh # Date 1318864634 -7200 # Node ID e63ac93fdbdec47013a7edd535088547b4973e87 # Parent 976d922e52f08664d7a710878d117933fed01ee4 add missing files diff -r 976d922e52f0 -r e63ac93fdbde Entity/DocumentListener.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Entity/DocumentListener.php Mon Oct 17 17:17:14 2011 +0200 @@ -0,0 +1,101 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace IRI\Bundle\WikiTagBundle\Entity; + +use Doctrine\Common\EventSubscriber; +use Doctrine\ORM\Events; +use Doctrine\ORM\Event\LifecycleEventArgs; +use Doctrine\ORM\Event\PreUpdateEventArgs; +use IRI\Bundle\WikiTagBundle\Model\DocumentInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + + +/** + * Doctrine ORM listener updating the document index + * + * @author ymh + * + */ +class DocumentListener implements EventSubscriber +{ + + /** + * @var ContainerInterface + */ + private $container; + + /** + * Constructor + * + * @param ContainerInterface $container + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + public function getSubscribedEvents() + { + return array( + Events::postPersist, + Events::postUpdate, + Events::preRemove, + ); + } + + public function postPersist(LifecycleEventArgs $args) + { + $logger = $this->container->get('logger'); + $logger->debug("HandleEvent : PERSISTS"); + $this->handleEvent($args); + + } + + public function postUpdate(LifecycleEventArgs $args) + { + $logger = $this->container->get('logger'); + $logger->debug("HandleEvent : UPDATE"); + $this->handleEvent($args); + } + + public function preRemove(LifecycleEventArgs $args) + { + $logger = $this->container->get('logger'); + $logger->debug("HandleEvent : REMOVE"); + $entity = $args->getEntity(); + if ($entity instanceof DocumentInterface && !($entity instanceof Document)) + { + $this->container->get('doctrine')->getRepository("WikiTagBundle:Document")->removeDocument($entity); + } + } + + + private function handleEvent(LifecycleEventArgs $args) + { +// if (null === $this->userManager) { +// $this->userManager = $this->container->get('fos_user.user_manager'); +// } + + $logger = $this->container->get('logger'); + $logger->debug("HandleEvent : HELLO############"); + + + $entity = $args->getEntity(); + if ($entity instanceof DocumentInterface && !($entity instanceof Document)) + { + $logger->debug("treating document : " . $entity->getTitle()); + $this->container->get('doctrine')->getRepository("WikiTagBundle:Document")->writeDocument($entity); + } + + } + + +} \ No newline at end of file diff -r 976d922e52f0 -r e63ac93fdbde Model/BaseDocumentInterface.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Model/BaseDocumentInterface.php Mon Oct 17 17:17:14 2011 +0200 @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace IRI\Bundle\WikiTagBundle\Model; + +interface BaseDocumentInterface extends DocumentInterface { + + /** + * TODO: Enter description here ... + * + * @param text $externalId + */ + function setExternalId($externalId); + + /** + * TODO: Enter description here ... + */ + function getExternalId(); + + + /** + * Set manualOrder + * + * @param boolean $manualOrder + */ + function setManualOrder($manualOrder); + + /** + * Get manualOrder + * + * @return boolean + */ + function getManualOrder(); + + + +}