protected function build() { if ($this->importURL) { $this->where[] = " import_url_result.import_url_id = :import_url_id "; $this->params['import_url_id'] = $this->importURL->getId(); } }
/** * @dataProvider dataForTestIsValid */ function testIsValid($url, $result, $newURL) { $import = new ImportURLModel(); $import->setUrl($url); $site = new SiteModel(); $importRun = new ImportURLRun($import, $site); $handler = new ImportURLMeetupHandler(); $handler->setImportURLRun($importRun); $this->assertEquals($result, $handler->canHandle()); if ($result) { $this->assertEquals($newURL, $handler->getNewFeedURL()); } }
public function fetchAll() { $this->buildStart(); $this->build(); $this->buildStat(); $results = array(); while ($data = $this->stat->fetch()) { $importURL = new ImportURLModel(); $importURL->setFromDataBaseRow($data); $results[] = $importURL; } return $results; }
/** * @dataProvider dataForTestIsValid */ function testIsValid($currentYear, $url, $result, $newURL) { \TimeSource::mock($currentYear); $import = new ImportURLModel(); $import->setUrl($url); $site = new SiteModel(); $importRun = new ImportURLRun($import, $site); $handler = new ImportURLLanyrdHandler(); $handler->setImportURLRun($importRun); $this->assertEquals($result, $handler->canHandle()); if ($result) { $this->assertEquals($newURL, $handler->getNewFeedURL()); } }
/** * @dataProvider dataForTestIsValid */ function testIsValid($webIndexDomain, $webSiteDomain, $hasSSL, $webSiteDomain, $webSiteDomainSSL, $url, $result) { global $CONFIG; $CONFIG->webIndexDomain = $webIndexDomain; $CONFIG->webSiteDomain = $webSiteDomain; $CONFIG->hasSSL = $hasSSL; $CONFIG->webSiteDomain = $webSiteDomain; $CONFIG->webSiteDomainSSL = $webSiteDomainSSL; $import = new ImportURLModel(); $import->setUrl($url); $site = new SiteModel(); $importRun = new ImportURLRun($import, $site); $handler = new ImportURLNotUsHandler(); $handler->setImportURLRun($importRun); $this->assertEquals($result, $handler->canHandle()); }
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 run(ImportedEventOccurrenceModel $importedEventOccurrenceModel) { $eventRepo = new EventRepository(); $eventRecurSetRepo = new EventRecurSetRepository(); if ($importedEventOccurrenceModel->hasReoccurence()) { // Have to load it looking for the right time to! $event = $this->loadEventForImportedReoccurredEvent($importedEventOccurrenceModel); } else { // just load it. $event = $this->loadEventForImportedEvent($importedEventOccurrenceModel); } if ($event) { $this->eventsSeenIDs[] = $event->getId(); // Set Existing Event From Import Event URL if ($importedEventOccurrenceModel->getIsDeleted()) { if (!$event->getIsDeleted()) { $eventRepo->delete($event); return true; } } else { if ($event->setFromImportedEventModel($importedEventOccurrenceModel) || $event->getIsDeleted()) { $event->setIsDeleted(false); $eventRepo->edit($event); return true; } } } else { if (!$this->importURL->getIsManualEventsCreation()) { // New Event From Import Event URL $event = $this->newEventFromImportedEventModel($importedEventOccurrenceModel); if ($this->eventRecurSet) { $event->setEventRecurSetId($this->eventRecurSet->getId()); } $eventRepo->create($event, $this->site, null, $this->group, null, $importedEventOccurrenceModel); $this->eventsSeenIDs[] = $event->getId(); if (!$this->eventRecurSet && $this->makeEventRecurSetIfNone) { $this->eventRecurSet = $eventRecurSetRepo->getForEvent($event); } return true; } else { return false; } } return false; }
protected function build() { global $DB; $this->select[] = 'imported_event.*'; if ($this->site) { $this->joins[] = " JOIN import_url_information ON imported_event.import_url_id = import_url_information.id "; $this->where[] = " import_url_information.site_id = :site_id "; $this->params['site_id'] = $this->site->getId(); } if ($this->importURL) { $this->where[] = " imported_event.import_url_id = :import_url_id "; $this->params['import_url_id'] = $this->importURL->getId(); } if ($this->after) { $this->where[] = ' imported_event.end_at > :after'; $this->params['after'] = $this->after->format("Y-m-d H:i:s"); } }
function testBasic() { global $CONFIG; \TimeSource::mock(2013, 10, 1, 1, 1, 1); $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000; // 90 days $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $group = new GroupModel(); $group->setTitle("test"); $group->setDescription("test test"); $group->setUrl("http://www.group.com"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $importURLRepository = new ImportURLRepository(); $importURL = new ImportURLModel(); $importURL->setIsEnabled(true); $importURL->setSiteId($site->getId()); $importURL->setGroupId($group->getId()); $importURL->setTitle("Test"); $importURL->setUrl("http://test.com"); $importURLRepository->create($importURL, $site, $user); // Import $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Lanyrd1.ical'); $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Load! $erb = new EventRepositoryBuilder(); $erb->setSite($site); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $event = $events[0]; $this->assertEquals("State of the Map Scotland 2013", $event->getSummary()); $this->assertEquals('2013-10-11 00:00:00', $event->getStartAt()->format('Y-m-d H:i:s')); $this->assertEquals('2013-10-14 23:59:59', $event->getEndAt()->format('Y-m-d H:i:s')); $this->assertEquals("http://sotms.eventbrite.com/\n\nhttp://lanyrd.com/crkmt", $event->getDescription()); $this->assertEquals('http://lanyrd.com/2013/sotmscot2013/', $event->getURL()); $this->assertFalse($event->getIsDeleted()); // Look for event $erb = new EventRepositoryBuilder(); $erb->setSite($site); $erb->setImportURL($importURL); $this->assertEquals(1, count($erb->fetchAll())); }
function testBasic() { global $CONFIG; \TimeSource::mock(2013, 10, 1, 1, 1, 1); $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000; // 90 days $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $group = new GroupModel(); $group->setTitle("test"); $group->setDescription("test test"); $group->setUrl("http://www.group.com"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $importURLRepository = new ImportURLRepository(); $importURL = new ImportURLModel(); $importURL->setIsEnabled(true); $importURL->setSiteId($site->getId()); $importURL->setGroupId($group->getId()); $importURL->setTitle("Test"); $importURL->setUrl("http://test.com"); $importURLRepository->create($importURL, $site, $user); // Import $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Eventbrite1.ical'); $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS); $importURLRun->setFlag(ImportURLRun::$FLAG_SET_TICKET_URL_AS_URL); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Load! $erb = new EventRepositoryBuilder(); $erb->setSite($site); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $event = $events[0]; $this->assertEquals("Computing At School Scotland Conference 2013", $event->getSummary()); $this->assertEquals('2013-10-26 07:30:00', $event->getStartAt()->format('Y-m-d H:i:s')); $this->assertEquals('2013-10-26 16:00:00', $event->getEndAt()->format('Y-m-d H:i:s')); $this->assertEquals('For details, click here: https://casscot13.eventbrite.co.uk', $event->getDescription()); $this->assertEquals('https://casscot13.eventbrite.co.uk', $event->getURL()); $this->assertEquals('https://casscot13.eventbrite.co.uk', $event->getTicketURL()); $this->assertFalse($event->getIsDeleted()); }
function testBasic() { global $CONFIG; \TimeSource::mock(2013, 10, 1, 1, 1, 1); $CONFIG->importURLAllowEventsSecondsIntoFuture = 7776000; // 90 days $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $group = new GroupModel(); $group->setTitle("test"); $group->setDescription("test test"); $group->setUrl("http://www.group.com"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $importURLRepository = new ImportURLRepository(); $importURL = new ImportURLModel(); $importURL->setIsEnabled(true); $importURL->setSiteId($site->getId()); $importURL->setGroupId($group->getId()); $importURL->setTitle("Test"); $importURL->setUrl("http://test.com"); $importURLRepository->create($importURL, $site, $user); // Import $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/Meetup1.ics'); $importURLRun->setFlag(ImportURLRun::$FLAG_ADD_UIDS); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Load! $erb = new EventRepositoryBuilder(); $erb->setSite($site); $events = $erb->fetchAll(); $this->assertEquals(1, count($events)); $event = $events[0]; $this->assertEquals("Talk & Build AngularJS", $event->getSummary()); $this->assertEquals('2013-10-17 18:00:00', $event->getStartAt()->format('Y-m-d H:i:s')); $this->assertEquals('2013-10-17 21:00:00', $event->getEndAt()->format('Y-m-d H:i:s')); $this->assertEquals("AngularJS - Edinburgh\nThursday, October 17 at 7:00 PM\n\nDetails: http://www.meetup.com/AngularJS-Edinburgh/events/141654792/", $event->getDescription()); $this->assertEquals('http://www.meetup.com/AngularJS-Edinburgh/events/141654792/', $event->getURL()); $this->assertFalse($event->getIsDeleted()); }
function __construct(ImportURLModel $importURL, SiteModel $site = null) { $this->importURL = $importURL; $this->realurl = $importURL->getUrl(); if ($site) { $this->site = $site; } else { $siteRepo = new SiteRepository(); $this->site = $siteRepo->loadById($importURL->getSiteId()); } if ($importURL->getCountryId()) { $countryRepo = new CountryRepository(); $this->country = $countryRepo->loadById($importURL->getCountryId()); } if ($importURL->getAreaId()) { $areaRepo = new AreaRepository(); $this->area = $areaRepo->loadById($importURL->getAreaId()); } $groupRepository = new GroupRepository(); $this->group = $groupRepository->loadById($importURL->getGroupId()); }
function test1() { $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $group = new GroupModel(); $group->setTitle("test"); $group->setDescription("test test"); $group->setUrl("http://www.group.com"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $importURLRepository = new ImportURLRepository(); $newImportURL = new ImportURLModel(); $newImportURL->setIsEnabled(true); $newImportURL->setSiteId($site->getId()); $newImportURL->setGroupId($group->getId()); $newImportURL->setTitle("Test"); $newImportURL->setUrl("http://test.com"); # no clash $clash = $importURLRepository->loadClashForImportUrl($newImportURL); $this->assertNull($clash); # save import, now clash! $importURLRepository->create($newImportURL, $site, $user); $newImportURL2 = new ImportURLModel(); $newImportURL2->setIsEnabled(true); $newImportURL2->setSiteId($site->getId()); $newImportURL2->setGroupId($group->getId()); $newImportURL2->setTitle("Test.com site"); $newImportURL2->setUrl("http://TEST.com"); # no clash $clash = $importURLRepository->loadClashForImportUrl($newImportURL2); $this->assertTrue($clash != null); }
protected function build() { global $DB; $this->select[] = 'event_information.*'; $this->select[] = " group_information.title AS group_title "; $this->select[] = " group_information.id AS group_id "; $this->joins[] = " LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL AND event_in_group.is_main_group = '1' "; $this->joins[] = " LEFT JOIN group_information ON group_information.id = event_in_group.group_id "; $joinsVenueInfoSQL = " LEFT JOIN venue_information ON venue_information.id = event_information.venue_id "; if ($this->site) { $this->where[] = " event_information.site_id = :site_id "; $this->params['site_id'] = $this->site->getId(); } if ($this->group) { // We use a seperate table here so if event is in 2 groups and we select events in 1 group that isn't the main group only, // the normal event_in_group table still shows the main group. $this->joins[] = " JOIN event_in_group AS event_in_group_select ON event_in_group_select.event_id = event_information.id " . "AND event_in_group_select.removed_at IS NULL AND event_in_group_select.group_id = :group_id "; $this->params['group_id'] = $this->group->getId(); } if ($this->country) { $this->where[] = " event_information.country_id = :country_id "; $this->params['country_id'] = $this->country->getId(); } if ($this->area) { // We were doing // $this->joins[] = " LEFT JOIN cached_area_has_parent ON cached_area_has_parent.area_id = venue_information.area_id"; // $this->where[] = " (venue_information.area_id = :area_id OR cached_area_has_parent.has_parent_area_id = :area_id )"; // but then we got duplicates $areaids = array($this->area->getId()); $this->statAreas = $DB->prepare("SELECT area_id FROM cached_area_has_parent WHERE has_parent_area_id=:id"); $this->statAreas->execute(array('id' => $this->area->getId())); while ($d = $this->statAreas->fetch()) { $areaids[] = $d['area_id']; } $this->joins[] = $joinsVenueInfoSQL; $this->where[] = " (venue_information.area_id IN (" . implode(",", $areaids) . ") " . "OR event_information.area_id IN (" . implode(",", $areaids) . ")) "; } if ($this->venue) { $this->where[] = " event_information.venue_id = :venue_id "; $this->params['venue_id'] = $this->venue->getId(); } if ($this->importURL) { $this->joins[] = " LEFT JOIN imported_event_is_event ON imported_event_is_event.event_id = event_information.id "; $this->joins[] = " LEFT JOIN imported_event ON imported_event.id = imported_event_is_event.imported_event_id "; $this->where[] = " (imported_event.import_url_id = :import_url_id OR event_information.import_url_id = :import_url_id )"; $this->params['import_url_id'] = $this->importURL->getId(); } if ($this->importedEvent) { $this->joins[] = " JOIN imported_event_is_event ON imported_event_is_event.event_id = event_information.id AND imported_event_is_event.imported_event_id = :imported_event_id "; $this->params['imported_event_id'] = $this->importedEvent->getId(); } if (!$this->site && !$this->group) { $this->joins[] = " JOIN site_information ON event_information.site_id = site_information.id "; $this->select[] = " site_information.slug AS site_slug "; if (!$this->includeEventsFromClosedSites) { $this->where[] = " site_information.is_closed_by_sys_admin = '0' "; } } if ($this->curatedList) { $this->joins[] = " LEFT JOIN event_in_curated_list ON event_in_curated_list.event_id = event_information.id " . " AND event_in_curated_list.removed_at IS NULL AND event_in_curated_list.curated_list_id = :curated_list"; $this->joins[] = " LEFT JOIN ( SELECT event_in_group.event_id, MAX(event_in_group.group_id) AS group_id" . " FROM event_in_group " . " JOIN group_in_curated_list ON group_in_curated_list.group_id = event_in_group.group_id " . " WHERE group_in_curated_list.curated_list_id = :curated_list AND group_in_curated_list.removed_at IS NULL AND event_in_group.removed_at IS NULL " . " GROUP BY event_in_group.event_id " . ") AS event_in_group_in_curated_list ON event_in_group_in_curated_list.event_id = event_information.id "; $this->where[] = " ( event_in_curated_list.curated_list_id IS NOT NULL OR event_in_group_in_curated_list.event_id IS NOT NULL )"; $this->params['curated_list'] = $this->curatedList->getId(); if ($this->curatedListInformation) { $this->joins[] = " LEFT JOIN group_information AS group_information_cl ON group_information_cl.id = event_in_group_in_curated_list.group_id "; $this->select[] = " (CASE WHEN event_in_curated_list.event_id IS NULL THEN 0 ELSE 1 END) AS is_event_in_curated_list "; $this->select[] = " group_information_cl.id AS in_curated_list_group_id "; $this->select[] = " group_information_cl.slug AS in_curated_list_group_slug "; $this->select[] = " group_information_cl.title AS in_curated_list_group_title "; } } if ($this->end) { $this->where[] = ' event_information.end_at = :end'; $this->params['end'] = $this->end->format("Y-m-d H:i:s"); } else { if ($this->after) { $this->where[] = ' event_information.end_at > :after'; $this->params['after'] = $this->after->format("Y-m-d H:i:s"); } else { if ($this->endBefore) { $this->where[] = ' event_information.end_at < :before'; $this->params['before'] = $this->endBefore->format("Y-m-d H:i:s"); } } } if ($this->start) { $this->where[] = ' event_information.start_at = :start'; $this->params['start'] = $this->start->format("Y-m-d H:i:s"); } else { if ($this->before) { $this->where[] = ' event_information.start_at < :before'; $this->params['before'] = $this->before->format("Y-m-d H:i:s"); } else { if ($this->startAfter) { $this->where[] = ' event_information.start_at > :startAfter'; $this->params['startAfter'] = $this->startAfter->format("Y-m-d H:i:s"); } } } if (!$this->include_deleted) { $this->where[] = " event_information.is_deleted = '0' "; } if (!$this->include_cancelled) { $this->where[] = " event_information.is_cancelled = '0' "; } if (!$this->include_imported) { $this->where[] = " event_information.import_url_id is null "; } if ($this->userAccount) { // user at event. we want info on this always for the extra selects, so outside if statement $this->joins[] = " LEFT JOIN user_at_event_information ON user_at_event_information.event_id = event_information.id " . "AND user_at_event_information.user_account_id = :user_account_id "; $this->select[] = " user_at_event_information.is_plan_attending AS user_is_plan_attending "; $this->select[] = " user_at_event_information.is_plan_maybe_attending AS user_is_plan_maybe_attending "; if (!$this->userAccountIncludeAll) { $w = array(); if ($this->userAccountIncludeWatching) { $w[] = " event_information.id IN (SELECT event_information.id FROM event_information " . " LEFT JOIN user_watches_site_information ON user_watches_site_information.site_id = event_information.site_id " . "AND user_watches_site_information.user_account_id = :user_account_id AND user_watches_site_information.is_watching='1' " . " LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL " . " LEFT JOIN user_watches_group_information ON user_watches_group_information.group_id = event_in_group.group_id " . "AND user_watches_group_information.user_account_id = :user_account_id AND user_watches_group_information.is_watching='1' " . " LEFT JOIN venue_information ON venue_information.id = event_information.venue_id " . " LEFT JOIN cached_area_has_parent ON ( venue_information.area_id = cached_area_has_parent.area_id OR event_information.area_id = cached_area_has_parent.area_id) " . " LEFT JOIN user_watches_area_information ON ( " . "user_watches_area_information.area_id = event_information.area_id OR user_watches_area_information.area_id = venue_information.area_id " . " OR user_watches_area_information.area_id = cached_area_has_parent.has_parent_area_id " . ") " . "AND user_watches_area_information.user_account_id = :user_account_id AND user_watches_area_information.is_watching='1' " . " WHERE user_watches_site_information.is_watching='1' OR user_watches_group_information.is_watching='1' OR user_watches_area_information.is_watching='1'" . " ) "; } if ($this->userAccountIncludeAttending) { if ($this->userAccountIncludePrivate) { $w[] = " user_at_event_information.is_plan_attending = '1' "; $w[] = " user_at_event_information.is_plan_maybe_attending = '1' "; } else { $w[] = " (user_at_event_information.is_plan_attending = '1' AND user_at_event_information.is_plan_public = '1' )"; $w[] = " (user_at_event_information.is_plan_maybe_attending = '1' AND user_at_event_information.is_plan_public = '1' )"; } } $this->where[] = " ( " . implode(" OR ", $w) . ") "; } $this->params['user_account_id'] = $this->userAccount->getId(); } if ($this->include_venue_information || $this->include_area_information || $this->must_have_lat_lng) { if (!in_array($joinsVenueInfoSQL, $this->joins)) { $this->joins[] = $joinsVenueInfoSQL; } if ($this->include_venue_information) { $this->select[] = " venue_information.lng AS venue_lng"; $this->select[] = " venue_information.lat AS venue_lat"; $this->select[] = " venue_information.title AS venue_title"; $this->select[] = " venue_information.slug AS venue_slug"; $this->select[] = " venue_information.description AS venue_description"; $this->select[] = " venue_information.address AS venue_address"; $this->select[] = " venue_information.address_code AS venue_address_code"; } if ($this->include_area_information) { $this->joins[] = " LEFT JOIN area_information ON area_information.id = event_information.area_id OR area_information.id = venue_information.area_id"; $this->select[] = " area_information.title AS area_title"; $this->select[] = " area_information.slug AS area_slug"; $this->select[] = " area_information.id AS area_information_id"; // we already have a area_id so called something different } if ($this->must_have_lat_lng) { $this->where[] = " venue_information.lat IS NOT NULL "; $this->where[] = " venue_information.lng IS NOT NULL "; } } if ($this->include_country_information) { $this->joins[] = " LEFT JOIN country ON country.id = event_information.country_id "; $this->select[] = " country.two_char_code AS country_two_char_code"; $this->select[] = " country.title AS country_title"; } if ($this->venueVirtualOnly) { $this->where[] = " event_information.is_virtual = '1' "; } if ($this->event_recur_set_id) { $this->where[] = " event_information.event_recur_set_id = :event_recur_set_id "; $this->params['event_recur_set_id'] = $this->event_recur_set_id; } if ($this->tag) { $this->joins[] = " JOIN event_has_tag ON event_has_tag.event_id = event_information.id AND event_has_tag.tag_id = :tag_id AND event_has_tag.removed_at IS NULL"; $this->params['tag_id'] = $this->tag->getId(); } if ($this->freeTextSearch) { $this->where[] = '(CASE WHEN event_information.summary IS NULL THEN \'\' ELSE event_information.summary END) || ' . '\' \' || ' . '(CASE WHEN event_information.description IS NULL THEN \'\' ELSE event_information.description END) || ' . '\' \' || ' . '(CASE WHEN group_information.title IS NULL THEN \'\' ELSE group_information.title END)' . ' ILIKE :free_text_search '; $this->params['free_text_search'] = "%" . strtolower($this->freeTextSearch) . "%"; } if ($this->includeMediasSlugs) { $this->select[] = " (SELECT array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_event ON media_information.id = media_in_event.media_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_event.removal_approved_at IS NULL AND media_in_event.event_id = event_information.id " . " GROUP BY event_information.id ) AS media_event_slugs "; $this->select[] = " (SELECT array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_group ON media_information.id = media_in_group.media_id " . " JOIN event_in_group ON event_in_group.group_id = media_in_group.group_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_group.removal_approved_at IS NULL " . " AND event_in_group.removal_approved_at IS NULL AND event_in_group.event_id = event_information.id " . " GROUP BY event_information.id ) AS media_group_slugs "; $this->select[] = " (SELECT array_to_string(array_agg(media_information.slug), ',') FROM media_information " . " JOIN media_in_venue ON media_information.id = media_in_venue.media_id " . " WHERE media_information.deleted_at IS NULL AND media_information.is_file_lost='0' " . " AND media_in_venue.removal_approved_at IS NULL AND media_in_venue.venue_id = event_information.venue_id " . " GROUP BY event_information.venue_id ) AS media_venue_slugs "; } if ($this->editedByUser) { $this->where[] = " event_information.id IN (SELECT event_id FROM event_history WHERE user_account_id = :editedByUser) "; $this->params['editedByUser'] = $this->editedByUser->getId(); } }
function testRRuleDeleteByExDate1() { global $CONFIG; \TimeSource::mock(2015, 1, 1, 1, 1, 1); $CONFIG->importURLAllowEventsSecondsIntoFuture = 77760000; $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $group = new GroupModel(); $group->setTitle("test"); $group->setDescription("test test"); $group->setUrl("http://www.group.com"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $importURLRepository = new ImportURLRepository(); $importURL = new ImportURLModel(); $importURL->setIsEnabled(true); $importURL->setSiteId($site->getId()); $importURL->setGroupId($group->getId()); $importURL->setTitle("Test"); $importURL->setUrl("http://test.com"); $importURLRepository->create($importURL, $site, $user); // ============================================= Import CREATE $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part1.ics'); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $i->setLimitToSaveOnEachRun(7); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Is it loaded on Imported Events? $ierb = new \repositories\builders\ImportedEventRepositoryBuilder(); $importedEvents = $ierb->fetchAll(); $this->assertEquals(1, count($importedEvents)); $importedEvent = $importedEvents[0]; $reoccur = $importedEvent->getReoccur(); $this->assertEquals(true, is_array($reoccur)); $this->assertEquals(true, isset($reoccur['ical_rrule'])); $this->assertEquals(true, is_array($reoccur['ical_rrule'])); $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]); $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]); // now test real events $erb = new EventRepositoryBuilder(); $erb->setImportedEvent($importedEvent); $erb->setAfterNow(); $events = $erb->fetchAll(); $this->assertTrue(count($events) > 5); $event = $events[0]; $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertFalse($event->getIsDeleted()); $event = $events[1]; $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertFalse($event->getIsDeleted()); $event = $events[2]; $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertFalse($event->getIsDeleted()); \TimeSource::mock(2015, 1, 2, 1, 1, 1); // ============================================= Import With no changes $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part1.ics'); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $i->setLimitToSaveOnEachRun(7); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Is it loaded on Imported Events? $ierb = new \repositories\builders\ImportedEventRepositoryBuilder(); $importedEvents = $ierb->fetchAll(); $this->assertEquals(1, count($importedEvents)); $importedEvent = $importedEvents[0]; $reoccur = $importedEvent->getReoccur(); $this->assertEquals(true, is_array($reoccur)); $this->assertEquals(true, isset($reoccur['ical_rrule'])); $this->assertEquals(true, is_array($reoccur['ical_rrule'])); $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]); $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]); // now test real events $erb = new EventRepositoryBuilder(); $erb->setImportedEvent($importedEvent); $erb->setAfterNow(); $events = $erb->fetchAll(); $this->assertTrue(count($events) > 5); $event = $events[0]; $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertFalse($event->getIsDeleted()); $event = $events[1]; $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertFalse($event->getIsDeleted()); $event = $events[2]; $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertFalse($event->getIsDeleted()); \TimeSource::mock(2015, 1, 3, 1, 1, 1); // ============================================= Import WITH ONE DELETED! $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ImportRRuleDeleteByExDate1Part2.ics'); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $i->setLimitToSaveOnEachRun(7); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Is it loaded on Imported Events? $ierb = new \repositories\builders\ImportedEventRepositoryBuilder(); $importedEvents = $ierb->fetchAll(); $this->assertEquals(1, count($importedEvents)); $importedEvent = $importedEvents[0]; $reoccur = $importedEvent->getReoccur(); $this->assertEquals(true, is_array($reoccur)); $this->assertEquals(true, isset($reoccur['ical_rrule'])); $this->assertEquals(true, is_array($reoccur['ical_rrule'])); $this->assertEquals("WEEKLY", $reoccur['ical_rrule']["FREQ"]); $this->assertEquals("TH", $reoccur['ical_rrule']["BYDAY"]); // now test real events $erb = new EventRepositoryBuilder(); $erb->setImportedEvent($importedEvent); $erb->setAfterNow(); $erb->setIncludeDeleted(true); $events = $erb->fetchAll(); $this->assertTrue(count($events) > 5); $event = $events[0]; $this->assertEquals("2015-02-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-02-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertFalse($event->getIsDeleted()); $event = $events[1]; $this->assertEquals("2015-02-26T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-02-26T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertTrue($event->getIsDeleted()); $event = $events[2]; $this->assertEquals("2015-03-12T09:00:00+00:00", $event->getStartAtInUTC()->format("c")); $this->assertEquals("2015-03-12T10:00:00+00:00", $event->getEndAtInUTC()->format("c")); $this->assertFalse($event->getIsDeleted()); }
public function update(ImportURLModel $importURL, $fields, ImportURLEditMetaDataModel $importURLEditMetaDataModel) { $alreadyInTransaction = $this->db->inTransaction(); // Make Information Data $fieldsSQL1 = array(); $fieldsParams1 = array('id' => $importURL->getId()); foreach ($fields as $field) { $fieldsSQL1[] = " " . $field . "=:" . $field . " "; if ($field == 'title') { $fieldsParams1['title'] = substr($importURL->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED); } else { if ($field == 'area_id') { $fieldsParams1['area_id'] = $importURL->getAreaId(); } else { if ($field == 'is_enabled') { $fieldsParams1['is_enabled'] = $importURL->getIsEnabled() ? 1 : 0; } else { if ($field == 'is_manual_events_creation') { $fieldsParams1['is_manual_events_creation'] = $importURL->getIsManualEventsCreation() ? 1 : 0; } else { if ($field == 'country_id') { $fieldsParams1['country_id'] = $importURL->getCountryId(); } else { if ($field == 'expired_at') { $fieldsParams1['expired_at'] = $importURL->getExpiredAt() ? $importURL->getExpiredAt()->format("Y-m-d H:i:s") : null; } else { if ($field == 'group_id') { $fieldsParams1['group_id'] = $importURL->getGroupId(); } } } } } } } } // Make History Data $fieldsSQL2 = array('import_url_id', 'user_account_id', 'created_at', 'approved_at'); $fieldsSQLParams2 = array(':import_url_id', ':user_account_id', ':created_at', ':approved_at'); $fieldsParams2 = array('import_url_id' => $importURL->getId(), 'user_account_id' => $importURLEditMetaDataModel->getUserAccount() ? $importURLEditMetaDataModel->getUserAccount()->getId() : null, 'created_at' => $this->timesource->getFormattedForDataBase(), 'approved_at' => $this->timesource->getFormattedForDataBase()); if ($importURLEditMetaDataModel->getEditComment()) { $fieldsSQL2[] = ' edit_comment '; $fieldsSQLParams2[] = ' :edit_comment '; $fieldsParams2['edit_comment'] = $importURLEditMetaDataModel->getEditComment(); } foreach ($this->possibleFields as $field) { if (in_array($field, $fields) || $field == 'title') { $fieldsSQL2[] = " " . $field . " "; $fieldsSQLParams2[] = " :" . $field . " "; if ($field == 'title') { $fieldsParams2['title'] = substr($importURL->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED); } else { if ($field == 'area_id') { $fieldsParams2['area_id'] = $importURL->getAreaId(); } else { if ($field == 'country_id') { $fieldsParams2['country_id'] = $importURL->getCountryId(); } else { if ($field == 'group_id') { $fieldsParams2['group_id'] = $importURL->getGroupId(); } else { if ($field == 'expired_at') { $fieldsParams2['expired_at'] = $importURL->getExpiredAt() ? $importURL->getExpiredAt()->format("Y-m-d H:i:s") : null; } else { if ($field == 'is_enabled') { $fieldsParams2['is_enabled'] = $importURL->getIsEnabled() ? 1 : 0; } else { if ($field == 'is_manual_events_creation') { $fieldsParams2['is_manual_events_creation'] = $importURL->getIsManualEventsCreation() ? 1 : 0; } } } } } } } $fieldsSQL2[] = " " . $field . "_changed "; $fieldsSQLParams2[] = " 0 "; } else { $fieldsSQL2[] = " " . $field . "_changed "; $fieldsSQLParams2[] = " -2 "; } } try { if (!$alreadyInTransaction) { $this->db->beginTransaction(); } // Information SQL $stat = $this->db->prepare("UPDATE import_url_information SET " . implode(",", $fieldsSQL1) . " WHERE id=:id"); $stat->execute($fieldsParams1); // History SQL $stat = $this->db->prepare("INSERT INTO import_url_history (" . implode(",", $fieldsSQL2) . ") VALUES (" . implode(",", $fieldsSQLParams2) . ")"); $stat->execute($fieldsParams2); if (!$alreadyInTransaction) { $this->db->commit(); } } catch (Exception $e) { if (!$alreadyInTransaction) { $this->db->rollBack(); } throw $e; } }
function testLimits() { global $CONFIG; \TimeSource::mock(2012, 9, 1, 1, 1, 1); $CONFIG->importURLAllowEventsSecondsIntoFuture = 77760000; $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $group = new GroupModel(); $group->setTitle("test"); $group->setDescription("test test"); $group->setUrl("http://www.group.com"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $importURLRepository = new ImportURLRepository(); $importURL = new ImportURLModel(); $importURL->setIsEnabled(true); $importURL->setSiteId($site->getId()); $importURL->setGroupId($group->getId()); $importURL->setTitle("Test"); $importURL->setUrl("http://test.com"); $importURLRepository->create($importURL, $site, $user); // Import $importURLRun = new ImportURLRun($importURL, $site); $importURLRun->setTemporaryFileStorageForTesting(dirname(__FILE__) . '/data/ICALManyEvents.ical'); $i = new ImportURLICalHandler(); $i->setImportURLRun($importURLRun); $i->setLimitToSaveOnEachRun(2); $this->assertTrue($i->canHandle()); $r = $i->handle(); // Load! $erb = new EventRepositoryBuilder(); $erb->setSite($site); $events = $erb->fetchAll(); $this->assertEquals(2, count($events)); }
public function getNotificationURL() { global $CONFIG; $this->loadImportURLIfNeeded(); return $CONFIG->getWebSiteDomainSecure($this->site->getSlug()) . '/importurl/' . $this->importURL->getSlug(); }
function newImportURL($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Group does not exist."); } $importurl = new ImportURLModel(); // we must setSiteId() here so loadClashForImportUrl() works $importurl->setSiteId($app['currentSite']->getId()); $importurl->setGroupId($this->parameters['group']->getId()); $form = $app['form.factory']->create(new ImportURLNewForm($app['currentSite'], $app['currentTimeZone']), $importurl); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $importURLRepository = new ImportURLRepository(); $clash = $importURLRepository->loadClashForImportUrl($importurl); if ($clash) { $importurl->setIsEnabled(false); $app['flashmessages']->addMessage("There was a problem enabling this importer. Please try to enable it for details."); } else { $importurl->setIsEnabled(true); } $area = null; $areaRepository = new AreaRepository(); $areasPost = $request->request->get('areas'); if (is_array($areasPost)) { foreach ($areasPost as $areaCode) { if (substr($areaCode, 0, 9) == 'EXISTING:') { $area = $areaRepository->loadBySlug($app['currentSite'], substr($areaCode, 9)); } } } $importurl->setAreaId($area ? $area->getId() : null); $importURLRepository->create($importurl, $app['currentSite'], $app['currentUser']); return $app->redirect("/importurl/" . $importurl->getSlug()); } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/group/newimporturl.html.twig', $this->parameters); }
public function loadClashForImportUrl(ImportURLModel $importURL) { global $DB; $sql = "SELECT import_url_information.* FROM import_url_information WHERE " . "is_enabled='1' AND expired_at IS NULL AND site_id=:site_id AND url_canonical=:url_canonical "; $params = array('site_id' => $importURL->getSiteId(), 'url_canonical' => $importURL->getUrlCanonical()); if ($importURL->getId()) { $sql .= " AND id != :id"; $params['id'] = $importURL->getId(); } $stat = $DB->prepare($sql); $stat->execute($params); if ($stat->rowCount() > 0) { $iurl = new ImportURLModel(); $iurl->setFromDataBaseRow($stat->fetch()); return $iurl; } }