Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8470: Upgraded codebase to Symfony 6 #19

Merged
merged 8 commits into from
Feb 4, 2025
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/vendor/
.php_cs.cache
.php-cs-fixer.cache
/composer.lock
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"php": " >=8.3",
"cron/cron": "^1.4",
"ibexa/core": "~5.0.x-dev",
"symfony/config": "^5.0",
"symfony/console": "^5.0",
"symfony/dependency-injection": "^5.0",
"symfony/http-kernel": "^5.0",
"symfony/process": "^5.0"
"symfony/config": "^6.4",
"symfony/console": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/process": "^6.4"
},
"require-dev": {
"ibexa/code-style": "~2.0.0",
Expand Down
13 changes: 4 additions & 9 deletions src/bundle/Command/CronRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

final class CronRunCommand extends Command
{
/** @var \Ibexa\Bundle\Cron\Registry\CronJobsRegistry */
private $cronJobsRegistry;
private CronJobsRegistry $cronJobsRegistry;

/** @var \Psr\Log\LoggerInterface */
private $logger;
private LoggerInterface $logger;

public function __construct(LoggerInterface $logger, CronJobsRegistry $cronJobsRegistry, ?string $name = null)
{
Expand All @@ -42,7 +40,6 @@ protected function configure(): void
new InputOption('category', null, InputOption::VALUE_REQUIRED, 'Job category to run', 'default'),
])
->setName('ibexa:cron:run')
->setAliases(['ezplatform:cron:run'])
->setDescription('Perform one-time cron tasks run.')
->setHelp(
<<<EOT
Expand Down Expand Up @@ -70,10 +67,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
usleep(10000);
}

if ($this->logger) {
/** @var \Cron\Report\CronReport $reports */
$this->logReportsOutput($reports);
}
/** @var \Cron\Report\CronReport $reports */
$this->logReportsOutput($reports);

return Command::SUCCESS;
}
Expand Down
13 changes: 3 additions & 10 deletions src/bundle/DependencyInjection/Compiler/CronJobCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

class CronJobCompilerPass implements CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if (!$container->has(CronJobsRegistry::class)) {
return;
Expand All @@ -32,13 +27,11 @@ public function process(ContainerBuilder $container)
foreach ($tags as $cronJob) {
$reference = new Reference($id);

if (!isset($cronJob['schedule']) || empty($cronJob['schedule'])) {
if (empty($cronJob['schedule'])) {
throw new \RuntimeException(sprintf('Invalid %s cron job configuration, schedule argument missing', $id));
}

$cronJob['category'] = isset($cronJob['category'])
? $cronJob['category']
: CronJobsRegistry::DEFAULT_CATEGORY;
$cronJob['category'] = $cronJob['category'] ?? CronJobsRegistry::DEFAULT_CATEGORY;

$registry->addMethodCall('addCronJob', [
$reference,
Expand Down
8 changes: 3 additions & 5 deletions src/bundle/DependencyInjection/IbexaCronExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
class IbexaCronExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');
}

/**
* Allow an extension to prepend the extension configurations.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
$config = Yaml::parse(file_get_contents(__DIR__ . '/../Resources/config/monolog.yml'));
$container->prependExtensionConfig('monolog', $config);
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/IbexaCronBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class IbexaCronBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
54 changes: 24 additions & 30 deletions src/bundle/Registry/CronJobsRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,55 @@

use Cron\Job\ShellJob;
use Cron\Schedule\CrontabSchedule;
use Ibexa\Core\MVC\Symfony\SiteAccess;
use Ibexa\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Process\PhpExecutableFinder;

class CronJobsRegistry
{
public const DEFAULT_CATEGORY = 'default';
public const string DEFAULT_CATEGORY = 'default';

/**
* @var array
* @var array<string, \Cron\Job\ShellJob[]>
*/
protected $cronJobs = [];
protected array $cronJobs = [];

/**
* @var false|string
*/
protected $executable;
protected string $executable;

/**
* @var string
*/
protected $environment;
protected string $environment;

/**
* @var \Ibexa\Core\MVC\Symfony\SiteAccess
*/
protected $siteaccess;
protected SiteAccessServiceInterface $siteAccessService;

/**
* @var string
*/
protected $options;
protected string $options;

public function __construct(string $environment, SiteAccess $siteaccess)
public function __construct(string $environment, SiteAccessServiceInterface $siteAccessService)
{
$finder = new PhpExecutableFinder();

$this->executable = $finder->find();
$phpBinary = $finder->find();
if (false === $phpBinary) {
throw new \LogicException('CronJobsRegistry: Unable to find PHP binary');
}

$this->executable = $phpBinary;
$this->environment = $environment;
$this->siteaccess = $siteaccess;
$this->siteAccessService = $siteAccessService;
}

public function addCronJob(Command $command, string $schedule = null, string $category = self::DEFAULT_CATEGORY, string $options = ''): void
{
$commandName = $command->getName();
if (null === $commandName) {
throw new \LogicException('CronJobsRegistry: Unable to get a command name');
}

$command = sprintf(
'%s %s %s %s --siteaccess=%s --env=%s',
$this->executable,
$_SERVER['SCRIPT_NAME'],
$command->getName(),
$commandName,
$options,
$this->siteaccess->name,
$this->siteAccessService->getCurrent()->name,
$this->environment
);

Expand All @@ -75,10 +73,6 @@ public function addCronJob(Command $command, string $schedule = null, string $ca
*/
public function getCategoryCronJobs(string $category): array
{
if (!isset($this->cronJobs[$category])) {
return [];
}

return $this->cronJobs[$category];
return $this->cronJobs[$category] ?? [];
}
}
3 changes: 1 addition & 2 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ services:
Ibexa\Bundle\Cron\Registry\CronJobsRegistry:
lazy: true
arguments:
- '%kernel.environment%'
- '@Ibexa\Core\MVC\Symfony\SiteAccess'
$environment: '%kernel.environment%'

Ibexa\Bundle\Cron\Command\CronRunCommand:
arguments:
Expand Down
Empty file added src/contracts/.gitkeep
Empty file.
Empty file added src/lib/.gitkeep
Empty file.
Empty file added tests/bundle/.gitkeep
Empty file.
Empty file added tests/lib/.gitkeep
Empty file.
Loading