Skip to content

Commit

Permalink
Merge pull request #773 from verdigado/restrict-icsimport-to-pid
Browse files Browse the repository at this point in the history
Restrict ics-import to pid per calendar
  • Loading branch information
lochmueller authored Nov 17, 2023
2 parents 50a3c8c + b8048fc commit 06d0c99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions Classes/Domain/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ public function findBySearch(Search $search): array
return $ids;
}

public function findOneByImportId(string $importId): ?object
public function findOneByImportId(string $importId, int $pid): ?object
{
$query = $this->createQuery();

$querySettings = $query->getQuerySettings();
$querySettings->setRespectStoragePage(false);
$querySettings->setIgnoreEnableFields(true);

$query->matching($query->equals('importId', $importId));
$query->matching($query->logicalAnd(
$query->equals('importId', $importId),
$query->equals('pid', $pid),
));

return $query->execute()->getFirst();
}
Expand Down
7 changes: 4 additions & 3 deletions Classes/EventListener/ImportSingleIcalEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __invoke(ImportSingleIcalEvent $event): void
$pid = $event->getPid();

$importId = \strlen($calEvent->getUid()) <= 100 ? $calEvent->getUid() : md5($calEvent->getUid());
$eventObj = $this->initializeEventRecord($importId);
$eventObj = $this->initializeEventRecord($importId, $pid);
$this->hydrateEventRecord($eventObj, $calEvent, $pid);

if (null !== $eventObj->getUid() && (int)$eventObj->getUid() > 0) {
Expand All @@ -54,12 +54,13 @@ public function __invoke(ImportSingleIcalEvent $event): void
* Initializes or gets an event by import id.
*
* @param string $importId
* @param int $pid
*
* @return Event
*/
private function initializeEventRecord(string $importId): Event
private function initializeEventRecord(string $importId, int $pid): Event
{
$eventObj = $this->eventRepository->findOneByImportId($importId);
$eventObj = $this->eventRepository->findOneByImportId($importId, $pid);

if (!($eventObj instanceof Event)) {
$eventObj = new Event();
Expand Down

0 comments on commit 06d0c99

Please sign in to comment.