protected function makeSureHistoriesAreCorrect($contentsToSend)
 {
     $eventHistoryRepository = new EventHistoryRepository();
     $groupHistoryRepository = new GroupHistoryRepository();
     $areaHistoryRepository = new AreaHistoryRepository();
     $venueHistoryRepository = new VenueHistoryRepository();
     $importURLHistoryRepository = new ImportURLHistoryRepository();
     foreach ($contentsToSend as $contentToSend) {
         foreach ($contentToSend->getHistories() as $history) {
             $found = false;
             if ($history instanceof \models\EventHistoryModel) {
                 $eventHistoryRepository->ensureChangedFlagsAreSet($history);
                 $found = true;
             } elseif ($history instanceof \models\GroupHistoryModel) {
                 $groupHistoryRepository->ensureChangedFlagsAreSet($history);
                 $found = true;
             } elseif ($history instanceof \models\VenueHistoryModel) {
                 $venueHistoryRepository->ensureChangedFlagsAreSet($history);
                 $found = true;
             } elseif ($history instanceof \models\AreaHistoryModel) {
                 $areaHistoryRepository->ensureChangedFlagsAreSet($history);
                 $found = true;
             } elseif ($history instanceof \models\ImportURLHistoryModel) {
                 $importURLHistoryRepository->ensureChangedFlagsAreSet($history);
                 $found = true;
             }
             if (!$found) {
                 foreach ($this->app['extensions']->getExtensions() as $extension) {
                     $extension->makeSureHistoriesAreCorrect($history);
                 }
             }
         }
     }
 }
 function testIntegration2()
 {
     $this->addCountriesToTestDB();
     \TimeSource::mock(2014, 1, 1, 12, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     $countryRepo = new CountryRepository();
     $gb = $countryRepo->loadByTwoCharCode('GB');
     ## Create venue
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $venue = new VenueModel();
     $venue->setTitle("test");
     $venue->setDescription("test test");
     $venue->setCountryId($gb->getId());
     $venueRepo = new VenueRepository();
     $venueRepo->create($venue, $site, $user);
     ## Edit venue
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $venue = $venueRepo->loadById($venue->getId());
     $venue->setDescription("testy");
     $venue->setLat(3.6);
     $venue->setLng(3.7);
     $venueRepo->edit($venue, $user);
     ## Delete venue
     \TimeSource::mock(2014, 1, 1, 15, 0, 0);
     $venueRepo->delete($venue, $user);
     ## Now save changed flags on these .....
     $venueHistoryRepo = new VenueHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM venue_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $venueHistory = new VenueHistoryModel();
         $venueHistory->setFromDataBaseRow($data);
         $venueHistoryRepo->ensureChangedFlagsAreSet($venueHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setVenue($venue);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeGroupHistory(false);
     $historyRepo->setIncludeVenueHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(3, count($histories));
     #the delete
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getCountryIdChanged());
     $this->assertEquals(true, $histories[0]->getIsDeletedChanged());
     $this->assertEquals(false, $histories[0]->getLatChanged());
     $this->assertEquals(false, $histories[0]->getLngChanged());
     #the edit
     $this->assertEquals(FALSE, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(false, $histories[1]->getCountryIdChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
     $this->assertEquals(true, $histories[1]->getLatChanged());
     $this->assertEquals(true, $histories[1]->getLngChanged());
     #the create
     $this->assertEquals(true, $histories[2]->getTitleChanged());
     $this->assertEquals(true, $histories[2]->getDescriptionChanged());
     $this->assertEquals(true, $histories[2]->getCountryIdChanged());
     $this->assertEquals(false, $histories[2]->getIsDeletedChanged());
     $this->assertEquals(false, $histories[2]->getLatChanged());
     $this->assertEquals(false, $histories[2]->getLngChanged());
 }