function test1() { \TimeSource::mock(2014, 1, 1, 0, 0, 0); $this->addCountriesToTestDB(); $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'); $venue = new VenueModel(); $venue->setTitle("test"); $venue->setDescription("test test"); $venue->setCountryId($gb->getId()); \TimeSource::mock(2014, 1, 1, 1, 0, 0); $venueRepo = new VenueRepository(); $venueRepo->create($venue, $site, $user); \TimeSource::mock(2014, 1, 1, 2, 0, 0); $venueRepo->delete($venue, $user); $this->checkVenueInTest1($venueRepo->loadById($venue->getId())); $this->checkVenueInTest1($venueRepo->loadBySlug($site, $venue->getSlug())); $vrb = new VenueRepositoryBuilder(); $vrb->setIncludeDeleted(true); $this->assertEquals(1, count($vrb->fetchAll())); $vrb = new VenueRepositoryBuilder(); $vrb->setIncludeDeleted(false); $this->assertEquals(0, count($vrb->fetchAll())); }
function index($siteid, $slug, Request $request, Application $app) { global $CONFIG; $this->build($siteid, $slug, $request, $app); $form = $app['form.factory']->create(new ActionForm()); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); $action = new ActionParser($data['action']); if ($action->getCommand() == 'delete' && !$this->parameters['venue']->getIsDeleted()) { $vr = new VenueRepository(); $vr->delete($this->parameters['venue'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/venue/' . $this->parameters['venue']->getSlug()); } else { if ($action->getCommand() == 'undelete' && $this->parameters['venue']->getIsDeleted()) { $this->parameters['venue']->setIsDeleted(false); $vr = new VenueRepository(); $vr->undelete($this->parameters['venue'], $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/venue/' . $this->parameters['venue']->getSlug()); } else { if ($action->getCommand() == 'isduplicateof') { $vr = new VenueRepository(); $originalVenue = $vr->loadBySlug($this->parameters['site'], $action->getParam(0)); if ($originalVenue && $originalVenue->getId() != $this->parameters['venue']->getId()) { $vr->markDuplicate($this->parameters['venue'], $originalVenue, $app['currentUser']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/venue/' . $this->parameters['venue']->getSlug()); } } else { if ($action->getCommand() == 'purge' && $CONFIG->sysAdminExtraPurgeVenuePassword && $CONFIG->sysAdminExtraPurgeVenuePassword == $action->getParam(0)) { $vr = new VenueRepository(); $vr->purge($this->parameters['venue']); return $app->redirect('/sysadmin/site/' . $this->parameters['site']->getId() . '/venue/'); } } } } } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('sysadmin/venue/index.html.twig', $this->parameters); }
function delete($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Venue does not exist."); } if ($this->parameters['venue']->getIsDeleted()) { die("No"); // TODO } $form = $app['form.factory']->create(new VenueDeleteForm()); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $eventRepository = new EventRepository(); $eventRepository->moveAllFutureEventsAtVenueToNoSetVenue($this->parameters['venue'], $app['currentUser']); $venueRepository = new VenueRepository(); $venueRepository->delete($this->parameters['venue'], $app['currentUser']); return $app->redirect("/venue/" . $this->parameters['venue']->getSlugForURL()); } } $rb = new EventRepositoryBuilder(); $rb->setVenue($this->parameters['venue']); $rb->setAfterNow(true); $rb->setIncludeDeleted(false); $this->parameters['events'] = $rb->fetchAll(); $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/venue/delete.html.twig', $this->parameters); }
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()); }