public function handle()
 {
     $iurlr = new ImportURLResultModel();
     $iurlr->setIsSuccess(false);
     $iurlr->setMessage("You can't import from the same site!");
     return $iurlr;
 }
 public function handle()
 {
     global $CONFIG;
     $this->new = $this->existing = $this->saved = $this->inpast = $this->tofarinfuture = $this->notvalid = 0;
     $this->addUIDCounter = 1;
     $this->importedEventOccurrenceToEvent = new ImportedEventOccurrenceToEvent();
     $this->importedEventOccurrenceToEvent->setFromImportURlRun($this->importURLRun);
     foreach ($this->icalParser->getEvents() as $icalevent) {
         if ($this->importURLRun->hasFlag(ImportURLRun::$FLAG_ADD_UIDS) && !$icalevent->getUid()) {
             $icalevent->setUid("ADDEDBYIMPORTER" . $this->addUIDCounter);
             ++$this->addUIDCounter;
         }
         if ($icalevent->getStart() && $icalevent->getEnd() && $icalevent->getUid() && $icalevent->getStart()->getTimeStamp() <= $icalevent->getEnd()->getTimeStamp()) {
             $this->processICalEvent($icalevent);
         } else {
             $this->notvalid++;
         }
     }
     $this->saved += $this->importedEventOccurrenceToEvent->deleteEventsNotSeenAfterRun();
     $iurlr = new ImportURLResultModel();
     $iurlr->setIsSuccess(true);
     $iurlr->setNewCount($this->new);
     $iurlr->setExistingCount($this->existing);
     $iurlr->setSavedCount($this->saved);
     $iurlr->setInPastCount($this->inpast);
     $iurlr->setToFarInFutureCount($this->tofarinfuture);
     $iurlr->setNotValidCount($this->notvalid);
     $iurlr->setMessage("ICAL Feed found");
     return $iurlr;
 }
 public function handle()
 {
     global $app;
     $this->countNew = 0;
     $this->countExisting = 0;
     $this->countSaved = 0;
     $this->countInPast = 0;
     $this->countToFarInFuture = 0;
     $this->countNotValid = 0;
     $this->importedEventsToEvents = new ImportedEventsToEvents();
     $this->importedEventsToEvents->setFromImportURlRun($this->importURLRun);
     $iurlr = new ImportURLResultModel();
     $iurlr->setIsSuccess(true);
     $iurlr->setMessage("Meetup data found");
     try {
         if ($this->eventId) {
             $meetupData = $this->getMeetupDataForEventID($this->eventId);
             if ($meetupData) {
                 $this->processMeetupData($meetupData);
             }
         } else {
             if ($this->groupName) {
                 foreach ($this->getMeetupDatasForGroupname($this->groupName) as $meetupData) {
                     $this->processMeetupData($meetupData);
                 }
             }
         }
     } catch (ImportURLMeetupHandlerAPIError $err) {
         $iurlr->setIsSuccess(false);
         $iurlr->setMessage("Meetup API error: " . $err->getCode() . " " . $err->getMessage());
     }
     // Now run the thing to make imported events real events!
     $this->importedEventsToEvents->run();
     $iurlr->setNewCount($this->countNew);
     $iurlr->setExistingCount($this->countExisting);
     $iurlr->setSavedCount($this->countSaved);
     $iurlr->setInPastCount($this->countInPast);
     $iurlr->setToFarInFutureCount($this->countToFarInFuture);
     $iurlr->setNotValidCount($this->countNotValid);
     return $iurlr;
 }
 public function handle()
 {
     global $app;
     $this->countNew = 0;
     $this->countExisting = 0;
     $this->countSaved = 0;
     $this->countInPast = 0;
     $this->countToFarInFuture = 0;
     $this->countNotValid = 0;
     $extension = $app['extensions']->getExtensionById('org.openacalendar.facebook');
     $appID = $app['appconfig']->getValue($extension->getAppConfigurationDefinition('app_id'));
     $appSecret = $app['appconfig']->getValue($extension->getAppConfigurationDefinition('app_secret'));
     $userToken = $app['appconfig']->getValue($extension->getAppConfigurationDefinition('user_token'));
     FacebookSession::setDefaultApplication($appID, $appSecret);
     $this->importedEventsToEvents = new ImportedEventsToEvents();
     $this->importedEventsToEvents->setFromImportURlRun($this->importURLRun);
     $iurlr = new ImportURLResultModel();
     $iurlr->setIsSuccess(true);
     $iurlr->setMessage("Facebook data found");
     if ($this->eventId && $appID && $appSecret && $userToken) {
         try {
             $fbData = $this->getFBDataForEventID($this->eventId);
             if ($fbData) {
                 $this->processFBData($this->eventId, $fbData);
             }
         } catch (FacebookAuthorizationException $err) {
             $iurlr->setIsSuccess(false);
             $iurlr->setMessage("Facebook API error: " . $err->getCode() . " " . $err->getMessage());
         }
     }
     // Now run the thing to make imported events real events!
     $this->importedEventsToEvents->run();
     $iurlr->setNewCount($this->countNew);
     $iurlr->setExistingCount($this->countExisting);
     $iurlr->setSavedCount($this->countSaved);
     $iurlr->setInPastCount($this->countInPast);
     $iurlr->setToFarInFutureCount($this->countToFarInFuture);
     $iurlr->setNotValidCount($this->countNotValid);
     return $iurlr;
 }
 public function go(ImportURLModel $importURL)
 {
     global $app;
     $iurlrRepo = new ImportURLResultRepository();
     $importURLRun = new ImportURLRun($importURL);
     $handlers = array();
     // Get
     foreach ($app['extensions']->getExtensionsIncludingCore() as $extension) {
         foreach ($extension->getImportURLHandlers() as $handler) {
             $handlers[] = $handler;
         }
     }
     // Sort
     usort($handlers, function ($a, $b) {
         if ($a->getSortOrder() == $b->getSortOrder()) {
             return 0;
         } else {
             if ($a->getSortOrder() > $b->getSortOrder()) {
                 return 1;
             } else {
                 if ($a->getSortOrder() < $b->getSortOrder()) {
                     return -1;
                 }
             }
         }
     });
     // Run
     foreach ($handlers as $handler) {
         $handler->setImportURLRun($importURLRun);
         if ($handler->canHandle()) {
             if ($handler->isStopAfterHandling()) {
                 $iurlr = $handler->handle();
                 $iurlr->setImportUrlId($importURL->getId());
                 $iurlrRepo->create($iurlr);
                 return;
             } else {
                 $handler->handle();
             }
         }
     }
     // Log that couldn't handle feed
     $iurlr = new ImportURLResultModel();
     $iurlr->setImportUrlId($importURL->getId());
     $iurlr->setIsSuccess(false);
     $iurlr->setMessage("Did not recognise data");
     $iurlrRepo->create($iurlr);
 }
 public function handle()
 {
     $this->new = $this->existing = $this->saved = $this->inpast = $this->tofarinfuture = $this->notvalid = 0;
     $this->importedEventOccurrenceToEvent = new ImportedEventOccurrenceToEvent();
     $this->importedEventOccurrenceToEvent->setFromImportURlRun($this->importURLRun);
     $postdata = array('action' => 'searchHustings', 'constitId' => 0, 'constitName' => '');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "https://ctbielections.org.uk/wp-admin/admin-ajax.php");
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 5.0.1; Nexus 9 Build/LRX22C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.93 Safari/537.36');
     $data = curl_exec($ch);
     $response = curl_getinfo($ch);
     curl_close($ch);
     if ($response['http_code'] != 200) {
         $iurlr = new ImportURLResultModel();
         $iurlr->setIsSuccess(false);
         $iurlr->setMessage("Special CTBI feed found, but error code: " . $response['http_code']);
         return $iurlr;
     }
     $dataObj = json_decode($data);
     foreach ($dataObj as $hustingJSON) {
         if ($hustingJSON->eventType == 'E') {
             $this->processEvent($hustingJSON);
         }
     }
     $iurlr = new ImportURLResultModel();
     $iurlr->setIsSuccess(true);
     $iurlr->setNewCount($this->new);
     $iurlr->setExistingCount($this->existing);
     $iurlr->setSavedCount($this->saved);
     $iurlr->setInPastCount($this->inpast);
     $iurlr->setToFarInFutureCount($this->tofarinfuture);
     $iurlr->setNotValidCount($this->notvalid);
     $iurlr->setMessage("Special CTBI feed found");
     return $iurlr;
 }