aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-04-17 23:50:18 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-05-29 20:19:58 +0200
commit4bd9bc7b06c143ad0db8f11dfa31cec8842e34f0 (patch)
treec90fa7394ab9200a76b46eb9bc26b9bbc6acfdd9 /apps/files/lib
parenta5fd623469b40c44881e4635de073d334b371bae (diff)
downloadnextcloud-server-4bd9bc7b06c143ad0db8f11dfa31cec8842e34f0.tar.gz
nextcloud-server-4bd9bc7b06c143ad0db8f11dfa31cec8842e34f0.zip
feat(files): Use receiving users language for the ownership transfer target folder
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/Service/OwnershipTransferService.php21
1 files changed, 13 insertions, 8 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php
index bbb8b157941..a624df4a924 100644
--- a/apps/files/lib/Service/OwnershipTransferService.php
+++ b/apps/files/lib/Service/OwnershipTransferService.php
@@ -23,6 +23,7 @@ use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\L10N\IFactory;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use Symfony\Component\Console\Helper\ProgressBar;
@@ -45,6 +46,7 @@ class OwnershipTransferService {
private IMountManager $mountManager,
private IUserMountCache $userMountCache,
private IUserManager $userManager,
+ private IFactory $l10nFactory,
) {
$this->encryptionManager = $encryptionManager;
}
@@ -93,19 +95,15 @@ class OwnershipTransferService {
if ($move) {
$finalTarget = "$destinationUid/files/";
} else {
+ $l = $this->l10nFactory->get('files', $this->l10nFactory->getUserLanguage($destinationUser));
$date = date('Y-m-d H-i-s');
- // Remove some characters which are prone to cause errors
- $cleanUserName = str_replace(['\\', '/', ':', '.', '?', '#', '\'', '"'], '-', $sourceUser->getDisplayName());
- // Replace multiple dashes with one dash
- $cleanUserName = preg_replace('/-{2,}/s', '-', $cleanUserName);
- $cleanUserName = $cleanUserName ?: $sourceUid;
-
- $finalTarget = "$destinationUid/files/transferred from $cleanUserName on $date";
+ $cleanUserName = $this->sanitizeFolderName($sourceUser->getDisplayName()) ?: $sourceUid;
+ $finalTarget = "$destinationUid/files/" . $this->sanitizeFolderName($l->t('Transferred from %1$s on %2$s', [$cleanUserName, $date]));
try {
$view->verifyPath(dirname($finalTarget), basename($finalTarget));
} catch (InvalidPathException $e) {
- $finalTarget = "$destinationUid/files/transferred from $sourceUid on $date";
+ $finalTarget = "$destinationUid/files/" . $this->sanitizeFolderName($l->t('Transferred from %1$s on %2$s', [$sourceUid, $date]));
}
}
@@ -185,6 +183,13 @@ class OwnershipTransferService {
}
}
+ private function sanitizeFolderName(string $name): string {
+ // Remove some characters which are prone to cause errors
+ $name = str_replace(['\\', '/', ':', '.', '?', '#', '\'', '"'], '-', $name);
+ // Replace multiple dashes with one dash
+ return preg_replace('/-{2,}/s', '-', $name);
+ }
+
private function walkFiles(View $view, $path, Closure $callBack) {
foreach ($view->getDirectoryContent($path) as $fileInfo) {
if (!$callBack($fileInfo)) {