Skip to content

Commit 4d10526

Browse files
committed
fix active from/to in cache mode
1 parent 9099b93 commit 4d10526

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Controller/FrontendPageController.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function indexAction(Request $request)
6565

6666
if($phpCache->isCacheable($request, $this->getUser()) && $page instanceof PageSnapshotInterface){
6767

68+
if (!$this->isSnapshotActive($page)) {
69+
throw new NotFoundHttpException();
70+
}
71+
6872
$updatedAt = $phpCache->get(sprintf('page_%s_created_at', $page->getId()));
6973
$cacheKey = $request->getLocale().$request->getPathInfo();
7074

@@ -438,4 +442,53 @@ public function getPageHelper()
438442
return $this->container->get('networking_init_cms.helper.page_helper');
439443
}
440444

445+
/**
446+
* @param PageSnapshotInterface $page
447+
* @return bool
448+
*/
449+
public function isSnapshotActive(PageSnapshotInterface $page)
450+
{
451+
$jsonObject = json_decode($page->getVersionedData());
452+
453+
454+
$now = new \DateTime();
455+
456+
if ($now->getTimestamp() >= $this->getActiveStart($jsonObject)->getTimestamp() &&
457+
$now->getTimestamp() <= $this->getActiveEnd($jsonObject)->getTimestamp()
458+
) {
459+
return ($jsonObject->status == PageInterface::STATUS_PUBLISHED);
460+
}
461+
462+
return false;
463+
464+
}
465+
/**
466+
* Get activeFrom
467+
*
468+
* @return \DateTime
469+
*/
470+
public function getActiveStart($page)
471+
{
472+
if (!property_exists($page, 'active_from')) {
473+
474+
return new \DateTime();
475+
}
476+
477+
return new \DateTime($page->active_from);
478+
}
479+
480+
481+
482+
/**
483+
* @return \Datetime
484+
*/
485+
public function getActiveEnd($page)
486+
{
487+
if (!property_exists($page, 'active_to')) {
488+
return new \DateTime();
489+
}
490+
491+
return new \DateTime($page->active_to);
492+
}
493+
441494
}

0 commit comments

Comments
 (0)