Skip to content

Commit 3ab069d

Browse files
authored
Merge pull request #53 from magento-cia/MC-41844
Bugfixes
2 parents ef2cca0 + 563de40 commit 3ab069d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

AdobeStockImage/Model/Storage/Save.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\Filesystem\DirectoryList;
1212
use Magento\Framework\Exception\AlreadyExistsException;
1313
use Magento\Framework\Exception\FileSystemException;
14+
use Magento\Framework\Exception\InputException;
1415
use Magento\Framework\Filesystem;
1516
use Magento\Framework\Filesystem\Driver\Https;
1617
use Magento\Framework\Filesystem\DriverInterface;
@@ -30,15 +31,23 @@ class Save
3031
*/
3132
private $driver;
3233

34+
/**
35+
* @var int|null
36+
*/
37+
private $maxFileLength;
38+
3339
/**
3440
* Storage constructor.
3541
* @param Filesystem $filesystem
3642
* @param Https $driver
43+
* @param int|null $maxFileLength
3744
*/
3845
public function __construct(
3946
Filesystem $filesystem,
40-
Https $driver
47+
Https $driver,
48+
int $maxFileLength = null
4149
) {
50+
$this->maxFileLength = $maxFileLength ?: 255;
4251
$this->filesystem = $filesystem;
4352
$this->driver = $driver;
4453
}
@@ -51,10 +60,16 @@ public function __construct(
5160
* @return string
5261
* @throws AlreadyExistsException
5362
* @throws FileSystemException
63+
* @throws InputException
5464
*/
5565
public function execute(string $imageUrl, string $destinationPath = '') : string
5666
{
5767
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
68+
if (strlen($destinationPath) > $this->maxFileLength) {
69+
throw new InputException(
70+
__('Destination path is too long; must be %1 characters or less', $this->maxFileLength)
71+
);
72+
}
5873

5974
if ($mediaDirectory->isExist($destinationPath)) {
6075
throw new AlreadyExistsException(__('Image with the same file name already exits.'));

AdobeStockImage/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<type name="Magento\AdobeStockImage\Model\Storage\Save">
3838
<arguments>
3939
<argument name="driver" xsi:type="object">Magento\Framework\Filesystem\Driver\Https</argument>
40+
<argument name="maxFileLength" xsi:type="number">255</argument>
4041
</arguments>
4142
</type>
4243
<type name="Magento\AdobeStockImage\Model\GetRelatedImages">

0 commit comments

Comments
 (0)