private function getUniqueFileName($folder, $fileName, $counter = 0)
{
$newFileName = $fileName;
if ($counter > 0) {
$fileNameParts = explode('.', $fileName, 2);
$newFileName = $fileNameParts[0] . '-' . $counter;
if (isset($fileNameParts[1])) {
$newFileName .= '.' . $fileNameParts[1];
}
}
$filePath = $this->getPathByFolderAndFileName($folder, $newFileName);
$this->logger->debug('Check FilePath: ' . $filePath);
if (!$this->filesystem->exists($filePath)) {
return $newFileName;
}
++$counter;
return $this->getUniqueFileName($folder, $fileName, $counter);
}