From 3b6723f53c63d6d1b85ad18e5b3bc51a65052682 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Thu, 27 Jun 2024 10:30:37 +0200 Subject: [PATCH 1/2] fix: only close stream in case the resource is valid --- common/oatbox/task/AbstractTaskAction.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/oatbox/task/AbstractTaskAction.php b/common/oatbox/task/AbstractTaskAction.php index 4fd806792..6f268d0d4 100644 --- a/common/oatbox/task/AbstractTaskAction.php +++ b/common/oatbox/task/AbstractTaskAction.php @@ -56,7 +56,17 @@ protected function saveFile($path, $name) $stream = fopen($path, 'r+'); $filesystem->writeStream($filename, $stream); - fclose($stream); + + if (is_resource($stream)) { + fclose($stream); + } else { + $this->logWarning( + sprintf( + 'Stream for file "%s" is not valid. It may be already closed', + $name + ) + ); + } $file = $dir->getFile($filename); return $this->getFileReferenceSerializer()->serialize($file); From 17f39eb3d8403ace739bdede7d31c6ab7840aaf0 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Thu, 27 Jun 2024 10:34:38 +0200 Subject: [PATCH 2/2] chore: fix cs --- common/oatbox/task/AbstractTaskAction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/oatbox/task/AbstractTaskAction.php b/common/oatbox/task/AbstractTaskAction.php index 6f268d0d4..4b00d8e8d 100644 --- a/common/oatbox/task/AbstractTaskAction.php +++ b/common/oatbox/task/AbstractTaskAction.php @@ -56,9 +56,9 @@ protected function saveFile($path, $name) $stream = fopen($path, 'r+'); $filesystem->writeStream($filename, $stream); - + if (is_resource($stream)) { - fclose($stream); + fclose($stream); } else { $this->logWarning( sprintf(