Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddWordPressPostSlugToEvents extends AbstractMigration
{
public function change(): void
{
$this
->table('interview')
->addColumn('wordpress_post_slug', 'string', [
'null' => true,
'default' => null,
])
->save()
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions sources/AppBundle/Event/Entity/Interview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, Speaker> */
#[ORM\JoinTable(name: 'interview_speaker')]
#[ORM\JoinColumn(name: 'interview_id', referencedColumnName: 'id')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
13 changes: 13 additions & 0 deletions sources/AppBundle/Event/Wordpress/Dto/PersistedInterview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Wordpress\Dto;

final readonly class PersistedInterview
{
public function __construct(
public int $id,
public string $slug,
) {}
}
10 changes: 6 additions & 4 deletions sources/AppBundle/Event/Wordpress/HttpWordpressClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
use CuyZ\Valinor\Mapper\Source\Source;
use CuyZ\Valinor\MapperBuilder;
use LogicException;
Expand Down Expand Up @@ -38,7 +39,7 @@ public function listCategories(): array
->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) {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion sources/AppBundle/Event/Wordpress/WordpressClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -21,5 +22,5 @@ public function listCategories(): array;
* @param array<Speaker> $speakers
* @param array<Talk> $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;
}
15 changes: 13 additions & 2 deletions templates/admin/event/interview/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<tr>
<th>Speaker(s)</th>
<th class="center aligned">Date de publication</th>
<th>URL</th>
<th></th>
</tr>
</thead>
Expand All @@ -43,6 +44,16 @@
<td class="center aligned">
{{ row.interview.datePublication|date('d/m/Y H:i') }}
</td>
<td>
{% if row.interview.wordpressPostSlug %}
<a href="{{ wordpressBaseUri }}/{{ row.interview.wordpressPostSlug }}"
data-position="left center"
data-tooltip="{{ wordpressBaseUri }}/{{ row.interview.wordpressPostSlug }}"
class="compact ui icon button">
<i class="eye icon"></i>
</a>
{% endif %}
</td>
<td>
<a href="{{ path('admin_event_interview_edit', {interviewId: row.interview.id, id: event.id}) }}"
data-position="left center"
Expand All @@ -51,9 +62,9 @@
<i class="pencil icon"></i>
</a>
{% if row.interview.wordpressPostId is not null %}
<a href="{{ wordpressBaseUri }}?page_id={{ row.interview.wordpressPostId }}"
<a href="{{ wordpressBaseUri }}?p={{ row.interview.wordpressPostId }}"
data-position="left center"
data-tooltip="Voir sur le site"
data-tooltip="Aperçu sur le site"
class="compact ui icon button">
<i class="linkify icon"></i>
</a>
Expand Down
5 changes: 3 additions & 2 deletions tests/support/Wordpress/FakeWordpressClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
Loading