Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2283: Fix event <> feeditem mapping error #49

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions migrations/Version20240918103538.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240918103538 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE event DROP feed_item_id');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE event ADD feed_item_id VARCHAR(255) DEFAULT NULL');
}
}
4 changes: 0 additions & 4 deletions src/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ class Event implements IndexItemInterface, EditableEntityInterface
#[ORM\ManyToOne(inversedBy: 'events')]
private ?Feed $feed = null;

/** @deprecated field kept to allow mapping of already imported events. Replaced by FeedItem relation. */
#[ORM\Column(length: 255, nullable: true)]
private ?string $feedItemId = null;

#[ORM\OneToOne(mappedBy: 'event', cascade: ['persist', 'remove'])]
private ?FeedItem $feedItem = null;

Expand Down
7 changes: 4 additions & 3 deletions src/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function createOrUpdate(FeedItemData $item, FeedItem $feedItemEntity): Ev
if (is_null($feed)) {
throw new FactoryException('Missing feed in event factory');
}
$event = $this->getEvent(['feed' => $feed, 'feedItemId' => $item->id]);

$editedBy = $feed->getUser() ?? $feed;

$event = $feedItemEntity->getEvent();

if (is_null($event)) {
$event = new Event();

Expand Down Expand Up @@ -87,7 +87,8 @@ private function setValues(Event $entity, FeedItem $feedItemEntity, FeedItemData
->setExcerpt($item->excerpt)
->setFeedItem($feedItemEntity)
->setPublicAccess($item->publicAccess)
->setFeed($feed);
->setFeed($feed)
->setFeedItem($feedItemEntity);

$description = $entity->getDescription();

Expand Down
1 change: 0 additions & 1 deletion src/MessageHandler/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function __invoke(EventMessage $message): void
try {
$event = $this->eventFactory->createOrUpdate($feedItemData, $feedItemEntity);

$feedItemEntity->setEvent($event);
$this->entityManager->persist($feedItemEntity);
$this->entityManager->flush();

Expand Down
8 changes: 0 additions & 8 deletions src/MessageHandler/FeedItemDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Entity\FeedItem;
use App\Message\FeedItemDataMessage;
use App\Message\FeedItemNormalizationMessage;
use App\Repository\EventRepository;
use App\Repository\FeedItemRepository;
use App\Repository\FeedRepository;
use App\Service\Feeds\Mapper\FeedMapperInterface;
Expand All @@ -22,7 +21,6 @@ public function __construct(
private FeedMapperInterface $feedMapper,
private FeedRepository $feedRepository,
private FeedItemRepository $feedItemRepository,
private EventRepository $eventRepository,
) {
}

Expand All @@ -45,12 +43,6 @@ public function __invoke(FeedItemDataMessage $message): void
$feedItemEntity = new FeedItem($feed, $feedItemData->id, $message->getData());
}

// Map previously imported events.
$event = $this->eventRepository->findOneBy(['feed' => $feed, 'feedItemId' => $feedItemData->id]);
if (null !== $event) {
$feedItemEntity->setEvent($event);
}

$feedItemEntity->setLastSeenAt();
$this->feedItemRepository->save($feedItemEntity, true);

Expand Down
Loading