Skip to content

Commit 2013bba

Browse files
committed
chore: migrate away from deprecated OC_Helper to IUserFolder
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent c10107b commit 2013bba

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

core/Command/User/Info.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
namespace OC\Core\Command\User;
77

88
use OC\Core\Command\Base;
9-
use OCP\Files\NotFoundException;
9+
use OC\User\NoUserException;
10+
use OCP\Files\IRootFolder;
1011
use OCP\IGroupManager;
1112
use OCP\IUser;
1213
use OCP\IUserManager;
14+
use OCP\Server;
1315
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
1416
use Symfony\Component\Console\Input\InputArgument;
1517
use Symfony\Component\Console\Input\InputInterface;
@@ -81,20 +83,13 @@ private function formatLoginDate(int $timestamp): string {
8183
* @return array
8284
*/
8385
protected function getStorageInfo(IUser $user): array {
84-
\OC_Util::tearDownFS();
85-
\OC_Util::setupFS($user->getUID());
86+
$root = Server::get(IRootFolder::class);
8687
try {
87-
$storage = \OC_Helper::getStorageInfo('/');
88-
} catch (NotFoundException $e) {
88+
$userFolder = $root->getUserFolder($user->getUID());
89+
return $userFolder->getUserQuota();
90+
} catch (NoUserException) {
8991
return [];
9092
}
91-
return [
92-
'free' => $storage['free'],
93-
'used' => $storage['used'],
94-
'total' => $storage['total'],
95-
'relative' => $storage['relative'],
96-
'quota' => $storage['quota'],
97-
];
9893
}
9994

10095
/**

lib/private/User/User.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\Accounts\IAccountManager;
1515
use OCP\Comments\ICommentsManager;
1616
use OCP\EventDispatcher\IEventDispatcher;
17+
use OCP\Files\IRootFolder;
1718
use OCP\Group\Events\BeforeUserRemovedEvent;
1819
use OCP\Group\Events\UserRemovedEvent;
1920
use OCP\IAvatarManager;
@@ -25,6 +26,7 @@
2526
use OCP\IUser;
2627
use OCP\IUserBackend;
2728
use OCP\Notification\IManager as INotificationManager;
29+
use OCP\Server;
2830
use OCP\User\Backend\IGetHomeBackend;
2931
use OCP\User\Backend\IPasswordHashBackend;
3032
use OCP\User\Backend\IProvideAvatarBackend;
@@ -592,7 +594,11 @@ public function setQuota($quota) {
592594
$this->config->setUserValue($this->uid, 'files', 'quota', $quota);
593595
$this->triggerChange('quota', $quota, $oldQuota);
594596
}
595-
\OC_Helper::clearStorageInfo('/' . $this->uid . '/files');
597+
598+
// clear the quota cache
599+
$root = Server::get(IRootFolder::class);
600+
$userFolder = $root->getUserFolder($this->uid);
601+
$userFolder->getUserQuota(false);
596602
}
597603

598604
public function getManagerUids(): array {

lib/private/legacy/OC_Helper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public static function findBinaryPath(string $program): ?string {
219219
* @psalm-suppress LessSpecificReturnStatement Legacy code outputs weird types - manually validated that they are correct
220220
* @return StorageInfo
221221
* @throws \OCP\Files\NotFoundException
222+
* @deprecated 32.0.0 use \OCP\Files\IUserFolder::getUserQuota
222223
*/
223224
public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) {
224225
if (!self::$cacheFactory) {
@@ -281,7 +282,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
281282

282283
// TODO: need a better way to get total space from storage
283284
if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) {
284-
/** @var \OC\Files\Storage\Wrapper\Quota $storage */
285+
/** @var \OC\Files\Storage\Wrapper\Quota $sourceStorage */
285286
$quota = $sourceStorage->getQuota();
286287
}
287288
try {
@@ -403,6 +404,9 @@ private static function getGlobalStorageInfo(int|float $quota, IUser $user, IMou
403404
];
404405
}
405406

407+
/**
408+
* @deprecated 32.0.0
409+
*/
406410
public static function clearStorageInfo(string $absolutePath): void {
407411
/** @var ICacheFactory $cacheFactory */
408412
$cacheFactory = \OC::$server->get(ICacheFactory::class);

0 commit comments

Comments
 (0)