diff --git a/db/migrations/20260818212525_add_word_press_post_slug_to_events.php b/db/migrations/20260818212525_add_word_press_post_slug_to_events.php new file mode 100644 index 000000000..5e3f0ec69 --- /dev/null +++ b/db/migrations/20260818212525_add_word_press_post_slug_to_events.php @@ -0,0 +1,20 @@ +table('interview') + ->addColumn('wordpress_post_slug', 'string', [ + 'null' => true, + 'default' => null, + ]) + ->save() + ; + } +} diff --git a/sources/AppBundle/Controller/Admin/Event/Interview/AddOrEditAction.php b/sources/AppBundle/Controller/Admin/Event/Interview/AddOrEditAction.php index 45bde0fe1..3d66aa673 100644 --- a/sources/AppBundle/Controller/Admin/Event/Interview/AddOrEditAction.php +++ b/sources/AppBundle/Controller/Admin/Event/Interview/AddOrEditAction.php @@ -123,14 +123,15 @@ private function saveToWordpress(Interview $interview, Event $event): bool } try { - $wordpressPostId = $this->wordpressClient->persistInterview( + $persistedInterview = $this->wordpressClient->persistInterview( $interview, $event, $interview->speakers->toArray(), $plannedTalks, ); - $interview->wordpressPostId = $wordpressPostId; + $interview->wordpressPostId = $persistedInterview->id; + $interview->wordpressPostSlug = $persistedInterview->slug; $this->interviewRepository->save($interview); return true; diff --git a/sources/AppBundle/Event/Entity/Interview.php b/sources/AppBundle/Event/Entity/Interview.php index 9cb4465b7..fbe6f6ec7 100644 --- a/sources/AppBundle/Event/Entity/Interview.php +++ b/sources/AppBundle/Event/Entity/Interview.php @@ -28,6 +28,9 @@ class Interview #[ORM\Column(name: 'wordpress_post_id', nullable: true)] public ?int $wordpressPostId = null; + #[ORM\Column(name: 'wordpress_post_slug', nullable: true)] + public ?string $wordpressPostSlug = null; + /** @var Collection */ #[ORM\JoinTable(name: 'interview_speaker')] #[ORM\JoinColumn(name: 'interview_id', referencedColumnName: 'id')] diff --git a/sources/AppBundle/Event/Model/Repository/EventRepository.php b/sources/AppBundle/Event/Model/Repository/EventRepository.php index 7a668a443..e95f33da5 100644 --- a/sources/AppBundle/Event/Model/Repository/EventRepository.php +++ b/sources/AppBundle/Event/Model/Repository/EventRepository.php @@ -44,7 +44,7 @@ public function getNextEvent(): ?Event public function getNextEvents(): ?CollectionInterface { $query = $this - ->getQuery('SELECT id, path, titre, text, date_debut, date_fin, date_debut_appel_conferencier, date_fin_appel_conferencier, date_fin_vente, nb_places FROM afup_forum WHERE date_debut > NOW() ORDER BY date_debut') + ->getQuery('SELECT id, path, titre, text, date_debut, date_fin, date_debut_appel_conferencier, date_fin_appel_conferencier, date_fin_vente, nb_places, interviews_wp_category_id, interviews_intro, interviews_cta_text FROM afup_forum WHERE date_debut > NOW() ORDER BY date_debut') ; $events = $query->query($this->getCollection(new HydratorSingleObject())); diff --git a/sources/AppBundle/Event/Wordpress/Dto/PersistedInterview.php b/sources/AppBundle/Event/Wordpress/Dto/PersistedInterview.php new file mode 100644 index 000000000..84ba4213c --- /dev/null +++ b/sources/AppBundle/Event/Wordpress/Dto/PersistedInterview.php @@ -0,0 +1,13 @@ +map('array<' . Category::class . '>', Source::json($response->getContent())); } - public function persistInterview(Interview $interview, Event $event, array $speakers, array $talks): ?int + public function persistInterview(Interview $interview, Event $event, array $speakers, array $talks): PersistedInterview { $categoryId = $event->getInterviewsWordpressCategoryId(); if ($categoryId === null) { @@ -87,9 +88,10 @@ public function persistInterview(Interview $interview, Event $event, array $spea ], ]); - $id = $response->toArray()['id'] ?? null; - - return is_int($id) ? $id : null; + return $this->mapperBuilder + ->allowSuperfluousKeys() + ->mapper() + ->map(PersistedInterview::class, Source::json($response->getContent())); } private function getCategory(int $id): ?Category diff --git a/sources/AppBundle/Event/Wordpress/WordpressClient.php b/sources/AppBundle/Event/Wordpress/WordpressClient.php index cf9f5bf93..aff5e9079 100644 --- a/sources/AppBundle/Event/Wordpress/WordpressClient.php +++ b/sources/AppBundle/Event/Wordpress/WordpressClient.php @@ -9,6 +9,7 @@ use AppBundle\Event\Model\Event; use AppBundle\Event\Model\Talk; use AppBundle\Event\Wordpress\Dto\Category; +use AppBundle\Event\Wordpress\Dto\PersistedInterview; interface WordpressClient { @@ -21,5 +22,5 @@ public function listCategories(): array; * @param array $speakers * @param array $talks */ - public function persistInterview(Interview $interview, Event $event, array $speakers, array $talks): ?int; + public function persistInterview(Interview $interview, Event $event, array $speakers, array $talks): PersistedInterview; } diff --git a/templates/admin/event/interview/list.html.twig b/templates/admin/event/interview/list.html.twig index d19ebfd30..79dd37a85 100644 --- a/templates/admin/event/interview/list.html.twig +++ b/templates/admin/event/interview/list.html.twig @@ -33,6 +33,7 @@ Speaker(s) Date de publication + URL @@ -43,6 +44,16 @@ {{ row.interview.datePublication|date('d/m/Y H:i') }} + + {% if row.interview.wordpressPostSlug %} + + + + {% endif %} + {% if row.interview.wordpressPostId is not null %} - diff --git a/tests/support/Wordpress/FakeWordpressClient.php b/tests/support/Wordpress/FakeWordpressClient.php index 7257f38da..aeafe99a0 100644 --- a/tests/support/Wordpress/FakeWordpressClient.php +++ b/tests/support/Wordpress/FakeWordpressClient.php @@ -7,6 +7,7 @@ use AppBundle\Event\Entity\Interview; use AppBundle\Event\Model\Event; use AppBundle\Event\Wordpress\Dto\Category; +use AppBundle\Event\Wordpress\Dto\PersistedInterview; use AppBundle\Event\Wordpress\WordpressClient; final class FakeWordpressClient implements WordpressClient @@ -18,8 +19,8 @@ public function listCategories(): array ]; } - public function persistInterview(Interview $interview, Event $event, array $speakers, array $talks): ?int + public function persistInterview(Interview $interview, Event $event, array $speakers, array $talks): PersistedInterview { - return 123; + return new PersistedInterview(123, 'super-slug'); } }