/** * Add (1), (2), etc. if name non unique in target dir * @param $name * @param $iblockId * @param $sectionId * @return string */ public static function regenerateNameIfNonUnique($name, $iblockId, $sectionId) { $mainPartName = $name; $newName = $mainPartName; $count = 0; if (self::isMetaName($newName)) { $count++; if (strstr($mainPartName, '.', true)) { $newName = strstr($mainPartName, '.', true) . " ({$count})" . strstr($mainPartName, '.'); } else { $newName = $mainPartName . " ({$count})"; } } while (!CWebDavIblock::sCheckUniqueName($iblockId, $sectionId, '', $newName, $res)) { $count++; if (strstr($mainPartName, '.', true)) { $newName = strstr($mainPartName, '.', true) . " ({$count})" . strstr($mainPartName, '.'); } else { $newName = $mainPartName . " ({$count})"; } } return $newName; }