function create(Request $request, Application $app) { $siteRepository = new SiteRepository(); $form = $app['form.factory']->create(new CreateForm()); if ('POST' == $request->getMethod()) { $form->bind($request); $data = $form->getData(); $site = $siteRepository->loadBySlug($data['slug']); if ($site) { $form->addError(new FormError('That address is already taken')); } if ($form->isValid()) { $site = new SiteModel(); $site->setSlug($data['slug']); $site->setTitle($data['title']); if ($data['read'] == 'public') { $site->setIsListedInIndex(true); $site->setIsWebRobotsAllowed(true); } else { $site->setIsListedInIndex(false); $site->setIsWebRobotsAllowed(false); } if ($data['write'] == 'public') { $isAllUsersEditors = true; } else { $isAllUsersEditors = false; } $site->setPromptEmailsDaysInAdvance($app['config']->newSitePromptEmailsDaysInAdvance); $countryRepository = new CountryRepository(); $siteQuotaRepository = new SiteQuotaRepository(); $siteRepository->create($site, $app['currentUser'], array($countryRepository->loadByTwoCharCode("GB")), $siteQuotaRepository->loadByCode($app['config']->newSiteHasQuotaCode), $isAllUsersEditors); if ($app['config']->hasSSL) { return $app->redirect("https://" . $site->getSlug() . "." . $app['config']->webSiteDomainSSL); } else { return $app->redirect("http://" . $site->getSlug() . "." . $app['config']->webSiteDomain); } } } $sites = array(); $repo = new SiteRepository(); if (isset($_COOKIE['sitesSeen'])) { foreach (explode(",", $_COOKIE['sitesSeen']) as $siteID) { if (intval($siteID) > 0) { $site = $repo->loadById($siteID); if ($site && !$site->getIsClosedBySysAdmin() && $site->getSlug() != $app['config']->siteSlugDemoSite) { $sites[$site->getId()] = $site; } } } } $srb = new SiteRepositoryBuilder(); $srb->setIsOpenBySysAdminsOnly(true); $srb->setUserInterestedIn($app['currentUser']); foreach ($srb->fetchAll() as $site) { $sites[$site->getId()] = $site; } return $app['twig']->render('index/index/create.html.twig', array('form' => $form->createView(), 'sites' => $sites)); }
function index(Request $request, Application $app) { $form = $app['form.factory']->create(new NewSiteForm()); if ('POST' == $request->getMethod()) { $form->bind($request); $data = $form->getData(); $siteRepository = new SiteRepository(); $site = $siteRepository->loadBySlug($data['slug']); if ($site) { $form->addError(new FormError('That address is already taken')); } if ($form->isValid()) { $userRepo = new UserAccountRepository(); $user = $userRepo->loadByEmail($data['email']); if ($user) { $data = $form->getData(); $site = new SiteModel(); $site->setSlug($data['slug']); $site->setTitle($data['title']); if ($data['read'] == 'public') { $site->setIsListedInIndex(true); $site->setIsWebRobotsAllowed(true); } else { $site->setIsListedInIndex(false); $site->setIsWebRobotsAllowed(false); } if ($data['write'] == 'public') { $site->setIsAllUsersEditors(true); $site->setIsRequestAccessAllowed(false); } else { $site->setIsAllUsersEditors(false); $site->setIsRequestAccessAllowed(true); } $site->setIsFeatureCuratedList($app['config']->newSiteHasFeatureCuratedList); $site->setIsFeatureImporter($app['config']->newSiteHasFeatureImporter); $site->setIsFeatureMap($app['config']->newSiteHasFeatureMap); $site->setIsFeatureVirtualEvents($app['config']->newSiteHasFeatureVirtualEvents); $site->setIsFeaturePhysicalEvents($app['config']->newSiteHasFeaturePhysicalEvents); $site->setIsFeatureGroup($app['config']->newSiteHasFeatureGroup); $site->setPromptEmailsDaysInAdvance($app['config']->newSitePromptEmailsDaysInAdvance); $site->setIsFeatureTag($app['config']->newSiteHasFeatureTag); $countryRepository = new CountryRepository(); $siteQuotaRepository = new SiteQuotaRepository(); $siteRepository->create($site, $user, array($countryRepository->loadByTwoCharCode("GB")), $siteQuotaRepository->loadByCode($app['config']->newSiteHasQuotaCode)); return $app->redirect("/sysadmin/site/" . $site->getId()); } else { $app['flashmessages']->addError('Existing user not found!'); } } } return $app['twig']->render('sysadmin/sitenew/index.html.twig', array('form' => $form->createView())); }
$slug = $argv[1]; $email = $argv[2]; if (!$slug || !$email) { die("Slug and Email?\n\n"); } if (!SiteModel::isSlugValid($slug, $CONFIG)) { die("Slug is not valid!\n\n"); } print "Slug: " . $slug . "\n"; print "Email: " . $email . "\n"; sleep(10); print "Starting ...\n"; $userRepository = new UserAccountRepository(); $user = $userRepository->loadByUserNameOrEmail($email); if (!$user) { die("Can't load user!\n\n"); } $site = new SiteModel(); $site->setSlug($slug); $site->setTitle($slug); $site->setIsListedInIndex(true); $site->setIsWebRobotsAllowed(true); $site->setPromptEmailsDaysInAdvance($CONFIG->newSitePromptEmailsDaysInAdvance); $siteRepository = new SiteRepository(); $countryRepository = new CountryRepository(); $siteQuotaRepository = new SiteQuotaRepository(); $gb = $countryRepository->loadByTwoCharCode("GB"); if (!$gb) { die("Can't load Country GB - have you loaded static data?\n\n"); } $siteRepository->create($site, $user, array($gb), $siteQuotaRepository->loadByCode($CONFIG->newSiteHasQuotaCode), false);