Skip to content

Commit

Permalink
Update page last modified time after changes to files
Browse files Browse the repository at this point in the history
  • Loading branch information
giuscris committed Feb 10, 2025
1 parent 6038abc commit 08ea8c9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions formwork/src/Panel/Controllers/PagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]));
}
Expand Down Expand Up @@ -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')]));
}
Expand Down Expand Up @@ -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');
}
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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]));
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 08ea8c9

Please sign in to comment.