Skip to content

Commit

Permalink
Merge pull request #23 from oveleon/develop
Browse files Browse the repository at this point in the history
Skip cronjob if table does not exist
  • Loading branch information
doishub authored Dec 22, 2023
2 parents 50826cd + b2352f7 commit c3d52b1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Cron/PurgeRecommendationsCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,30 @@

use Contao\CoreBundle\DependencyInjection\Attribute\AsCronJob;
use Contao\CoreBundle\Framework\ContaoFramework;
use Doctrine\DBAL\Connection;
use Oveleon\ContaoRecommendationBundle\Model\RecommendationModel;
use Psr\Log\LoggerInterface;

#[AsCronJob('daily')]
class PurgeRecommendationsCron
{
public function __construct(private ContaoFramework $framework, private LoggerInterface|null $logger)
{
}
public function __construct(
private ContaoFramework $framework,
private Connection $connection,
private LoggerInterface|null $logger
){}

public function __invoke(): void
{
$this->framework->initialize();

$schemaManager = $this->connection->createSchemaManager();

if(!$schemaManager->tablesExist('tl_recommendation'))
{
return;
}

$recommendations = $this->framework->getAdapter(RecommendationModel::class)->findExpiredRecommendations();

if (null === $recommendations)
Expand Down

0 comments on commit c3d52b1

Please sign in to comment.