Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update flysystem usage after upgrade #493

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest ]
php-version: [ '7.4', '8.0', '8.1' ]
php-version: [ '8.1', '8.2', '8.3' ]
include:
- php-version: '8.1'
- php-version: '8.3'
coverage: true

steps:
Expand Down
25 changes: 9 additions & 16 deletions model/DataStore/PersistDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use common_Exception;
use common_exception_Error;
use common_exception_NotFound;
use oat\oatbox\filesystem\FileSystem;
use oat\oatbox\filesystem\FilesystemInterface;
use oat\oatbox\filesystem\FileSystemService;
use oat\oatbox\service\ConfigurableService;
use oat\tao\helpers\FileHelperService;
Expand Down Expand Up @@ -71,7 +71,7 @@ public function remove(ResourceSyncDTO $resourceSyncDTO): void
* @throws common_exception_Error
* @throws common_exception_NotFound
*/
private function getDataStoreFilesystem(string $fileSystemId): FileSystem
private function getDataStoreFilesystem(string $fileSystemId): FilesystemInterface
{
return $this->getFileSystemManager()->getFileSystem($fileSystemId);
}
Expand All @@ -90,13 +90,13 @@ private function removeArchive(string $resourceId, string $fileSystemId, string
// There is a bug for gcp storage adapter - when deleting a dir with only one file exception is thrown
// This is why the file itself is removed first
$zipFileName = $this->getZipFileName($resourceId, $tenantId);
if ($this->getDataStoreFilesystem($fileSystemId)->has($zipFileName)) {
if ($this->getDataStoreFilesystem($fileSystemId)->fileExists($zipFileName)) {
$this->getDataStoreFilesystem($fileSystemId)->delete($zipFileName);
}

$directoryPath = $this->getZipFileDirectory($resourceId, $tenantId);
if ($this->getDataStoreFilesystem($fileSystemId)->has($directoryPath)) {
$this->getDataStoreFilesystem($fileSystemId)->deleteDir($directoryPath);
if ($this->getDataStoreFilesystem($fileSystemId)->directoryExists($directoryPath)) {
$this->getDataStoreFilesystem($fileSystemId)->deleteDirectory($directoryPath);
}
}

Expand Down Expand Up @@ -150,17 +150,10 @@ private function moveExportedZipTest(

$contents = file_get_contents($zipFile);

if ($this->getDataStoreFilesystem($fileSystemId)->has($zipFileName)) {
$this->getDataStoreFilesystem($fileSystemId)->update(
$zipFileName,
$contents
);
} else {
$this->getDataStoreFilesystem($fileSystemId)->write(
$zipFileName,
$contents
);
}
$this->getDataStoreFilesystem($fileSystemId)->write(
$zipFileName,
$contents
);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions model/DeliveryArchiveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function archive($compiledDelivery, $force = false)
{
$fileName = $this->getArchiveFileName($compiledDelivery);

if (!$force && $this->getArchiveFileSystem()->has($fileName)) {
if (!$force && $this->getArchiveFileSystem()->fileExists($fileName)) {
throw new DeliverArchiveExistingException(
'Delivery archive already created: ' . $compiledDelivery->getUri()
);
Expand Down Expand Up @@ -135,7 +135,7 @@ public function unArchive($compiledDelivery, $force = false)
{
$fileName = $this->getArchiveFileName($compiledDelivery);

if (!$this->getArchiveFileSystem()->has($fileName)) {
if (!$this->getArchiveFileSystem()->fileExists($fileName)) {
throw new DeliveryArchiveNotExistingException(
'Delivery archive not exist please generate: ' . $compiledDelivery->getUri()
);
Expand Down Expand Up @@ -172,7 +172,7 @@ public function unArchive($compiledDelivery, $force = false)
public function deleteArchive($compiledDelivery)
{
$fileName = $this->getArchiveFileName($compiledDelivery);
if ($this->getArchiveFileSystem()->has($fileName)) {
if ($this->getArchiveFileSystem()->fileExists($fileName)) {
$this->getArchiveFileSystem()->delete($fileName);
}

Expand Down Expand Up @@ -207,7 +207,7 @@ private function copyFromZip($zip)
$entryName = implode('/', $parts);
$stream = $zip->getStream($zipEntryName);
if (is_resource($stream)) {
$fileSystem->getFileSystem($bucketDestination)->putStream($entryName, $stream);
$fileSystem->getFileSystem($bucketDestination)->writeStream($entryName, $stream);
}
}
}
Expand All @@ -229,7 +229,7 @@ private function uploadZip($compiledDelivery)
if (!file_exists($zipPath) || ($stream = fopen($zipPath, 'r')) === false) {
throw new DeliveryZipException('Cannot open local tmp zip archive');
}
$this->getArchiveFileSystem()->putStream($fileName, $stream);
$this->getArchiveFileSystem()->writeStream($fileName, $stream);
fclose($stream);

return $fileName;
Expand Down
Loading