Skip to content

Commit 169d575

Browse files
Merge pull request #44 from magento-cia/MC-41838
MC-41838: Simplify paths
2 parents 33a090f + f93ba9e commit 169d575

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

AdobeStockImage/Model/Storage/Save.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,27 @@ class Save
3939
*/
4040
private $isPathExcluded;
4141

42+
/**
43+
* @var int|null
44+
*/
45+
private $maxFileLength;
46+
4247
/**
4348
* @param Filesystem $filesystem
4449
* @param Https $driver
4550
* @param IsPathExcludedInterface $isPathExcluded
51+
* @param int|null $maxFileLength
4652
*/
4753
public function __construct(
4854
Filesystem $filesystem,
4955
Https $driver,
50-
IsPathExcludedInterface $isPathExcluded
56+
IsPathExcludedInterface $isPathExcluded,
57+
int $maxFileLength = null
5158
) {
5259
$this->filesystem = $filesystem;
5360
$this->driver = $driver;
5461
$this->isPathExcluded = $isPathExcluded;
62+
$this->maxFileLength = $maxFileLength ?: 255;
5563
}
5664

5765
/**
@@ -66,6 +74,10 @@ public function __construct(
6674
*/
6775
public function execute(string $imageUrl, string $destinationPath, bool $allowOverwrite = false): void
6876
{
77+
if (strlen($destinationPath) > $this->maxFileLength) {
78+
throw new LocalizedException(__('Destination Path is too long; must be %1 characters or less', $this->maxFileLength));
79+
}
80+
6981
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
7082

7183
if ($this->isPathExcluded->execute($destinationPath)) {

AdobeStockImage/etc/di.xml

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

0 commit comments

Comments
 (0)