1

I have issue with the following code:

public function getNameReplacementInFolder(string $originalFilename, int $folderId): string
{
    $folder = $this->getFolderById($folderId);

    if (!$folder) {
        throw new InvalidArgumentException('Invalid folder ID: '.$folderId);
    }

    $volume = $folder->getVolume();
    $fileList = $volume->getFileList((string)$folder->path, false);

The problem if I am using an external filesystem the getFileList is a very heavy API call for the external filesystem. It would be much easier to check the filename in the Asset database, than to check it on the filesystem.

Is there any way to avoid this call? Also if the flysystem driver is poorly written it could stuck in case of huge files or folders.

I badly need solution for disable this call - we can take care the indivudual file nameing, or to tweak it or change it for the database call

Thank you for your help

2

Not the "best" solution but if you really want to "disable" it you are free to overwrite the class via Dependency Injection and Service Locators.

You can overwrite the service with your custom one that extends Crafts service and "remove" the function

Craft::$container->set('craft\services\Assets', [
    'class' => 'prefix\namespace\services\MyCustomAwesomeAssetService'
]);

Since this function is only really needed in the AssetLocationValidator you can as well replace it with your custom validation

1
  • thx, very nice workaround! May 10 '18 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.