Skip to content

Commit

Permalink
respect the conflict strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Aug 1, 2023
1 parent 017df4c commit 27c4beb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/helpers/AssetHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ public static function downloadFile($srcName, $dstName, int $chunkSize = 1, bool
* @throws \craft\errors\VolumeException
* @throws \yii\base\InvalidConfigException
*/
public static function indexExistingFile($urlFromFeed, $field = null, $element = null, $folderId = null, $newFilename = null): AssetElement|bool
public static function indexExistingFile($urlFromFeed, string $conflict, $field = null, $element = null, $folderId = null, $newFilename = null): AssetElement|bool
{
// if the conflict strategy is to replace or create, just bail straight away
// and allow for creation of the asset even the file exists
if ($conflict == AssetElement::SCENARIO_REPLACE || $conflict == AssetElement::SCENARIO_CREATE) {
return false;
}
$folder = self::_getAssetFolder($folderId, $field, $element);
$volume = $folder->getVolume();
$filename = $newFilename ? AssetsHelper::prepareAssetName($newFilename, false) : self::getRemoteUrlFilename($urlFromFeed);
Expand Down Expand Up @@ -166,7 +171,7 @@ public static function fetchRemoteImage(array $urls, $fieldInfo, $feed, $field =
// user has set to use that instead, so we're good to proceed.
foreach ($urls as $url) {
try {
$indexedAsset = self::indexExistingFile($url, $field, $element, $folderId, $newFilename);
$indexedAsset = self::indexExistingFile($url, $conflict, $field, $element, $folderId, $newFilename);

if ($indexedAsset instanceof AssetElement) {
$uploadedAssets[] = $indexedAsset->id;
Expand Down

0 comments on commit 27c4beb

Please sign in to comment.