Skip to content

Commit b9fb1db

Browse files
authored
Merge pull request #48009 from nextcloud/fix/remove-references-to-deprected-storage-interface
fix: Remove OCP\Files\Storage interface deprecated since version 9
2 parents ede0c26 + 03b969f commit b9fb1db

File tree

38 files changed

+167
-656
lines changed

38 files changed

+167
-656
lines changed

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use OCP\Files\LockNotAcquiredException;
2929
use OCP\Files\NotFoundException;
3030
use OCP\Files\NotPermittedException;
31-
use OCP\Files\Storage;
31+
use OCP\Files\Storage\IWriteStreamStorage;
3232
use OCP\Files\StorageNotAvailableException;
3333
use OCP\IL10N;
3434
use OCP\IRequest;
@@ -117,8 +117,10 @@ public function put($data) {
117117
// verify path of the target
118118
$this->verifyPath();
119119

120-
/** @var Storage $partStorage */
121120
[$partStorage] = $this->fileView->resolvePath($this->path);
121+
if ($partStorage === null) {
122+
throw new ServiceUnavailable($this->l10n->t('Failed to get storage for file'));
123+
}
122124
$needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1);
123125

124126
$view = \OC\Files\Filesystem::getView();
@@ -141,10 +143,11 @@ public function put($data) {
141143
}
142144

143145
// the part file and target file might be on a different storage in case of a single file storage (e.g. single file share)
144-
/** @var \OC\Files\Storage\Storage $partStorage */
145146
[$partStorage, $internalPartPath] = $this->fileView->resolvePath($partFilePath);
146-
/** @var \OC\Files\Storage\Storage $storage */
147147
[$storage, $internalPath] = $this->fileView->resolvePath($this->path);
148+
if ($partStorage === null || $storage === null) {
149+
throw new ServiceUnavailable($this->l10n->t('Failed to get storage for file'));
150+
}
148151
try {
149152
if (!$needsPartFile) {
150153
try {
@@ -196,7 +199,7 @@ public function put($data) {
196199
}
197200
}
198201

199-
if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) {
202+
if ($partStorage->instanceOfStorage(IWriteStreamStorage::class)) {
200203
$isEOF = false;
201204
$wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) {
202205
$isEOF = feof($stream);
@@ -535,7 +538,6 @@ public function getDirectDownload() {
535538
if (\OCP\Server::get(\OCP\App\IAppManager::class)->isEnabledForUser('encryption')) {
536539
return [];
537540
}
538-
/** @var \OCP\Files\Storage $storage */
539541
[$storage, $internalPath] = $this->fileView->resolvePath($this->path);
540542
if (is_null($storage)) {
541543
return [];

apps/dav/tests/unit/Connector/Sabre/FileTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use OCP\Constants;
1818
use OCP\Files\FileInfo;
1919
use OCP\Files\ForbiddenException;
20-
use OCP\Files\Storage;
20+
use OCP\Files\Storage\IStorage;
2121
use OCP\IConfig;
2222
use OCP\IRequestId;
2323
use OCP\ITempManager;
@@ -72,22 +72,16 @@ protected function tearDown(): void {
7272
parent::tearDown();
7373
}
7474

75-
/**
76-
* @return MockObject|Storage
77-
*/
78-
private function getMockStorage() {
79-
$storage = $this->getMockBuilder(Storage::class)
75+
private function getMockStorage(): MockObject&IStorage {
76+
$storage = $this->getMockBuilder(IStorage::class)
8077
->disableOriginalConstructor()
8178
->getMock();
8279
$storage->method('getId')
8380
->willReturn('home::someuser');
8481
return $storage;
8582
}
8683

87-
/**
88-
* @param string $string
89-
*/
90-
private function getStream($string) {
84+
private function getStream(string $string) {
9185
$stream = fopen('php://temp', 'r+');
9286
fwrite($stream, $string);
9387
fseek($stream, 0);

apps/dav/tests/unit/Connector/Sabre/NodeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use OCP\Constants;
1919
use OCP\Files\Cache\ICacheEntry;
2020
use OCP\Files\Mount\IMountPoint;
21-
use OCP\Files\Storage;
21+
use OCP\Files\Storage\IStorage;
2222
use OCP\ICache;
2323
use OCP\Share\IManager;
2424
use OCP\Share\IShare;
@@ -75,7 +75,7 @@ public function testDavPermissions($permissions, $type, $shared, $shareRootPermi
7575
return $this->createMock(MountPoint::class);
7676
}
7777
});
78-
$storage = $this->createMock(Storage\IStorage::class);
78+
$storage = $this->createMock(IStorage::class);
7979
if ($shared) {
8080
$storage->method('instanceOfStorage')
8181
->willReturn(true);
@@ -145,7 +145,7 @@ public function sharePermissionsProvider() {
145145
* @dataProvider sharePermissionsProvider
146146
*/
147147
public function testSharePermissions($type, $user, $permissions, $expected): void {
148-
$storage = $this->getMockBuilder(Storage::class)
148+
$storage = $this->getMockBuilder(IStorage::class)
149149
->disableOriginalConstructor()
150150
->getMock();
151151
$storage->method('getPermissions')->willReturn($permissions);
@@ -223,7 +223,7 @@ public function testShareAttributes(): void {
223223
}
224224

225225
public function testShareAttributesNonShare(): void {
226-
$storage = $this->getMockBuilder(Storage::class)
226+
$storage = $this->getMockBuilder(IStorage::class)
227227
->disableOriginalConstructor()
228228
->getMock();
229229

apps/encryption/tests/Crypto/EncryptionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
use OCA\Encryption\KeyManager;
1616
use OCA\Encryption\Session;
1717
use OCA\Encryption\Util;
18-
use OCP\Files\Storage;
18+
use OCP\Files\Storage\IStorage;
1919
use OCP\IL10N;
20+
use PHPUnit\Framework\MockObject\MockObject;
2021
use Psr\Log\LoggerInterface;
2122
use Symfony\Component\Console\Input\InputInterface;
2223
use Symfony\Component\Console\Output\OutputInterface;
@@ -50,13 +51,12 @@ class EncryptionTest extends TestCase {
5051
/** @var \OCP\IL10N|\PHPUnit\Framework\MockObject\MockObject */
5152
private $l10nMock;
5253

53-
/** @var \OCP\Files\Storage|\PHPUnit\Framework\MockObject\MockObject */
54-
private $storageMock;
54+
private IStorage&MockObject $storageMock;
5555

5656
protected function setUp(): void {
5757
parent::setUp();
5858

59-
$this->storageMock = $this->getMockBuilder(Storage::class)
59+
$this->storageMock = $this->getMockBuilder(IStorage::class)
6060
->disableOriginalConstructor()->getMock();
6161
$this->cryptMock = $this->getMockBuilder(Crypt::class)
6262
->disableOriginalConstructor()

apps/encryption/tests/KeyManagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use OCA\Encryption\Util;
1616
use OCP\Encryption\Keys\IStorage;
1717
use OCP\Files\Cache\ICache;
18-
use OCP\Files\Storage;
18+
use OCP\Files\Storage\IStorage as FilesIStorage;
1919
use OCP\IConfig;
2020
use OCP\IUserSession;
2121
use OCP\Lock\ILockingProvider;
@@ -687,7 +687,7 @@ public function testSetVersionWithFileInfo(): void {
687687
$cache->expects($this->once())
688688
->method('update')
689689
->with(123, ['encrypted' => 5, 'encryptedVersion' => 5]);
690-
$storage = $this->getMockBuilder(Storage::class)
690+
$storage = $this->getMockBuilder(FilesIStorage::class)
691691
->disableOriginalConstructor()->getMock();
692692
$storage->expects($this->once())
693693
->method('getCache')

apps/encryption/tests/UtilTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use OCA\Encryption\Crypto\Crypt;
1212
use OCA\Encryption\Util;
1313
use OCP\Files\Mount\IMountPoint;
14-
use OCP\Files\Storage;
14+
use OCP\Files\Storage\IStorage;
1515
use OCP\IConfig;
1616
use OCP\IUser;
1717
use OCP\IUserManager;
@@ -181,7 +181,7 @@ public function dataTestSetEncryptHomeStorage() {
181181
}
182182

183183
public function testGetStorage(): void {
184-
$return = $this->getMockBuilder(Storage::class)
184+
$return = $this->getMockBuilder(IStorage::class)
185185
->disableOriginalConstructor()
186186
->getMock();
187187

apps/files_external/lib/Config/ConfigAdapter.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use OCA\Files_External\Service\UserGlobalStoragesService;
1515
use OCA\Files_External\Service\UserStoragesService;
1616
use OCP\Files\Config\IMountProvider;
17-
use OCP\Files\Storage;
17+
use OCP\Files\ObjectStore\IObjectStore;
18+
use OCP\Files\Storage\IStorage;
1819
use OCP\Files\Storage\IStorageFactory;
1920
use OCP\Files\StorageNotAvailableException;
2021
use OCP\IUser;
@@ -34,19 +35,17 @@ public function __construct(
3435
/**
3536
* Process storage ready for mounting
3637
*
37-
* @param StorageConfig $storage
38-
* @param IUser $user
3938
* @throws \OCP\AppFramework\QueryException
4039
*/
41-
private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
40+
private function prepareStorageConfig(StorageConfig &$storage, IUser $user): void {
4241
foreach ($storage->getBackendOptions() as $option => $value) {
4342
$storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
4443
}
4544

4645
$objectStore = $storage->getBackendOption('objectstore');
4746
if ($objectStore) {
4847
$objectClass = $objectStore['class'];
49-
if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
48+
if (!is_subclass_of($objectClass, IObjectStore::class)) {
5049
throw new \InvalidArgumentException('Invalid object store');
5150
}
5251
$storage->setBackendOption('objectstore', new $objectClass($objectStore));
@@ -60,9 +59,8 @@ private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
6059
* Construct the storage implementation
6160
*
6261
* @param StorageConfig $storageConfig
63-
* @return Storage
6462
*/
65-
private function constructStorage(StorageConfig $storageConfig) {
63+
private function constructStorage(StorageConfig $storageConfig): IStorage {
6664
$class = $storageConfig->getBackend()->getStorageClass();
6765
$storage = new $class($storageConfig->getBackendOptions());
6866

@@ -76,8 +74,6 @@ private function constructStorage(StorageConfig $storageConfig) {
7674
/**
7775
* Get all mountpoints applicable for the user
7876
*
79-
* @param \OCP\IUser $user
80-
* @param \OCP\Files\Storage\IStorageFactory $loader
8177
* @return \OCP\Files\Mount\IMountPoint[]
8278
*/
8379
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
@@ -97,11 +93,11 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
9793
}, $storageConfigs);
9894

9995

100-
\OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
96+
\OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (IStorage $storage) {
10197
return $storage->getId();
10298
}, $storages));
10399

104-
$availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
100+
$availableStorages = array_map(function (IStorage $storage, StorageConfig $storageConfig): IStorage {
105101
try {
106102
$availability = $storage->getAvailability();
107103
if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
@@ -116,7 +112,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
116112
return $storage;
117113
}, $storages, $storageConfigs);
118114

119-
$mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
115+
$mounts = array_map(function (StorageConfig $storageConfig, IStorage $storage) use ($user, $loader) {
120116
$storage->setOwner($user->getUID());
121117
if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAL) {
122118
return new PersonalMount(

apps/files_external/lib/Lib/Auth/Password/SessionCredentials.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use OCA\Files_External\Lib\StorageConfig;
1313
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
1414
use OCP\Authentication\LoginCredentials\IStore as CredentialsStore;
15-
use OCP\Files\Storage;
15+
use OCP\Files\Storage\IStorage;
1616
use OCP\Files\StorageAuthException;
1717
use OCP\IL10N;
1818
use OCP\IUser;
@@ -56,7 +56,7 @@ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user =
5656
$storage->setBackendOption('password', $credentials->getPassword());
5757
}
5858

59-
public function wrapStorage(Storage $storage) {
59+
public function wrapStorage(IStorage $storage): IStorage {
6060
return new SessionStorageWrapper(['storage' => $storage]);
6161
}
6262
}

apps/files_external/lib/Lib/StorageModifierTrait.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
namespace OCA\Files_External\Lib;
88

9-
use OCP\Files\Storage;
9+
use OCP\Files\Storage\IStorage;
1010
use OCP\Files\StorageNotAvailableException;
1111
use OCP\IUser;
1212

@@ -28,8 +28,8 @@ trait StorageModifierTrait {
2828
/**
2929
* Modify a StorageConfig parameters
3030
*
31-
* @param StorageConfig $storage
32-
* @param IUser $user User the storage is being used as
31+
* @param StorageConfig &$storage
32+
* @param ?IUser $user User the storage is being used as
3333
* @return void
3434
* @throws InsufficientDataForMeaningfulAnswerException
3535
* @throws StorageNotAvailableException
@@ -38,14 +38,12 @@ public function manipulateStorageConfig(StorageConfig &$storage, ?IUser $user =
3838
}
3939

4040
/**
41-
* Wrap a Storage if necessary
41+
* Wrap a storage if necessary
4242
*
43-
* @param Storage $storage
44-
* @return Storage
4543
* @throws InsufficientDataForMeaningfulAnswerException
4644
* @throws StorageNotAvailableException
4745
*/
48-
public function wrapStorage(Storage $storage) {
46+
public function wrapStorage(IStorage $storage): IStorage {
4947
return $storage;
5048
}
5149
}

apps/files_sharing/lib/External/Storage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public function getScanner($path = '', $storage = null) {
149149
if (!isset($this->scanner)) {
150150
$this->scanner = new Scanner($storage);
151151
}
152+
/** @var \OCA\Files_Sharing\External\Scanner */
152153
return $this->scanner;
153154
}
154155

0 commit comments

Comments
 (0)