Skip to content

Commit

Permalink
Merge branch '4.x' into feature/canonical
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Nov 4, 2021
2 parents 9122bea + e01d0e6 commit e6f6fbd
Show file tree
Hide file tree
Showing 115 changed files with 1,672 additions and 978 deletions.
11 changes: 7 additions & 4 deletions calendar-bundle/src/Resources/contao/classes/Events.php
Expand Up @@ -11,6 +11,7 @@
namespace Contao;

use Contao\CoreBundle\Security\ContaoCorePermissions;
use Contao\CoreBundle\String\HtmlDecoder;

/**
* Provide methods to get all events of a certain period from the database.
Expand Down Expand Up @@ -353,7 +354,7 @@ protected function addEvent($objEvents, $intStart, $intEnd, $intBegin, $intLimit
};
}

// Get todays start and end timestamp
// Get today's start and end timestamp
if ($this->intTodayBegin === null)
{
$this->intTodayBegin = strtotime('00:00:00');
Expand Down Expand Up @@ -490,10 +491,12 @@ public static function generateEventUrl($objEvent, $blnAbsolute=false)
*/
public static function getSchemaOrgData(CalendarEventsModel $objEvent): array
{
$htmlDecoder = System::getContainer()->get(HtmlDecoder::class);

$jsonLd = array(
'@type' => 'Event',
'identifier' => '#/schema/events/' . $objEvent->id,
'name' => StringUtil::inputEncodedToPlainText($objEvent->title),
'name' => $htmlDecoder->inputEncodedToPlainText($objEvent->title),
'url' => self::generateEventUrl($objEvent),
'startDate' => $objEvent->addTime ? date('Y-m-d\TH:i:sP', $objEvent->startTime) : date('Y-m-d', $objEvent->startTime)
);
Expand All @@ -507,14 +510,14 @@ public static function getSchemaOrgData(CalendarEventsModel $objEvent): array
{
$jsonLd['location'] = array(
'@type' => 'Place',
'name' => StringUtil::inputEncodedToPlainText($objEvent->location)
'name' => $htmlDecoder->inputEncodedToPlainText($objEvent->location)
);

if ($objEvent->address)
{
$jsonLd['location']['address'] = array(
'@type' => 'PostalAddress',
'description' => StringUtil::inputEncodedToPlainText($objEvent->address)
'description' => $htmlDecoder->inputEncodedToPlainText($objEvent->address)
);
}
}
Expand Down
Expand Up @@ -16,6 +16,7 @@
use Contao\CoreBundle\Image\Studio\Studio;
use Contao\CoreBundle\Routing\ResponseContext\HtmlHeadBag\HtmlHeadBag;
use Contao\CoreBundle\Routing\ResponseContext\ResponseContextAccessor;
use Contao\CoreBundle\String\HtmlDecoder;

/**
* Front end module "event reader".
Expand Down Expand Up @@ -135,23 +136,24 @@ protected function compile()
{
/** @var HtmlHeadBag $htmlHeadBag */
$htmlHeadBag = $responseContext->get(HtmlHeadBag::class);
$htmlDecoder = System::getContainer()->get(HtmlDecoder::class);

if ($objEvent->pageTitle)
{
$htmlHeadBag->setTitle($objEvent->pageTitle); // Already stored decoded
}
elseif ($objEvent->title)
{
$htmlHeadBag->setTitle(StringUtil::inputEncodedToPlainText($objEvent->title));
$htmlHeadBag->setTitle($htmlDecoder->inputEncodedToPlainText($objEvent->title));
}

if ($objEvent->description)
{
$htmlHeadBag->setMetaDescription(StringUtil::inputEncodedToPlainText($objEvent->description));
$htmlHeadBag->setMetaDescription($htmlDecoder->inputEncodedToPlainText($objEvent->description));
}
elseif ($objEvent->teaser)
{
$htmlHeadBag->setMetaDescription(StringUtil::htmlToPlainText($objEvent->teaser));
$htmlHeadBag->setMetaDescription($htmlDecoder->htmlToPlainText($objEvent->teaser));
}

if ($objEvent->robots)
Expand Down
4 changes: 1 addition & 3 deletions calendar-bundle/tests/Picker/EventPickerProviderTest.php
Expand Up @@ -244,9 +244,7 @@ static function (string $name, array $data) use ($menuFactory): ItemInterface {
$router = $this->createMock(RouterInterface::class);
$router
->method('generate')
->willReturnCallback(
static fn (string $name, array $params): string => $name.'?'.http_build_query($params)
)
->willReturnCallback(static fn (string $name, array $params): string => $name.'?'.http_build_query($params))
;

$translator = $this->createMock(TranslatorInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion comments-bundle/src/Resources/contao/classes/Comments.php
Expand Up @@ -661,7 +661,7 @@ public static function notifyCommentsSubscribers(CommentsModel $objComment)

while ($objNotify->next())
{
// Don't notify the commentor about his own comment
// Don't notify the commenter about his own comment
if ($objNotify->email == $objComment->email)
{
continue;
Expand Down
12 changes: 5 additions & 7 deletions core-bundle/src/Asset/ContaoContext.php
Expand Up @@ -37,14 +37,12 @@ public function __construct(RequestStack $requestStack, ContaoFramework $framewo

public function getBasePath(): string
{
if ($this->debug) {
if (null === ($request = $this->requestStack->getMainRequest())) {
return '';
}

$request = $this->requestStack->getCurrentRequest();

if (null === $request || '' === ($staticUrl = $this->getFieldValue($this->getPageModel()))) {
return '';
if ($this->debug || '' === ($staticUrl = $this->getFieldValue($this->getPageModel()))) {
return $request->getBasePath();
}

$protocol = $this->isSecure() ? 'https' : 'http';
Expand All @@ -61,7 +59,7 @@ public function isSecure(): bool
return (bool) $page->loadDetails()->rootUseSSL;
}

$request = $this->requestStack->getCurrentRequest();
$request = $this->requestStack->getMainRequest();

if (null === $request) {
return false;
Expand All @@ -84,7 +82,7 @@ public function getStaticUrl(): string

private function getPageModel(): ?PageModel
{
$request = $this->requestStack->getCurrentRequest();
$request = $this->requestStack->getMainRequest();

if (null === $request || !$request->attributes->has('pageModel')) {
if (isset($GLOBALS['objPage']) && $GLOBALS['objPage'] instanceof PageModel) {
Expand Down
8 changes: 4 additions & 4 deletions core-bundle/src/Command/DebugPagesCommand.php
Expand Up @@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);

$rows = [];
$types = array_keys($GLOBALS['TL_PTY']);
$types = array_unique(array_merge(array_keys($GLOBALS['TL_PTY']), $this->pageRegistry->keys()));
natsort($types);

foreach ($types as $type) {
Expand All @@ -79,8 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$rows[] = [
$type,
$config ? $config->getPath() : '*',
$config ? $config->getUrlSuffix() : '*',
$config && $config->getPath() ? $config->getPath() : '*',
$config && $config->getUrlSuffix() ? $config->getUrlSuffix() : '*',
$this->pageRegistry->supportsContentComposition($page) ? 'yes' : 'no',
isset($this->routeEnhancers[$type]) ? \get_class($this->routeEnhancers[$type]) : '-',
$config ? $this->generateArray($config->getRequirements()) : '-',
Expand Down Expand Up @@ -117,6 +117,6 @@ static function ($carry, $item): int {
$return[] = sprintf('%s : %s', str_pad($k, $length, ' ', STR_PAD_RIGHT), (string) $v);
}

return implode("\n", $return);
return !empty($return) ? implode("\n", $return) : '-';
}
}
2 changes: 1 addition & 1 deletion core-bundle/src/Command/MigrateCommand.php
Expand Up @@ -121,7 +121,7 @@ private function executeCommand(InputInterface $input): int
return 1;
}

if (!$dryRun && !$this->executeMigrations($dryRun, $asJson)) {
if (!$dryRun && !$this->executeMigrations(false, $asJson)) {
return 1;
}

Expand Down
15 changes: 15 additions & 0 deletions core-bundle/src/Controller/AbstractFragmentController.php
Expand Up @@ -12,6 +12,7 @@

namespace Contao\CoreBundle\Controller;

use Contao\CoreBundle\EventListener\SubrequestCacheSubscriber;
use Contao\CoreBundle\Fragment\FragmentOptionsAwareInterface;
use Contao\CoreBundle\Routing\ScopeMatcher;
use Contao\FrontendTemplate;
Expand All @@ -21,6 +22,7 @@
use Contao\Template;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;

abstract class AbstractFragmentController extends AbstractController implements FragmentOptionsAwareInterface
{
Expand Down Expand Up @@ -151,4 +153,17 @@ protected function getType(): string

return Container::underscore($className);
}

protected function render(string $view, array $parameters = [], Response $response = null): Response
{
if (null === $response) {
$response = new Response();

// Mark this response to affect the caching of the current page but remove any default cache headers
$response->headers->set(SubrequestCacheSubscriber::MERGE_CACHE_HEADER, '1');
$response->headers->remove('Cache-Control');
}

return parent::render($view, $parameters, $response);
}
}
31 changes: 31 additions & 0 deletions core-bundle/src/Controller/ContentElement/TemplateController.php
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

namespace Contao\CoreBundle\Controller\ContentElement;

use Contao\ContentModel;
use Contao\StringUtil;
use Contao\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class TemplateController extends AbstractContentElementController
{
protected function getResponse(Template $template, ContentModel $model, Request $request): ?Response
{
$this->initializeContaoFramework();

$template->data = StringUtil::deserialize($model->data, true);

return $template->getResponse();
}
}
31 changes: 31 additions & 0 deletions core-bundle/src/Controller/FrontendModule/TemplateController.php
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

namespace Contao\CoreBundle\Controller\FrontendModule;

use Contao\ModuleModel;
use Contao\StringUtil;
use Contao\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class TemplateController extends AbstractFrontendModuleController
{
protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response
{
$this->initializeContaoFramework();

$template->data = StringUtil::deserialize($model->data, true);

return $template->getResponse();
}
}
6 changes: 1 addition & 5 deletions core-bundle/src/Crawl/Escargot/Factory.php
Expand Up @@ -93,11 +93,7 @@ public function createLazyQueue(): LazyQueue
{
return new LazyQueue(
new InMemoryQueue(),
new DoctrineQueue(
$this->connection,
static fn (): string => Uuid::uuid4()->toString(),
'tl_crawl_queue'
)
new DoctrineQueue($this->connection, static fn (): string => Uuid::uuid4()->toString(), 'tl_crawl_queue')
);
}

Expand Down
53 changes: 53 additions & 0 deletions core-bundle/src/Doctrine/ORM/FailTolerantProxyCacheWarmer.php
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

namespace Contao\CoreBundle\Doctrine\ORM;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception as DoctrineDbalException;
use Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer;

class FailTolerantProxyCacheWarmer extends ProxyCacheWarmer
{
private ProxyCacheWarmer $inner;
private Connection $connection;

public function __construct(ProxyCacheWarmer $inner, Connection $connection)
{
$this->inner = $inner;
$this->connection = $connection;
}

public function isOptional(): bool
{
return (bool) $this->inner->isOptional();
}

/**
* @return array<string>
*/
public function warmUp(string $cacheDir): array
{
// If there are no DB credentials yet (install tool) and the
// server_version was not configured, we have to skip the ORM warmup to
// prevent a DBAL exception during the automatic version detection
try {
$this->connection->getDatabasePlatform();
} catch (DoctrineDbalException | \mysqli_sql_exception $e) {
return [];
}

$this->inner->warmUp($cacheDir);

return [];
}
}
17 changes: 12 additions & 5 deletions core-bundle/src/EventListener/CommandSchedulerListener.php
Expand Up @@ -17,24 +17,26 @@
use Contao\CoreBundle\Framework\ContaoFramework;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Contracts\Service\ServiceSubscriberInterface;

/**
* @internal
*/
class CommandSchedulerListener
class CommandSchedulerListener implements ServiceSubscriberInterface
{
private ContainerInterface $locator;
private ContaoFramework $framework;
private Connection $connection;
private string $fragmentPath;
private Cron $cron;

public function __construct(ContaoFramework $framework, Connection $connection, Cron $cron, string $fragmentPath = '_fragment')
public function __construct(ContainerInterface $locator, ContaoFramework $framework, Connection $connection, string $fragmentPath = '_fragment')
{
$this->locator = $locator;
$this->framework = $framework;
$this->connection = $connection;
$this->cron = $cron;
$this->fragmentPath = $fragmentPath;
}

Expand All @@ -44,10 +46,15 @@ public function __construct(ContaoFramework $framework, Connection $connection,
public function __invoke(TerminateEvent $event): void
{
if ($this->framework->isInitialized() && $this->canRunCron($event->getRequest())) {
$this->cron->run(Cron::SCOPE_WEB);
$this->locator->get(Cron::class)->run(Cron::SCOPE_WEB);
}
}

public static function getSubscribedServices(): array
{
return [Cron::class];
}

private function canRunCron(Request $request): bool
{
$pathInfo = $request->getPathInfo();
Expand Down

0 comments on commit e6f6fbd

Please sign in to comment.