From 8cf563173a050086979981071f11725b4ef214e2 Mon Sep 17 00:00:00 2001 From: roadiz-ci Date: Wed, 20 Mar 2024 12:27:16 +0000 Subject: [PATCH] Merge tag v2.2.14 into develop --- .../WebResponseOutputDataTransformer.php | 1 + src/Api/Extension/ArchiveExtension.php | 2 +- src/Api/Model/WebResponseInterface.php | 2 ++ src/Api/Model/WebResponseTrait.php | 17 +++++++++++++++++ src/Console/NodesDetailsCommand.php | 2 +- src/CustomForm/CustomFormHelper.php | 2 +- src/Model/AttributeValueTranslationTrait.php | 2 +- src/SearchEngine/NodeSourceSearchHandler.php | 10 +++++----- src/Xlsx/XlsxExporter.php | 2 +- 9 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/Api/DataTransformer/WebResponseOutputDataTransformer.php b/src/Api/DataTransformer/WebResponseOutputDataTransformer.php index 5c7c2a69..d4d46109 100644 --- a/src/Api/DataTransformer/WebResponseOutputDataTransformer.php +++ b/src/Api/DataTransformer/WebResponseOutputDataTransformer.php @@ -93,6 +93,7 @@ public function transform(PersistableInterface $object, string $to, array $conte ], UrlGeneratorInterface::ABSOLUTE_PATH)); $output->setHead($this->nodesSourcesHeadFactory->createForNodeSource($object)); $output->setBreadcrumbs($this->breadcrumbsFactory->create($object)); + $output->setMaxAge($object->getNode()->getTtl() * 60); } if ($object instanceof TranslationInterface) { $output->setHead($this->nodesSourcesHeadFactory->createForTranslation($object)); diff --git a/src/Api/Extension/ArchiveExtension.php b/src/Api/Extension/ArchiveExtension.php index 33cc5132..e61a3305 100644 --- a/src/Api/Extension/ArchiveExtension.php +++ b/src/Api/Extension/ArchiveExtension.php @@ -104,7 +104,7 @@ public function getResult( foreach ($paginator as $result) { $dateTimeField = reset($result); - if ($dateTimeField instanceof \DateTime) { + if ($dateTimeField instanceof \DateTimeInterface) { $year = $dateTimeField->format('Y'); $month = $dateTimeField->format('Y-m'); diff --git a/src/Api/Model/WebResponseInterface.php b/src/Api/Model/WebResponseInterface.php index b295c30f..8a43399b 100644 --- a/src/Api/Model/WebResponseInterface.php +++ b/src/Api/Model/WebResponseInterface.php @@ -14,4 +14,6 @@ public function setBreadcrumbs(?BreadcrumbsInterface $breadcrumbs): self; public function setItem(?PersistableInterface $item): self; public function setPath(?string $path): self; public function getItem(): ?PersistableInterface; + public function getMaxAge(): ?int; + public function setMaxAge(?int $maxAge): self; } diff --git a/src/Api/Model/WebResponseTrait.php b/src/Api/Model/WebResponseTrait.php index da99f808..141afde7 100644 --- a/src/Api/Model/WebResponseTrait.php +++ b/src/Api/Model/WebResponseTrait.php @@ -39,6 +39,23 @@ trait WebResponseTrait #[Serializer\Groups(["web_response"])] private bool $hidingBlocks = false; + /** + * @var int|null WebResponse item maximum age in seconds + */ + #[Serializer\Groups(["web_response"])] + private ?int $maxAge = null; + + public function getMaxAge(): ?int + { + return $this->maxAge; + } + + public function setMaxAge(?int $maxAge): self + { + $this->maxAge = $maxAge; + return $this; + } + public function setPath(?string $path): self { $this->path = $path; diff --git a/src/Console/NodesDetailsCommand.php b/src/Console/NodesDetailsCommand.php index 444d3850..53515526 100644 --- a/src/Console/NodesDetailsCommand.php +++ b/src/Console/NodesDetailsCommand.php @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (is_array($data)) { $data = implode(', ', $data); } - if ($data instanceof \DateTime) { + if ($data instanceof \DateTimeInterface) { $data = $data->format('c'); } if ($data instanceof \stdClass) { diff --git a/src/CustomForm/CustomFormHelper.php b/src/CustomForm/CustomFormHelper.php index c333572c..ce8a28de 100644 --- a/src/CustomForm/CustomFormHelper.php +++ b/src/CustomForm/CustomFormHelper.php @@ -213,7 +213,7 @@ protected function getDocumentFolderForCustomForm(): ?Folder */ private function formValueToString($rawValue): string { - if ($rawValue instanceof \DateTime) { + if ($rawValue instanceof \DateTimeInterface) { return $rawValue->format('Y-m-d H:i:s'); } elseif (is_array($rawValue)) { $values = $rawValue; diff --git a/src/Model/AttributeValueTranslationTrait.php b/src/Model/AttributeValueTranslationTrait.php index 8db411b1..57cb8ae2 100644 --- a/src/Model/AttributeValueTranslationTrait.php +++ b/src/Model/AttributeValueTranslationTrait.php @@ -72,7 +72,7 @@ public function setValue(mixed $value) return $this; case AttributeInterface::DATETIME_T: case AttributeInterface::DATE_T: - if ($value instanceof \DateTime) { + if ($value instanceof \DateTimeInterface) { $this->value = $value->format('Y-m-d H:i:s'); } else { $this->value = (string) $value; diff --git a/src/SearchEngine/NodeSourceSearchHandler.php b/src/SearchEngine/NodeSourceSearchHandler.php index 00d48dcf..bc4dc90d 100644 --- a/src/SearchEngine/NodeSourceSearchHandler.php +++ b/src/SearchEngine/NodeSourceSearchHandler.php @@ -168,15 +168,15 @@ protected function argFqProcess(array &$args): array */ if (isset($args['publishedAt'])) { $tmp = "published_at_dt:"; - if (!is_array($args['publishedAt']) && $args['publishedAt'] instanceof \DateTime) { + if (!is_array($args['publishedAt']) && $args['publishedAt'] instanceof \DateTimeInterface) { $tmp .= $this->formatDateTimeToUTC($args['publishedAt']); } elseif ( isset($args['publishedAt'][0]) && $args['publishedAt'][0] === "BETWEEN" && isset($args['publishedAt'][1]) && - $args['publishedAt'][1] instanceof \DateTime && + $args['publishedAt'][1] instanceof \DateTimeInterface && isset($args['publishedAt'][2]) && - $args['publishedAt'][2] instanceof \DateTime + $args['publishedAt'][2] instanceof \DateTimeInterface ) { $tmp .= "[" . $this->formatDateTimeToUTC($args['publishedAt'][1]) . @@ -186,14 +186,14 @@ protected function argFqProcess(array &$args): array isset($args['publishedAt'][0]) && $args['publishedAt'][0] === "<=" && isset($args['publishedAt'][1]) && - $args['publishedAt'][1] instanceof \DateTime + $args['publishedAt'][1] instanceof \DateTimeInterface ) { $tmp .= "[* TO " . $this->formatDateTimeToUTC($args['publishedAt'][1]) . "]"; } elseif ( isset($args['publishedAt'][0]) && $args['publishedAt'][0] === ">=" && isset($args['publishedAt'][1]) && - $args['publishedAt'][1] instanceof \DateTime + $args['publishedAt'][1] instanceof \DateTimeInterface ) { $tmp .= "[" . $this->formatDateTimeToUTC($args['publishedAt'][1]) . " TO *]"; } diff --git a/src/Xlsx/XlsxExporter.php b/src/Xlsx/XlsxExporter.php index 2c24e292..633d7017 100644 --- a/src/Xlsx/XlsxExporter.php +++ b/src/Xlsx/XlsxExporter.php @@ -107,7 +107,7 @@ public function exportXlsx($data, $keys = []) continue; } - if ($value instanceof \DateTime) { + if ($value instanceof \DateTimeInterface) { $value = Date::PHPToExcel($value); $activeSheet->getStyle($columnAlpha . ($activeRow)) ->getNumberFormat()