public function __construct(SiteModel $site = null, $timeZone = null, $title = null)
 {
     parent::__construct($site, $timeZone, $title);
     $this->historyRepositoryBuilder = new HistoryRepositoryBuilder();
     if ($site) {
         $this->historyRepositoryBuilder->setSite($site);
     }
 }
 function index(Request $request, Application $app)
 {
     $historyRepositoryBuilder = new HistoryRepositoryBuilder();
     $historyRepositoryBuilder->setSite($app['currentSite']);
     $historyRepositoryBuilder->getHistoryRepositoryBuilderConfig()->setLimit(200);
     return $app['twig']->render('site/history/index.html.twig', array('historyItems' => $historyRepositoryBuilder->fetchAll()));
 }
 /**
  * @return BaseUserWatchesNotifyContent|null
  */
 public function getUserNotifyContentForSiteAndUser(SiteModel $siteModel, UserAccountModel $userAccountModel)
 {
     global $CONFIG;
     $userWatchesSite = $this->loadByUserAndSite($userAccountModel, $siteModel);
     if ($userWatchesSite && $userWatchesSite->getIsWatching()) {
         $dateSince = $userWatchesSite->getSinceDateForNotifyChecking();
         $checkTime = \TimeSource::getDateTime();
         $historyRepositoryBuilder = new HistoryRepositoryBuilder();
         $historyRepositoryBuilder->setSite($siteModel);
         $historyRepositoryBuilder->setSince($dateSince);
         $historyRepositoryBuilder->setNotUser($userAccountModel);
         // Only admins can change tags at the moment so don't include
         $historyRepositoryBuilder->setIncludeTagHistory(false);
         $histories = $historyRepositoryBuilder->fetchAll();
         if ($histories) {
             $content = new UserWatchesSiteNotifyContent();
             $content->setHistories($histories);
             $userWatchesSiteStopRepository = new UserWatchesSiteStopRepository();
             $userWatchesSiteStop = $userWatchesSiteStopRepository->getForUserAndSite($userAccountModel, $siteModel);
             $content->setUnwatchURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/stopWatchingFromEmail/' . $userAccountModel->getId() . '/' . $userWatchesSiteStop->getAccessKey());
             $content->setUserAccount($userAccountModel);
             $content->setSite($siteModel);
             $content->setWatchedThingTitle($siteModel->getTitle());
             $content->setWatchedThingURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/history');
             return $content;
         }
     }
 }
 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 Event
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 9, 1, 1, 1, 1));
     $event->setEndAt(getUTCDateTime(2014, 9, 1, 1, 1, 1));
     $eventRepo = new EventRepository();
     $eventRepo->create($event, $site, $user);
     ## Edit event
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $event = $eventRepo->loadBySlug($site, $event->getSlug());
     $event->setDescription("testy 123");
     $eventRepo->edit($event, $user);
     # delete event
     \TimeSource::mock(2014, 1, 1, 15, 0, 0);
     $eventRepo->delete($event, $user);
     ## Now save changed flags on these .....
     $eventHistoryRepo = new EventHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM event_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $eventHistory = new EventHistoryModel();
         $eventHistory->setFromDataBaseRow($data);
         $eventHistoryRepo->ensureChangedFlagsAreSet($eventHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setSite($site);
     $historyRepo->setIncludeEventHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(3, count($histories));
     #the delete
     $this->assertEquals(FALSE, $histories[0]->getSummaryChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(true, $histories[0]->getIsDeletedChanged());
     #the edit
     $this->assertEquals(FALSE, $histories[1]->getSummaryChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[2]->getSummaryChanged());
     $this->assertEquals(true, $histories[2]->getDescriptionChanged());
     $this->assertEquals(false, $histories[2]->getIsDeletedChanged());
     ## Now load history at a certain point; this is to test rollback!
     $history = $eventHistoryRepo->loadByEventAndtimeStamp($event, getUTCDateTime(2014, 1, 1, 15, 0, 0)->getTimestamp());
     $this->assertEquals("test", $history->getSummary());
     $this->assertEquals("testy 123", $history->getDescription());
 }