From 08ea8c9188b810c748c2bfa85095f7b2e9226f73 Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Mon, 10 Feb 2025 21:59:14 +0100 Subject: [PATCH] Update page last modified time after changes to files --- .../src/Panel/Controllers/PagesController.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/formwork/src/Panel/Controllers/PagesController.php b/formwork/src/Panel/Controllers/PagesController.php index 1cbbb5aa..43768e76 100644 --- a/formwork/src/Panel/Controllers/PagesController.php +++ b/formwork/src/Panel/Controllers/PagesController.php @@ -369,6 +369,8 @@ public function uploadFile(RouteParams $routeParams): Response } } + $this->updateLastModifiedTime($page); + $this->panel->notify($this->translate('panel.uploader.uploaded'), 'success'); return $this->redirect($this->generateRoute('panel.pages.edit', ['page' => $routeParams->get('page')])); } @@ -396,6 +398,8 @@ public function deleteFile(RouteParams $routeParams): Response FileSystem::delete($page->contentPath() . $routeParams->get('filename')); + $this->updateLastModifiedTime($page); + $this->panel->notify($this->translate('panel.pages.page.fileDeleted'), 'success'); return $this->redirect($this->generateRoute('panel.pages.edit', ['page' => $routeParams->get('page')])); } @@ -439,6 +443,8 @@ public function renameFile(RouteParams $routeParams): Response $this->panel->notify($this->translate('panel.pages.page.cannotRenameFile.fileAlreadyExists'), 'error'); } else { FileSystem::move($page->contentPath() . $previousName, $page->contentPath() . $newName); + $this->updateLastModifiedTime($page); + $this->panel->notify($this->translate('panel.pages.page.fileRenamed'), 'success'); } } @@ -491,6 +497,8 @@ public function replaceFile(RouteParams $routeParams): Response } } + $this->updateLastModifiedTime($page); + $this->panel->notify($this->translate('panel.uploader.uploaded'), 'success'); return $this->redirectToReferer(default: $this->generateRoute('panel.pages'), base: $this->panel->panelRoot()); } @@ -537,6 +545,8 @@ public function file(RouteParams $routeParams): Response $this->updateFileMetadata($file, $file->fields()); + $this->updateLastModifiedTime($page); + $this->panel->notify($this->translate('panel.files.metadata.updated'), 'success'); return $this->redirect($this->generateRoute('panel.pages.file', ['page' => $page->route(), 'filename' => $filename])); @@ -586,6 +596,7 @@ private function updatePage(Page $page, RequestData $requestData, FieldCollectio if (!$field->isEmpty()) { $uploadedFiles = $field->is('multiple') ? $field->value() : [$field->value()]; $this->processPageUploads($uploadedFiles, $page, $field->acceptMimeTypes()); + $this->updateLastModifiedTime($page); } $fieldCollection->remove($field->name()); } @@ -676,6 +687,16 @@ private function resolveParent(string $parent): Page|Site return $this->site->findPage($parent) ?? throw new UnexpectedValueException('Invalid parent'); } + /** + * Update last modified time of the given page + */ + private function updateLastModifiedTime(Page $page): void + { + if ($page->contentFile()?->path() !== null) { + FileSystem::touch($page->contentFile()->path()); + } + } + /** * Get previous and next page helper *