Skip to content
Draft
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
2 changes: 1 addition & 1 deletion config/routes/fos_js_routing.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing-sf4.xml"
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.php"
4 changes: 2 additions & 2 deletions config/routes/web_profiler.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
when@dev:
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
resource: '@WebProfilerBundle/Resources/config/routing/wdt.php'
prefix: /_wdt

web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
resource: '@WebProfilerBundle/Resources/config/routing/profiler.php'
prefix: /_profiler
14 changes: 10 additions & 4 deletions src/Command/Update/RemoveRemoteEntriesFromLocalDomainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Repository\DomainRepository;
use App\Service\SettingsManager;
use Doctrine\DBAL\ParameterType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -42,19 +43,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$countBeforeSql = 'SELECT COUNT(*) as ctn FROM entry WHERE domain_id = :dId';
$stmt1 = $this->entityManager->getConnection()->prepare($countBeforeSql);
$countBefore = \intval($stmt1->executeQuery(['dId' => $domain->getId()])->fetchOne());
$stmt1->bindValue('dId', $domain->getId(), ParameterType::INTEGER);
$countBefore = \intval($stmt1->executeQuery()->fetchOne());

$sql = 'UPDATE entry SET domain_id = NULL WHERE domain_id = :dId AND ap_id IS NOT NULL';
$stmt2 = $this->entityManager->getConnection()->prepare($sql);
$stmt2->executeStatement(['dId' => $domain->getId()]);
$stmt2->bindValue('dId', $domain->getId(), ParameterType::INTEGER);
$stmt2->executeStatement();

$countAfterSql = 'SELECT COUNT(*) as ctn FROM entry WHERE domain_id = :dId';
$stmt3 = $this->entityManager->getConnection()->prepare($countAfterSql);
$countAfter = \intval($stmt3->executeQuery(['dId' => $domain->getId()])->fetchOne());
$stmt3->bindValue('dId', $domain->getId(), ParameterType::INTEGER);
$countAfter = \intval($stmt3->executeQuery()->fetchOne());

$sql = 'UPDATE domain SET entry_count = :c WHERE id = :dId';
$stmt4 = $this->entityManager->getConnection()->prepare($sql);
$stmt4->executeStatement(['c' => $countAfter, 'dId' => $domain->getId()]);
$stmt4->bindValue('dId', $domain->getId(), ParameterType::INTEGER);
$stmt4->bindValue('c', $countAfter, ParameterType::INTEGER);
$stmt4->executeStatement();

$io->success(\sprintf('Removed %d entries from the domain %s, now only %d entries are left', $countBefore - $countAfter, $domainName, $countAfter));

Expand Down
18 changes: 11 additions & 7 deletions src/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
use App\Service\SettingsManager;
use App\Service\UserNoteManager;
use App\Utils\Embed;
use Doctrine\DBAL\ParameterType;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Emoji\EmojiTransliterator;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -105,7 +107,7 @@ public function fetchEmbed(Embed $embed, Request $request): JsonResponse
);
}

public function fetchEntry(Entry $entry, Request $request): JsonResponse
public function fetchEntry(#[MapEntity(id: 'id')] Entry $entry, Request $request): JsonResponse
{
return new JsonResponse(
[
Expand All @@ -122,7 +124,7 @@ public function fetchEntry(Entry $entry, Request $request): JsonResponse
);
}

public function fetchEntryComment(EntryComment $comment): JsonResponse
public function fetchEntryComment(#[MapEntity(id: 'id')] EntryComment $comment): JsonResponse
{
return new JsonResponse(
[
Expand All @@ -141,7 +143,7 @@ public function fetchEntryComment(EntryComment $comment): JsonResponse
);
}

public function fetchPost(Post $post): JsonResponse
public function fetchPost(#[MapEntity(id: 'id')] Post $post): JsonResponse
{
return new JsonResponse(
[
Expand All @@ -158,7 +160,7 @@ public function fetchPost(Post $post): JsonResponse
);
}

public function fetchPostComment(PostComment $comment): JsonResponse
public function fetchPostComment(#[MapEntity(id: 'id')] PostComment $comment): JsonResponse
{
return new JsonResponse(
[
Expand All @@ -175,7 +177,7 @@ public function fetchPostComment(PostComment $comment): JsonResponse
);
}

public function fetchPostComments(Post $post, PostCommentRepository $repository): JsonResponse
public function fetchPostComments(#[MapEntity(id: 'id')] Post $post, PostCommentRepository $repository): JsonResponse
{
$criteria = new PostCommentPageView(1, $this->security);
$criteria->post = $post;
Expand Down Expand Up @@ -217,7 +219,7 @@ public function fetchOnline(
]);
}

public function fetchUserPopup(User $user, UserNoteManager $manager): JsonResponse
public function fetchUserPopup(#[MapEntity(mapping: ['username' => 'username'])] User $user, UserNoteManager $manager): JsonResponse
{
if ($this->getUser()) {
$dto = $manager->createDto($this->getUserOrThrow(), $user);
Expand Down Expand Up @@ -322,7 +324,9 @@ public function unregisterPushNotifications(#[MapRequestPayload] UnRegisterPushR
try {
$conn = $this->entityManager->getConnection();
$stmt = $conn->prepare('DELETE FROM user_push_subscription WHERE user_id = :user AND device_key = :device');
$stmt->executeQuery(['user' => $this->getUserOrThrow()->getId(), 'device' => $payload->deviceKey]);
$stmt->bindValue('user', $this->getUserOrThrow()->getId(), ParameterType::INTEGER);
$stmt->bindValue('device', $payload->deviceKey, ParameterType::STRING);
$stmt->executeQuery();

return new JsonResponse();
} catch (\Exception $e) {
Expand Down
1 change: 1 addition & 0 deletions src/Controller/Api/Notification/NotificationPushApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function deleteSubscription(
try {
$conn = $this->entityManager->getConnection();
$stmt = $conn->prepare('DELETE FROM user_push_subscription WHERE user_id = :user AND api_token = :token');
// TODO fix deprecation
$stmt->executeQuery(['user' => $user->getId(), 'token' => $apiToken]);

return new JsonResponse(headers: $headers);
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Domain/DomainBlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controller\AbstractController;
use App\Entity\Domain;
use App\Service\DomainManager;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -20,7 +21,7 @@ public function __construct(
}

#[IsGranted('ROLE_USER')]
public function block(Domain $domain, Request $request): Response
public function block(#[MapEntity(mapping: ['name' => 'name'])] Domain $domain, Request $request): Response
{
$this->manager->block($domain, $this->getUserOrThrow());

Expand All @@ -32,7 +33,7 @@ public function block(Domain $domain, Request $request): Response
}

#[IsGranted('ROLE_USER')]
public function unblock(Domain $domain, Request $request): Response
public function unblock(#[MapEntity(mapping: ['name' => 'name'])] Domain $domain, Request $request): Response
{
$this->manager->unblock($domain, $this->getUserOrThrow());

Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Domain/DomainSubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controller\AbstractController;
use App\Entity\Domain;
use App\Service\DomainManager;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -20,7 +21,7 @@ public function __construct(
}

#[IsGranted('ROLE_USER')]
public function subscribe(Domain $domain, Request $request): Response
public function subscribe(#[MapEntity(mapping: ['name' => 'name'])] Domain $domain, Request $request): Response
{
$this->manager->subscribe($domain, $this->getUserOrThrow());

Expand All @@ -32,7 +33,7 @@ public function subscribe(Domain $domain, Request $request): Response
}

#[IsGranted('ROLE_USER')]
public function unsubscribe(Domain $domain, Request $request): Response
public function unsubscribe(#[MapEntity(mapping: ['name' => 'name'])] Domain $domain, Request $request): Response
{
$this->manager->unsubscribe($domain, $this->getUserOrThrow());

Expand Down
9 changes: 7 additions & 2 deletions src/Controller/Entry/Comment/EntryCommentFrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ public function __construct(
) {
}

public function front(?Magazine $magazine, ?string $sortBy, ?string $time, Request $request, #[MapQueryParameter] ?string $federation): Response
{
public function front(
?Magazine $magazine,
?string $sortBy,
?string $time,
Request $request,
#[MapQueryParameter] ?string $federation,
): Response {
$params = [];
$criteria = new EntryCommentPageView($this->getPageNb($request), $this->security);
$criteria->showSortOption($criteria->resolveSort($sortBy ?? Criteria::SORT_DEFAULT))
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Magazine/MagazineBlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controller\AbstractController;
use App\Entity\Magazine;
use App\Service\MagazineManager;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -20,7 +21,7 @@ public function __construct(private readonly MagazineManager $manager)

#[IsGranted('ROLE_USER')]
#[IsGranted('block', subject: 'magazine')]
public function block(Magazine $magazine, Request $request): Response
public function block(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->manager->block($magazine, $this->getUserOrThrow());

Expand All @@ -33,7 +34,7 @@ public function block(Magazine $magazine, Request $request): Response

#[IsGranted('ROLE_USER')]
#[IsGranted('block', subject: 'magazine')]
public function unblock(Magazine $magazine, Request $request): Response
public function unblock(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->manager->unblock($magazine, $this->getUserOrThrow());

Expand Down
9 changes: 5 additions & 4 deletions src/Controller/Magazine/MagazineDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controller\AbstractController;
use App\Entity\Magazine;
use App\Service\MagazineManager;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Attribute\IsGranted;
Expand All @@ -19,7 +20,7 @@ public function __construct(private readonly MagazineManager $manager)

#[IsGranted('ROLE_USER')]
#[IsGranted('delete', subject: 'magazine')]
public function delete(Magazine $magazine, Request $request): Response
public function delete(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_delete', $request->getPayload()->get('token'));

Expand All @@ -30,7 +31,7 @@ public function delete(Magazine $magazine, Request $request): Response

#[IsGranted('ROLE_USER')]
#[IsGranted('delete', subject: 'magazine')]
public function restore(Magazine $magazine, Request $request): Response
public function restore(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_restore', $request->getPayload()->get('token'));

Expand All @@ -41,7 +42,7 @@ public function restore(Magazine $magazine, Request $request): Response

#[IsGranted('ROLE_USER')]
#[IsGranted('purge', subject: 'magazine')]
public function purge(Magazine $magazine, Request $request): Response
public function purge(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_purge', $request->getPayload()->get('token'));

Expand All @@ -52,7 +53,7 @@ public function purge(Magazine $magazine, Request $request): Response

#[IsGranted('ROLE_USER')]
#[IsGranted('purge', subject: 'magazine')]
public function purgeContent(Magazine $magazine, Request $request): Response
public function purgeContent(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_purge_content', $request->getPayload()->get('token'));

Expand Down
9 changes: 7 additions & 2 deletions src/Controller/Magazine/MagazineModController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
use App\Controller\AbstractController;
use App\Entity\Magazine;
use App\Repository\MagazineRepository;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class MagazineModController extends AbstractController
{
public function __invoke(Magazine $magazine, MagazineRepository $repository, Request $request): Response
{
public function __invoke(
#[MapEntity(mapping: ['name' => 'name'])]
Magazine $magazine,
MagazineRepository $repository,
Request $request,
): Response {
$moderators = $repository->findModerators($magazine, $this->getPageNb($request));

return $this->render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controller\AbstractController;
use App\Entity\Magazine;
use App\Service\MagazineManager;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
Expand All @@ -20,7 +21,7 @@ public function __construct(private readonly MagazineManager $manager)

#[IsGranted('ROLE_USER')]
#[IsGranted('subscribe', subject: 'magazine')]
public function __invoke(Magazine $magazine, Request $request): Response
public function __invoke(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
// applying to be a moderator is only supported for local magazines
if ($magazine->apId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controller\AbstractController;
use App\Entity\Magazine;
use App\Service\MagazineManager;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
Expand All @@ -20,7 +21,7 @@ public function __construct(private readonly MagazineManager $manager)

#[IsGranted('ROLE_USER')]
#[IsGranted('subscribe', subject: 'magazine')]
public function toggle(Magazine $magazine, Request $request): Response
public function toggle(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
// applying to be owner is only supported for local magazines
if ($magazine->apId) {
Expand All @@ -35,7 +36,7 @@ public function toggle(Magazine $magazine, Request $request): Response
}

#[IsGranted('ROLE_ADMIN')]
public function accept(Magazine $magazine, Request $request): Response
public function accept(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_ownership_request', $request->getPayload()->get('token'));

Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Magazine/MagazinePeopleFrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Entity\Magazine;
use App\Repository\MagazineRepository;
use App\Repository\UserRepository;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -20,6 +21,7 @@ public function __construct(
}

public function __invoke(
#[MapEntity(mapping: ['name' => 'name'])]
Magazine $magazine,
?string $category,
Request $request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controller\AbstractController;
use App\Entity\Magazine;
use App\Service\MagazineManager;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Attribute\IsGranted;
Expand All @@ -18,7 +19,7 @@ public function __construct(private readonly MagazineManager $manager)
}

#[IsGranted('ROLE_ADMIN')]
public function __invoke(Magazine $magazine, Request $request): Response
public function __invoke(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->validateCsrf('magazine_remove_subscriptions', $request->getPayload()->get('token'));

Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Magazine/MagazineSubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Controller\AbstractController;
use App\Entity\Magazine;
use App\Service\MagazineManager;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -20,7 +21,7 @@ public function __construct(private readonly MagazineManager $manager)

#[IsGranted('ROLE_USER')]
#[IsGranted('subscribe', subject: 'magazine')]
public function subscribe(Magazine $magazine, Request $request): Response
public function subscribe(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->manager->subscribe($magazine, $this->getUserOrThrow());

Expand All @@ -33,7 +34,7 @@ public function subscribe(Magazine $magazine, Request $request): Response

#[IsGranted('ROLE_USER')]
#[IsGranted('subscribe', subject: 'magazine')]
public function unsubscribe(Magazine $magazine, Request $request): Response
public function unsubscribe(#[MapEntity(mapping: ['name' => 'name'])] Magazine $magazine, Request $request): Response
{
$this->manager->unsubscribe($magazine, $this->getUserOrThrow());

Expand Down
Loading
Loading