Skip to content

Commit

Permalink
Merge pull request #52 from alexander-schranz/bugfix/fix-regression-i…
Browse files Browse the repository at this point in the history
…n-sulu-master

Fix regression in sulu master segments
  • Loading branch information
niklasnatter authored Oct 2, 2020
2 parents 4e3859c + 13043be commit 1bea2a1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ jobs:
- name: Prepare functional testcases
run: composer bootstrap-test-environment

- name: Run functional tests
run: composer phpunit -- Tests/Functional --log-junit var/junit.xml

- name: Linting code
run: composer lint

- name: Run functional tests
run: composer phpunit -- Tests/Functional --log-junit var/junit.xml

php-cs-fixer:
name: Run php-cs-fixer
runs-on: ubuntu-18.04
Expand Down
14 changes: 10 additions & 4 deletions Controller/HeadlessWebsiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use JMS\Serializer\SerializerInterface;
use Sulu\Bundle\HeadlessBundle\Content\StructureResolverInterface;
use Sulu\Bundle\HttpCacheBundle\CacheLifetime\CacheLifetimeEnhancer;
use Sulu\Bundle\HttpCacheBundle\CacheLifetime\CacheLifetimeEnhancerInterface;
use Sulu\Bundle\PreviewBundle\Preview\Preview;
use Sulu\Component\Content\Compat\PageInterface;
use Sulu\Component\Content\Compat\StructureInterface;
Expand Down Expand Up @@ -53,8 +54,9 @@ public function indexAction(
$response->headers->set('Content-Type', 'application/json');
}

if (!$preview && $this->getCacheTimeLifeEnhancer()) {
$this->getCacheTimeLifeEnhancer()->enhance($response, $structure);
$cacheLifetimeEnhancer = $this->getCacheLifetimeEnhancer();
if (!$preview && $cacheLifetimeEnhancer) {
$cacheLifetimeEnhancer->enhance($response, $structure);
}

return $response;
Expand Down Expand Up @@ -117,16 +119,20 @@ public static function getSubscribedServices(): array
$subscribedServices = parent::getSubscribedServices();
$subscribedServices['sulu_headless.structure_resolver'] = StructureResolverInterface::class;
$subscribedServices['jms_serializer'] = SerializerInterface::class;
$subscribedServices['sulu_http_cache.cache_lifetime.enhancer'] = '?' . CacheLifetimeEnhancerInterface::class;

return $subscribedServices;
}

protected function getCacheTimeLifeEnhancer(): ?CacheLifetimeEnhancer
protected function getCacheLifetimeEnhancer(): ?CacheLifetimeEnhancer
{
if (!$this->has('sulu_http_cache.cache_lifetime.enhancer')) {
return null;
}

return $this->get('sulu_http_cache.cache_lifetime.enhancer');
/** @var CacheLifetimeEnhancer $cacheLifetimeEnhancer */
$cacheLifetimeEnhancer = $this->get('sulu_http_cache.cache_lifetime.enhancer');

return $cacheLifetimeEnhancer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"categories": [],
"tags": [],
"images": [],
"segment": null,
"segments": [],
"icon": [],
"audience_targeting_groups": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"categories": [],
"audience_targeting_groups": [],
"tags": [],
"segment": "",
"segments": [],
"icon": [],
"images": []
},
Expand Down Expand Up @@ -67,7 +67,7 @@
"categories": [],
"audience_targeting_groups": [],
"tags": [],
"segment": "",
"segments": [],
"icon": [
{
"id": "@integer@",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ parameters:
symfony:
container_xml_path: %rootDir%/../../../Tests/Application/var/cache/admin/dev/Sulu_Bundle_HeadlessBundle_Tests_Application_KernelDevDebugContainer.xml
console_application_loader: Tests/phpstan/console-application.php
constant_hassers: false
doctrine:
objectManagerLoader: Tests/phpstan/object-manager.php

0 comments on commit 1bea2a1

Please sign in to comment.