Skip to content

Commit 16a99ed

Browse files
committed
[TASK] Move cms-install and cms-scheduler to suggest + require-dev
The wizard class and Task wrapper load lazily — when their respective TYPO3 packages aren't installed, nothing autoloads them. Guard the scheduler-task registration in ext_localconf.php with class_exists for explicit clarity.
1 parent 0c23edc commit 16a99ed

6 files changed

Lines changed: 56 additions & 19 deletions

File tree

Classes/Command/ProcessWebpQueueCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Plan2net\Webp\Service\FolderScanner;
1212
use Plan2net\Webp\Service\ProcessedFileWriter;
1313
use Plan2net\Webp\Service\Webp as WebpService;
14-
use Plan2net\Webp\Task\ProcessWebpQueueTask;
1514
use Psr\Log\LoggerAwareInterface;
1615
use Psr\Log\LoggerAwareTrait;
1716
use Symfony\Component\Console\Attribute\AsCommand;
@@ -52,7 +51,10 @@ public function __construct(
5251

5352
protected function configure(): void
5453
{
55-
$this->addOption('batch', null, InputOption::VALUE_REQUIRED, 'Maximum number of queue entries to process per run', (string) ProcessWebpQueueTask::DEFAULT_BATCH_SIZE);
54+
// Inline default mirrors ProcessWebpQueueTask::DEFAULT_BATCH_SIZE.
55+
// Not a class-constant reference because the command must work even when
56+
// typo3/cms-scheduler is absent (the Task class extends AbstractTask).
57+
$this->addOption('batch', null, InputOption::VALUE_REQUIRED, 'Maximum number of queue entries to process per run', '50');
5658
$this->addOption('folder', null, InputOption::VALUE_REQUIRED, 'Filesystem folder to sweep (relative to public web root). When set, bypasses the queue.');
5759
}
5860

Classes/Updates/TruncateFailedAttemptsBeforeColumnResizeUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Plan2net\Webp\Updates;
66

7+
use TYPO3\CMS\Core\Attribute\UpgradeWizard;
78
use TYPO3\CMS\Core\Database\ConnectionPool;
89
use TYPO3\CMS\Core\Utility\GeneralUtility;
9-
use TYPO3\CMS\Install\Attribute\UpgradeWizard;
1010
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
1111

1212
#[UpgradeWizard('webp.truncateFailedAttemptsBeforeColumnResize')]

Configuration/Services.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Plan2net\Webp;
6+
7+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
9+
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
10+
11+
return static function (ContainerConfigurator $configurator): void {
12+
$services = $configurator->services();
13+
14+
// Service classes that extend or implement types from TYPO3 packages we
15+
// treat as soft dependencies. Register only when the respective package
16+
// is installed; otherwise loading the file would fatal at the
17+
// extends/implements clause.
18+
19+
if (\interface_exists(UpgradeWizardInterface::class)) {
20+
$services
21+
->set(Updates\TruncateFailedAttemptsBeforeColumnResizeUpdate::class)
22+
->autowire()
23+
->tag('install.upgradewizard', ['identifier' => 'webp.truncateFailedAttemptsBeforeColumnResize']);
24+
}
25+
26+
if (\class_exists(AbstractAdditionalFieldProvider::class)) {
27+
$services
28+
->set(Task\ProcessWebpQueueTaskAdditionalFieldProvider::class)
29+
->autowire()
30+
->public();
31+
}
32+
};

Configuration/Services.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ services:
5454
tags:
5555
- name: 'console.command'
5656

57-
Plan2net\Webp\Task\ProcessWebpQueueTaskAdditionalFieldProvider:
58-
public: true
59-
60-
Plan2net\Webp\Updates\TruncateFailedAttemptsBeforeColumnResizeUpdate: ~
61-
6257
# public: true required so GeneralUtility::makeInstance(Configuration::class) resolves
6358
# the service from the container (called from FileNameFilter::filterWebpFiles and from
6459
# ext_localconf.php — neither has a DI constructor injection point).

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
"require": {
3131
"php": ">=8.2",
3232
"symfony/finder": "^6.4 || ^7.0",
33-
"typo3/cms-core": "^12.4 || ^13.4 || ^14.0",
34-
"typo3/cms-install": "^12.4 || ^13.4 || ^14.0",
35-
"typo3/cms-scheduler": "^12.4 || ^13.4 || ^14.0"
33+
"typo3/cms-core": "^12.4 || ^13.4 || ^14.0"
3634
},
3735
"suggest": {
38-
"ext-gd": "Use GD for image processing"
36+
"ext-gd": "Use GD for image processing",
37+
"typo3/cms-install": "Required only if you run the UpgradeWizard that clears legacy tx_webp_failed rows during a configuration_hash column resize",
38+
"typo3/cms-scheduler": "Required only when async = 1; provides the scheduler task that drains tx_webp_queue out-of-band"
3939
},
4040
"autoload": {
4141
"psr-4": {
@@ -60,6 +60,8 @@
6060
},
6161
"require-dev": {
6262
"phpunit/phpunit": "^10.5 || ^11",
63+
"typo3/cms-install": "^12.4 || ^13.4 || ^14.0",
64+
"typo3/cms-scheduler": "^12.4 || ^13.4 || ^14.0",
6365
"typo3/testing-framework": "^8.0 || ^9.0",
6466
"friendsofphp/php-cs-fixer": "^3.75"
6567
}

ext_localconf.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
];
1414
}
1515

16-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][Plan2net\Webp\Task\ProcessWebpQueueTask::class] = [
17-
'extension' => 'webp',
18-
'title' => 'LLL:EXT:webp/Resources/Private/Language/locallang.xlf:task.processQueue.title',
19-
'description' => 'LLL:EXT:webp/Resources/Private/Language/locallang.xlf:task.processQueue.description',
20-
'icon' => 'mimetypes-x-tx_scheduler_task_group',
21-
'additionalFields' => Plan2net\Webp\Task\ProcessWebpQueueTaskAdditionalFieldProvider::class,
22-
];
16+
// Register the scheduler task only when cms-scheduler is installed.
17+
// Both cms-scheduler and cms-install are soft dependencies of this extension;
18+
// the task wrapper class and the upgrade wizard load lazily so missing
19+
// packages don't fatal at boot.
20+
if (\class_exists(TYPO3\CMS\Scheduler\Task\AbstractTask::class)) {
21+
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][Plan2net\Webp\Task\ProcessWebpQueueTask::class] = [
22+
'extension' => 'webp',
23+
'title' => 'LLL:EXT:webp/Resources/Private/Language/locallang.xlf:task.processQueue.title',
24+
'description' => 'LLL:EXT:webp/Resources/Private/Language/locallang.xlf:task.processQueue.description',
25+
'icon' => 'mimetypes-x-tx_scheduler_task_group',
26+
'additionalFields' => Plan2net\Webp\Task\ProcessWebpQueueTaskAdditionalFieldProvider::class,
27+
];
28+
}
2329
})();

0 commit comments

Comments
 (0)