function testIntegration1()
 {
     \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());
     ## Create group
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     ## Edit group
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $group = $groupRepo->loadById($group->getId());
     $group->setTwitterUsername("testy");
     $groupRepo->edit($group, $user);
     ## Now save changed flags on these .....
     $groupHistoryRepo = new GroupHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM group_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $groupHistory = new GroupHistoryModel();
         $groupHistory->setFromDataBaseRow($data);
         $groupHistoryRepo->ensureChangedFlagsAreSet($groupHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setGroup($group);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getUrlChanged());
     $this->assertEquals(true, $histories[0]->getTwitterUsernameChanged());
     $this->assertEquals(false, $histories[0]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(true, $histories[1]->getUrlChanged());
     $this->assertEquals(false, $histories[1]->getTwitterUsernameChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 protected function run()
 {
     $groupHistoryRepo = new GroupHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM group_history");
     $stat->execute();
     $count = 0;
     while ($data = $stat->fetch()) {
         $groupHistory = new GroupHistoryModel();
         $groupHistory->setFromDataBaseRow($data);
         $groupHistoryRepo->ensureChangedFlagsAreSet($groupHistory);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 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);
                 }
             }
         }
     }
 }