fix: sync tags relation table on import
This commit is contained in:
@@ -212,6 +212,7 @@ class ImportEventsCommand extends Command
|
||||
}
|
||||
|
||||
$this->syncOrganization($eventId);
|
||||
$this->syncTags($eventId, self::DEFAULT_TAGS);
|
||||
}
|
||||
|
||||
private function findEventIdByExternalId(string $externalId): int|null
|
||||
@@ -240,6 +241,33 @@ class ImportEventsCommand extends Command
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $tagIds
|
||||
*/
|
||||
private function syncTags(int $eventId, array $tagIds): void
|
||||
{
|
||||
$normalizedTagIds = array_values(array_unique(array_map('intval', $tagIds)));
|
||||
|
||||
$this->connection->delete('tl_tags_rel', [
|
||||
'pid' => $eventId,
|
||||
'ptable' => 'tl_calendar_events',
|
||||
'field' => 'tags',
|
||||
]);
|
||||
|
||||
foreach ($normalizedTagIds as $tagId) {
|
||||
if ($tagId <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->connection->insert('tl_tags_rel', [
|
||||
'tag_id' => $tagId,
|
||||
'pid' => $eventId,
|
||||
'ptable' => 'tl_calendar_events',
|
||||
'field' => 'tags',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function generateAlias(string $title, int $startDate, string $preferredAlias, int|null $eventId): string
|
||||
{
|
||||
$candidate = $preferredAlias !== '' ? $this->normalizeAlias($preferredAlias) : '';
|
||||
|
||||
Reference in New Issue
Block a user