Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Check field casting in your entity setters
- * Anything that has a new type will be included in the changeset, and possibly trigger this event pointlessly. for example:
- * an integer not casted accordingly and passed as a string will trigger off this event (as there is a changeset present)
- */
- use DoctrineExtensions\NestedSet;
- class System_Doctrine_Events_Solr_UpdateRecord
- {
- public function preUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs $eventArgs)
- {
- switch(get_class($eventArgs->getEntity()))
- {
- // Service Holiday MASTER record
- case 'Entities\ServiceHoliday':
- $serviceType = new System_Solr_Service_MasterHolidays();
- $nsConfig = new NestedSet\Config($eventArgs->getEntityManager(), 'Entities\Location');
- $nsManager = new NestedSet\Manager($nsConfig);
- // Inject the nsManager
- $serviceType->setLocationNsManager($nsManager);
- $solrService = new System_Solr_Service(APPLICATION_PATH . '/configs/solr.ini', $serviceType);
- $entry = $solrService->createEntry($eventArgs->getEntity());
- $solrService->add($entry);
- //todo: we also need to update its children accordingly
- break;
- case 'Entities\ServiceHotel':
- //todo: update the master record stored in the solr index
- $serviceType = new System_Solr_Service_MasterHotels();
- $nsConfig = new NestedSet\Config($eventArgs->getEntityManager(), 'Entities\Location');
- $nsManager = new NestedSet\Manager($nsConfig);
- // Inject the nsManager
- $serviceType->setLocationNsManager($nsManager);
- $solrService = new System_Solr_Service(APPLICATION_PATH . '/configs/solr.ini', $serviceType);
- $entry = $solrService->createEntry($eventArgs->getEntity());
- $solrService->add($entry);
- //todo: update all the children of that master record
- case 'Entities\ServiceCarhire':
- //todo: we dont need to update the master records, but children should be updated
- break;
- case 'Entities\ServiceFlight':
- //todo: we dont need to update the master records, but children should be updated
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment