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
10 changes: 3 additions & 7 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

$ignoreErrors = [];
$ignoreErrors[] = [
Expand Down Expand Up @@ -2683,12 +2685,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Event/Subscriber/AuthSubscriber.php',
];
$ignoreErrors[] = [
'message' => '#^Call to an undefined method object\\:\\:executeUpdate\\(\\)\\.$#',
'identifier' => 'method.notFound',
'count' => 2,
'path' => __DIR__ . '/src/Event/Subscriber/TimedPublishSubscriber.php',
];
$ignoreErrors[] = [
'message' => '#^Method Bolt\\\\Event\\\\Subscriber\\\\TimedPublishSubscriber\\:\\:__construct\\(\\) has parameter \\$tablePrefix with no type specified\\.$#',
'identifier' => 'missingType.parameter',
Expand Down
25 changes: 17 additions & 8 deletions src/Event/Subscriber/TimedPublishSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
use Bolt\Doctrine\TablePrefixTrait;
use Bolt\Entity\Content;
use Carbon\Carbon;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Throwable;
Expand All @@ -18,12 +21,17 @@ class TimedPublishSubscriber implements EventSubscriberInterface

public const PRIORITY = 30;

private object $defaultConnection;
private Connection $defaultConnection;
private string $tablePrefix;

public function __construct($tablePrefix, ManagerRegistry $managerRegistry)
{
$this->defaultConnection = $managerRegistry->getConnection('default');
public function __construct(
$tablePrefix,
ManagerRegistry $managerRegistry,
private LoggerInterface $logger
) {
/** @var Connection $connection */
$connection = $managerRegistry->getConnection('default');
$this->defaultConnection = $connection;
$this->tablePrefix = $this
->setTablePrefixes($tablePrefix, $managerRegistry)
->getTablePrefix($managerRegistry->getManager('default'));
Expand All @@ -49,10 +57,11 @@ public function onKernelRequest(): void
);

try {
$conn->executeUpdate($queryPublish, [':now' => $now]);
$conn->executeUpdate($queryDepublish, [':now' => $now]);
} catch (Throwable) {
// Fail silently, output user-friendly exception elsewhere.
$conn->executeStatement($queryPublish, ['now' => $now], ['now' => Types::DATETIME_MUTABLE]);
$conn->executeStatement($queryDepublish, ['now' => $now], ['now' => Types::DATETIME_MUTABLE]);
} catch (Throwable $exception) {
// Fail silently for the user, but log at debug level for diagnostics.
$this->logger->debug('Failed to publish/depublish timed content', ['exception' => $exception]);
}
}

Expand Down
Loading