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

[BUGFIX] Remove usage of getStorageObjectFromCombinedIdentifier on file upload. Fix upload test. Force exit on first fail of postman tests instead of running other postman test files. #116

Merged
merged 1 commit into from
Oct 19, 2024
Merged
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
5 changes: 4 additions & 1 deletion Build/postman/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

source .ddev/test/utils.sh

set +x
set -e

POSTMAN_BUILD_PATH=/var/www/html/Build/postman/
cd ${POSTMAN_BUILD_PATH} || exit

Expand Down Expand Up @@ -46,7 +49,7 @@ else
./node_modules/.bin/newman run "../../Tests/Postman/$TEST_FILE" --verbose --bail --env-var "baseUrl=$DOMAIN"
else
for TEST_FILE in ../../Tests/Postman/*.json; do
./node_modules/.bin/newman run "$TEST_FILE" --verbose --bail --env-var "baseUrl=$DOMAIN"
./node_modules/.bin/newman run "$TEST_FILE" --verbose --bail --env-var "baseUrl=$DOMAIN"
done
fi
done
Expand Down
24 changes: 19 additions & 5 deletions Classes/Service/FileUploadService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@
use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\Security\FileNameValidator;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;

class FileUploadService implements SingletonInterface
{
public function __construct(protected readonly ResourceFactory $resourceFactory) {}
public function __construct(
protected readonly ResourceFactory $resourceFactory,
protected readonly StorageRepository $storageRepository
) {}

/**
* @throws Exception
Expand All @@ -33,6 +37,7 @@ public function process(OperationInterface $operation, Request $request): File
{
/** @var UploadedFile $uploadedFile */
$uploadedFile = $request->files->get('originalResource');

$uploadSettings = $operation->getUploadSettings();

$this->verifyFileExtension($uploadSettings, $uploadedFile);
Expand Down Expand Up @@ -95,11 +100,20 @@ protected function getUploadFolder(UploadSettings $uploadSettings): Folder
$uploadFolder = $this->resourceFactory->getFolderObjectFromCombinedIdentifier(
$uploadSettings->getFolder()
);
} catch (ResourceDoesNotExistException $resourceDoesNotExistException) {
$resource = $this->resourceFactory->getStorageObjectFromCombinedIdentifier(
$uploadSettings->getFolder()
} catch (\Throwable $e) {

[$storageId, $objectIdentifier] = array_pad(
GeneralUtility::trimExplode(':', $uploadSettings->getFolder()),
2,
null
);

if ($objectIdentifier === null && !MathUtility::canBeInterpretedAsInteger($storageId)) {
$resource = $this->storageRepository->findByUid(0);
} else {
$resource = $this->storageRepository->findByUid((int)$storageId);
}

if (!$resource instanceof ResourceStorage) {
throw new \InvalidArgumentException(
sprintf('Invalid upload path (`%s`). Storage does not exist?', $uploadSettings->getFolder()),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Postman/t3apinews.crud.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"value": "multipart/form-data",
"type": "text"
}
],
Expand Down
Loading