function uncancel($slug, Request $request, Application $app)
 {
     if (!$this->build($slug, $request, $app)) {
         $app->abort(404, "Event does not exist.");
     }
     //TODO It's inefective to get them all when really we just want the latest one!
     $ehrb = new EventHistoryRepositoryBuilder();
     $ehrb->setEvent($this->parameters['event']);
     $ehrb->setOrderByCreatedAt(true);
     $eventHistories = $ehrb->fetchAll();
     $eventHistory = $eventHistories[0];
     return $app->redirect("/event/" . $this->parameters['event']->getSlugForURL() . '/rollback/' . $eventHistory->getCreatedAtTimeStamp());
 }
 public function testAddCustomFieldThenCreateEventWithContent()
 {
     TimeSource::mock(2014, 5, 1, 7, 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());
     $customFieldDefinition1 = new EventCustomFieldDefinitionModel();
     $customFieldDefinition1->setSiteId($site->getId());
     $customFieldDefinition1->setExtensionId('org.openacalendar');
     $customFieldDefinition1->setType('TextSingleLine');
     $customFieldDefinition1->setKey('cats');
     $customFieldDefinition1->setLabel('cats');
     $customFieldDefinition2 = new EventCustomFieldDefinitionModel();
     $customFieldDefinition2->setSiteId($site->getId());
     $customFieldDefinition2->setExtensionId('org.openacalendar');
     $customFieldDefinition2->setType('TextSingleLine');
     $customFieldDefinition2->setKey('dogs');
     $customFieldDefinition2->setLabel('dogs');
     $ecfRepo = new EventCustomFieldDefinitionRepository();
     $ecfRepo->create($customFieldDefinition1, $user);
     $ecfRepo->create($customFieldDefinition2, $user);
     $event = new EventModel();
     $event->setSummary("test");
     $event->setDescription("test test");
     $event->setStartAt(getUTCDateTime(2014, 5, 10, 19, 0, 0));
     $event->setEndAt(getUTCDateTime(2014, 5, 10, 21, 0, 0));
     $event->setUrl("http://www.info.com");
     $event->setTicketUrl("http://www.tickets.com");
     $event->setCustomField($customFieldDefinition1, "CATS");
     // CREATE WITH
     TimeSource::mock(2014, 5, 1, 7, 1, 0);
     $eventRepository = new EventRepository();
     $eventRepository->create($event, $site, $user);
     $event = $eventRepository->loadByID($event->getId());
     $this->assertEquals(true, $event->hasCustomField($customFieldDefinition1));
     $this->assertEquals(false, $event->hasCustomField($customFieldDefinition2));
     $this->assertFalse($event->getIsDeleted());
     // LET's CHECK HISTORY
     $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);
     }
     $eventHistoryRepoBuilder = new EventHistoryRepositoryBuilder();
     $eventHistoryRepoBuilder->setEvent($event);
     $histories = $eventHistoryRepoBuilder->fetchAll();
     $this->assertEquals(1, count($histories));
     $historyCreate = $histories[0];
     $this->assertTrue($historyCreate->getCustomFieldChangedKnown($customFieldDefinition1));
     $this->assertTrue($historyCreate->getCustomFieldChanged($customFieldDefinition1));
     $this->assertFalse($historyCreate->getCustomFieldChanged($customFieldDefinition2));
 }