Skip to content

Commit 61431b3

Browse files
committed
unlock Contao 5
1 parent 7d62547 commit 61431b3

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

.php-cs-fixer.dist.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
'escape_implicit_backslashes' => true,
3333
'fully_qualified_strict_types' => true,
3434
'general_phpdoc_annotation_remove' => [
35-
'author',
36-
'expectedException',
37-
'expectedExceptionMessage',
35+
'annotations' => [
36+
'author',
37+
'expectedException',
38+
'expectedExceptionMessage',
39+
],
3840
],
3941
'header_comment' => ['header' => $header],
4042
'heredoc_to_nowdoc' => true,

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
],
2828
"require": {
2929
"php": "^7.1 || ^8.0",
30-
"contao/core-bundle": "^4.9",
31-
"symfony/config": "^4.4 || ^5.2",
32-
"symfony/dependency-injection": "^4.4 || ^5.2",
33-
"symfony/http-foundation": "^4.4 || ^5.2",
34-
"symfony/http-kernel": "^4.4 || ^5.2",
30+
"contao/core-bundle": "^4.9 || ^5.0",
31+
"symfony/config": "^4.4 || ^5.2 || ^6.0",
32+
"symfony/dependency-injection": "^4.4 || ^5.2 || ^6.0",
33+
"symfony/http-foundation": "^4.4 || ^5.2 || ^6.0",
34+
"symfony/http-kernel": "^4.4 || ^5.2 || ^6.0",
3535
"webmozart/path-util": "^2.3"
3636
},
3737
"autoload": {

src/Controller/FilesController.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Contao\CoreBundle\Exception\InsufficientAuthenticationException;
1818
use Contao\CoreBundle\Exception\PageNotFoundException;
1919
use Contao\CoreBundle\Framework\ContaoFramework;
20+
use Contao\CoreBundle\Security\Authentication\Token\TokenChecker;
21+
use Contao\Date;
2022
use Contao\Dbafs;
2123
use Contao\FilesModel;
2224
use Contao\FrontendUser;
@@ -35,14 +37,16 @@ class FilesController
3537
protected $framework;
3638
protected $security;
3739
protected $db;
40+
protected $tokenChecker;
3841

39-
public function __construct(string $rootDir, Session $session, ContaoFramework $framework, Security $security, Connection $db)
42+
public function __construct(string $rootDir, Session $session, ContaoFramework $framework, Security $security, Connection $db, TokenChecker $tokenChecker)
4043
{
4144
$this->rootDir = $rootDir;
4245
$this->session = $session;
4346
$this->framework = $framework;
4447
$this->security = $security;
4548
$this->db = $db;
49+
$this->tokenChecker = $tokenChecker;
4650
}
4751

4852
public function fileAction(Request $request, string $file): BinaryFileResponse
@@ -56,9 +60,9 @@ public function fileAction(Request $request, string $file): BinaryFileResponse
5660

5761
// Initialize the Contao framework
5862
$this->framework->initialize(true);
59-
63+
FilesModel::findById(null);
6064
// Set the root page for the domain as the pageModel attribute
61-
$root = PageModel::findFirstPublishedRootByHostAndLanguage($request->getHost(), $request->getLocale());
65+
$root = $this->findFirstPublishedRootByHostAndLanguage($request->getHost(), $request->getLocale());
6266

6367
if (null !== $root) {
6468
$request->attributes->set('pageModel', $root);
@@ -117,7 +121,7 @@ public function fileAction(Request $request, string $file): BinaryFileResponse
117121
}
118122

119123
// Get the parent folder
120-
$filesModel = FilesModel::findById($filesModel->pid);
124+
$filesModel = $filesModel->pid ? FilesModel::findById($filesModel->pid) : null;
121125
} while (null !== $filesModel);
122126

123127
// Throw 404 exception, if there were no user homes or folders with member groups
@@ -145,4 +149,18 @@ public function fileAction(Request $request, string $file): BinaryFileResponse
145149
// Return file to browser
146150
return new BinaryFileResponse(Path::join($this->rootDir, $file));
147151
}
152+
153+
protected function findFirstPublishedRootByHostAndLanguage(string $host, string $language): ?PageModel
154+
{
155+
$columns = ["type='root' AND (dns=? OR dns='') AND (language=? OR fallback='1')"];
156+
$values = [$host, $language];
157+
$options = ['order' => 'dns DESC, fallback'];
158+
159+
if (!$this->tokenChecker->isPreviewMode()) {
160+
$time = Date::floorToMinute();
161+
$columns[] = "published='1' AND (start='' OR start<='$time') AND (stop='' OR stop>'$time')";
162+
}
163+
164+
return PageModel::findOneBy($columns, $values, $options);
165+
}
148166
}

src/DataContainer/FilesCallbacks.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ class FilesCallbacks
2525
*/
2626
public function onLoadCallback(DataContainer $dc): void
2727
{
28+
if (!$dc->id) {
29+
return;
30+
}
31+
2832
if ('editAll' === Input::get('act') || (null !== ($filesModel = FilesModel::findOneByPath($dc->id)) && 'folder' === $filesModel->type)) {
2933
PaletteManipulator::create()
30-
->addField('groups', null)
34+
// We have to use a non-existent legend here (see https://github.com/contao/contao/pull/5032)
35+
->addField('groups', 'foobar')
3136
->applyToPalette('default', 'tl_files')
3237
;
3338
}

src/Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
- '@contao.framework'
77
- '@security.helper'
88
- '@database_connection'
9+
- '@contao.security.token_checker'
910
tags: ['controller.service_arguments']
1011

1112
InspiredMinds\ContaoFileAccessBundle\DataContainer\FilesCallbacks:

0 commit comments

Comments
 (0)