Guest User

Untitled

a guest
Jun 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Check field casting in your entity setters
  5. * Anything that has a new type will be included in the changeset, and possibly trigger this event pointlessly. for example:
  6. * an integer not casted accordingly and passed as a string will trigger off this event (as there is a changeset present)
  7. */
  8.  
  9. use DoctrineExtensions\NestedSet;
  10.  
  11. class System_Doctrine_Events_Solr_UpdateRecord
  12. {
  13.  
  14. public function preUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs $eventArgs)
  15. {
  16. switch(get_class($eventArgs->getEntity()))
  17. {
  18. // Service Holiday MASTER record
  19. case 'Entities\ServiceHoliday':
  20. $serviceType = new System_Solr_Service_MasterHolidays();
  21. $nsConfig = new NestedSet\Config($eventArgs->getEntityManager(), 'Entities\Location');
  22. $nsManager = new NestedSet\Manager($nsConfig);
  23. // Inject the nsManager
  24. $serviceType->setLocationNsManager($nsManager);
  25. $solrService = new System_Solr_Service(APPLICATION_PATH . '/configs/solr.ini', $serviceType);
  26. $entry = $solrService->createEntry($eventArgs->getEntity());
  27. $solrService->add($entry);
  28.  
  29. //todo: we also need to update its children accordingly
  30. break;
  31. case 'Entities\ServiceHotel':
  32. //todo: update the master record stored in the solr index
  33. $serviceType = new System_Solr_Service_MasterHotels();
  34. $nsConfig = new NestedSet\Config($eventArgs->getEntityManager(), 'Entities\Location');
  35. $nsManager = new NestedSet\Manager($nsConfig);
  36. // Inject the nsManager
  37. $serviceType->setLocationNsManager($nsManager);
  38. $solrService = new System_Solr_Service(APPLICATION_PATH . '/configs/solr.ini', $serviceType);
  39. $entry = $solrService->createEntry($eventArgs->getEntity());
  40. $solrService->add($entry);
  41. //todo: update all the children of that master record
  42. case 'Entities\ServiceCarhire':
  43. //todo: we dont need to update the master records, but children should be updated
  44. break;
  45. case 'Entities\ServiceFlight':
  46. //todo: we dont need to update the master records, but children should be updated
  47. break;
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment