Skip to content

Commit

Permalink
Merge pull request #217 from AmpersandTarski/bugfix/migrate-to-flyway…
Browse files Browse the repository at this point in the history
…-v3-api

Migrate to flyway v3 api
  • Loading branch information
Michiel-s authored Dec 3, 2024
2 parents 85b31f2 + 65d56e2 commit 809e4c0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
with:
php-version: '8.3'
# extensions: # allows to install php extensions with PECL
tools: phan:v5.3 # allows to install other tools, see: https://github.com/shivammathur/setup-php
tools: phan:v5.4 # allows to install other tools, see: https://github.com/shivammathur/setup-php

- name: Install dependencies
run: composer install --prefer-dist --no-dev --profile --optimize-autoloader --no-scripts --ignore-platform-reqs
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.2",
"phan/phan": "^5.3"
"phan/phan": "^5.4"
},
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Ampersand/Controller/FileObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getFile(Request $request, Response $response, array $args): Resp
$filePath = $args['filePath'];

// Check if filePath exists
if (!$fs->has($filePath)) {
if (!$fs->fileExists($filePath)) {
throw new NotFoundException("File not found");
}

Expand Down
7 changes: 1 addition & 6 deletions src/Ampersand/Interfacing/ResourceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Ampersand\Interfacing\InterfaceObjectInterface;
use Ampersand\Interfacing\Resource;
use Ampersand\Core\Concept;
use Ampersand\Exception\AmpersandException;
use Ampersand\Exception\AtomNotFoundException;
use Ampersand\Exception\BadRequestException;
use Ampersand\Exception\UploadException;
Expand Down Expand Up @@ -189,15 +188,11 @@ public function post(?stdClass $resourceToPost = null): Resource
$filePath = getSafeFileName($fs, $filePath);

$stream = fopen($tmp_name, 'r+');
$result = $fs->writeStream($filePath, $stream);
$fs->writeStream($filePath, $stream);
if (is_resource($stream)) {
fclose($stream);
}

if (!$result) {
throw new AmpersandException("Error in file upload");
}

// Populate filePath and originalFileName relations in database
$newResource->link($filePath, 'filePath[FileObject*FilePath]')->add();
$newResource->link($originalFileName, 'originalFileName[FileObject*FileName]')->add();
Expand Down
4 changes: 2 additions & 2 deletions src/Ampersand/Misc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function isSequential(array $arr): bool
*/
function getSafeFileName(FilesystemOperator $fileSystem, string $filePath): string
{
if (!$fileSystem->has($filePath)) {
if (!$fileSystem->fileExists($filePath)) {
return $filePath;
}

Expand All @@ -51,7 +51,7 @@ function getSafeFileName(FilesystemOperator $fileSystem, string $filePath): stri
$ext = pathinfo($filePath, PATHINFO_EXTENSION);

$i = 1;
while ($fileSystem->has($dir . DIRECTORY_SEPARATOR . "{$filename}_{$i}.{$ext}")) {
while ($fileSystem->fileExists($dir . DIRECTORY_SEPARATOR . "{$filename}_{$i}.{$ext}")) {
$i++;
}
return $dir . DIRECTORY_SEPARATOR . "{$filename}_{$i}.{$ext}";
Expand Down

0 comments on commit 809e4c0

Please sign in to comment.