protected function processEvent($event) { global $CONFIG; $importedEventRepo = new ImportedEventRepository(); $importedEventChangesToSave = false; $importedEvent = $importedEventRepo->loadByImportURLIDAndImportId($this->importURLRun->getImportURL()->getId(), $event->id); if (!$importedEvent) { $importedEvent = new ImportedEventModel(); $importedEvent->setImportId($event->id); $importedEvent->setImportUrlId($this->importURLRun->getImportURL()->getId()); $this->setOurEventFromEventObject($importedEvent, $event); $importedEventChangesToSave = true; } else { $importedEventChangesToSave = $this->setOurEventFromEventObject($importedEvent, $event); } $ietieo = new ImportedEventToImportedEventOccurrences($importedEvent); $this->importedEventOccurrenceToEvent->setEventRecurSet(null, false); foreach ($ietieo->getImportedEventOccurrences() as $importedEventOccurrence) { if ($importedEventOccurrence->getEndAt()->getTimeStamp() < TimeSource::time()) { $this->inpast++; } else { if ($importedEventOccurrence->getStartAt()->getTimeStamp() > TimeSource::time() + $CONFIG->importURLAllowEventsSecondsIntoFuture) { $this->tofarinfuture++; } else { if ($this->saved < $this->limitToSaveOnEachRun) { // Imported Event if ($importedEventChangesToSave) { if ($importedEvent->getId()) { if ($importedEvent->getIsDeleted()) { $importedEventRepo->delete($importedEvent); } else { $importedEventRepo->edit($importedEvent); } } else { $importedEventRepo->create($importedEvent); // the ID will not be set until this point. So make sure we copy over the ID below just to be sure. } $importedEventChangesToSave = false; } // ... and the Imported Event Occurrence becomes a real event! $importedEventOccurrence->setId($importedEvent->getId()); if ($this->importedEventOccurrenceToEvent->run($importedEventOccurrence)) { $this->saved++; } } } } } }
protected function processMeetupData($meetupData) { global $CONFIG; $start = new \DateTime('', new \DateTimeZone('UTC')); $start->setTimestamp($meetupData->time / 1000); if (property_exists($meetupData, 'duration') && $meetupData->duration) { $end = new \DateTime('', new \DateTimeZone('UTC')); $end->setTimestamp($meetupData->time / 1000); $end->add(new \DateInterval("PT" . $meetupData->duration / 1000 . "S")); } else { $end = clone $start; $end->add(new \DateInterval("PT3H")); } if ($start && $end && $start <= $end) { if ($end->getTimeStamp() < \TimeSource::time()) { $this->countInPast++; } else { if ($start->getTimeStamp() > \TimeSource::time() + $CONFIG->importURLAllowEventsSecondsIntoFuture) { $this->countToFarInFuture++; } else { $importedEventRepo = new \repositories\ImportedEventRepository(); $id = "event_" . $meetupData->id . "@meetup.com"; $importedEvent = $importedEventRepo->loadByImportURLIDAndImportId($this->importURLRun->getImportURL()->getId(), $id); $changesToSave = false; if (!$importedEvent) { if ($meetupData->status != 'cancelled') { ++$this->countNew; $importedEvent = new ImportedEventModel(); $importedEvent->setImportId($id); $importedEvent->setImportUrlId($this->importURLRun->getImportURL()->getId()); $this->setImportedEventFromMeetupData($importedEvent, $meetupData); $changesToSave = true; } } else { ++$this->countExisting; if ($meetupData->status == 'cancelled') { if (!$importedEvent->getIsDeleted()) { $importedEvent->setIsDeleted(true); $changesToSave = true; } } else { $changesToSave = $this->setImportedEventFromMeetupData($importedEvent, $meetupData); // if was deleted, undelete if ($importedEvent->getIsDeleted()) { $importedEvent->setIsDeleted(false); $changesToSave = true; } } } if ($changesToSave && $this->countSaved < $this->limitToSaveOnEachRun) { ++$this->countSaved; $this->importedEventsToEvents->addImportedEvent($importedEvent); if ($importedEvent->getId()) { if ($importedEvent->getIsDeleted()) { $importedEventRepo->delete($importedEvent); } else { $importedEventRepo->edit($importedEvent); } } else { $importedEventRepo->create($importedEvent); } } } } } }
protected function processFBData($id, $fbData) { global $CONFIG; $start = new \DateTime($fbData['start_time'], new \DateTimeZone('UTC')); if ($fbData['end_time']) { $end = new \DateTime($fbData['end_time'], new \DateTimeZone('UTC')); } else { $end = clone $start; } if ($start && $end && $start <= $end) { if ($end->getTimeStamp() < \TimeSource::time()) { $this->countInPast++; } else { if ($start->getTimeStamp() > \TimeSource::time() + $CONFIG->importURLAllowEventsSecondsIntoFuture) { $this->countToFarInFuture++; } else { $importedEventRepo = new \repositories\ImportedEventRepository(); $importedEvent = $importedEventRepo->loadByImportURLIDAndImportId($this->importURLRun->getImportURL()->getId(), $id); $changesToSave = false; if (!$importedEvent) { ++$this->countNew; $importedEvent = new ImportedEventModel(); $importedEvent->setImportId($id); $importedEvent->setImportUrlId($this->importURLRun->getImportURL()->getId()); $this->setImportedEventFromFBData($importedEvent, $fbData); $changesToSave = true; } else { ++$this->countExisting; $changesToSave = $this->setImportedEventFromFBData($importedEvent, $fbData); // if was deleted, undelete if ($importedEvent->getIsDeleted()) { $importedEvent->setIsDeleted(false); $changesToSave = true; } } if ($changesToSave && $this->countSaved < $this->limitToSaveOnEachRun) { ++$this->countSaved; $this->importedEventsToEvents->addImportedEvent($importedEvent); if ($importedEvent->getId()) { if ($importedEvent->getIsDeleted()) { $importedEventRepo->delete($importedEvent); } else { $importedEventRepo->edit($importedEvent); } } else { $importedEventRepo->create($importedEvent); } } } } } }