Skip to content
Open
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
5 changes: 5 additions & 0 deletions app/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ doctrine:
is_bundle: false
dir: '%kernel.project_dir%/../sources/AppBundle/Veille/Entity'
prefix: 'AppBundle\Veille\Entity'
PlanetePHP:
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/../sources/PlanetePHP'
prefix: 'PlanetePHP'
when@test:
doctrine:
dbal:
Expand Down
1 change: 1 addition & 0 deletions app/config/reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@
* }>,
* autoescape_service?: scalar|Param|null, // Default: null
* autoescape_service_method?: scalar|Param|null, // Default: null
* base_template_class?: scalar|Param|null, // Deprecated: The child node "base_template_class" at path "twig.base_template_class" is deprecated.
* cache?: scalar|Param|null, // Default: true
* charset?: scalar|Param|null, // Default: "%kernel.charset%"
* debug?: bool|Param, // Default: "%kernel.debug%"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CleanupUserIdInPlaneteFlux extends AbstractMigration
{
public function change(): void
{
$this->query(<<<SQL
UPDATE afup_planete_flux
SET id_personne_physique = NULL
WHERE id_personne_physique = 0;
SQL);
}
}
22 changes: 10 additions & 12 deletions sources/AppBundle/Controller/Admin/Planete/FeedAddAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace AppBundle\Controller\Admin\Planete;

use AppBundle\AuditLog\Audit;
use AppBundle\Planete\FeedFormData;
use AppBundle\Planete\FeedFormType;
use Exception;
use PlanetePHP\Feed;
use PlanetePHP\FeedRepository;
use PlanetePHP\FeedStatus;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -22,20 +23,17 @@ public function __construct(

public function __invoke(Request $request): Response
{
$data = new FeedFormData();
$form = $this->createForm(FeedFormType::class, $data);
$feed = new Feed();
$feed->url = 'https://';
$feed->feed = 'https://';
$feed->status = FeedStatus::Active;
$form = $this->createForm(FeedFormType::class, $feed);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$this->feedRepository->insert(
$data->name,
$data->url,
$data->feed,
$data->status,
$data->userId,
);

$this->audit->log('Ajout du flux ' . $data->name);
$this->feedRepository->save($feed);

$this->audit->log('Ajout du flux ' . $feed->name);
$this->addFlash('notice', 'Le flux a été ajouté');

return $this->redirectToRoute('admin_planete_feed_list');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace AppBundle\Controller\Admin\Planete;

use PlanetePHP\FeedArticleRepository;
use PlanetePHP\ArticleRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

final readonly class FeedArticleListAction
{
public function __construct(
private FeedArticleRepository $feedArticleRepository,
private ArticleRepository $articleRepository,
private Environment $twig,
) {}

Expand All @@ -22,7 +22,7 @@ public function __invoke(Request $request): Response
$direction = $request->query->getString('direction', 'asc');

return new Response($this->twig->render('admin/planete/feed_article_list.html.twig', [
'articles' => $this->feedArticleRepository->search($sort, $direction, 20),
'articles' => $this->articleRepository->search($sort, $direction, 20),
'sort' => $sort,
'direction' => $direction,
]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public function __invoke(Request $request): RedirectResponse
$id = $request->query->getInt('id');

try {
$this->feedRepository->delete($id);
$feed = $this->feedRepository->find($id);
if ($feed !== null) {
$this->feedRepository->delete($feed);
}

$this->audit->log('Suppression du flux ' . $id);
$this->addFlash('notice', 'Le flux a été supprimé');
Expand Down
27 changes: 8 additions & 19 deletions sources/AppBundle/Controller/Admin/Planete/FeedEditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace AppBundle\Controller\Admin\Planete;

use AppBundle\AuditLog\Audit;
use AppBundle\Planete\FeedFormData;
use AppBundle\Planete\FeedFormType;
use Exception;
use PlanetePHP\FeedRepository;
Expand All @@ -23,27 +22,17 @@ public function __construct(
public function __invoke(Request $request): Response
{
$id = $request->query->getInt('id');
$feed = $this->feedRepository->get($id);
$data = new FeedFormData();
$data->name = $feed->name;
$data->feed = $feed->feed;
$data->url = $feed->url;
$data->userId = $feed->userId;
$data->status = $feed->status;
$form = $this->createForm(FeedFormType::class, $data);
$feed = $this->feedRepository->find($id);
if ($feed === null) {
throw $this->createNotFoundException();
}
$form = $this->createForm(FeedFormType::class, $feed);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$this->feedRepository->update(
$id,
$data->name,
$data->url,
$data->feed,
$data->status,
$data->userId,
);

$this->audit->log(sprintf("Modification du flux %s (%d)", $data->name, $id));
$this->feedRepository->save($feed);

$this->audit->log(sprintf("Modification du flux %s (%d)", $feed->name, $id));
$this->addFlash('notice', 'Le flux a été modifié');

return $this->redirectToRoute('admin_planete_feed_list');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
public function __invoke(Request $request): Response
{
$testFeeds = $request->query->getBoolean('testFeeds');
$feeds = $this->feedRepository->find();
$feeds = $this->feedRepository->findAllOrderedByName();

return new Response($this->twig->render('admin/planete/feed_list.html.twig', [
'feeds' => $feeds,
Expand Down
20 changes: 10 additions & 10 deletions sources/AppBundle/Controller/Planete/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace AppBundle\Controller\Planete;

use PlanetePHP\DisplayableFeedArticle;
use PlanetePHP\FeedArticleRepository;
use PlanetePHP\Article;
use PlanetePHP\ArticleRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final readonly class ArticlesController
{
public function __construct(private FeedArticleRepository $feedArticleRepository) {}
public function __construct(private ArticleRepository $articleRepository) {}

public function __invoke(Request $request): Response
{
Expand All @@ -22,21 +22,21 @@ public function __invoke(Request $request): Response
$page = 1;
}

$totalCount = $this->feedArticleRepository->countRelevant();
$articles = $this->feedArticleRepository->findLatest($page - 1, DATE_RSS, $perPage);
$totalCount = $this->articleRepository->countRelevant();
$articles = $this->articleRepository->findLatest($page - 1, $perPage);

$data = [];

foreach ($articles as $article) {
$data[] = [
'title' => $article->title,
'url' => $this->getArticleUrl($article),
'date' => $article->update,
'date' => $article->updatedAt?->format(DATE_RSS),
'author' => $article->author,
'content' => $article->content,
'feed' => [
'name' => $article->feedName,
'url' => $article->feedUrl,
'name' => $article->feed?->name,
'url' => $article->feed?->url,
],
];
}
Expand All @@ -53,7 +53,7 @@ public function __invoke(Request $request): Response
);
}

private function getArticleUrl(DisplayableFeedArticle $article): string
private function getArticleUrl(Article $article): string
{
$url = $article->url;

Expand All @@ -62,7 +62,7 @@ private function getArticleUrl(DisplayableFeedArticle $article): string
}

if (!str_starts_with($url, 'http')) {
$feedUrl = rtrim((string) $article->feedUrl, '/');
$feedUrl = rtrim((string) $article->feed?->url, '/');
$articleUrl = ltrim($url, '/');

return implode('/', [$feedUrl, $articleUrl]);
Expand Down
27 changes: 0 additions & 27 deletions sources/AppBundle/Planete/FeedFormData.php

This file was deleted.

15 changes: 15 additions & 0 deletions sources/AppBundle/Planete/FeedFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;

class FeedFormType extends AbstractType
{
Expand All @@ -32,6 +33,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'size' => 30,
'maxlength' => 40,
],
'constraints' => [
new Assert\NotBlank(),
],
])
->add('url', UrlType::class, [
'label' => 'URL',
Expand All @@ -40,6 +44,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'size' => 50,
'maxlength' => 200,
],
'constraints' => [
new Assert\NotBlank(),
new Assert\Url(),
],
])
->add('feed', UrlType::class, [
'label' => 'Flux',
Expand All @@ -48,6 +56,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'size' => 50,
'maxlength' => 200,
],
'constraints' => [
new Assert\NotBlank(),
new Assert\Url(),
],
])
->add('userId', ChoiceType::class, [
'label' => 'Personne physique',
Expand All @@ -58,6 +70,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'État',
'required' => true,
'class' => FeedStatus::class,
'constraints' => [
new Assert\NotNull(),
],
])
->add('save', SubmitType::class, ['label' => 'Ajouter']);
}
Expand Down
46 changes: 46 additions & 0 deletions sources/PlanetePHP/Article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace PlanetePHP;

use AppBundle\Doctrine\Type\UnixTimestampType;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ArticleRepository::class)]
#[ORM\Table(name: 'afup_planete_billet')]
class Article
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public ?int $id = null;

#[ORM\ManyToOne(targetEntity: Feed::class)]
#[ORM\JoinColumn(name: 'afup_planete_flux_id', nullable: true)]
public ?Feed $feed = null;

#[ORM\Column(name: 'clef', length: 255, nullable: true)]
public ?string $key = null;

#[ORM\Column(name: 'titre', type: 'text', nullable: true)]
public ?string $title = null;

#[ORM\Column(length: 255, nullable: true)]
public ?string $url = null;

#[ORM\Column(name: 'maj', type: UnixTimestampType::NAME, nullable: true)]
public ?\DateTime $updatedAt = null;

#[ORM\Column(name: 'auteur', type: 'text', nullable: true)]
public ?string $author = null;

#[ORM\Column(name: 'resume', type: 'text', nullable: true)]
public ?string $summary = null;

#[ORM\Column(name: 'contenu', type: 'text', nullable: true)]
public ?string $content = null;

#[ORM\Column(name: 'etat', nullable: false)]
public bool $isRelevant = false;
}
Loading
Loading