function getUniqueDocumentName($oFolder, $sFilename) { // this is just a quick refactoring. We should look at a more optimal way of doing this as there are // quite a lot of queries. $iFolderId = $oFolder->getId(); while (KTDocumentUtil::nameExists($oFolder, $sFilename)) { $oDoc = Document::getByNameAndFolder($sFilename, $iFolderId); $sFilename = KTDocumentUtil::generateNewDocumentName($oDoc->getName()); } return $sFilename; }