diff --git a/src/Controller/WopiController.php b/src/Controller/WopiController.php index 826526ec..c7d8c227 100644 --- a/src/Controller/WopiController.php +++ b/src/Controller/WopiController.php @@ -15,6 +15,7 @@ use Drupal\collabora_online\Exception\CollaboraNotAvailableException; use Drupal\collabora_online\Jwt\JwtTranscoderInterface; use Drupal\collabora_online\MediaHelperInterface; +use Drupal\collabora_online\Util\IsoDateTime; use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\DependencyInjection\AutowireTrait; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; @@ -73,8 +74,6 @@ public function __construct( * The response with file contents. */ public function wopiCheckFileInfo(MediaInterface $media, FileInterface $file, UserInterface $user, bool $can_write): Response { - $mtime = date_create_immutable_from_format('U', $file->getChangedTime()); - if ($can_write && !$media->access('edit in collabora', $user)) { $this->logger->error('Token and user permissions do not match.'); throw new AccessDeniedHttpException('The user does not have collabora edit access for this media.'); @@ -83,7 +82,7 @@ public function wopiCheckFileInfo(MediaInterface $media, FileInterface $file, Us $response_data = [ 'BaseFileName' => $file->getFilename(), 'Size' => $file->getSize(), - 'LastModifiedTime' => $mtime->format('c'), + 'LastModifiedTime' => IsoDateTime::format($file->getChangedTime()), 'UserId' => $user->id(), 'UserFriendlyName' => $user->getDisplayName(), 'UserCanWrite' => $can_write, @@ -149,7 +148,6 @@ public function wopiPutFile(MediaInterface $media, FileInterface $file, UserInte $new_file_content = $request->getContent(); $new_file = $this->createNewFileEntity($file, $new_file_content); - $mtime = date_create_immutable_from_format('U', $new_file->getChangedTime()); $save_reason = $this->buildSaveReason($request); @@ -163,7 +161,7 @@ public function wopiPutFile(MediaInterface $media, FileInterface $file, UserInte return new JsonResponse( [ - 'LastModifiedTime' => $mtime->format('c'), + 'LastModifiedTime' => IsoDateTime::format($new_file->getChangedTime()), ], Response::HTTP_OK, ['content-type' => 'application/json'], diff --git a/src/Util/IsoDateTime.php b/src/Util/IsoDateTime.php new file mode 100644 index 00000000..bd2a5606 --- /dev/null +++ b/src/Util/IsoDateTime.php @@ -0,0 +1,27 @@ +format('c'); + } + +}