Skip to content

Commit

Permalink
Use DI for files_sharing Cache
Browse files Browse the repository at this point in the history
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
  • Loading branch information
MorrisJobke committed Jun 17, 2021
1 parent 0954184 commit 2690481
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
17 changes: 7 additions & 10 deletions apps/files_sharing/lib/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@
* don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
*/
class Cache extends CacheJail {
/**
* @var \OCA\Files_Sharing\SharedStorage
*/
/** @var \OCA\Files_Sharing\SharedStorage */
private $storage;

/**
* @var ICacheEntry
*/
/** @var ICacheEntry */
private $sourceRootInfo;
/** @var IUserManager */
private $userManager;

private $rootUnchanged = true;

Expand All @@ -64,11 +61,11 @@ class Cache extends CacheJail {

/**
* @param \OCA\Files_Sharing\SharedStorage $storage
* @param ICacheEntry $sourceRootInfo
*/
public function __construct($storage, ICacheEntry $sourceRootInfo) {
public function __construct($storage, ICacheEntry $sourceRootInfo, IUserManager $userManager) {
$this->storage = $storage;
$this->sourceRootInfo = $sourceRootInfo;
$this->userManager = $userManager;
$this->numericId = $sourceRootInfo->getStorageId();

parent::__construct(
Expand Down Expand Up @@ -176,7 +173,7 @@ protected function formatCacheEntry($entry, $path = null) {
private function getOwnerDisplayName() {
if (!$this->ownerDisplayName) {
$uid = $this->storage->getOwner('');
$user = \OC::$server->get(IUserManager::class)->get($uid);
$user = $this->userManager->get($uid);
if ($user) {
$this->ownerDisplayName = $user->getDisplayName();
} else {
Expand Down
7 changes: 6 additions & 1 deletion apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IStorage;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Share\IShare;

Expand Down Expand Up @@ -385,7 +386,11 @@ public function getCache($path = '', $storage = null) {
return new FailedCache();
}

$this->cache = new \OCA\Files_Sharing\Cache($storage, $sourceRoot, $this->superShare);
$this->cache = new \OCA\Files_Sharing\Cache(
$storage,
$sourceRoot,
\OC::$server->get(IUserManager::class)
);
return $this->cache;
}

Expand Down

0 comments on commit 2690481

Please sign in to comment.