protected function run()
 {
     $this->localTimeZone = new \DateTimeZone("Europe/London");
     $siteRepo = new \repositories\SiteRepository();
     $site = $siteRepo->loadById($this->app['config']->singleSiteID);
     // TODO assumes single site!
     $areaRepository = new AreaRepository();
     $venueRepository = new VenueRepository();
     $countryRepository = new CountryRepository();
     $countries = array();
     $humanPopItRepository = new HumanPopItInfoRepository();
     $areaMapItRepo = new AreaMapItInfoRepository();
     $out = array('data' => array(), 'areasPastEvents' => array());
     $erb = new EventRepositoryBuilder();
     $erb->setSite($site);
     $erb->setIncludeDeleted(true);
     $erb->setIncludeCancelled(true);
     $erb->setAfterNow();
     foreach ($erb->fetchAll() as $event) {
         $venue = null;
         $country = null;
         $area = null;
         $humans = array();
         if ($event->getCountryId()) {
             if (!isset($countries[$event->getCountryId()])) {
                 $countries[$event->getCountryId()] = $countryRepository->loadById($event->getCountryId());
             }
             $country = $countries[$event->getCountryId()];
         }
         if ($event->getVenueId()) {
             $venue = $venueRepository->loadById($event->getVenueId());
         }
         if ($event->getAreaId()) {
             $area = $areaRepository->loadById($event->getAreaId());
         } else {
             if ($venue && $venue->getAreaId()) {
                 $area = $areaRepository->loadById($venue->getAreaId());
             }
         }
         $thisOut = $this->addEvent($event, $venue, $area, $country);
         $thisOut['humans'] = array();
         $mapitids = array();
         if ($area) {
             $areamapit = $areaMapItRepo->getByAreaID($area->getId());
             if ($areamapit) {
                 $mapitids[] = $areamapit->getMapitId();
             }
         }
         $hrb = new HumanRepositoryBuilder();
         $hrb->setHumansForEvent($event);
         foreach ($hrb->fetchAll() as $human) {
             $popit = $humanPopItRepository->getByHumanID($human->getId());
             $thisOut['humans'][] = array('popit_id' => $popit->getPopitId());
             $arb = new AreaRepositoryBuilder();
             $arb->setIncludeDeleted(false);
             $arb->setHuman($human);
             foreach ($arb->fetchAll() as $areaForHuman) {
                 if (!$area || $area->getId() != $areaForHuman->getId()) {
                     $areamapit = $areaMapItRepo->getByAreaID($areaForHuman->getId());
                     if ($areamapit) {
                         $mapitids[] = $areamapit->getMapitId();
                     }
                 }
             }
         }
         $thisOut['mapitids'] = array_values(array_unique($mapitids));
         $out['data'][] = $thisOut;
     }
     $arb = new \com\meetyournextmp\repositories\builders\AreaRepositoryBuilder();
     $arb->setLimit(1000);
     $arb->setIncludeDeleted(false);
     $arb->setIsMapItAreaOnly(true);
     foreach ($arb->fetchAll() as $area) {
         $erb = new EventRepositoryBuilder();
         $erb->setIncludeDeleted(false);
         $erb->setIncludeCancelled(false);
         $erb->setArea($area);
         $erb->setBeforeNow();
         $areamapit = $areaMapItRepo->getByAreaID($area->getId());
         $out['areasPastEvents'][$areamapit->getMapitId()] = $erb->fetchCount();
     }
     file_put_contents(APP_ROOT_DIR . DIRECTORY_SEPARATOR . 'webSingleSite' . DIRECTORY_SEPARATOR . 'datadump' . DIRECTORY_SEPARATOR . 'ynmpread.json', json_encode($out));
     return array('result' => 'ok');
 }