Skip to content

Commit

Permalink
Use folder id directly from request
Browse files Browse the repository at this point in the history
As the value is saved from request, there is totally no point to fixate this variable in the service, temporary we can just use it directly from request where needed, while we will not have better solution, at least the complexity will be lowered.

Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Jan 8, 2024
1 parent 5c7075b commit 0e0ea9c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Application/Controller/Admin/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function render()

$this->addTplParam('sResourceUrl', $this->imageResource->getMediaUrl());
$this->addTplParam('sThumbsUrl', $this->imageResource->getThumbnailUrl());
$this->addTplParam('sFolderId', $uiRequest->getFolderId());
$this->addTplParam('sFoldername', $this->imageResource->getFolderName());
$this->addTplParam('sFolderId', $this->imageResource->getFolderId());
$this->addTplParam('sTab', $request->getRequestEscapedParameter('tab'));

$this->addTplParam('request', $uiRequest);
Expand Down
8 changes: 0 additions & 8 deletions src/Image/Service/ImageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ public function setFolderName($sFolderName): void
$this->_sFolderName = $sFolderName;
}

/**
* @deprecated This is temporary solution, it should be removed in next release.
*/
public function getFolderId(): string
{
return $this->_sFolderId;
}

/**
* @param $sId
*
Expand Down
2 changes: 0 additions & 2 deletions src/Image/Service/ImageResourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public function getFolderName(): string;

public function setFolderName($sFolderName): void;

public function getFolderId(): string;

public function setFolder($sFolderId = ''): void;

public function getDefaultThumbnailSize(): int;
Expand Down
6 changes: 3 additions & 3 deletions src/Service/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@

use Doctrine\DBAL\Connection;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\UtilsObject;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface;
use OxidEsales\MediaLibrary\Image\DataTransfer\ImageSize;
use OxidEsales\MediaLibrary\Image\Service\ThumbnailGeneratorInterface;
use OxidEsales\MediaLibrary\Image\Service\ImageResourceInterface;
use OxidEsales\MediaLibrary\Media\DataType\Media as MediaDataType;
use OxidEsales\MediaLibrary\Media\Repository\MediaRepositoryInterface;
use OxidEsales\MediaLibrary\Transput\RequestData\UIRequestInterface;
use Symfony\Component\Filesystem\Path;
use Webmozart\Glob\Glob;

Expand All @@ -34,6 +33,7 @@ public function __construct(
protected MediaRepositoryInterface $mediaRepository,
private FileSystemServiceInterface $fileSystemService,
protected ShopAdapterInterface $shopAdapter,
protected UIRequestInterface $UIRequest,
) {
$this->connection = $connectionProvider->get();
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public function uploadMedia($sSourcePath, $sDestPath, $sFileSize, $sFileType)
fileType: $sFileType,
thumbFileName: '',
imageSize: $imageSize,
folderId: $this->imageResource->getFolderId()
folderId: $this->UIRequest->getFolderId()
);

$this->mediaRepository->addMedia($newMedia);
Expand Down
4 changes: 3 additions & 1 deletion tests/Integration/Service/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\MediaLibrary\Image\Service\ThumbnailGeneratorInterface;
use OxidEsales\MediaLibrary\Transput\RequestData\UIRequestInterface;

/**
* @covers \OxidEsales\MediaLibrary\Service\Media
Expand Down Expand Up @@ -235,7 +236,8 @@ protected function getSut(
namingService: $namingService ?: $this->containerFactory->get(NamingServiceInterface::class),
mediaRepository: $this->containerFactory->get(MediaRepositoryInterface::class),
fileSystemService: $this->containerFactory->get(FileSystemServiceInterface::class),
shopAdapter: $shopAdapterStub
shopAdapter: $shopAdapterStub,
UIRequest: $this->createStub(UIRequestInterface::class),
);
}

Expand Down
6 changes: 2 additions & 4 deletions tests/Unit/Service/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace OxidEsales\MediaLibrary\Tests\Unit\Service;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception as DBALException;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
use OxidEsales\Eshop\Core\Config;
Expand All @@ -17,16 +16,14 @@
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface;
use OxidEsales\MediaLibrary\Image\Service\ImageResource;
use OxidEsales\MediaLibrary\Image\Service\ImageResourceInterface;
use OxidEsales\MediaLibrary\Image\Service\ThumbnailGeneratorInterface;
use OxidEsales\MediaLibrary\Media\Repository\MediaRepositoryInterface;
use OxidEsales\MediaLibrary\Service\FileSystemService;
use OxidEsales\MediaLibrary\Service\FileSystemServiceInterface;
use OxidEsales\MediaLibrary\Service\FolderServiceInterface;
use OxidEsales\MediaLibrary\Service\Media;
use OxidEsales\MediaLibrary\Service\ModuleSettings;
use OxidEsales\MediaLibrary\Service\NamingService;
use OxidEsales\MediaLibrary\Service\NamingServiceInterface;
use OxidEsales\MediaLibrary\Transput\RequestData\UIRequestInterface;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -564,6 +561,7 @@ protected function getSut(
mediaRepository: $mediaRepository ?? $this->createStub(MediaRepositoryInterface::class),
fileSystemService: $fileSystemService ?? $this->createPartialMock(FileSystemService::class, []),
shopAdapter: $this->createStub(ShopAdapterInterface::class),
UIRequest: $this->createStub(UIRequestInterface::class)
);
}

Expand Down

0 comments on commit 0e0ea9c

Please sign in to comment.