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()));
 }
 /**
  *
  * @deprecated */
 public function setFeaturesOnSite(SiteModel $siteModel)
 {
     if (isset($this->featuresAsTree['org.openacalendar']) && isset($this->featuresAsTree['org.openacalendar']['Map'])) {
         $siteModel->setIsFeatureMap($this->featuresAsTree['org.openacalendar']['Map']->isOn());
     }
     if (isset($this->featuresAsTree['org.openacalendar']) && isset($this->featuresAsTree['org.openacalendar']['Group'])) {
         $siteModel->setIsFeatureGroup($this->featuresAsTree['org.openacalendar']['Group']->isOn());
     }
     if (isset($this->featuresAsTree['org.openacalendar']) && isset($this->featuresAsTree['org.openacalendar']['Tag'])) {
         $siteModel->setIsFeatureTag($this->featuresAsTree['org.openacalendar']['Tag']->isOn());
     }
     if (isset($this->featuresAsTree['org.openacalendar']) && isset($this->featuresAsTree['org.openacalendar']['Importer'])) {
         $siteModel->setIsFeatureImporter($this->featuresAsTree['org.openacalendar']['Importer']->isOn());
     }
     if (isset($this->featuresAsTree['org.openacalendar']) && isset($this->featuresAsTree['org.openacalendar']['PhysicalEvents'])) {
         $siteModel->setIsFeaturePhysicalEvents($this->featuresAsTree['org.openacalendar']['PhysicalEvents']->isOn());
     }
     if (isset($this->featuresAsTree['org.openacalendar']) && isset($this->featuresAsTree['org.openacalendar']['VirtualEvents'])) {
         $siteModel->setIsFeatureVirtualEvents($this->featuresAsTree['org.openacalendar']['VirtualEvents']->isOn());
     }
     if (isset($this->featuresAsTree['org.openacalendar.curatedlists']) && isset($this->featuresAsTree['org.openacalendar.curatedlists']['CuratedList'])) {
         $siteModel->setIsFeatureCuratedList($this->featuresAsTree['org.openacalendar.curatedlists']['CuratedList']->isOn());
     }
 }
 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->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, $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));
 }
    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->setIsFeatureCuratedList($CONFIG->newSiteHasFeatureCuratedList);
$site->setIsFeatureImporter($CONFIG->newSiteHasFeatureImporter);
$site->setIsFeatureMap($CONFIG->newSiteHasFeatureMap);
$site->setIsFeatureVirtualEvents($CONFIG->newSiteHasFeatureVirtualEvents);
$site->setIsFeaturePhysicalEvents($CONFIG->newSiteHasFeaturePhysicalEvents);
$site->setIsFeatureGroup($CONFIG->newSiteHasFeatureGroup);
$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);
 /** @deprecated */
 public function loadLegacyFeaturesOnSite(SiteModel $siteModel)
 {
     global $DB;
     $stat = $DB->prepare("SELECT extension_id,feature_id,is_on FROM site_feature_information WHERE site_id=:site_id AND is_on = '1' ");
     $stat->execute(array('site_id' => $siteModel->getId()));
     while ($data = $stat->fetch()) {
         if ($data['extension_id'] == 'org.openacalendar.curatedlists' && $data['feature_id'] == 'CuratedList') {
             $siteModel->setIsFeatureCuratedList(true);
         }
         if ($data['extension_id'] == 'org.openacalendar' && $data['feature_id'] == 'Importer') {
             $siteModel->setIsFeatureImporter(true);
         }
         if ($data['extension_id'] == 'org.openacalendar' && $data['feature_id'] == 'Map') {
             $siteModel->setIsFeatureMap(true);
         }
         if ($data['extension_id'] == 'org.openacalendar' && $data['feature_id'] == 'VirtualEvents') {
             $siteModel->setIsFeatureVirtualEvents(true);
         }
         if ($data['extension_id'] == 'org.openacalendar' && $data['feature_id'] == 'PhysicalEvents') {
             $siteModel->setIsFeaturePhysicalEvents(true);
         }
         if ($data['extension_id'] == 'org.openacalendar' && $data['feature_id'] == 'Group') {
             $siteModel->setIsFeatureGroup(true);
         }
         if ($data['extension_id'] == 'org.openacalendar' && $data['feature_id'] == 'Tag') {
             $siteModel->setIsFeatureTag(true);
         }
     }
 }