Skip to content

Commit c71730b

Browse files
hannesbochmannRiiiad
authored andcommitted
[TASK] add TYPO3 12 compatibility
1 parent 647970f commit c71730b

File tree

9 files changed

+72
-39
lines changed

9 files changed

+72
-39
lines changed

Classes/Controller/CleanupController.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
use TYPO3\CMS\Backend\Utility\BackendUtility;
1111
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
1212
use TYPO3\CMS\Core\Imaging\Icon;
13+
use TYPO3\CMS\Core\Imaging\IconFactory;
14+
use TYPO3\CMS\Core\Information\Typo3Version;
1315
use TYPO3\CMS\Core\Localization\LanguageService;
1416
use TYPO3\CMS\Core\Messaging\FlashMessage;
17+
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
1518
use TYPO3\CMS\Core\Page\PageRenderer;
1619
use TYPO3\CMS\Core\Resource\Exception;
1720
use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException;
@@ -22,7 +25,7 @@
2225
use TYPO3\CMS\Core\Resource\ResourceStorage;
2326
use TYPO3\CMS\Core\Utility\GeneralUtility;
2427
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
25-
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
28+
use TYPO3Fluid\Fluid\View\ViewInterface;
2629
use WebVision\WvFileCleanup\Domain\Repository\FileRepository;
2730

2831
/**
@@ -42,14 +45,18 @@ class CleanupController extends ActionController
4245

4346
protected FileRepository $fileRepository;
4447

48+
protected IconFactory $iconFactory;
49+
4550
public function __construct(
4651
FileRepository $fileRepository,
4752
PageRenderer $pageRenderer,
48-
ModuleTemplateFactory $moduleTemplateFactory
53+
ModuleTemplateFactory $moduleTemplateFactory,
54+
IconFactory $iconFactory
4955
) {
5056
$this->fileRepository = $fileRepository;
5157
$this->pageRenderer = $pageRenderer;
5258
$this->moduleTemplateFactory = $moduleTemplateFactory;
59+
$this->iconFactory = $iconFactory;
5360
}
5461

5562
public function initializeAction(): void
@@ -219,7 +226,6 @@ protected function initializeIndexAction(): void
219226
protected function registerDocHeaderButtons(): void
220227
{
221228
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
222-
$iconFactory = $this->moduleTemplate->getIconFactory();
223229

224230
// Refresh page
225231
$refreshLink = GeneralUtility::linkThisScript(
@@ -234,7 +240,7 @@ protected function registerDocHeaderButtons(): void
234240
$refreshButton = $buttonBar->makeLinkButton($buttonFactory)
235241
->setHref($refreshLink)
236242
->setTitle($buttonTitle)
237-
->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
243+
->setIcon($this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
238244

239245
$buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
240246

@@ -250,10 +256,6 @@ protected function registerDocHeaderButtons(): void
250256
if (!$levelUpTitle) {
251257
$levelUpTitle = 'Up one level';
252258
}
253-
$levelUpClick = 'top.document.getElementsByName("navigation")[0].';
254-
$levelUpClick .= 'contentWindow.Tree.highlightActiveItem("file","folder';
255-
$levelUpClick .= GeneralUtility::md5int($parentFolder->getCombinedIdentifier());
256-
$levelUpClick .= '_"+top.fsMod.currentBank)';
257259
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
258260
$levelUpButton = $buttonBar->makeLinkButton($buttonFactory)
259261
->setHref(
@@ -262,9 +264,15 @@ protected function registerDocHeaderButtons(): void
262264
['id' => $parentFolder->getCombinedIdentifier()]
263265
)
264266
)
265-
->setOnClick($levelUpClick)
266267
->setTitle($levelUpTitle)
267-
->setIcon($iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL));
268+
->setIcon($this->iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL));
269+
if ((new Typo3Version())->getMajorVersion() < 12) {
270+
$levelUpClick = 'top.document.getElementsByName("navigation")[0].';
271+
$levelUpClick .= 'contentWindow.Tree.highlightActiveItem("file","folder';
272+
$levelUpClick .= GeneralUtility::md5int($parentFolder->getCombinedIdentifier());
273+
$levelUpClick .= '_"+top.fsMod.currentBank)';
274+
$levelUpButton->setOnClick($levelUpClick);
275+
}
268276
$buttonBar->addButton($levelUpButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
269277
}
270278
} catch (\Exception $e) {
@@ -273,7 +281,9 @@ protected function registerDocHeaderButtons(): void
273281

274282
// Shortcut
275283
if ($this->getBackendUser()->mayMakeShortcut()) {
276-
$shortCutButton = $buttonBar->makeShortcutButton()->setModuleName('file_WvFileCleanupCleanup');
284+
$shortCutButton = $buttonBar->makeShortcutButton()
285+
->setRouteIdentifier('file_WvFileCleanupCleanup')
286+
->setDisplayName('File cleanup');
277287
$buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
278288
}
279289
}
@@ -283,7 +293,7 @@ protected function registerDocHeaderButtons(): void
283293
*/
284294
public function indexAction(): ResponseInterface
285295
{
286-
$this->view->assign('files', $this->fileRepository->findUnusedFile($this->folder, $this->moduleSettings['recursive']));
296+
$this->view->assign('files', $this->fileRepository->findUnusedFile($this->folder, $this->moduleSettings['recursive'] ?? false));
287297
$this->view->assign('folder', $this->folder);
288298
$backendUserTsconfig = $this->getBackendUserTsconfig();
289299
$this->view->assign('checkboxes', [
@@ -307,12 +317,12 @@ public function indexAction(): ResponseInterface
307317
'html' => BackendUtility::getFuncCheck(
308318
$this->folder ? $this->folder->getCombinedIdentifier() : '',
309319
'SET[recursive]',
310-
$this->moduleSettings['recursive'],
320+
$this->moduleSettings['recursive'] ?? false,
311321
'',
312322
'',
313323
'id="checkRecursive"'
314324
),
315-
'checked' => $this->moduleSettings['recursive'],
325+
'checked' => $this->moduleSettings['recursive'] ?? false,
316326
],
317327
]);
318328

@@ -328,7 +338,7 @@ public function indexAction(): ResponseInterface
328338
* @throws InsufficientFolderAccessPermissionsException
329339
* @throws \TYPO3\CMS\Core\Exception
330340
*/
331-
public function cleanupAction(array $files): void
341+
public function cleanupAction(array $files): ResponseInterface
332342
{
333343
/** @var $resourceFactory ResourceFactory **/
334344
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
@@ -371,7 +381,7 @@ public function cleanupAction(array $files): void
371381
);
372382
}
373383

374-
$this->redirect('index');
384+
return $this->redirect('index');
375385
}
376386

377387
/**
@@ -405,7 +415,7 @@ public function addFlashMessage(
405415
$severity,
406416
$storeInSession
407417
);
408-
$this->controllerContext->getFlashMessageQueue('core.template.flashMessages')->enqueue($flashMessage);
418+
GeneralUtility::makeInstance(FlashMessageQueue::class, 'core.template.flashMessages')->enqueue($flashMessage);
409419
}
410420

411421
protected function getLanguageService(): LanguageService

Classes/Domain/Repository/FileRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function getReferenceCount(File $file): int
181181
)
182182
)
183183
->execute();
184-
$refIndexCount = (int)$res1->fetchColumn(0);
184+
$refIndexCount = (int)$res1->fetchOne();
185185

186186
// sys_file_reference
187187
$queryBuilder2 = $this->connection->getQueryBuilderForTable('sys_file_reference');
@@ -199,7 +199,7 @@ public function getReferenceCount(File $file): int
199199
),
200200
)
201201
->execute();
202-
$fileReferenceCount = (int)$res2->fetchColumn(0);
202+
$fileReferenceCount = (int)$res2->fetchOne();
203203

204204
return max($refIndexCount, $fileReferenceCount);
205205
}

Classes/FileFacade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public function getLastReferenceTimestamp()
255255

256256
if (!isset(self::$lastReferenceTimestamps[$uid])) {
257257
self::$lastReferenceTimestamps[$uid] = 0;
258+
$row = null;
258259

259260
if ($this->queryBuilder) {
260261
$queryBuilder = $this->queryBuilder->getQueryBuilderForTable('sys_file_reference');

Configuration/Backend/Modules.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
return [
4+
'file_WvFileCleanupCleanup' => [
5+
'parent' => 'file',
6+
'access' => 'user,group',
7+
'workspaces' => 'online,custom',
8+
'path' => '/file/wvfilecleanup',
9+
'icon' => 'EXT:wv_file_cleanup/Resources/Public/Icons/module-cleanup.svg',
10+
'labels' => 'LLL:EXT:wv_file_cleanup/Resources/Private/Language/locallang_mod_cleanup.xlf',
11+
'extensionName' => 'wv_file_cleanup',
12+
'controllerActions' => [
13+
\WebVision\WvFileCleanup\Controller\CleanupController::class => ['index', 'cleanup'],
14+
],
15+
],
16+
];

Configuration/Services.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ services:
2424
- name: event.listener
2525
method: 'postFileMove'
2626
event: TYPO3\CMS\Core\Resource\Event\AfterFileMovedEvent
27+
28+
WebVision\WvFileCleanup\Controller\CleanupController:
29+
tags: [ 'backend.controller' ]
30+

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"license": ["GPL-3.0+"],
77
"require": {
88
"php": ">=7.4 || >= 8.0",
9-
"typo3/cms-core": "^11.5"
9+
"typo3/cms-core": "^11.5 || ^12.4"
1010
},
1111
"require-dev": {
12-
"typo3/testing-framework": "^6.16",
12+
"typo3/testing-framework": "^6.16 || ^7.0",
1313
"saschaegerer/phpstan-typo3": "^1.8",
1414
"phpstan/phpstan": "^1.10",
1515
"friendsofphp/php-cs-fixer": "^v3.0"

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'author_company' => 'beech.it, web-vision GmbH',
1212
'constraints' => [
1313
'depends' => [
14-
'typo3' => '10.4.1-11.5.99',
14+
'typo3' => '11.5.1-12.4.99',
1515
],
1616
],
1717
];

ext_localconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
defined('TYPO3_MODE') || die();
3+
defined('TYPO3') || die();

ext_tables.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<?php
22

3-
defined('TYPO3_MODE') || die();
3+
defined('TYPO3') || die();
44

5-
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
6-
'WebVision.WvFileCleanup',
7-
'file',
8-
'cleanup',
9-
'',
10-
[
11-
\WebVision\WvFileCleanup\Controller\CleanupController::class => 'index, cleanup',
12-
],
13-
[
14-
'access' => 'user,group',
15-
'workspaces' => 'online,custom',
16-
'icon' => 'EXT:wv_file_cleanup/Resources/Public/Icons/module-cleanup.svg',
17-
'labels' => 'LLL:EXT:wv_file_cleanup/Resources/Private/Language/locallang_mod_cleanup.xlf',
18-
]
19-
);
5+
if ((new \TYPO3\CMS\Core\Information\Typo3Version())->getMajorVersion() < 12) {
6+
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
7+
'WebVision.WvFileCleanup',
8+
'file',
9+
'cleanup',
10+
'',
11+
[
12+
\WebVision\WvFileCleanup\Controller\CleanupController::class => 'index, cleanup',
13+
],
14+
[
15+
'access' => 'user,group',
16+
'workspaces' => 'online,custom',
17+
'icon' => 'EXT:wv_file_cleanup/Resources/Public/Icons/module-cleanup.svg',
18+
'labels' => 'LLL:EXT:wv_file_cleanup/Resources/Private/Language/locallang_mod_cleanup.xlf',
19+
]
20+
);
21+
}

0 commit comments

Comments
 (0)