georgringer / news_importicsxml

Import of ICS and XML into EXT:news
GNU General Public License v2.0
2 stars 20 forks source link

Category mapping for ICS import does not handle multiple categories #45

Closed tkowtsch closed 1 month ago

tkowtsch commented 3 months ago

ICS format allows to have multiple categories assigned, e.g.:

BEGIN:VEVENT UID:22727521 DTSTAMP:20230705T182121Z DTSTART:20240421T073000Z DTEND:20240421T083000Z SUMMARY:Summer Greetings SEQUENCE:77438066 LOCATION:Festival Area DESCRIPTION: STATUS:CONFIRMED CATEGORIES:2.0 Outdoor-Events, 1.3 Kids, 1.4 Families, 1.1 Seniorship END:VEVENT

This event has four categories assigned:

As the ordering depends on the sending application it's not possible to provide a valid mapping string to overcome this.

Although it's an ancient format with a very bad data structure, it'd be nice if multiple categories could be supported.

tkowtsch commented 3 months ago

Suggestion to fix that issue (sorry, I'm not sure about how to create a valid pull request :-/ )

in IcsMapper.php, in categoryTitles loop => split data and interate over the result:


    protected function getCategories(array $categoryTitles, TaskConfiguration $configuration): array
    {
        $categoryIds = [];
        if (!empty($categoryTitles)) {
            if (!$configuration->getMapping()) {
                $this->logger->info('Categories found during import but no mapping assigned in the task!');
            } else {
                $categoryMapping = $configuration->getMappingConfigured();

                foreach ($categoryTitles as $rawTitle) {
                    $splitTitle = GeneralUtility::trimExplode(',', $rawTitle, true, 0);

                    foreach ($splitTitle as $title) {
                        if (!isset($categoryMapping[$title])) {
                            $this->logger->warning(sprintf('Category mapping is missing for category "%s"', $title));
                        } else {
                            $categoryIds[] = $categoryMapping[$title];
                        }
                    }
                }
            }
        }

        return $categoryIds;

    }