@@ -22,39 +22,39 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | #[CoversClass(PreviewService::class)] |
| 24 | 24 | class PreviewServiceTest extends TestCase { |
| 25 | - private PreviewService $previewService; |
|
| 26 | - private PreviewMapper $previewMapper; |
|
| 27 | - |
|
| 28 | - protected function setUp(): void { |
|
| 29 | - $this->previewService = Server::get(PreviewService::class); |
|
| 30 | - $this->previewMapper = Server::get(PreviewMapper::class); |
|
| 31 | - $this->previewService->deleteAll(); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function tearDown(): void { |
|
| 35 | - $this->previewService->deleteAll(); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function testGetAvailableFileIds(): void { |
|
| 39 | - foreach (range(1, 20) as $i) { |
|
| 40 | - $preview = new Preview(); |
|
| 41 | - $preview->setFileId($i % 10); |
|
| 42 | - $preview->setStorageId(1); |
|
| 43 | - $preview->setWidth($i); |
|
| 44 | - $preview->setHeight($i); |
|
| 45 | - $preview->setMax(true); |
|
| 46 | - $preview->setSourceMimeType('image/jpeg'); |
|
| 47 | - $preview->setCropped(true); |
|
| 48 | - $preview->setEncrypted(false); |
|
| 49 | - $preview->setMimetype('image/jpeg'); |
|
| 50 | - $preview->setEtag('abc'); |
|
| 51 | - $preview->setMtime((new \DateTime())->getTimestamp()); |
|
| 52 | - $preview->setSize(0); |
|
| 53 | - $this->previewMapper->insert($preview); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $files = iterator_to_array($this->previewService->getAvailableFileIds()); |
|
| 57 | - $this->assertCount(1, $files); |
|
| 58 | - $this->assertCount(10, $files[0]['fileIds']); |
|
| 59 | - } |
|
| 25 | + private PreviewService $previewService; |
|
| 26 | + private PreviewMapper $previewMapper; |
|
| 27 | + |
|
| 28 | + protected function setUp(): void { |
|
| 29 | + $this->previewService = Server::get(PreviewService::class); |
|
| 30 | + $this->previewMapper = Server::get(PreviewMapper::class); |
|
| 31 | + $this->previewService->deleteAll(); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function tearDown(): void { |
|
| 35 | + $this->previewService->deleteAll(); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function testGetAvailableFileIds(): void { |
|
| 39 | + foreach (range(1, 20) as $i) { |
|
| 40 | + $preview = new Preview(); |
|
| 41 | + $preview->setFileId($i % 10); |
|
| 42 | + $preview->setStorageId(1); |
|
| 43 | + $preview->setWidth($i); |
|
| 44 | + $preview->setHeight($i); |
|
| 45 | + $preview->setMax(true); |
|
| 46 | + $preview->setSourceMimeType('image/jpeg'); |
|
| 47 | + $preview->setCropped(true); |
|
| 48 | + $preview->setEncrypted(false); |
|
| 49 | + $preview->setMimetype('image/jpeg'); |
|
| 50 | + $preview->setEtag('abc'); |
|
| 51 | + $preview->setMtime((new \DateTime())->getTimestamp()); |
|
| 52 | + $preview->setSize(0); |
|
| 53 | + $this->previewMapper->insert($preview); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $files = iterator_to_array($this->previewService->getAvailableFileIds()); |
|
| 57 | + $this->assertCount(1, $files); |
|
| 58 | + $this->assertCount(10, $files[0]['fileIds']); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -33,192 +33,192 @@ |
||
| 33 | 33 | * @group DB |
| 34 | 34 | */ |
| 35 | 35 | class MovePreviewJobTest extends TestCase { |
| 36 | - private IAppData $previewAppData; |
|
| 37 | - private PreviewMapper $previewMapper; |
|
| 38 | - private IAppConfig&MockObject $appConfig; |
|
| 39 | - private IConfig $config; |
|
| 40 | - private StorageFactory $storageFactory; |
|
| 41 | - private PreviewService $previewService; |
|
| 42 | - private IDBConnection $db; |
|
| 43 | - private IMimeTypeLoader&MockObject $mimeTypeLoader; |
|
| 44 | - private IMimeTypeDetector&MockObject $mimeTypeDetector; |
|
| 45 | - private LoggerInterface&MockObject $logger; |
|
| 46 | - |
|
| 47 | - public function setUp(): void { |
|
| 48 | - parent::setUp(); |
|
| 49 | - $this->previewAppData = Server::get(IAppDataFactory::class)->get('preview'); |
|
| 50 | - $this->previewMapper = Server::get(PreviewMapper::class); |
|
| 51 | - $this->config = Server::get(IConfig::class); |
|
| 52 | - $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 53 | - $this->appConfig->expects($this->any()) |
|
| 54 | - ->method('getValueBool') |
|
| 55 | - ->willReturn(false); |
|
| 56 | - $this->appConfig->expects($this->any()) |
|
| 57 | - ->method('setValueBool') |
|
| 58 | - ->willReturn(true); |
|
| 59 | - $this->storageFactory = Server::get(StorageFactory::class); |
|
| 60 | - $this->previewService = Server::get(PreviewService::class); |
|
| 61 | - $this->db = Server::get(IDBConnection::class); |
|
| 62 | - |
|
| 63 | - $qb = $this->db->getQueryBuilder(); |
|
| 64 | - $qb->delete('filecache') |
|
| 65 | - ->where($qb->expr()->eq('fileid', $qb->createNamedParameter(5))) |
|
| 66 | - ->executeStatement(); |
|
| 67 | - |
|
| 68 | - $qb = $this->db->getQueryBuilder(); |
|
| 69 | - $qb->insert('filecache') |
|
| 70 | - ->values([ |
|
| 71 | - 'fileid' => $qb->createNamedParameter(5), |
|
| 72 | - 'storage' => $qb->createNamedParameter(1), |
|
| 73 | - 'path' => $qb->createNamedParameter('test/abc'), |
|
| 74 | - 'path_hash' => $qb->createNamedParameter(md5('test')), |
|
| 75 | - 'parent' => $qb->createNamedParameter(0), |
|
| 76 | - 'name' => $qb->createNamedParameter('abc'), |
|
| 77 | - 'mimetype' => $qb->createNamedParameter(42), |
|
| 78 | - 'size' => $qb->createNamedParameter(1000), |
|
| 79 | - 'mtime' => $qb->createNamedParameter(1000), |
|
| 80 | - 'storage_mtime' => $qb->createNamedParameter(1000), |
|
| 81 | - 'encrypted' => $qb->createNamedParameter(0), |
|
| 82 | - 'unencrypted_size' => $qb->createNamedParameter(0), |
|
| 83 | - 'etag' => $qb->createNamedParameter('abcdefg'), |
|
| 84 | - 'permissions' => $qb->createNamedParameter(0), |
|
| 85 | - 'checksum' => $qb->createNamedParameter('abcdefg'), |
|
| 86 | - ])->executeStatement(); |
|
| 87 | - |
|
| 88 | - $this->mimeTypeDetector = $this->createMock(IMimeTypeDetector::class); |
|
| 89 | - $this->mimeTypeDetector->method('detectPath')->willReturn('image/png'); |
|
| 90 | - $this->mimeTypeLoader = $this->createMock(IMimeTypeLoader::class); |
|
| 91 | - $this->mimeTypeLoader->method('getId')->with('image/png')->willReturn(42); |
|
| 92 | - $this->mimeTypeLoader->method('getMimetypeById')->with(42)->willReturn('image/png'); |
|
| 93 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function tearDown(): void { |
|
| 97 | - foreach ($this->previewAppData->getDirectoryListing() as $folder) { |
|
| 98 | - $folder->delete(); |
|
| 99 | - } |
|
| 100 | - $this->previewService->deleteAll(); |
|
| 101 | - |
|
| 102 | - $qb = $this->db->getQueryBuilder(); |
|
| 103 | - $qb->delete('filecache') |
|
| 104 | - ->where($qb->expr()->eq('fileid', $qb->createNamedParameter(5))) |
|
| 105 | - ->executeStatement(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - #[TestDox('Test the migration from the legacy flat hierarchy to the new database format')] |
|
| 109 | - public function testMigrationLegacyPath(): void { |
|
| 110 | - $folder = $this->previewAppData->newFolder('5'); |
|
| 111 | - $folder->newFile('64-64-crop.jpg', 'abcdefg'); |
|
| 112 | - $folder->newFile('128-128-crop.png', 'abcdefg'); |
|
| 113 | - $this->assertEquals(1, count($this->previewAppData->getDirectoryListing())); |
|
| 114 | - $this->assertEquals(2, count($folder->getDirectoryListing())); |
|
| 115 | - $this->assertEquals(0, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 116 | - |
|
| 117 | - $job = new MovePreviewJob( |
|
| 118 | - Server::get(ITimeFactory::class), |
|
| 119 | - $this->appConfig, |
|
| 120 | - $this->config, |
|
| 121 | - $this->previewMapper, |
|
| 122 | - $this->storageFactory, |
|
| 123 | - Server::get(IDBConnection::class), |
|
| 124 | - Server::get(IRootFolder::class), |
|
| 125 | - $this->mimeTypeDetector, |
|
| 126 | - $this->mimeTypeLoader, |
|
| 127 | - $this->logger, |
|
| 128 | - Server::get(IAppDataFactory::class), |
|
| 129 | - ); |
|
| 130 | - $this->invokePrivate($job, 'run', [[]]); |
|
| 131 | - $this->assertEquals(0, count($this->previewAppData->getDirectoryListing())); |
|
| 132 | - $this->assertEquals(2, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - private static function getInternalFolder(string $name): string { |
|
| 136 | - return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - #[TestDox("Test the migration from the 'new' nested hierarchy to the database format")] |
|
| 140 | - public function testMigrationPath(): void { |
|
| 141 | - $folder = $this->previewAppData->newFolder(self::getInternalFolder((string)5)); |
|
| 142 | - $folder->newFile('64-64-crop.jpg', 'abcdefg'); |
|
| 143 | - $folder->newFile('128-128-crop.png', 'abcdefg'); |
|
| 144 | - |
|
| 145 | - $folder = $this->previewAppData->getFolder(self::getInternalFolder((string)5)); |
|
| 146 | - $this->assertEquals(2, count($folder->getDirectoryListing())); |
|
| 147 | - $this->assertEquals(0, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 148 | - |
|
| 149 | - $job = new MovePreviewJob( |
|
| 150 | - Server::get(ITimeFactory::class), |
|
| 151 | - $this->appConfig, |
|
| 152 | - $this->config, |
|
| 153 | - $this->previewMapper, |
|
| 154 | - $this->storageFactory, |
|
| 155 | - Server::get(IDBConnection::class), |
|
| 156 | - Server::get(IRootFolder::class), |
|
| 157 | - $this->mimeTypeDetector, |
|
| 158 | - $this->mimeTypeLoader, |
|
| 159 | - $this->logger, |
|
| 160 | - Server::get(IAppDataFactory::class) |
|
| 161 | - ); |
|
| 162 | - $this->invokePrivate($job, 'run', [[]]); |
|
| 163 | - $this->assertEquals(0, count($this->previewAppData->getDirectoryListing())); |
|
| 164 | - $this->assertEquals(2, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - #[TestDox("Test the migration from the 'new' nested hierarchy to the database format")] |
|
| 168 | - public function testMigrationPathWithVersion(): void { |
|
| 169 | - $folder = $this->previewAppData->newFolder(self::getInternalFolder((string)5)); |
|
| 170 | - // No version |
|
| 171 | - $folder->newFile('128-128-crop.png', 'abcdefg'); |
|
| 172 | - $folder->newFile('256-256-max.png', 'abcdefg'); |
|
| 173 | - $folder->newFile('128-128.png', 'abcdefg'); |
|
| 174 | - |
|
| 175 | - // Version 1000 |
|
| 176 | - $folder->newFile('1000-128-128-crop.png', 'abcdefg'); |
|
| 177 | - $folder->newFile('1000-256-256-max.png', 'abcdefg'); |
|
| 178 | - $folder->newFile('1000-128-128.png', 'abcdefg'); |
|
| 179 | - |
|
| 180 | - // Version 1001 |
|
| 181 | - $folder->newFile('1001-128-128-crop.png', 'abcdefg'); |
|
| 182 | - $folder->newFile('1001-256-256-max.png', 'abcdefg'); |
|
| 183 | - $folder->newFile('1001-128-128.png', 'abcdefg'); |
|
| 184 | - |
|
| 185 | - $folder = $this->previewAppData->getFolder(self::getInternalFolder((string)5)); |
|
| 186 | - $this->assertEquals(9, count($folder->getDirectoryListing())); |
|
| 187 | - $this->assertEquals(0, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 188 | - |
|
| 189 | - $job = new MovePreviewJob( |
|
| 190 | - Server::get(ITimeFactory::class), |
|
| 191 | - $this->appConfig, |
|
| 192 | - $this->config, |
|
| 193 | - $this->previewMapper, |
|
| 194 | - $this->storageFactory, |
|
| 195 | - Server::get(IDBConnection::class), |
|
| 196 | - Server::get(IRootFolder::class), |
|
| 197 | - $this->mimeTypeDetector, |
|
| 198 | - $this->mimeTypeLoader, |
|
| 199 | - $this->logger, |
|
| 200 | - Server::get(IAppDataFactory::class) |
|
| 201 | - ); |
|
| 202 | - $this->invokePrivate($job, 'run', [[]]); |
|
| 203 | - $previews = iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)); |
|
| 204 | - $this->assertEquals(9, count($previews)); |
|
| 205 | - $this->assertEquals(0, count($this->previewAppData->getDirectoryListing())); |
|
| 206 | - |
|
| 207 | - $nameVersionMapping = []; |
|
| 208 | - foreach ($previews as $preview) { |
|
| 209 | - $nameVersionMapping[$preview->getName($this->mimeTypeLoader)] = $preview->getVersion(); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $this->assertEquals([ |
|
| 213 | - '1000-128-128-crop.png' => 1000, |
|
| 214 | - '1000-128-128.png' => 1000, |
|
| 215 | - '1000-256-256-max.png' => 1000, |
|
| 216 | - '1001-128-128-crop.png' => 1001, |
|
| 217 | - '1001-128-128.png' => 1001, |
|
| 218 | - '1001-256-256-max.png' => 1001, |
|
| 219 | - '128-128-crop.png' => null, |
|
| 220 | - '128-128.png' => null, |
|
| 221 | - '256-256-max.png' => null, |
|
| 222 | - ], $nameVersionMapping); |
|
| 223 | - } |
|
| 36 | + private IAppData $previewAppData; |
|
| 37 | + private PreviewMapper $previewMapper; |
|
| 38 | + private IAppConfig&MockObject $appConfig; |
|
| 39 | + private IConfig $config; |
|
| 40 | + private StorageFactory $storageFactory; |
|
| 41 | + private PreviewService $previewService; |
|
| 42 | + private IDBConnection $db; |
|
| 43 | + private IMimeTypeLoader&MockObject $mimeTypeLoader; |
|
| 44 | + private IMimeTypeDetector&MockObject $mimeTypeDetector; |
|
| 45 | + private LoggerInterface&MockObject $logger; |
|
| 46 | + |
|
| 47 | + public function setUp(): void { |
|
| 48 | + parent::setUp(); |
|
| 49 | + $this->previewAppData = Server::get(IAppDataFactory::class)->get('preview'); |
|
| 50 | + $this->previewMapper = Server::get(PreviewMapper::class); |
|
| 51 | + $this->config = Server::get(IConfig::class); |
|
| 52 | + $this->appConfig = $this->createMock(IAppConfig::class); |
|
| 53 | + $this->appConfig->expects($this->any()) |
|
| 54 | + ->method('getValueBool') |
|
| 55 | + ->willReturn(false); |
|
| 56 | + $this->appConfig->expects($this->any()) |
|
| 57 | + ->method('setValueBool') |
|
| 58 | + ->willReturn(true); |
|
| 59 | + $this->storageFactory = Server::get(StorageFactory::class); |
|
| 60 | + $this->previewService = Server::get(PreviewService::class); |
|
| 61 | + $this->db = Server::get(IDBConnection::class); |
|
| 62 | + |
|
| 63 | + $qb = $this->db->getQueryBuilder(); |
|
| 64 | + $qb->delete('filecache') |
|
| 65 | + ->where($qb->expr()->eq('fileid', $qb->createNamedParameter(5))) |
|
| 66 | + ->executeStatement(); |
|
| 67 | + |
|
| 68 | + $qb = $this->db->getQueryBuilder(); |
|
| 69 | + $qb->insert('filecache') |
|
| 70 | + ->values([ |
|
| 71 | + 'fileid' => $qb->createNamedParameter(5), |
|
| 72 | + 'storage' => $qb->createNamedParameter(1), |
|
| 73 | + 'path' => $qb->createNamedParameter('test/abc'), |
|
| 74 | + 'path_hash' => $qb->createNamedParameter(md5('test')), |
|
| 75 | + 'parent' => $qb->createNamedParameter(0), |
|
| 76 | + 'name' => $qb->createNamedParameter('abc'), |
|
| 77 | + 'mimetype' => $qb->createNamedParameter(42), |
|
| 78 | + 'size' => $qb->createNamedParameter(1000), |
|
| 79 | + 'mtime' => $qb->createNamedParameter(1000), |
|
| 80 | + 'storage_mtime' => $qb->createNamedParameter(1000), |
|
| 81 | + 'encrypted' => $qb->createNamedParameter(0), |
|
| 82 | + 'unencrypted_size' => $qb->createNamedParameter(0), |
|
| 83 | + 'etag' => $qb->createNamedParameter('abcdefg'), |
|
| 84 | + 'permissions' => $qb->createNamedParameter(0), |
|
| 85 | + 'checksum' => $qb->createNamedParameter('abcdefg'), |
|
| 86 | + ])->executeStatement(); |
|
| 87 | + |
|
| 88 | + $this->mimeTypeDetector = $this->createMock(IMimeTypeDetector::class); |
|
| 89 | + $this->mimeTypeDetector->method('detectPath')->willReturn('image/png'); |
|
| 90 | + $this->mimeTypeLoader = $this->createMock(IMimeTypeLoader::class); |
|
| 91 | + $this->mimeTypeLoader->method('getId')->with('image/png')->willReturn(42); |
|
| 92 | + $this->mimeTypeLoader->method('getMimetypeById')->with(42)->willReturn('image/png'); |
|
| 93 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function tearDown(): void { |
|
| 97 | + foreach ($this->previewAppData->getDirectoryListing() as $folder) { |
|
| 98 | + $folder->delete(); |
|
| 99 | + } |
|
| 100 | + $this->previewService->deleteAll(); |
|
| 101 | + |
|
| 102 | + $qb = $this->db->getQueryBuilder(); |
|
| 103 | + $qb->delete('filecache') |
|
| 104 | + ->where($qb->expr()->eq('fileid', $qb->createNamedParameter(5))) |
|
| 105 | + ->executeStatement(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + #[TestDox('Test the migration from the legacy flat hierarchy to the new database format')] |
|
| 109 | + public function testMigrationLegacyPath(): void { |
|
| 110 | + $folder = $this->previewAppData->newFolder('5'); |
|
| 111 | + $folder->newFile('64-64-crop.jpg', 'abcdefg'); |
|
| 112 | + $folder->newFile('128-128-crop.png', 'abcdefg'); |
|
| 113 | + $this->assertEquals(1, count($this->previewAppData->getDirectoryListing())); |
|
| 114 | + $this->assertEquals(2, count($folder->getDirectoryListing())); |
|
| 115 | + $this->assertEquals(0, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 116 | + |
|
| 117 | + $job = new MovePreviewJob( |
|
| 118 | + Server::get(ITimeFactory::class), |
|
| 119 | + $this->appConfig, |
|
| 120 | + $this->config, |
|
| 121 | + $this->previewMapper, |
|
| 122 | + $this->storageFactory, |
|
| 123 | + Server::get(IDBConnection::class), |
|
| 124 | + Server::get(IRootFolder::class), |
|
| 125 | + $this->mimeTypeDetector, |
|
| 126 | + $this->mimeTypeLoader, |
|
| 127 | + $this->logger, |
|
| 128 | + Server::get(IAppDataFactory::class), |
|
| 129 | + ); |
|
| 130 | + $this->invokePrivate($job, 'run', [[]]); |
|
| 131 | + $this->assertEquals(0, count($this->previewAppData->getDirectoryListing())); |
|
| 132 | + $this->assertEquals(2, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + private static function getInternalFolder(string $name): string { |
|
| 136 | + return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + #[TestDox("Test the migration from the 'new' nested hierarchy to the database format")] |
|
| 140 | + public function testMigrationPath(): void { |
|
| 141 | + $folder = $this->previewAppData->newFolder(self::getInternalFolder((string)5)); |
|
| 142 | + $folder->newFile('64-64-crop.jpg', 'abcdefg'); |
|
| 143 | + $folder->newFile('128-128-crop.png', 'abcdefg'); |
|
| 144 | + |
|
| 145 | + $folder = $this->previewAppData->getFolder(self::getInternalFolder((string)5)); |
|
| 146 | + $this->assertEquals(2, count($folder->getDirectoryListing())); |
|
| 147 | + $this->assertEquals(0, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 148 | + |
|
| 149 | + $job = new MovePreviewJob( |
|
| 150 | + Server::get(ITimeFactory::class), |
|
| 151 | + $this->appConfig, |
|
| 152 | + $this->config, |
|
| 153 | + $this->previewMapper, |
|
| 154 | + $this->storageFactory, |
|
| 155 | + Server::get(IDBConnection::class), |
|
| 156 | + Server::get(IRootFolder::class), |
|
| 157 | + $this->mimeTypeDetector, |
|
| 158 | + $this->mimeTypeLoader, |
|
| 159 | + $this->logger, |
|
| 160 | + Server::get(IAppDataFactory::class) |
|
| 161 | + ); |
|
| 162 | + $this->invokePrivate($job, 'run', [[]]); |
|
| 163 | + $this->assertEquals(0, count($this->previewAppData->getDirectoryListing())); |
|
| 164 | + $this->assertEquals(2, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + #[TestDox("Test the migration from the 'new' nested hierarchy to the database format")] |
|
| 168 | + public function testMigrationPathWithVersion(): void { |
|
| 169 | + $folder = $this->previewAppData->newFolder(self::getInternalFolder((string)5)); |
|
| 170 | + // No version |
|
| 171 | + $folder->newFile('128-128-crop.png', 'abcdefg'); |
|
| 172 | + $folder->newFile('256-256-max.png', 'abcdefg'); |
|
| 173 | + $folder->newFile('128-128.png', 'abcdefg'); |
|
| 174 | + |
|
| 175 | + // Version 1000 |
|
| 176 | + $folder->newFile('1000-128-128-crop.png', 'abcdefg'); |
|
| 177 | + $folder->newFile('1000-256-256-max.png', 'abcdefg'); |
|
| 178 | + $folder->newFile('1000-128-128.png', 'abcdefg'); |
|
| 179 | + |
|
| 180 | + // Version 1001 |
|
| 181 | + $folder->newFile('1001-128-128-crop.png', 'abcdefg'); |
|
| 182 | + $folder->newFile('1001-256-256-max.png', 'abcdefg'); |
|
| 183 | + $folder->newFile('1001-128-128.png', 'abcdefg'); |
|
| 184 | + |
|
| 185 | + $folder = $this->previewAppData->getFolder(self::getInternalFolder((string)5)); |
|
| 186 | + $this->assertEquals(9, count($folder->getDirectoryListing())); |
|
| 187 | + $this->assertEquals(0, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
|
| 188 | + |
|
| 189 | + $job = new MovePreviewJob( |
|
| 190 | + Server::get(ITimeFactory::class), |
|
| 191 | + $this->appConfig, |
|
| 192 | + $this->config, |
|
| 193 | + $this->previewMapper, |
|
| 194 | + $this->storageFactory, |
|
| 195 | + Server::get(IDBConnection::class), |
|
| 196 | + Server::get(IRootFolder::class), |
|
| 197 | + $this->mimeTypeDetector, |
|
| 198 | + $this->mimeTypeLoader, |
|
| 199 | + $this->logger, |
|
| 200 | + Server::get(IAppDataFactory::class) |
|
| 201 | + ); |
|
| 202 | + $this->invokePrivate($job, 'run', [[]]); |
|
| 203 | + $previews = iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)); |
|
| 204 | + $this->assertEquals(9, count($previews)); |
|
| 205 | + $this->assertEquals(0, count($this->previewAppData->getDirectoryListing())); |
|
| 206 | + |
|
| 207 | + $nameVersionMapping = []; |
|
| 208 | + foreach ($previews as $preview) { |
|
| 209 | + $nameVersionMapping[$preview->getName($this->mimeTypeLoader)] = $preview->getVersion(); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $this->assertEquals([ |
|
| 213 | + '1000-128-128-crop.png' => 1000, |
|
| 214 | + '1000-128-128.png' => 1000, |
|
| 215 | + '1000-256-256-max.png' => 1000, |
|
| 216 | + '1001-128-128-crop.png' => 1001, |
|
| 217 | + '1001-128-128.png' => 1001, |
|
| 218 | + '1001-256-256-max.png' => 1001, |
|
| 219 | + '128-128-crop.png' => null, |
|
| 220 | + '128-128.png' => null, |
|
| 221 | + '256-256-max.png' => null, |
|
| 222 | + ], $nameVersionMapping); |
|
| 223 | + } |
|
| 224 | 224 | } |
@@ -133,16 +133,16 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | private static function getInternalFolder(string $name): string { |
| 136 | - return implode('/', str_split(substr(md5($name), 0, 7))) . '/' . $name; |
|
| 136 | + return implode('/', str_split(substr(md5($name), 0, 7))).'/'.$name; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | #[TestDox("Test the migration from the 'new' nested hierarchy to the database format")] |
| 140 | 140 | public function testMigrationPath(): void { |
| 141 | - $folder = $this->previewAppData->newFolder(self::getInternalFolder((string)5)); |
|
| 141 | + $folder = $this->previewAppData->newFolder(self::getInternalFolder((string) 5)); |
|
| 142 | 142 | $folder->newFile('64-64-crop.jpg', 'abcdefg'); |
| 143 | 143 | $folder->newFile('128-128-crop.png', 'abcdefg'); |
| 144 | 144 | |
| 145 | - $folder = $this->previewAppData->getFolder(self::getInternalFolder((string)5)); |
|
| 145 | + $folder = $this->previewAppData->getFolder(self::getInternalFolder((string) 5)); |
|
| 146 | 146 | $this->assertEquals(2, count($folder->getDirectoryListing())); |
| 147 | 147 | $this->assertEquals(0, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
| 148 | 148 | |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | #[TestDox("Test the migration from the 'new' nested hierarchy to the database format")] |
| 168 | 168 | public function testMigrationPathWithVersion(): void { |
| 169 | - $folder = $this->previewAppData->newFolder(self::getInternalFolder((string)5)); |
|
| 169 | + $folder = $this->previewAppData->newFolder(self::getInternalFolder((string) 5)); |
|
| 170 | 170 | // No version |
| 171 | 171 | $folder->newFile('128-128-crop.png', 'abcdefg'); |
| 172 | 172 | $folder->newFile('256-256-max.png', 'abcdefg'); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $folder->newFile('1001-256-256-max.png', 'abcdefg'); |
| 183 | 183 | $folder->newFile('1001-128-128.png', 'abcdefg'); |
| 184 | 184 | |
| 185 | - $folder = $this->previewAppData->getFolder(self::getInternalFolder((string)5)); |
|
| 185 | + $folder = $this->previewAppData->getFolder(self::getInternalFolder((string) 5)); |
|
| 186 | 186 | $this->assertEquals(9, count($folder->getDirectoryListing())); |
| 187 | 187 | $this->assertEquals(0, count(iterator_to_array($this->previewMapper->getAvailablePreviewsForFile(5)))); |
| 188 | 188 | |
@@ -33,429 +33,429 @@ |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | class GeneratorTest extends TestCase { |
| 36 | - private IConfig&MockObject $config; |
|
| 37 | - private IPreview&MockObject $previewManager; |
|
| 38 | - private GeneratorHelper&MockObject $helper; |
|
| 39 | - private IEventDispatcher&MockObject $eventDispatcher; |
|
| 40 | - private Generator $generator; |
|
| 41 | - private LoggerInterface&MockObject $logger; |
|
| 42 | - private StorageFactory&MockObject $storageFactory; |
|
| 43 | - private PreviewMapper&MockObject $previewMapper; |
|
| 44 | - |
|
| 45 | - protected function setUp(): void { |
|
| 46 | - parent::setUp(); |
|
| 47 | - |
|
| 48 | - $this->config = $this->createMock(IConfig::class); |
|
| 49 | - $this->previewManager = $this->createMock(IPreview::class); |
|
| 50 | - $this->helper = $this->createMock(GeneratorHelper::class); |
|
| 51 | - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
| 52 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 53 | - $this->previewMapper = $this->createMock(PreviewMapper::class); |
|
| 54 | - $this->storageFactory = $this->createMock(StorageFactory::class); |
|
| 55 | - |
|
| 56 | - $this->generator = new Generator( |
|
| 57 | - $this->config, |
|
| 58 | - $this->previewManager, |
|
| 59 | - $this->helper, |
|
| 60 | - $this->eventDispatcher, |
|
| 61 | - $this->logger, |
|
| 62 | - $this->previewMapper, |
|
| 63 | - $this->storageFactory, |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - private function getFile(int $fileId, string $mimeType, bool $hasVersion = false): File { |
|
| 68 | - $mountPoint = $this->createMock(IMountPoint::class); |
|
| 69 | - $mountPoint->method('getNumericStorageId')->willReturn(42); |
|
| 70 | - if ($hasVersion) { |
|
| 71 | - $file = $this->createMock(VersionedPreviewFile::class); |
|
| 72 | - $file->method('getPreviewVersion')->willReturn('abc'); |
|
| 73 | - } else { |
|
| 74 | - $file = $this->createMock(File::class); |
|
| 75 | - } |
|
| 76 | - $file->method('isReadable') |
|
| 77 | - ->willReturn(true); |
|
| 78 | - $file->method('getMimeType') |
|
| 79 | - ->willReturn($mimeType); |
|
| 80 | - $file->method('getId') |
|
| 81 | - ->willReturn($fileId); |
|
| 82 | - $file->method('getMountPoint') |
|
| 83 | - ->willReturn($mountPoint); |
|
| 84 | - return $file; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - #[TestWith([true])] |
|
| 88 | - #[TestWith([false])] |
|
| 89 | - public function testGetCachedPreview(bool $hasPreview): void { |
|
| 90 | - $file = $this->getFile(42, 'myMimeType', $hasPreview); |
|
| 91 | - |
|
| 92 | - $this->previewManager->method('isMimeSupported') |
|
| 93 | - ->with($this->equalTo('myMimeType')) |
|
| 94 | - ->willReturn(true); |
|
| 95 | - |
|
| 96 | - $maxPreview = new Preview(); |
|
| 97 | - $maxPreview->setWidth(1000); |
|
| 98 | - $maxPreview->setHeight(1000); |
|
| 99 | - $maxPreview->setMax(true); |
|
| 100 | - $maxPreview->setSize(1000); |
|
| 101 | - $maxPreview->setCropped(false); |
|
| 102 | - $maxPreview->setStorageId(1); |
|
| 103 | - $maxPreview->setVersion($hasPreview ? 'abc' : null); |
|
| 104 | - $maxPreview->setMimeType('image/png'); |
|
| 105 | - |
|
| 106 | - $previewFile = new Preview(); |
|
| 107 | - $previewFile->setWidth(256); |
|
| 108 | - $previewFile->setHeight(256); |
|
| 109 | - $previewFile->setMax(false); |
|
| 110 | - $previewFile->setSize(1000); |
|
| 111 | - $previewFile->setVersion($hasPreview ? 'abc' : null); |
|
| 112 | - $previewFile->setCropped(false); |
|
| 113 | - $previewFile->setStorageId(1); |
|
| 114 | - $previewFile->setMimeType('image/png'); |
|
| 115 | - |
|
| 116 | - $this->previewMapper->method('getAvailablePreviews') |
|
| 117 | - ->with($this->equalTo([42])) |
|
| 118 | - ->willReturn([42 => [ |
|
| 119 | - $maxPreview, |
|
| 120 | - $previewFile, |
|
| 121 | - ]]); |
|
| 122 | - |
|
| 123 | - $this->eventDispatcher->expects($this->once()) |
|
| 124 | - ->method('dispatchTyped') |
|
| 125 | - ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); |
|
| 126 | - |
|
| 127 | - $result = $this->generator->getPreview($file, 100, 100); |
|
| 128 | - $this->assertSame($hasPreview ? 'abc-256-256.png' : '256-256.png', $result->getName()); |
|
| 129 | - $this->assertSame(1000, $result->getSize()); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - #[TestWith([true])] |
|
| 133 | - #[TestWith([false])] |
|
| 134 | - public function testGetNewPreview(bool $hasVersion): void { |
|
| 135 | - $file = $this->getFile(42, 'myMimeType', $hasVersion); |
|
| 136 | - |
|
| 137 | - $this->previewManager->method('isMimeSupported') |
|
| 138 | - ->with($this->equalTo('myMimeType')) |
|
| 139 | - ->willReturn(true); |
|
| 140 | - |
|
| 141 | - $this->previewMapper->method('getAvailablePreviews') |
|
| 142 | - ->with($this->equalTo([42])) |
|
| 143 | - ->willReturn([42 => []]); |
|
| 144 | - |
|
| 145 | - $this->config->method('getSystemValueString') |
|
| 146 | - ->willReturnCallback(function ($key, $default) { |
|
| 147 | - return $default; |
|
| 148 | - }); |
|
| 149 | - |
|
| 150 | - $this->config->method('getSystemValueInt') |
|
| 151 | - ->willReturnCallback(function ($key, $default) { |
|
| 152 | - return $default; |
|
| 153 | - }); |
|
| 154 | - |
|
| 155 | - $invalidProvider = $this->createMock(IProviderV2::class); |
|
| 156 | - $invalidProvider->method('isAvailable') |
|
| 157 | - ->willReturn(true); |
|
| 158 | - $unavailableProvider = $this->createMock(IProviderV2::class); |
|
| 159 | - $unavailableProvider->method('isAvailable') |
|
| 160 | - ->willReturn(false); |
|
| 161 | - $validProvider = $this->createMock(IProviderV2::class); |
|
| 162 | - $validProvider->method('isAvailable') |
|
| 163 | - ->with($file) |
|
| 164 | - ->willReturn(true); |
|
| 165 | - |
|
| 166 | - $this->previewManager->method('getProviders') |
|
| 167 | - ->willReturn([ |
|
| 168 | - '/image\/png/' => ['wrongProvider'], |
|
| 169 | - '/myMimeType/' => ['brokenProvider', 'invalidProvider', 'unavailableProvider', 'validProvider'], |
|
| 170 | - ]); |
|
| 171 | - |
|
| 172 | - $this->helper->method('getProvider') |
|
| 173 | - ->willReturnCallback(function ($provider) use ($invalidProvider, $validProvider, $unavailableProvider) { |
|
| 174 | - if ($provider === 'wrongProvider') { |
|
| 175 | - $this->fail('Wrongprovider should not be constructed!'); |
|
| 176 | - } elseif ($provider === 'brokenProvider') { |
|
| 177 | - return false; |
|
| 178 | - } elseif ($provider === 'invalidProvider') { |
|
| 179 | - return $invalidProvider; |
|
| 180 | - } elseif ($provider === 'validProvider') { |
|
| 181 | - return $validProvider; |
|
| 182 | - } elseif ($provider === 'unavailableProvider') { |
|
| 183 | - return $unavailableProvider; |
|
| 184 | - } |
|
| 185 | - $this->fail('Unexpected provider requested'); |
|
| 186 | - }); |
|
| 187 | - |
|
| 188 | - $image = $this->createMock(IImage::class); |
|
| 189 | - $image->method('width')->willReturn(2048); |
|
| 190 | - $image->method('height')->willReturn(2048); |
|
| 191 | - $image->method('valid')->willReturn(true); |
|
| 192 | - $image->method('dataMimeType')->willReturn('image/png'); |
|
| 193 | - |
|
| 194 | - $this->helper->method('getThumbnail') |
|
| 195 | - ->willReturnCallback(function ($provider, $file, $x, $y) use ($invalidProvider, $validProvider, $image): false|IImage { |
|
| 196 | - if ($provider === $validProvider) { |
|
| 197 | - return $image; |
|
| 198 | - } else { |
|
| 199 | - return false; |
|
| 200 | - } |
|
| 201 | - }); |
|
| 202 | - |
|
| 203 | - $image->method('data') |
|
| 204 | - ->willReturn('my data'); |
|
| 205 | - |
|
| 206 | - $this->previewMapper->method('insert') |
|
| 207 | - ->willReturnCallback(fn (Preview $preview): Preview => $preview); |
|
| 208 | - |
|
| 209 | - $this->previewMapper->method('update') |
|
| 210 | - ->willReturnCallback(fn (Preview $preview): Preview => $preview); |
|
| 211 | - |
|
| 212 | - $this->storageFactory->method('writePreview') |
|
| 213 | - ->willReturnCallback(function (Preview $preview, mixed $data) use ($hasVersion): int { |
|
| 214 | - $data = stream_get_contents($data); |
|
| 215 | - if ($hasVersion) { |
|
| 216 | - switch ($preview->getName()) { |
|
| 217 | - case 'abc-2048-2048-max.png': |
|
| 218 | - $this->assertSame('my data', $data); |
|
| 219 | - return 1000; |
|
| 220 | - case 'abc-256-256.png': |
|
| 221 | - $this->assertSame('my resized data', $data); |
|
| 222 | - return 1000; |
|
| 223 | - } |
|
| 224 | - } else { |
|
| 225 | - switch ($preview->getName()) { |
|
| 226 | - case '2048-2048-max.png': |
|
| 227 | - $this->assertSame('my data', $data); |
|
| 228 | - return 1000; |
|
| 229 | - case '256-256.png': |
|
| 230 | - $this->assertSame('my resized data', $data); |
|
| 231 | - return 1000; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - $this->fail('file name is wrong:' . $preview->getName()); |
|
| 235 | - }); |
|
| 236 | - |
|
| 237 | - $image = $this->getMockImage(2048, 2048, 'my resized data'); |
|
| 238 | - $this->helper->method('getImage') |
|
| 239 | - ->willReturn($image); |
|
| 240 | - |
|
| 241 | - $this->eventDispatcher->expects($this->once()) |
|
| 242 | - ->method('dispatchTyped') |
|
| 243 | - ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); |
|
| 244 | - |
|
| 245 | - $result = $this->generator->getPreview($file, 100, 100); |
|
| 246 | - $this->assertSame($hasVersion ? 'abc-256-256.png' : '256-256.png', $result->getName()); |
|
| 247 | - $this->assertSame(1000, $result->getSize()); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function testInvalidMimeType(): void { |
|
| 251 | - $this->expectException(NotFoundException::class); |
|
| 252 | - |
|
| 253 | - $file = $this->getFile(42, 'invalidType'); |
|
| 254 | - |
|
| 255 | - $this->previewManager->method('isMimeSupported') |
|
| 256 | - ->with('invalidType') |
|
| 257 | - ->willReturn(false); |
|
| 258 | - |
|
| 259 | - $maxPreview = new Preview(); |
|
| 260 | - $maxPreview->setWidth(2048); |
|
| 261 | - $maxPreview->setHeight(2048); |
|
| 262 | - $maxPreview->setMax(true); |
|
| 263 | - $maxPreview->setSize(1000); |
|
| 264 | - $maxPreview->setVersion(null); |
|
| 265 | - $maxPreview->setMimetype('image/png'); |
|
| 266 | - |
|
| 267 | - $this->previewMapper->method('getAvailablePreviews') |
|
| 268 | - ->with($this->equalTo([42])) |
|
| 269 | - ->willReturn([42 => [ |
|
| 270 | - $maxPreview, |
|
| 271 | - ]]); |
|
| 272 | - |
|
| 273 | - $this->eventDispatcher->expects($this->once()) |
|
| 274 | - ->method('dispatchTyped') |
|
| 275 | - ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType')); |
|
| 276 | - |
|
| 277 | - $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - public function testReturnCachedPreviewsWithoutCheckingSupportedMimetype(): void { |
|
| 281 | - $file = $this->getFile(42, 'myMimeType'); |
|
| 282 | - |
|
| 283 | - $maxPreview = new Preview(); |
|
| 284 | - $maxPreview->setWidth(2048); |
|
| 285 | - $maxPreview->setHeight(2048); |
|
| 286 | - $maxPreview->setMax(true); |
|
| 287 | - $maxPreview->setSize(1000); |
|
| 288 | - $maxPreview->setVersion(null); |
|
| 289 | - $maxPreview->setMimeType('image/png'); |
|
| 290 | - |
|
| 291 | - $previewFile = new Preview(); |
|
| 292 | - $previewFile->setWidth(1024); |
|
| 293 | - $previewFile->setHeight(512); |
|
| 294 | - $previewFile->setMax(false); |
|
| 295 | - $previewFile->setSize(1000); |
|
| 296 | - $previewFile->setCropped(true); |
|
| 297 | - $previewFile->setVersion(null); |
|
| 298 | - $previewFile->setMimeType('image/png'); |
|
| 299 | - |
|
| 300 | - $this->previewMapper->method('getAvailablePreviews') |
|
| 301 | - ->with($this->equalTo([42])) |
|
| 302 | - ->willReturn([42 => [ |
|
| 303 | - $maxPreview, |
|
| 304 | - $previewFile, |
|
| 305 | - ]]); |
|
| 306 | - |
|
| 307 | - $this->previewManager->expects($this->never()) |
|
| 308 | - ->method('isMimeSupported'); |
|
| 309 | - |
|
| 310 | - $this->eventDispatcher->expects($this->once()) |
|
| 311 | - ->method('dispatchTyped') |
|
| 312 | - ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType')); |
|
| 313 | - |
|
| 314 | - $result = $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); |
|
| 315 | - $this->assertSame('1024-512-crop.png', $result->getName()); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - public function testNoProvider(): void { |
|
| 319 | - $file = $this->getFile(42, 'myMimeType'); |
|
| 320 | - |
|
| 321 | - $this->previewMapper->method('getAvailablePreviews') |
|
| 322 | - ->with($this->equalTo([42])) |
|
| 323 | - ->willReturn([42 => []]); |
|
| 324 | - |
|
| 325 | - $this->previewManager->method('getProviders') |
|
| 326 | - ->willReturn([]); |
|
| 327 | - |
|
| 328 | - $this->eventDispatcher->expects($this->once()) |
|
| 329 | - ->method('dispatchTyped') |
|
| 330 | - ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); |
|
| 331 | - |
|
| 332 | - $this->expectException(NotFoundException::class); |
|
| 333 | - $this->generator->getPreview($file, 100, 100); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - private function getMockImage(int $width, int $height, string $data = '') { |
|
| 337 | - $image = $this->createMock(IImage::class); |
|
| 338 | - $image->method('height')->willReturn($width); |
|
| 339 | - $image->method('width')->willReturn($height); |
|
| 340 | - $image->method('valid')->willReturn(true); |
|
| 341 | - $image->method('dataMimeType')->willReturn('image/png'); |
|
| 342 | - $image->method('data')->willReturn($data); |
|
| 343 | - |
|
| 344 | - $image->method('resizeCopy')->willReturnCallback(function ($size) use ($data) { |
|
| 345 | - return $this->getMockImage($size, $size, $data); |
|
| 346 | - }); |
|
| 347 | - $image->method('preciseResizeCopy')->willReturnCallback(function ($width, $height) use ($data) { |
|
| 348 | - return $this->getMockImage($width, $height, $data); |
|
| 349 | - }); |
|
| 350 | - $image->method('cropCopy')->willReturnCallback(function ($x, $y, $width, $height) use ($data) { |
|
| 351 | - return $this->getMockImage($width, $height, $data); |
|
| 352 | - }); |
|
| 353 | - |
|
| 354 | - return $image; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - public static function dataSize(): array { |
|
| 358 | - return [ |
|
| 359 | - [1024, 2048, 512, 512, false, IPreview::MODE_FILL, 256, 512], |
|
| 360 | - [1024, 2048, 512, 512, false, IPreview::MODE_COVER, 512, 1024], |
|
| 361 | - [1024, 2048, 512, 512, true, IPreview::MODE_FILL, 1024, 1024], |
|
| 362 | - [1024, 2048, 512, 512, true, IPreview::MODE_COVER, 1024, 1024], |
|
| 363 | - |
|
| 364 | - [1024, 2048, -1, 512, false, IPreview::MODE_COVER, 256, 512], |
|
| 365 | - [1024, 2048, 512, -1, false, IPreview::MODE_FILL, 512, 1024], |
|
| 366 | - |
|
| 367 | - [1024, 2048, 250, 1100, true, IPreview::MODE_COVER, 256, 1126], |
|
| 368 | - [1024, 1100, 250, 1100, true, IPreview::MODE_COVER, 250, 1100], |
|
| 369 | - |
|
| 370 | - [1024, 2048, 4096, 2048, false, IPreview::MODE_FILL, 1024, 2048], |
|
| 371 | - [1024, 2048, 4096, 2048, false, IPreview::MODE_COVER, 1024, 2048], |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - [2048, 1024, 512, 512, false, IPreview::MODE_FILL, 512, 256], |
|
| 375 | - [2048, 1024, 512, 512, false, IPreview::MODE_COVER, 1024, 512], |
|
| 376 | - [2048, 1024, 512, 512, true, IPreview::MODE_FILL, 1024, 1024], |
|
| 377 | - [2048, 1024, 512, 512, true, IPreview::MODE_COVER, 1024, 1024], |
|
| 378 | - |
|
| 379 | - [2048, 1024, -1, 512, false, IPreview::MODE_FILL, 1024, 512], |
|
| 380 | - [2048, 1024, 512, -1, false, IPreview::MODE_COVER, 512, 256], |
|
| 381 | - |
|
| 382 | - [2048, 1024, 4096, 1024, true, IPreview::MODE_FILL, 2048, 512], |
|
| 383 | - [2048, 1024, 4096, 1024, true, IPreview::MODE_COVER, 2048, 512], |
|
| 384 | - |
|
| 385 | - //Test minimum size |
|
| 386 | - [2048, 1024, 32, 32, false, IPreview::MODE_FILL, 64, 32], |
|
| 387 | - [2048, 1024, 32, 32, false, IPreview::MODE_COVER, 64, 32], |
|
| 388 | - [2048, 1024, 32, 32, true, IPreview::MODE_FILL, 64, 64], |
|
| 389 | - [2048, 1024, 32, 32, true, IPreview::MODE_COVER, 64, 64], |
|
| 390 | - ]; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - #[DataProvider('dataSize')] |
|
| 394 | - public function testCorrectSize(int $maxX, int $maxY, int $reqX, int $reqY, bool $crop, string $mode, int $expectedX, int $expectedY): void { |
|
| 395 | - $file = $this->getFile(42, 'myMimeType'); |
|
| 396 | - |
|
| 397 | - $this->previewManager->method('isMimeSupported') |
|
| 398 | - ->with($this->equalTo('myMimeType')) |
|
| 399 | - ->willReturn(true); |
|
| 400 | - |
|
| 401 | - $maxPreview = new Preview(); |
|
| 402 | - $maxPreview->setWidth($maxX); |
|
| 403 | - $maxPreview->setHeight($maxY); |
|
| 404 | - $maxPreview->setMax(true); |
|
| 405 | - $maxPreview->setSize(1000); |
|
| 406 | - $maxPreview->setVersion(null); |
|
| 407 | - $maxPreview->setMimeType('image/png'); |
|
| 408 | - |
|
| 409 | - $this->assertSame($maxPreview->getName(), $maxX . '-' . $maxY . '-max.png'); |
|
| 410 | - $this->assertSame($maxPreview->getMimeType(), 'image/png'); |
|
| 411 | - |
|
| 412 | - $this->previewMapper->method('getAvailablePreviews') |
|
| 413 | - ->with($this->equalTo([42])) |
|
| 414 | - ->willReturn([42 => [ |
|
| 415 | - $maxPreview, |
|
| 416 | - ]]); |
|
| 417 | - |
|
| 418 | - $filename = $expectedX . '-' . $expectedY; |
|
| 419 | - if ($crop) { |
|
| 420 | - $filename .= '-crop'; |
|
| 421 | - } |
|
| 422 | - $filename .= '.png'; |
|
| 423 | - |
|
| 424 | - $image = $this->getMockImage($maxX, $maxY); |
|
| 425 | - $this->helper->method('getImage') |
|
| 426 | - ->willReturn($image); |
|
| 427 | - |
|
| 428 | - $this->previewMapper->method('insert') |
|
| 429 | - ->willReturnCallback(function (Preview $preview) use ($filename): Preview { |
|
| 430 | - $this->assertSame($preview->getName(), $filename); |
|
| 431 | - return $preview; |
|
| 432 | - }); |
|
| 433 | - |
|
| 434 | - $this->previewMapper->method('update') |
|
| 435 | - ->willReturnCallback(fn (Preview $preview): Preview => $preview); |
|
| 436 | - |
|
| 437 | - $this->storageFactory->method('writePreview') |
|
| 438 | - ->willReturn(1000); |
|
| 439 | - |
|
| 440 | - $this->eventDispatcher->expects($this->once()) |
|
| 441 | - ->method('dispatchTyped') |
|
| 442 | - ->with(new BeforePreviewFetchedEvent($file, $reqX, $reqY, $crop, $mode, null)); |
|
| 443 | - |
|
| 444 | - $result = $this->generator->getPreview($file, $reqX, $reqY, $crop, $mode); |
|
| 445 | - if ($expectedX === $maxX && $expectedY === $maxY) { |
|
| 446 | - $this->assertSame($maxPreview->getName(), $result->getName()); |
|
| 447 | - } else { |
|
| 448 | - $this->assertSame($filename, $result->getName()); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - public function testUnreadbleFile(): void { |
|
| 453 | - $file = $this->createMock(File::class); |
|
| 454 | - $file->method('isReadable') |
|
| 455 | - ->willReturn(false); |
|
| 456 | - |
|
| 457 | - $this->expectException(NotFoundException::class); |
|
| 458 | - |
|
| 459 | - $this->generator->getPreview($file, 100, 100, false); |
|
| 460 | - } |
|
| 36 | + private IConfig&MockObject $config; |
|
| 37 | + private IPreview&MockObject $previewManager; |
|
| 38 | + private GeneratorHelper&MockObject $helper; |
|
| 39 | + private IEventDispatcher&MockObject $eventDispatcher; |
|
| 40 | + private Generator $generator; |
|
| 41 | + private LoggerInterface&MockObject $logger; |
|
| 42 | + private StorageFactory&MockObject $storageFactory; |
|
| 43 | + private PreviewMapper&MockObject $previewMapper; |
|
| 44 | + |
|
| 45 | + protected function setUp(): void { |
|
| 46 | + parent::setUp(); |
|
| 47 | + |
|
| 48 | + $this->config = $this->createMock(IConfig::class); |
|
| 49 | + $this->previewManager = $this->createMock(IPreview::class); |
|
| 50 | + $this->helper = $this->createMock(GeneratorHelper::class); |
|
| 51 | + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); |
|
| 52 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 53 | + $this->previewMapper = $this->createMock(PreviewMapper::class); |
|
| 54 | + $this->storageFactory = $this->createMock(StorageFactory::class); |
|
| 55 | + |
|
| 56 | + $this->generator = new Generator( |
|
| 57 | + $this->config, |
|
| 58 | + $this->previewManager, |
|
| 59 | + $this->helper, |
|
| 60 | + $this->eventDispatcher, |
|
| 61 | + $this->logger, |
|
| 62 | + $this->previewMapper, |
|
| 63 | + $this->storageFactory, |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + private function getFile(int $fileId, string $mimeType, bool $hasVersion = false): File { |
|
| 68 | + $mountPoint = $this->createMock(IMountPoint::class); |
|
| 69 | + $mountPoint->method('getNumericStorageId')->willReturn(42); |
|
| 70 | + if ($hasVersion) { |
|
| 71 | + $file = $this->createMock(VersionedPreviewFile::class); |
|
| 72 | + $file->method('getPreviewVersion')->willReturn('abc'); |
|
| 73 | + } else { |
|
| 74 | + $file = $this->createMock(File::class); |
|
| 75 | + } |
|
| 76 | + $file->method('isReadable') |
|
| 77 | + ->willReturn(true); |
|
| 78 | + $file->method('getMimeType') |
|
| 79 | + ->willReturn($mimeType); |
|
| 80 | + $file->method('getId') |
|
| 81 | + ->willReturn($fileId); |
|
| 82 | + $file->method('getMountPoint') |
|
| 83 | + ->willReturn($mountPoint); |
|
| 84 | + return $file; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + #[TestWith([true])] |
|
| 88 | + #[TestWith([false])] |
|
| 89 | + public function testGetCachedPreview(bool $hasPreview): void { |
|
| 90 | + $file = $this->getFile(42, 'myMimeType', $hasPreview); |
|
| 91 | + |
|
| 92 | + $this->previewManager->method('isMimeSupported') |
|
| 93 | + ->with($this->equalTo('myMimeType')) |
|
| 94 | + ->willReturn(true); |
|
| 95 | + |
|
| 96 | + $maxPreview = new Preview(); |
|
| 97 | + $maxPreview->setWidth(1000); |
|
| 98 | + $maxPreview->setHeight(1000); |
|
| 99 | + $maxPreview->setMax(true); |
|
| 100 | + $maxPreview->setSize(1000); |
|
| 101 | + $maxPreview->setCropped(false); |
|
| 102 | + $maxPreview->setStorageId(1); |
|
| 103 | + $maxPreview->setVersion($hasPreview ? 'abc' : null); |
|
| 104 | + $maxPreview->setMimeType('image/png'); |
|
| 105 | + |
|
| 106 | + $previewFile = new Preview(); |
|
| 107 | + $previewFile->setWidth(256); |
|
| 108 | + $previewFile->setHeight(256); |
|
| 109 | + $previewFile->setMax(false); |
|
| 110 | + $previewFile->setSize(1000); |
|
| 111 | + $previewFile->setVersion($hasPreview ? 'abc' : null); |
|
| 112 | + $previewFile->setCropped(false); |
|
| 113 | + $previewFile->setStorageId(1); |
|
| 114 | + $previewFile->setMimeType('image/png'); |
|
| 115 | + |
|
| 116 | + $this->previewMapper->method('getAvailablePreviews') |
|
| 117 | + ->with($this->equalTo([42])) |
|
| 118 | + ->willReturn([42 => [ |
|
| 119 | + $maxPreview, |
|
| 120 | + $previewFile, |
|
| 121 | + ]]); |
|
| 122 | + |
|
| 123 | + $this->eventDispatcher->expects($this->once()) |
|
| 124 | + ->method('dispatchTyped') |
|
| 125 | + ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); |
|
| 126 | + |
|
| 127 | + $result = $this->generator->getPreview($file, 100, 100); |
|
| 128 | + $this->assertSame($hasPreview ? 'abc-256-256.png' : '256-256.png', $result->getName()); |
|
| 129 | + $this->assertSame(1000, $result->getSize()); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + #[TestWith([true])] |
|
| 133 | + #[TestWith([false])] |
|
| 134 | + public function testGetNewPreview(bool $hasVersion): void { |
|
| 135 | + $file = $this->getFile(42, 'myMimeType', $hasVersion); |
|
| 136 | + |
|
| 137 | + $this->previewManager->method('isMimeSupported') |
|
| 138 | + ->with($this->equalTo('myMimeType')) |
|
| 139 | + ->willReturn(true); |
|
| 140 | + |
|
| 141 | + $this->previewMapper->method('getAvailablePreviews') |
|
| 142 | + ->with($this->equalTo([42])) |
|
| 143 | + ->willReturn([42 => []]); |
|
| 144 | + |
|
| 145 | + $this->config->method('getSystemValueString') |
|
| 146 | + ->willReturnCallback(function ($key, $default) { |
|
| 147 | + return $default; |
|
| 148 | + }); |
|
| 149 | + |
|
| 150 | + $this->config->method('getSystemValueInt') |
|
| 151 | + ->willReturnCallback(function ($key, $default) { |
|
| 152 | + return $default; |
|
| 153 | + }); |
|
| 154 | + |
|
| 155 | + $invalidProvider = $this->createMock(IProviderV2::class); |
|
| 156 | + $invalidProvider->method('isAvailable') |
|
| 157 | + ->willReturn(true); |
|
| 158 | + $unavailableProvider = $this->createMock(IProviderV2::class); |
|
| 159 | + $unavailableProvider->method('isAvailable') |
|
| 160 | + ->willReturn(false); |
|
| 161 | + $validProvider = $this->createMock(IProviderV2::class); |
|
| 162 | + $validProvider->method('isAvailable') |
|
| 163 | + ->with($file) |
|
| 164 | + ->willReturn(true); |
|
| 165 | + |
|
| 166 | + $this->previewManager->method('getProviders') |
|
| 167 | + ->willReturn([ |
|
| 168 | + '/image\/png/' => ['wrongProvider'], |
|
| 169 | + '/myMimeType/' => ['brokenProvider', 'invalidProvider', 'unavailableProvider', 'validProvider'], |
|
| 170 | + ]); |
|
| 171 | + |
|
| 172 | + $this->helper->method('getProvider') |
|
| 173 | + ->willReturnCallback(function ($provider) use ($invalidProvider, $validProvider, $unavailableProvider) { |
|
| 174 | + if ($provider === 'wrongProvider') { |
|
| 175 | + $this->fail('Wrongprovider should not be constructed!'); |
|
| 176 | + } elseif ($provider === 'brokenProvider') { |
|
| 177 | + return false; |
|
| 178 | + } elseif ($provider === 'invalidProvider') { |
|
| 179 | + return $invalidProvider; |
|
| 180 | + } elseif ($provider === 'validProvider') { |
|
| 181 | + return $validProvider; |
|
| 182 | + } elseif ($provider === 'unavailableProvider') { |
|
| 183 | + return $unavailableProvider; |
|
| 184 | + } |
|
| 185 | + $this->fail('Unexpected provider requested'); |
|
| 186 | + }); |
|
| 187 | + |
|
| 188 | + $image = $this->createMock(IImage::class); |
|
| 189 | + $image->method('width')->willReturn(2048); |
|
| 190 | + $image->method('height')->willReturn(2048); |
|
| 191 | + $image->method('valid')->willReturn(true); |
|
| 192 | + $image->method('dataMimeType')->willReturn('image/png'); |
|
| 193 | + |
|
| 194 | + $this->helper->method('getThumbnail') |
|
| 195 | + ->willReturnCallback(function ($provider, $file, $x, $y) use ($invalidProvider, $validProvider, $image): false|IImage { |
|
| 196 | + if ($provider === $validProvider) { |
|
| 197 | + return $image; |
|
| 198 | + } else { |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 201 | + }); |
|
| 202 | + |
|
| 203 | + $image->method('data') |
|
| 204 | + ->willReturn('my data'); |
|
| 205 | + |
|
| 206 | + $this->previewMapper->method('insert') |
|
| 207 | + ->willReturnCallback(fn (Preview $preview): Preview => $preview); |
|
| 208 | + |
|
| 209 | + $this->previewMapper->method('update') |
|
| 210 | + ->willReturnCallback(fn (Preview $preview): Preview => $preview); |
|
| 211 | + |
|
| 212 | + $this->storageFactory->method('writePreview') |
|
| 213 | + ->willReturnCallback(function (Preview $preview, mixed $data) use ($hasVersion): int { |
|
| 214 | + $data = stream_get_contents($data); |
|
| 215 | + if ($hasVersion) { |
|
| 216 | + switch ($preview->getName()) { |
|
| 217 | + case 'abc-2048-2048-max.png': |
|
| 218 | + $this->assertSame('my data', $data); |
|
| 219 | + return 1000; |
|
| 220 | + case 'abc-256-256.png': |
|
| 221 | + $this->assertSame('my resized data', $data); |
|
| 222 | + return 1000; |
|
| 223 | + } |
|
| 224 | + } else { |
|
| 225 | + switch ($preview->getName()) { |
|
| 226 | + case '2048-2048-max.png': |
|
| 227 | + $this->assertSame('my data', $data); |
|
| 228 | + return 1000; |
|
| 229 | + case '256-256.png': |
|
| 230 | + $this->assertSame('my resized data', $data); |
|
| 231 | + return 1000; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + $this->fail('file name is wrong:' . $preview->getName()); |
|
| 235 | + }); |
|
| 236 | + |
|
| 237 | + $image = $this->getMockImage(2048, 2048, 'my resized data'); |
|
| 238 | + $this->helper->method('getImage') |
|
| 239 | + ->willReturn($image); |
|
| 240 | + |
|
| 241 | + $this->eventDispatcher->expects($this->once()) |
|
| 242 | + ->method('dispatchTyped') |
|
| 243 | + ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); |
|
| 244 | + |
|
| 245 | + $result = $this->generator->getPreview($file, 100, 100); |
|
| 246 | + $this->assertSame($hasVersion ? 'abc-256-256.png' : '256-256.png', $result->getName()); |
|
| 247 | + $this->assertSame(1000, $result->getSize()); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function testInvalidMimeType(): void { |
|
| 251 | + $this->expectException(NotFoundException::class); |
|
| 252 | + |
|
| 253 | + $file = $this->getFile(42, 'invalidType'); |
|
| 254 | + |
|
| 255 | + $this->previewManager->method('isMimeSupported') |
|
| 256 | + ->with('invalidType') |
|
| 257 | + ->willReturn(false); |
|
| 258 | + |
|
| 259 | + $maxPreview = new Preview(); |
|
| 260 | + $maxPreview->setWidth(2048); |
|
| 261 | + $maxPreview->setHeight(2048); |
|
| 262 | + $maxPreview->setMax(true); |
|
| 263 | + $maxPreview->setSize(1000); |
|
| 264 | + $maxPreview->setVersion(null); |
|
| 265 | + $maxPreview->setMimetype('image/png'); |
|
| 266 | + |
|
| 267 | + $this->previewMapper->method('getAvailablePreviews') |
|
| 268 | + ->with($this->equalTo([42])) |
|
| 269 | + ->willReturn([42 => [ |
|
| 270 | + $maxPreview, |
|
| 271 | + ]]); |
|
| 272 | + |
|
| 273 | + $this->eventDispatcher->expects($this->once()) |
|
| 274 | + ->method('dispatchTyped') |
|
| 275 | + ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType')); |
|
| 276 | + |
|
| 277 | + $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + public function testReturnCachedPreviewsWithoutCheckingSupportedMimetype(): void { |
|
| 281 | + $file = $this->getFile(42, 'myMimeType'); |
|
| 282 | + |
|
| 283 | + $maxPreview = new Preview(); |
|
| 284 | + $maxPreview->setWidth(2048); |
|
| 285 | + $maxPreview->setHeight(2048); |
|
| 286 | + $maxPreview->setMax(true); |
|
| 287 | + $maxPreview->setSize(1000); |
|
| 288 | + $maxPreview->setVersion(null); |
|
| 289 | + $maxPreview->setMimeType('image/png'); |
|
| 290 | + |
|
| 291 | + $previewFile = new Preview(); |
|
| 292 | + $previewFile->setWidth(1024); |
|
| 293 | + $previewFile->setHeight(512); |
|
| 294 | + $previewFile->setMax(false); |
|
| 295 | + $previewFile->setSize(1000); |
|
| 296 | + $previewFile->setCropped(true); |
|
| 297 | + $previewFile->setVersion(null); |
|
| 298 | + $previewFile->setMimeType('image/png'); |
|
| 299 | + |
|
| 300 | + $this->previewMapper->method('getAvailablePreviews') |
|
| 301 | + ->with($this->equalTo([42])) |
|
| 302 | + ->willReturn([42 => [ |
|
| 303 | + $maxPreview, |
|
| 304 | + $previewFile, |
|
| 305 | + ]]); |
|
| 306 | + |
|
| 307 | + $this->previewManager->expects($this->never()) |
|
| 308 | + ->method('isMimeSupported'); |
|
| 309 | + |
|
| 310 | + $this->eventDispatcher->expects($this->once()) |
|
| 311 | + ->method('dispatchTyped') |
|
| 312 | + ->with(new BeforePreviewFetchedEvent($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType')); |
|
| 313 | + |
|
| 314 | + $result = $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); |
|
| 315 | + $this->assertSame('1024-512-crop.png', $result->getName()); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + public function testNoProvider(): void { |
|
| 319 | + $file = $this->getFile(42, 'myMimeType'); |
|
| 320 | + |
|
| 321 | + $this->previewMapper->method('getAvailablePreviews') |
|
| 322 | + ->with($this->equalTo([42])) |
|
| 323 | + ->willReturn([42 => []]); |
|
| 324 | + |
|
| 325 | + $this->previewManager->method('getProviders') |
|
| 326 | + ->willReturn([]); |
|
| 327 | + |
|
| 328 | + $this->eventDispatcher->expects($this->once()) |
|
| 329 | + ->method('dispatchTyped') |
|
| 330 | + ->with(new BeforePreviewFetchedEvent($file, 100, 100, false, IPreview::MODE_FILL, null)); |
|
| 331 | + |
|
| 332 | + $this->expectException(NotFoundException::class); |
|
| 333 | + $this->generator->getPreview($file, 100, 100); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + private function getMockImage(int $width, int $height, string $data = '') { |
|
| 337 | + $image = $this->createMock(IImage::class); |
|
| 338 | + $image->method('height')->willReturn($width); |
|
| 339 | + $image->method('width')->willReturn($height); |
|
| 340 | + $image->method('valid')->willReturn(true); |
|
| 341 | + $image->method('dataMimeType')->willReturn('image/png'); |
|
| 342 | + $image->method('data')->willReturn($data); |
|
| 343 | + |
|
| 344 | + $image->method('resizeCopy')->willReturnCallback(function ($size) use ($data) { |
|
| 345 | + return $this->getMockImage($size, $size, $data); |
|
| 346 | + }); |
|
| 347 | + $image->method('preciseResizeCopy')->willReturnCallback(function ($width, $height) use ($data) { |
|
| 348 | + return $this->getMockImage($width, $height, $data); |
|
| 349 | + }); |
|
| 350 | + $image->method('cropCopy')->willReturnCallback(function ($x, $y, $width, $height) use ($data) { |
|
| 351 | + return $this->getMockImage($width, $height, $data); |
|
| 352 | + }); |
|
| 353 | + |
|
| 354 | + return $image; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + public static function dataSize(): array { |
|
| 358 | + return [ |
|
| 359 | + [1024, 2048, 512, 512, false, IPreview::MODE_FILL, 256, 512], |
|
| 360 | + [1024, 2048, 512, 512, false, IPreview::MODE_COVER, 512, 1024], |
|
| 361 | + [1024, 2048, 512, 512, true, IPreview::MODE_FILL, 1024, 1024], |
|
| 362 | + [1024, 2048, 512, 512, true, IPreview::MODE_COVER, 1024, 1024], |
|
| 363 | + |
|
| 364 | + [1024, 2048, -1, 512, false, IPreview::MODE_COVER, 256, 512], |
|
| 365 | + [1024, 2048, 512, -1, false, IPreview::MODE_FILL, 512, 1024], |
|
| 366 | + |
|
| 367 | + [1024, 2048, 250, 1100, true, IPreview::MODE_COVER, 256, 1126], |
|
| 368 | + [1024, 1100, 250, 1100, true, IPreview::MODE_COVER, 250, 1100], |
|
| 369 | + |
|
| 370 | + [1024, 2048, 4096, 2048, false, IPreview::MODE_FILL, 1024, 2048], |
|
| 371 | + [1024, 2048, 4096, 2048, false, IPreview::MODE_COVER, 1024, 2048], |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + [2048, 1024, 512, 512, false, IPreview::MODE_FILL, 512, 256], |
|
| 375 | + [2048, 1024, 512, 512, false, IPreview::MODE_COVER, 1024, 512], |
|
| 376 | + [2048, 1024, 512, 512, true, IPreview::MODE_FILL, 1024, 1024], |
|
| 377 | + [2048, 1024, 512, 512, true, IPreview::MODE_COVER, 1024, 1024], |
|
| 378 | + |
|
| 379 | + [2048, 1024, -1, 512, false, IPreview::MODE_FILL, 1024, 512], |
|
| 380 | + [2048, 1024, 512, -1, false, IPreview::MODE_COVER, 512, 256], |
|
| 381 | + |
|
| 382 | + [2048, 1024, 4096, 1024, true, IPreview::MODE_FILL, 2048, 512], |
|
| 383 | + [2048, 1024, 4096, 1024, true, IPreview::MODE_COVER, 2048, 512], |
|
| 384 | + |
|
| 385 | + //Test minimum size |
|
| 386 | + [2048, 1024, 32, 32, false, IPreview::MODE_FILL, 64, 32], |
|
| 387 | + [2048, 1024, 32, 32, false, IPreview::MODE_COVER, 64, 32], |
|
| 388 | + [2048, 1024, 32, 32, true, IPreview::MODE_FILL, 64, 64], |
|
| 389 | + [2048, 1024, 32, 32, true, IPreview::MODE_COVER, 64, 64], |
|
| 390 | + ]; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + #[DataProvider('dataSize')] |
|
| 394 | + public function testCorrectSize(int $maxX, int $maxY, int $reqX, int $reqY, bool $crop, string $mode, int $expectedX, int $expectedY): void { |
|
| 395 | + $file = $this->getFile(42, 'myMimeType'); |
|
| 396 | + |
|
| 397 | + $this->previewManager->method('isMimeSupported') |
|
| 398 | + ->with($this->equalTo('myMimeType')) |
|
| 399 | + ->willReturn(true); |
|
| 400 | + |
|
| 401 | + $maxPreview = new Preview(); |
|
| 402 | + $maxPreview->setWidth($maxX); |
|
| 403 | + $maxPreview->setHeight($maxY); |
|
| 404 | + $maxPreview->setMax(true); |
|
| 405 | + $maxPreview->setSize(1000); |
|
| 406 | + $maxPreview->setVersion(null); |
|
| 407 | + $maxPreview->setMimeType('image/png'); |
|
| 408 | + |
|
| 409 | + $this->assertSame($maxPreview->getName(), $maxX . '-' . $maxY . '-max.png'); |
|
| 410 | + $this->assertSame($maxPreview->getMimeType(), 'image/png'); |
|
| 411 | + |
|
| 412 | + $this->previewMapper->method('getAvailablePreviews') |
|
| 413 | + ->with($this->equalTo([42])) |
|
| 414 | + ->willReturn([42 => [ |
|
| 415 | + $maxPreview, |
|
| 416 | + ]]); |
|
| 417 | + |
|
| 418 | + $filename = $expectedX . '-' . $expectedY; |
|
| 419 | + if ($crop) { |
|
| 420 | + $filename .= '-crop'; |
|
| 421 | + } |
|
| 422 | + $filename .= '.png'; |
|
| 423 | + |
|
| 424 | + $image = $this->getMockImage($maxX, $maxY); |
|
| 425 | + $this->helper->method('getImage') |
|
| 426 | + ->willReturn($image); |
|
| 427 | + |
|
| 428 | + $this->previewMapper->method('insert') |
|
| 429 | + ->willReturnCallback(function (Preview $preview) use ($filename): Preview { |
|
| 430 | + $this->assertSame($preview->getName(), $filename); |
|
| 431 | + return $preview; |
|
| 432 | + }); |
|
| 433 | + |
|
| 434 | + $this->previewMapper->method('update') |
|
| 435 | + ->willReturnCallback(fn (Preview $preview): Preview => $preview); |
|
| 436 | + |
|
| 437 | + $this->storageFactory->method('writePreview') |
|
| 438 | + ->willReturn(1000); |
|
| 439 | + |
|
| 440 | + $this->eventDispatcher->expects($this->once()) |
|
| 441 | + ->method('dispatchTyped') |
|
| 442 | + ->with(new BeforePreviewFetchedEvent($file, $reqX, $reqY, $crop, $mode, null)); |
|
| 443 | + |
|
| 444 | + $result = $this->generator->getPreview($file, $reqX, $reqY, $crop, $mode); |
|
| 445 | + if ($expectedX === $maxX && $expectedY === $maxY) { |
|
| 446 | + $this->assertSame($maxPreview->getName(), $result->getName()); |
|
| 447 | + } else { |
|
| 448 | + $this->assertSame($filename, $result->getName()); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + public function testUnreadbleFile(): void { |
|
| 453 | + $file = $this->createMock(File::class); |
|
| 454 | + $file->method('isReadable') |
|
| 455 | + ->willReturn(false); |
|
| 456 | + |
|
| 457 | + $this->expectException(NotFoundException::class); |
|
| 458 | + |
|
| 459 | + $this->generator->getPreview($file, 100, 100, false); |
|
| 460 | + } |
|
| 461 | 461 | } |
@@ -143,12 +143,12 @@ discard block |
||
| 143 | 143 | ->willReturn([42 => []]); |
| 144 | 144 | |
| 145 | 145 | $this->config->method('getSystemValueString') |
| 146 | - ->willReturnCallback(function ($key, $default) { |
|
| 146 | + ->willReturnCallback(function($key, $default) { |
|
| 147 | 147 | return $default; |
| 148 | 148 | }); |
| 149 | 149 | |
| 150 | 150 | $this->config->method('getSystemValueInt') |
| 151 | - ->willReturnCallback(function ($key, $default) { |
|
| 151 | + ->willReturnCallback(function($key, $default) { |
|
| 152 | 152 | return $default; |
| 153 | 153 | }); |
| 154 | 154 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | ]); |
| 171 | 171 | |
| 172 | 172 | $this->helper->method('getProvider') |
| 173 | - ->willReturnCallback(function ($provider) use ($invalidProvider, $validProvider, $unavailableProvider) { |
|
| 173 | + ->willReturnCallback(function($provider) use ($invalidProvider, $validProvider, $unavailableProvider) { |
|
| 174 | 174 | if ($provider === 'wrongProvider') { |
| 175 | 175 | $this->fail('Wrongprovider should not be constructed!'); |
| 176 | 176 | } elseif ($provider === 'brokenProvider') { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $image->method('dataMimeType')->willReturn('image/png'); |
| 193 | 193 | |
| 194 | 194 | $this->helper->method('getThumbnail') |
| 195 | - ->willReturnCallback(function ($provider, $file, $x, $y) use ($invalidProvider, $validProvider, $image): false|IImage { |
|
| 195 | + ->willReturnCallback(function($provider, $file, $x, $y) use ($invalidProvider, $validProvider, $image): false | IImage { |
|
| 196 | 196 | if ($provider === $validProvider) { |
| 197 | 197 | return $image; |
| 198 | 198 | } else { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | ->willReturnCallback(fn (Preview $preview): Preview => $preview); |
| 211 | 211 | |
| 212 | 212 | $this->storageFactory->method('writePreview') |
| 213 | - ->willReturnCallback(function (Preview $preview, mixed $data) use ($hasVersion): int { |
|
| 213 | + ->willReturnCallback(function(Preview $preview, mixed $data) use ($hasVersion): int { |
|
| 214 | 214 | $data = stream_get_contents($data); |
| 215 | 215 | if ($hasVersion) { |
| 216 | 216 | switch ($preview->getName()) { |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | return 1000; |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | - $this->fail('file name is wrong:' . $preview->getName()); |
|
| 234 | + $this->fail('file name is wrong:'.$preview->getName()); |
|
| 235 | 235 | }); |
| 236 | 236 | |
| 237 | 237 | $image = $this->getMockImage(2048, 2048, 'my resized data'); |
@@ -341,13 +341,13 @@ discard block |
||
| 341 | 341 | $image->method('dataMimeType')->willReturn('image/png'); |
| 342 | 342 | $image->method('data')->willReturn($data); |
| 343 | 343 | |
| 344 | - $image->method('resizeCopy')->willReturnCallback(function ($size) use ($data) { |
|
| 344 | + $image->method('resizeCopy')->willReturnCallback(function($size) use ($data) { |
|
| 345 | 345 | return $this->getMockImage($size, $size, $data); |
| 346 | 346 | }); |
| 347 | - $image->method('preciseResizeCopy')->willReturnCallback(function ($width, $height) use ($data) { |
|
| 347 | + $image->method('preciseResizeCopy')->willReturnCallback(function($width, $height) use ($data) { |
|
| 348 | 348 | return $this->getMockImage($width, $height, $data); |
| 349 | 349 | }); |
| 350 | - $image->method('cropCopy')->willReturnCallback(function ($x, $y, $width, $height) use ($data) { |
|
| 350 | + $image->method('cropCopy')->willReturnCallback(function($x, $y, $width, $height) use ($data) { |
|
| 351 | 351 | return $this->getMockImage($width, $height, $data); |
| 352 | 352 | }); |
| 353 | 353 | |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | $maxPreview->setVersion(null); |
| 407 | 407 | $maxPreview->setMimeType('image/png'); |
| 408 | 408 | |
| 409 | - $this->assertSame($maxPreview->getName(), $maxX . '-' . $maxY . '-max.png'); |
|
| 409 | + $this->assertSame($maxPreview->getName(), $maxX.'-'.$maxY.'-max.png'); |
|
| 410 | 410 | $this->assertSame($maxPreview->getMimeType(), 'image/png'); |
| 411 | 411 | |
| 412 | 412 | $this->previewMapper->method('getAvailablePreviews') |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | $maxPreview, |
| 416 | 416 | ]]); |
| 417 | 417 | |
| 418 | - $filename = $expectedX . '-' . $expectedY; |
|
| 418 | + $filename = $expectedX.'-'.$expectedY; |
|
| 419 | 419 | if ($crop) { |
| 420 | 420 | $filename .= '-crop'; |
| 421 | 421 | } |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | ->willReturn($image); |
| 427 | 427 | |
| 428 | 428 | $this->previewMapper->method('insert') |
| 429 | - ->willReturnCallback(function (Preview $preview) use ($filename): Preview { |
|
| 429 | + ->willReturnCallback(function(Preview $preview) use ($filename): Preview { |
|
| 430 | 430 | $this->assertSame($preview->getName(), $filename); |
| 431 | 431 | return $preview; |
| 432 | 432 | }); |
@@ -20,63 +20,63 @@ |
||
| 20 | 20 | * @group DB |
| 21 | 21 | */ |
| 22 | 22 | class PreviewMapperTest extends TestCase { |
| 23 | - private PreviewMapper $previewMapper; |
|
| 24 | - private IDBConnection $connection; |
|
| 23 | + private PreviewMapper $previewMapper; |
|
| 24 | + private IDBConnection $connection; |
|
| 25 | 25 | |
| 26 | - public function setUp(): void { |
|
| 27 | - $this->previewMapper = Server::get(PreviewMapper::class); |
|
| 28 | - $this->connection = Server::get(IDBConnection::class); |
|
| 29 | - } |
|
| 26 | + public function setUp(): void { |
|
| 27 | + $this->previewMapper = Server::get(PreviewMapper::class); |
|
| 28 | + $this->connection = Server::get(IDBConnection::class); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function testGetAvailablePreviews(): void { |
|
| 32 | - // Empty |
|
| 33 | - $this->assertEquals([], $this->previewMapper->getAvailablePreviews([])); |
|
| 31 | + public function testGetAvailablePreviews(): void { |
|
| 32 | + // Empty |
|
| 33 | + $this->assertEquals([], $this->previewMapper->getAvailablePreviews([])); |
|
| 34 | 34 | |
| 35 | - // No preview available |
|
| 36 | - $this->assertEquals([42 => []], $this->previewMapper->getAvailablePreviews([42])); |
|
| 35 | + // No preview available |
|
| 36 | + $this->assertEquals([42 => []], $this->previewMapper->getAvailablePreviews([42])); |
|
| 37 | 37 | |
| 38 | - $this->createPreviewForFileId(42); |
|
| 39 | - $previews = $this->previewMapper->getAvailablePreviews([42]); |
|
| 40 | - $this->assertNotEmpty($previews[42]); |
|
| 41 | - $this->assertNull($previews[42][0]->getLocationId()); |
|
| 42 | - $this->assertNull($previews[42][0]->getBucketName()); |
|
| 43 | - $this->assertNull($previews[42][0]->getObjectStoreName()); |
|
| 38 | + $this->createPreviewForFileId(42); |
|
| 39 | + $previews = $this->previewMapper->getAvailablePreviews([42]); |
|
| 40 | + $this->assertNotEmpty($previews[42]); |
|
| 41 | + $this->assertNull($previews[42][0]->getLocationId()); |
|
| 42 | + $this->assertNull($previews[42][0]->getBucketName()); |
|
| 43 | + $this->assertNull($previews[42][0]->getObjectStoreName()); |
|
| 44 | 44 | |
| 45 | - $this->createPreviewForFileId(43, 2); |
|
| 46 | - $previews = $this->previewMapper->getAvailablePreviews([43]); |
|
| 47 | - $this->assertNotEmpty($previews[43]); |
|
| 48 | - $this->assertEquals('preview-2', $previews[43][0]->getBucketName()); |
|
| 49 | - $this->assertEquals('default', $previews[43][0]->getObjectStoreName()); |
|
| 50 | - } |
|
| 45 | + $this->createPreviewForFileId(43, 2); |
|
| 46 | + $previews = $this->previewMapper->getAvailablePreviews([43]); |
|
| 47 | + $this->assertNotEmpty($previews[43]); |
|
| 48 | + $this->assertEquals('preview-2', $previews[43][0]->getBucketName()); |
|
| 49 | + $this->assertEquals('default', $previews[43][0]->getObjectStoreName()); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - private function createPreviewForFileId(int $fileId, ?int $bucket = null): void { |
|
| 53 | - $locationId = null; |
|
| 54 | - if ($bucket) { |
|
| 55 | - $qb = $this->connection->getQueryBuilder(); |
|
| 56 | - $qb->insert('preview_locations') |
|
| 57 | - ->values([ |
|
| 58 | - 'bucket_name' => $qb->createNamedParameter('preview-' . $bucket), |
|
| 59 | - 'object_store_name' => $qb->createNamedParameter('default'), |
|
| 60 | - ]); |
|
| 61 | - $qb->executeStatement(); |
|
| 62 | - $locationId = $qb->getLastInsertId(); |
|
| 63 | - } |
|
| 64 | - $preview = new Preview(); |
|
| 65 | - $preview->setFileId($fileId); |
|
| 66 | - $preview->setStorageId(1); |
|
| 67 | - $preview->setCropped(true); |
|
| 68 | - $preview->setMax(true); |
|
| 69 | - $preview->setWidth(100); |
|
| 70 | - $preview->setSourceMimeType('image/jpeg'); |
|
| 71 | - $preview->setHeight(100); |
|
| 72 | - $preview->setSize(100); |
|
| 73 | - $preview->setMtime(time()); |
|
| 74 | - $preview->setMimetype('image/jpeg'); |
|
| 75 | - $preview->setEtag('abcdefg'); |
|
| 52 | + private function createPreviewForFileId(int $fileId, ?int $bucket = null): void { |
|
| 53 | + $locationId = null; |
|
| 54 | + if ($bucket) { |
|
| 55 | + $qb = $this->connection->getQueryBuilder(); |
|
| 56 | + $qb->insert('preview_locations') |
|
| 57 | + ->values([ |
|
| 58 | + 'bucket_name' => $qb->createNamedParameter('preview-' . $bucket), |
|
| 59 | + 'object_store_name' => $qb->createNamedParameter('default'), |
|
| 60 | + ]); |
|
| 61 | + $qb->executeStatement(); |
|
| 62 | + $locationId = $qb->getLastInsertId(); |
|
| 63 | + } |
|
| 64 | + $preview = new Preview(); |
|
| 65 | + $preview->setFileId($fileId); |
|
| 66 | + $preview->setStorageId(1); |
|
| 67 | + $preview->setCropped(true); |
|
| 68 | + $preview->setMax(true); |
|
| 69 | + $preview->setWidth(100); |
|
| 70 | + $preview->setSourceMimeType('image/jpeg'); |
|
| 71 | + $preview->setHeight(100); |
|
| 72 | + $preview->setSize(100); |
|
| 73 | + $preview->setMtime(time()); |
|
| 74 | + $preview->setMimetype('image/jpeg'); |
|
| 75 | + $preview->setEtag('abcdefg'); |
|
| 76 | 76 | |
| 77 | - if ($locationId !== null) { |
|
| 78 | - $preview->setLocationId($locationId); |
|
| 79 | - } |
|
| 80 | - $this->previewMapper->insert($preview); |
|
| 81 | - } |
|
| 77 | + if ($locationId !== null) { |
|
| 78 | + $preview->setLocationId($locationId); |
|
| 79 | + } |
|
| 80 | + $this->previewMapper->insert($preview); |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | $qb = $this->connection->getQueryBuilder(); |
| 56 | 56 | $qb->insert('preview_locations') |
| 57 | 57 | ->values([ |
| 58 | - 'bucket_name' => $qb->createNamedParameter('preview-' . $bucket), |
|
| 58 | + 'bucket_name' => $qb->createNamedParameter('preview-'.$bucket), |
|
| 59 | 59 | 'object_store_name' => $qb->createNamedParameter('default'), |
| 60 | 60 | ]); |
| 61 | 61 | $qb->executeStatement(); |
@@ -30,115 +30,115 @@ |
||
| 30 | 30 | * @package Test\Preview |
| 31 | 31 | */ |
| 32 | 32 | class BackgroundCleanupJobTest extends \Test\TestCase { |
| 33 | - use MountProviderTrait; |
|
| 34 | - use UserTrait; |
|
| 35 | - private string $userId; |
|
| 36 | - private bool $trashEnabled; |
|
| 37 | - private IDBConnection $connection; |
|
| 38 | - private PreviewManager $previewManager; |
|
| 39 | - private IRootFolder $rootFolder; |
|
| 40 | - private IMimeTypeLoader $mimeTypeLoader; |
|
| 41 | - private ITimeFactory $timeFactory; |
|
| 42 | - private PreviewService $previewService; |
|
| 43 | - |
|
| 44 | - protected function setUp(): void { |
|
| 45 | - parent::setUp(); |
|
| 46 | - |
|
| 47 | - $this->userId = $this->getUniqueID(); |
|
| 48 | - $user = $this->createUser($this->userId, $this->userId); |
|
| 49 | - |
|
| 50 | - $storage = new Temporary([]); |
|
| 51 | - $this->registerMount($this->userId, $storage, ''); |
|
| 52 | - |
|
| 53 | - $this->loginAsUser($this->userId); |
|
| 54 | - $this->logout(); |
|
| 55 | - $this->loginAsUser($this->userId); |
|
| 56 | - |
|
| 57 | - $appManager = Server::get(IAppManager::class); |
|
| 58 | - $this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $user); |
|
| 59 | - $appManager->disableApp('files_trashbin'); |
|
| 60 | - |
|
| 61 | - $this->connection = Server::get(IDBConnection::class); |
|
| 62 | - $this->previewManager = Server::get(IPreview::class); |
|
| 63 | - $this->rootFolder = Server::get(IRootFolder::class); |
|
| 64 | - $this->mimeTypeLoader = Server::get(IMimeTypeLoader::class); |
|
| 65 | - $this->timeFactory = Server::get(ITimeFactory::class); |
|
| 66 | - $this->previewService = Server::get(PreviewService::class); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - protected function tearDown(): void { |
|
| 70 | - if ($this->trashEnabled) { |
|
| 71 | - $appManager = Server::get(IAppManager::class); |
|
| 72 | - $appManager->enableApp('files_trashbin'); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $this->logout(); |
|
| 76 | - |
|
| 77 | - foreach ($this->previewService->getAvailablePreviewsForFile(5) as $preview) { |
|
| 78 | - $this->previewService->deletePreview($preview); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - parent::tearDown(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - private function setup11Previews(): array { |
|
| 85 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 86 | - |
|
| 87 | - $files = []; |
|
| 88 | - foreach (range(0, 10) as $i) { |
|
| 89 | - $file = $userFolder->newFile($i . '.txt'); |
|
| 90 | - $file->putContent('hello world!'); |
|
| 91 | - $this->previewManager->getPreview($file); |
|
| 92 | - $files[] = $file; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $files; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - private function countPreviews(PreviewService $previewService, array $fileIds): int { |
|
| 99 | - $previews = $previewService->getAvailablePreviews($fileIds); |
|
| 100 | - return array_reduce($previews, fn (int $result, array $previews) => $result + count($previews), 0); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function testCleanupSystemCron(): void { |
|
| 104 | - $files = $this->setup11Previews(); |
|
| 105 | - $fileIds = array_map(fn (File $f): int => $f->getId(), $files); |
|
| 106 | - |
|
| 107 | - $this->assertSame(11, $this->countPreviews($this->previewService, $fileIds)); |
|
| 108 | - $job = new BackgroundCleanupJob($this->timeFactory, $this->connection, $this->previewService, true); |
|
| 109 | - $job->run([]); |
|
| 110 | - |
|
| 111 | - foreach ($files as $file) { |
|
| 112 | - $file->delete(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $this->assertSame(11, $this->countPreviews($this->previewService, $fileIds)); |
|
| 116 | - $job->run([]); |
|
| 117 | - |
|
| 118 | - $this->assertSame(0, $this->countPreviews($this->previewService, $fileIds)); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function testCleanupAjax(): void { |
|
| 122 | - if ($this->connection->getShardDefinition('filecache')) { |
|
| 123 | - $this->markTestSkipped('ajax cron is not supported for sharded setups'); |
|
| 124 | - } |
|
| 125 | - $files = $this->setup11Previews(); |
|
| 126 | - $fileIds = array_map(fn (File $f): int => $f->getId(), $files); |
|
| 127 | - |
|
| 128 | - $this->assertSame(11, $this->countPreviews($this->previewService, $fileIds)); |
|
| 129 | - $job = new BackgroundCleanupJob($this->timeFactory, $this->connection, $this->previewService, false); |
|
| 130 | - $job->run([]); |
|
| 131 | - |
|
| 132 | - foreach ($files as $file) { |
|
| 133 | - $file->delete(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $this->assertSame(11, $this->countPreviews($this->previewService, $fileIds)); |
|
| 137 | - $job->run([]); |
|
| 138 | - |
|
| 139 | - $this->assertSame(1, $this->countPreviews($this->previewService, $fileIds)); |
|
| 140 | - $job->run([]); |
|
| 33 | + use MountProviderTrait; |
|
| 34 | + use UserTrait; |
|
| 35 | + private string $userId; |
|
| 36 | + private bool $trashEnabled; |
|
| 37 | + private IDBConnection $connection; |
|
| 38 | + private PreviewManager $previewManager; |
|
| 39 | + private IRootFolder $rootFolder; |
|
| 40 | + private IMimeTypeLoader $mimeTypeLoader; |
|
| 41 | + private ITimeFactory $timeFactory; |
|
| 42 | + private PreviewService $previewService; |
|
| 43 | + |
|
| 44 | + protected function setUp(): void { |
|
| 45 | + parent::setUp(); |
|
| 46 | + |
|
| 47 | + $this->userId = $this->getUniqueID(); |
|
| 48 | + $user = $this->createUser($this->userId, $this->userId); |
|
| 49 | + |
|
| 50 | + $storage = new Temporary([]); |
|
| 51 | + $this->registerMount($this->userId, $storage, ''); |
|
| 52 | + |
|
| 53 | + $this->loginAsUser($this->userId); |
|
| 54 | + $this->logout(); |
|
| 55 | + $this->loginAsUser($this->userId); |
|
| 56 | + |
|
| 57 | + $appManager = Server::get(IAppManager::class); |
|
| 58 | + $this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $user); |
|
| 59 | + $appManager->disableApp('files_trashbin'); |
|
| 60 | + |
|
| 61 | + $this->connection = Server::get(IDBConnection::class); |
|
| 62 | + $this->previewManager = Server::get(IPreview::class); |
|
| 63 | + $this->rootFolder = Server::get(IRootFolder::class); |
|
| 64 | + $this->mimeTypeLoader = Server::get(IMimeTypeLoader::class); |
|
| 65 | + $this->timeFactory = Server::get(ITimeFactory::class); |
|
| 66 | + $this->previewService = Server::get(PreviewService::class); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + protected function tearDown(): void { |
|
| 70 | + if ($this->trashEnabled) { |
|
| 71 | + $appManager = Server::get(IAppManager::class); |
|
| 72 | + $appManager->enableApp('files_trashbin'); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $this->logout(); |
|
| 76 | + |
|
| 77 | + foreach ($this->previewService->getAvailablePreviewsForFile(5) as $preview) { |
|
| 78 | + $this->previewService->deletePreview($preview); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + parent::tearDown(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + private function setup11Previews(): array { |
|
| 85 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 86 | + |
|
| 87 | + $files = []; |
|
| 88 | + foreach (range(0, 10) as $i) { |
|
| 89 | + $file = $userFolder->newFile($i . '.txt'); |
|
| 90 | + $file->putContent('hello world!'); |
|
| 91 | + $this->previewManager->getPreview($file); |
|
| 92 | + $files[] = $file; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $files; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + private function countPreviews(PreviewService $previewService, array $fileIds): int { |
|
| 99 | + $previews = $previewService->getAvailablePreviews($fileIds); |
|
| 100 | + return array_reduce($previews, fn (int $result, array $previews) => $result + count($previews), 0); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function testCleanupSystemCron(): void { |
|
| 104 | + $files = $this->setup11Previews(); |
|
| 105 | + $fileIds = array_map(fn (File $f): int => $f->getId(), $files); |
|
| 106 | + |
|
| 107 | + $this->assertSame(11, $this->countPreviews($this->previewService, $fileIds)); |
|
| 108 | + $job = new BackgroundCleanupJob($this->timeFactory, $this->connection, $this->previewService, true); |
|
| 109 | + $job->run([]); |
|
| 110 | + |
|
| 111 | + foreach ($files as $file) { |
|
| 112 | + $file->delete(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $this->assertSame(11, $this->countPreviews($this->previewService, $fileIds)); |
|
| 116 | + $job->run([]); |
|
| 117 | + |
|
| 118 | + $this->assertSame(0, $this->countPreviews($this->previewService, $fileIds)); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function testCleanupAjax(): void { |
|
| 122 | + if ($this->connection->getShardDefinition('filecache')) { |
|
| 123 | + $this->markTestSkipped('ajax cron is not supported for sharded setups'); |
|
| 124 | + } |
|
| 125 | + $files = $this->setup11Previews(); |
|
| 126 | + $fileIds = array_map(fn (File $f): int => $f->getId(), $files); |
|
| 127 | + |
|
| 128 | + $this->assertSame(11, $this->countPreviews($this->previewService, $fileIds)); |
|
| 129 | + $job = new BackgroundCleanupJob($this->timeFactory, $this->connection, $this->previewService, false); |
|
| 130 | + $job->run([]); |
|
| 131 | + |
|
| 132 | + foreach ($files as $file) { |
|
| 133 | + $file->delete(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $this->assertSame(11, $this->countPreviews($this->previewService, $fileIds)); |
|
| 137 | + $job->run([]); |
|
| 138 | + |
|
| 139 | + $this->assertSame(1, $this->countPreviews($this->previewService, $fileIds)); |
|
| 140 | + $job->run([]); |
|
| 141 | 141 | |
| 142 | - $this->assertSame(0, $this->countPreviews($this->previewService, $fileIds)); |
|
| 143 | - } |
|
| 142 | + $this->assertSame(0, $this->countPreviews($this->previewService, $fileIds)); |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -86,7 +86,7 @@ |
||
| 86 | 86 | |
| 87 | 87 | $files = []; |
| 88 | 88 | foreach (range(0, 10) as $i) { |
| 89 | - $file = $userFolder->newFile($i . '.txt'); |
|
| 89 | + $file = $userFolder->newFile($i.'.txt'); |
|
| 90 | 90 | $file->putContent('hello world!'); |
| 91 | 91 | $this->previewManager->getPreview($file); |
| 92 | 92 | $files[] = $file; |
@@ -17,279 +17,279 @@ |
||
| 17 | 17 | use Test\TestCase; |
| 18 | 18 | |
| 19 | 19 | class PrimaryObjectStoreConfigTest extends TestCase { |
| 20 | - private array $systemConfig = []; |
|
| 21 | - private array $userConfig = []; |
|
| 22 | - private IConfig&MockObject $config; |
|
| 23 | - private IAppManager&MockObject $appManager; |
|
| 24 | - private PrimaryObjectStoreConfig $objectStoreConfig; |
|
| 25 | - |
|
| 26 | - protected function setUp(): void { |
|
| 27 | - parent::setUp(); |
|
| 28 | - |
|
| 29 | - $this->systemConfig = []; |
|
| 30 | - $this->config = $this->createMock(IConfig::class); |
|
| 31 | - $this->appManager = $this->createMock(IAppManager::class); |
|
| 32 | - $this->config->method('getSystemValue') |
|
| 33 | - ->willReturnCallback(function ($key, $default = '') { |
|
| 34 | - if (isset($this->systemConfig[$key])) { |
|
| 35 | - return $this->systemConfig[$key]; |
|
| 36 | - } else { |
|
| 37 | - return $default; |
|
| 38 | - } |
|
| 39 | - }); |
|
| 40 | - $this->config->method('getUserValue') |
|
| 41 | - ->willReturnCallback(function ($userId, $appName, $key, $default = '') { |
|
| 42 | - if (isset($this->userConfig[$userId][$appName][$key])) { |
|
| 43 | - return $this->userConfig[$userId][$appName][$key]; |
|
| 44 | - } else { |
|
| 45 | - return $default; |
|
| 46 | - } |
|
| 47 | - }); |
|
| 48 | - $this->config->method('setUserValue') |
|
| 49 | - ->willReturnCallback(function ($userId, $appName, $key, $value): void { |
|
| 50 | - $this->userConfig[$userId][$appName][$key] = $value; |
|
| 51 | - }); |
|
| 52 | - |
|
| 53 | - $this->objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->appManager); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - private function getUser(string $uid): IUser { |
|
| 57 | - $user = $this->createMock(IUser::class); |
|
| 58 | - $user->method('getUID') |
|
| 59 | - ->willReturn($uid); |
|
| 60 | - return $user; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - private function setConfig(string $key, $value) { |
|
| 64 | - $this->systemConfig[$key] = $value; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function testNewUserGetsDefault() { |
|
| 68 | - $this->setConfig('objectstore', [ |
|
| 69 | - 'default' => 'server1', |
|
| 70 | - 'server1' => [ |
|
| 71 | - 'class' => StorageObjectStore::class, |
|
| 72 | - 'arguments' => [ |
|
| 73 | - 'host' => 'server1', |
|
| 74 | - ], |
|
| 75 | - ], |
|
| 76 | - ]); |
|
| 77 | - |
|
| 78 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 79 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 80 | - |
|
| 81 | - $this->assertEquals('server1', $this->config->getUserValue('test', 'homeobjectstore', 'objectstore', null)); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function testExistingUserKeepsStorage() { |
|
| 85 | - // setup user with `server1` as storage |
|
| 86 | - $this->testNewUserGetsDefault(); |
|
| 87 | - |
|
| 88 | - $this->setConfig('objectstore', [ |
|
| 89 | - 'default' => 'server2', |
|
| 90 | - 'server1' => [ |
|
| 91 | - 'class' => StorageObjectStore::class, |
|
| 92 | - 'arguments' => [ |
|
| 93 | - 'host' => 'server1', |
|
| 94 | - 'bucket' => '1', |
|
| 95 | - ], |
|
| 96 | - ], |
|
| 97 | - 'server2' => [ |
|
| 98 | - 'class' => StorageObjectStore::class, |
|
| 99 | - 'arguments' => [ |
|
| 100 | - 'host' => 'server2', |
|
| 101 | - 'bucket' => '2', |
|
| 102 | - ], |
|
| 103 | - ], |
|
| 104 | - ]); |
|
| 105 | - |
|
| 106 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 107 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 108 | - |
|
| 109 | - $this->assertEquals('server1', $this->config->getUserValue('test', 'homeobjectstore', 'objectstore', null)); |
|
| 110 | - |
|
| 111 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('other-user')); |
|
| 112 | - $this->assertEquals('server2', $result['arguments']['host']); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function testNestedAliases() { |
|
| 116 | - $this->setConfig('objectstore', [ |
|
| 117 | - 'default' => 'a1', |
|
| 118 | - 'a1' => 'a2', |
|
| 119 | - 'a2' => 'server1', |
|
| 120 | - 'server1' => [ |
|
| 121 | - 'class' => StorageObjectStore::class, |
|
| 122 | - 'arguments' => [ |
|
| 123 | - 'host' => 'server1', |
|
| 124 | - 'bucket' => '1', |
|
| 125 | - ], |
|
| 126 | - ], |
|
| 127 | - ]); |
|
| 128 | - $this->assertEquals('server1', $this->objectStoreConfig->resolveAlias('default')); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function testMultibucketChangedConfig() { |
|
| 132 | - $this->setConfig('objectstore', [ |
|
| 133 | - 'default' => 'server1', |
|
| 134 | - 'server1' => [ |
|
| 135 | - 'class' => StorageObjectStore::class, |
|
| 136 | - 'arguments' => [ |
|
| 137 | - 'host' => 'server1', |
|
| 138 | - 'multibucket' => true, |
|
| 139 | - 'num_buckets' => 8, |
|
| 140 | - 'bucket' => 'bucket1-' |
|
| 141 | - ], |
|
| 142 | - ], |
|
| 143 | - ]); |
|
| 144 | - |
|
| 145 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 146 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 147 | - $this->assertEquals('bucket1-7', $result['arguments']['bucket']); |
|
| 148 | - |
|
| 149 | - $this->setConfig('objectstore', [ |
|
| 150 | - 'default' => 'server1', |
|
| 151 | - 'server1' => [ |
|
| 152 | - 'class' => StorageObjectStore::class, |
|
| 153 | - 'arguments' => [ |
|
| 154 | - 'host' => 'server1', |
|
| 155 | - 'multibucket' => true, |
|
| 156 | - 'num_buckets' => 64, |
|
| 157 | - 'bucket' => 'bucket1-' |
|
| 158 | - ], |
|
| 159 | - ], |
|
| 160 | - ]); |
|
| 161 | - |
|
| 162 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 163 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 164 | - $this->assertEquals('bucket1-7', $result['arguments']['bucket']); |
|
| 165 | - |
|
| 166 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test-foo')); |
|
| 167 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 168 | - $this->assertEquals('bucket1-40', $result['arguments']['bucket']); |
|
| 169 | - |
|
| 170 | - $this->setConfig('objectstore', [ |
|
| 171 | - 'default' => 'server2', |
|
| 172 | - 'server1' => [ |
|
| 173 | - 'class' => StorageObjectStore::class, |
|
| 174 | - 'arguments' => [ |
|
| 175 | - 'host' => 'server1', |
|
| 176 | - 'multibucket' => true, |
|
| 177 | - 'num_buckets' => 64, |
|
| 178 | - 'bucket' => 'bucket1-' |
|
| 179 | - ], |
|
| 180 | - ], |
|
| 181 | - 'server2' => [ |
|
| 182 | - 'class' => StorageObjectStore::class, |
|
| 183 | - 'arguments' => [ |
|
| 184 | - 'host' => 'server2', |
|
| 185 | - 'multibucket' => true, |
|
| 186 | - 'num_buckets' => 16, |
|
| 187 | - 'bucket' => 'bucket2-' |
|
| 188 | - ], |
|
| 189 | - ], |
|
| 190 | - ]); |
|
| 191 | - |
|
| 192 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 193 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 194 | - $this->assertEquals('bucket1-7', $result['arguments']['bucket']); |
|
| 195 | - |
|
| 196 | - $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test-bar')); |
|
| 197 | - $this->assertEquals('server2', $result['arguments']['host']); |
|
| 198 | - $this->assertEquals('bucket2-4', $result['arguments']['bucket']); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - public function testMultibucketOldConfig() { |
|
| 202 | - $this->setConfig('objectstore_multibucket', [ |
|
| 203 | - 'class' => StorageObjectStore::class, |
|
| 204 | - 'arguments' => [ |
|
| 205 | - 'host' => 'server1', |
|
| 206 | - 'multibucket' => true, |
|
| 207 | - 'num_buckets' => 8, |
|
| 208 | - 'bucket' => 'bucket-' |
|
| 209 | - ], |
|
| 210 | - ]); |
|
| 211 | - $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 212 | - $this->assertEquals([ |
|
| 213 | - 'default' => 'server1', |
|
| 214 | - 'root' => 'server1', |
|
| 215 | - 'preview' => 'server1', |
|
| 216 | - 'server1' => [ |
|
| 217 | - 'class' => StorageObjectStore::class, |
|
| 218 | - 'arguments' => [ |
|
| 219 | - 'host' => 'server1', |
|
| 220 | - 'multibucket' => true, |
|
| 221 | - 'num_buckets' => 8, |
|
| 222 | - 'bucket' => 'bucket-' |
|
| 223 | - ], |
|
| 224 | - ], |
|
| 225 | - ], $configs); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - public function testSingleObjectStore() { |
|
| 229 | - $this->setConfig('objectstore', [ |
|
| 230 | - 'class' => StorageObjectStore::class, |
|
| 231 | - 'arguments' => [ |
|
| 232 | - 'host' => 'server1', |
|
| 233 | - ], |
|
| 234 | - ]); |
|
| 235 | - $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 236 | - $this->assertEquals([ |
|
| 237 | - 'default' => 'server1', |
|
| 238 | - 'root' => 'server1', |
|
| 239 | - 'preview' => 'server1', |
|
| 240 | - 'server1' => [ |
|
| 241 | - 'class' => StorageObjectStore::class, |
|
| 242 | - 'arguments' => [ |
|
| 243 | - 'host' => 'server1', |
|
| 244 | - 'multibucket' => false, |
|
| 245 | - ], |
|
| 246 | - ], |
|
| 247 | - ], $configs); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function testRoot() { |
|
| 251 | - $this->setConfig('objectstore', [ |
|
| 252 | - 'default' => 'server1', |
|
| 253 | - 'server1' => [ |
|
| 254 | - 'class' => StorageObjectStore::class, |
|
| 255 | - 'arguments' => [ |
|
| 256 | - 'host' => 'server1', |
|
| 257 | - 'bucket' => '1', |
|
| 258 | - ], |
|
| 259 | - ], |
|
| 260 | - 'server2' => [ |
|
| 261 | - 'class' => StorageObjectStore::class, |
|
| 262 | - 'arguments' => [ |
|
| 263 | - 'host' => 'server2', |
|
| 264 | - 'bucket' => '2', |
|
| 265 | - ], |
|
| 266 | - ], |
|
| 267 | - ]); |
|
| 268 | - |
|
| 269 | - $result = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 270 | - $this->assertEquals('server1', $result['arguments']['host']); |
|
| 271 | - |
|
| 272 | - $this->setConfig('objectstore', [ |
|
| 273 | - 'default' => 'server1', |
|
| 274 | - 'root' => 'server2', |
|
| 275 | - 'preview' => 'server1', |
|
| 276 | - 'server1' => [ |
|
| 277 | - 'class' => StorageObjectStore::class, |
|
| 278 | - 'arguments' => [ |
|
| 279 | - 'host' => 'server1', |
|
| 280 | - 'bucket' => '1', |
|
| 281 | - ], |
|
| 282 | - ], |
|
| 283 | - 'server2' => [ |
|
| 284 | - 'class' => StorageObjectStore::class, |
|
| 285 | - 'arguments' => [ |
|
| 286 | - 'host' => 'server2', |
|
| 287 | - 'bucket' => '2', |
|
| 288 | - ], |
|
| 289 | - ], |
|
| 290 | - ]); |
|
| 291 | - |
|
| 292 | - $result = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 293 | - $this->assertEquals('server2', $result['arguments']['host']); |
|
| 294 | - } |
|
| 20 | + private array $systemConfig = []; |
|
| 21 | + private array $userConfig = []; |
|
| 22 | + private IConfig&MockObject $config; |
|
| 23 | + private IAppManager&MockObject $appManager; |
|
| 24 | + private PrimaryObjectStoreConfig $objectStoreConfig; |
|
| 25 | + |
|
| 26 | + protected function setUp(): void { |
|
| 27 | + parent::setUp(); |
|
| 28 | + |
|
| 29 | + $this->systemConfig = []; |
|
| 30 | + $this->config = $this->createMock(IConfig::class); |
|
| 31 | + $this->appManager = $this->createMock(IAppManager::class); |
|
| 32 | + $this->config->method('getSystemValue') |
|
| 33 | + ->willReturnCallback(function ($key, $default = '') { |
|
| 34 | + if (isset($this->systemConfig[$key])) { |
|
| 35 | + return $this->systemConfig[$key]; |
|
| 36 | + } else { |
|
| 37 | + return $default; |
|
| 38 | + } |
|
| 39 | + }); |
|
| 40 | + $this->config->method('getUserValue') |
|
| 41 | + ->willReturnCallback(function ($userId, $appName, $key, $default = '') { |
|
| 42 | + if (isset($this->userConfig[$userId][$appName][$key])) { |
|
| 43 | + return $this->userConfig[$userId][$appName][$key]; |
|
| 44 | + } else { |
|
| 45 | + return $default; |
|
| 46 | + } |
|
| 47 | + }); |
|
| 48 | + $this->config->method('setUserValue') |
|
| 49 | + ->willReturnCallback(function ($userId, $appName, $key, $value): void { |
|
| 50 | + $this->userConfig[$userId][$appName][$key] = $value; |
|
| 51 | + }); |
|
| 52 | + |
|
| 53 | + $this->objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->appManager); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + private function getUser(string $uid): IUser { |
|
| 57 | + $user = $this->createMock(IUser::class); |
|
| 58 | + $user->method('getUID') |
|
| 59 | + ->willReturn($uid); |
|
| 60 | + return $user; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + private function setConfig(string $key, $value) { |
|
| 64 | + $this->systemConfig[$key] = $value; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function testNewUserGetsDefault() { |
|
| 68 | + $this->setConfig('objectstore', [ |
|
| 69 | + 'default' => 'server1', |
|
| 70 | + 'server1' => [ |
|
| 71 | + 'class' => StorageObjectStore::class, |
|
| 72 | + 'arguments' => [ |
|
| 73 | + 'host' => 'server1', |
|
| 74 | + ], |
|
| 75 | + ], |
|
| 76 | + ]); |
|
| 77 | + |
|
| 78 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 79 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 80 | + |
|
| 81 | + $this->assertEquals('server1', $this->config->getUserValue('test', 'homeobjectstore', 'objectstore', null)); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function testExistingUserKeepsStorage() { |
|
| 85 | + // setup user with `server1` as storage |
|
| 86 | + $this->testNewUserGetsDefault(); |
|
| 87 | + |
|
| 88 | + $this->setConfig('objectstore', [ |
|
| 89 | + 'default' => 'server2', |
|
| 90 | + 'server1' => [ |
|
| 91 | + 'class' => StorageObjectStore::class, |
|
| 92 | + 'arguments' => [ |
|
| 93 | + 'host' => 'server1', |
|
| 94 | + 'bucket' => '1', |
|
| 95 | + ], |
|
| 96 | + ], |
|
| 97 | + 'server2' => [ |
|
| 98 | + 'class' => StorageObjectStore::class, |
|
| 99 | + 'arguments' => [ |
|
| 100 | + 'host' => 'server2', |
|
| 101 | + 'bucket' => '2', |
|
| 102 | + ], |
|
| 103 | + ], |
|
| 104 | + ]); |
|
| 105 | + |
|
| 106 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 107 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 108 | + |
|
| 109 | + $this->assertEquals('server1', $this->config->getUserValue('test', 'homeobjectstore', 'objectstore', null)); |
|
| 110 | + |
|
| 111 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('other-user')); |
|
| 112 | + $this->assertEquals('server2', $result['arguments']['host']); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function testNestedAliases() { |
|
| 116 | + $this->setConfig('objectstore', [ |
|
| 117 | + 'default' => 'a1', |
|
| 118 | + 'a1' => 'a2', |
|
| 119 | + 'a2' => 'server1', |
|
| 120 | + 'server1' => [ |
|
| 121 | + 'class' => StorageObjectStore::class, |
|
| 122 | + 'arguments' => [ |
|
| 123 | + 'host' => 'server1', |
|
| 124 | + 'bucket' => '1', |
|
| 125 | + ], |
|
| 126 | + ], |
|
| 127 | + ]); |
|
| 128 | + $this->assertEquals('server1', $this->objectStoreConfig->resolveAlias('default')); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function testMultibucketChangedConfig() { |
|
| 132 | + $this->setConfig('objectstore', [ |
|
| 133 | + 'default' => 'server1', |
|
| 134 | + 'server1' => [ |
|
| 135 | + 'class' => StorageObjectStore::class, |
|
| 136 | + 'arguments' => [ |
|
| 137 | + 'host' => 'server1', |
|
| 138 | + 'multibucket' => true, |
|
| 139 | + 'num_buckets' => 8, |
|
| 140 | + 'bucket' => 'bucket1-' |
|
| 141 | + ], |
|
| 142 | + ], |
|
| 143 | + ]); |
|
| 144 | + |
|
| 145 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 146 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 147 | + $this->assertEquals('bucket1-7', $result['arguments']['bucket']); |
|
| 148 | + |
|
| 149 | + $this->setConfig('objectstore', [ |
|
| 150 | + 'default' => 'server1', |
|
| 151 | + 'server1' => [ |
|
| 152 | + 'class' => StorageObjectStore::class, |
|
| 153 | + 'arguments' => [ |
|
| 154 | + 'host' => 'server1', |
|
| 155 | + 'multibucket' => true, |
|
| 156 | + 'num_buckets' => 64, |
|
| 157 | + 'bucket' => 'bucket1-' |
|
| 158 | + ], |
|
| 159 | + ], |
|
| 160 | + ]); |
|
| 161 | + |
|
| 162 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 163 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 164 | + $this->assertEquals('bucket1-7', $result['arguments']['bucket']); |
|
| 165 | + |
|
| 166 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test-foo')); |
|
| 167 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 168 | + $this->assertEquals('bucket1-40', $result['arguments']['bucket']); |
|
| 169 | + |
|
| 170 | + $this->setConfig('objectstore', [ |
|
| 171 | + 'default' => 'server2', |
|
| 172 | + 'server1' => [ |
|
| 173 | + 'class' => StorageObjectStore::class, |
|
| 174 | + 'arguments' => [ |
|
| 175 | + 'host' => 'server1', |
|
| 176 | + 'multibucket' => true, |
|
| 177 | + 'num_buckets' => 64, |
|
| 178 | + 'bucket' => 'bucket1-' |
|
| 179 | + ], |
|
| 180 | + ], |
|
| 181 | + 'server2' => [ |
|
| 182 | + 'class' => StorageObjectStore::class, |
|
| 183 | + 'arguments' => [ |
|
| 184 | + 'host' => 'server2', |
|
| 185 | + 'multibucket' => true, |
|
| 186 | + 'num_buckets' => 16, |
|
| 187 | + 'bucket' => 'bucket2-' |
|
| 188 | + ], |
|
| 189 | + ], |
|
| 190 | + ]); |
|
| 191 | + |
|
| 192 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test')); |
|
| 193 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 194 | + $this->assertEquals('bucket1-7', $result['arguments']['bucket']); |
|
| 195 | + |
|
| 196 | + $result = $this->objectStoreConfig->getObjectStoreConfigForUser($this->getUser('test-bar')); |
|
| 197 | + $this->assertEquals('server2', $result['arguments']['host']); |
|
| 198 | + $this->assertEquals('bucket2-4', $result['arguments']['bucket']); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + public function testMultibucketOldConfig() { |
|
| 202 | + $this->setConfig('objectstore_multibucket', [ |
|
| 203 | + 'class' => StorageObjectStore::class, |
|
| 204 | + 'arguments' => [ |
|
| 205 | + 'host' => 'server1', |
|
| 206 | + 'multibucket' => true, |
|
| 207 | + 'num_buckets' => 8, |
|
| 208 | + 'bucket' => 'bucket-' |
|
| 209 | + ], |
|
| 210 | + ]); |
|
| 211 | + $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 212 | + $this->assertEquals([ |
|
| 213 | + 'default' => 'server1', |
|
| 214 | + 'root' => 'server1', |
|
| 215 | + 'preview' => 'server1', |
|
| 216 | + 'server1' => [ |
|
| 217 | + 'class' => StorageObjectStore::class, |
|
| 218 | + 'arguments' => [ |
|
| 219 | + 'host' => 'server1', |
|
| 220 | + 'multibucket' => true, |
|
| 221 | + 'num_buckets' => 8, |
|
| 222 | + 'bucket' => 'bucket-' |
|
| 223 | + ], |
|
| 224 | + ], |
|
| 225 | + ], $configs); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + public function testSingleObjectStore() { |
|
| 229 | + $this->setConfig('objectstore', [ |
|
| 230 | + 'class' => StorageObjectStore::class, |
|
| 231 | + 'arguments' => [ |
|
| 232 | + 'host' => 'server1', |
|
| 233 | + ], |
|
| 234 | + ]); |
|
| 235 | + $configs = $this->objectStoreConfig->getObjectStoreConfigs(); |
|
| 236 | + $this->assertEquals([ |
|
| 237 | + 'default' => 'server1', |
|
| 238 | + 'root' => 'server1', |
|
| 239 | + 'preview' => 'server1', |
|
| 240 | + 'server1' => [ |
|
| 241 | + 'class' => StorageObjectStore::class, |
|
| 242 | + 'arguments' => [ |
|
| 243 | + 'host' => 'server1', |
|
| 244 | + 'multibucket' => false, |
|
| 245 | + ], |
|
| 246 | + ], |
|
| 247 | + ], $configs); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function testRoot() { |
|
| 251 | + $this->setConfig('objectstore', [ |
|
| 252 | + 'default' => 'server1', |
|
| 253 | + 'server1' => [ |
|
| 254 | + 'class' => StorageObjectStore::class, |
|
| 255 | + 'arguments' => [ |
|
| 256 | + 'host' => 'server1', |
|
| 257 | + 'bucket' => '1', |
|
| 258 | + ], |
|
| 259 | + ], |
|
| 260 | + 'server2' => [ |
|
| 261 | + 'class' => StorageObjectStore::class, |
|
| 262 | + 'arguments' => [ |
|
| 263 | + 'host' => 'server2', |
|
| 264 | + 'bucket' => '2', |
|
| 265 | + ], |
|
| 266 | + ], |
|
| 267 | + ]); |
|
| 268 | + |
|
| 269 | + $result = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 270 | + $this->assertEquals('server1', $result['arguments']['host']); |
|
| 271 | + |
|
| 272 | + $this->setConfig('objectstore', [ |
|
| 273 | + 'default' => 'server1', |
|
| 274 | + 'root' => 'server2', |
|
| 275 | + 'preview' => 'server1', |
|
| 276 | + 'server1' => [ |
|
| 277 | + 'class' => StorageObjectStore::class, |
|
| 278 | + 'arguments' => [ |
|
| 279 | + 'host' => 'server1', |
|
| 280 | + 'bucket' => '1', |
|
| 281 | + ], |
|
| 282 | + ], |
|
| 283 | + 'server2' => [ |
|
| 284 | + 'class' => StorageObjectStore::class, |
|
| 285 | + 'arguments' => [ |
|
| 286 | + 'host' => 'server2', |
|
| 287 | + 'bucket' => '2', |
|
| 288 | + ], |
|
| 289 | + ], |
|
| 290 | + ]); |
|
| 291 | + |
|
| 292 | + $result = $this->objectStoreConfig->getObjectStoreConfigForRoot(); |
|
| 293 | + $this->assertEquals('server2', $result['arguments']['host']); |
|
| 294 | + } |
|
| 295 | 295 | } |
@@ -14,641 +14,641 @@ |
||
| 14 | 14 | use OCP\Files\Storage\IWriteStreamStorage; |
| 15 | 15 | |
| 16 | 16 | abstract class Storage extends \Test\TestCase { |
| 17 | - /** |
|
| 18 | - * @var \OC\Files\Storage\Storage instance |
|
| 19 | - */ |
|
| 20 | - protected $instance; |
|
| 21 | - protected $waitDelay = 0; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Sleep for the number of seconds specified in the |
|
| 25 | - * $waitDelay attribute |
|
| 26 | - */ |
|
| 27 | - protected function wait() { |
|
| 28 | - if ($this->waitDelay > 0) { |
|
| 29 | - sleep($this->waitDelay); |
|
| 30 | - } |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * the root folder of the storage should always exist, be readable and be recognized as a directory |
|
| 35 | - */ |
|
| 36 | - public function testRoot(): void { |
|
| 37 | - $this->assertTrue($this->instance->file_exists('/'), 'Root folder does not exist'); |
|
| 38 | - $this->assertTrue($this->instance->isReadable('/'), 'Root folder is not readable'); |
|
| 39 | - $this->assertTrue($this->instance->is_dir('/'), 'Root folder is not a directory'); |
|
| 40 | - $this->assertFalse($this->instance->is_file('/'), 'Root folder is a file'); |
|
| 41 | - $this->assertEquals('dir', $this->instance->filetype('/')); |
|
| 42 | - |
|
| 43 | - //without this, any further testing would be useless, not an actual requirement for filestorage though |
|
| 44 | - $this->assertTrue($this->instance->isUpdatable('/'), 'Root folder is not writable'); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Check that the test() function works |
|
| 49 | - */ |
|
| 50 | - public function testTestFunction(): void { |
|
| 51 | - $this->assertTrue($this->instance->test()); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - #[\PHPUnit\Framework\Attributes\DataProvider('directoryProvider')] |
|
| 55 | - public function testDirectories($directory): void { |
|
| 56 | - $this->assertFalse($this->instance->file_exists('/' . $directory)); |
|
| 57 | - |
|
| 58 | - $this->assertTrue($this->instance->mkdir('/' . $directory)); |
|
| 59 | - |
|
| 60 | - $this->assertTrue($this->instance->file_exists('/' . $directory)); |
|
| 61 | - $this->assertTrue($this->instance->is_dir('/' . $directory)); |
|
| 62 | - $this->assertFalse($this->instance->is_file('/' . $directory)); |
|
| 63 | - $this->assertEquals('dir', $this->instance->filetype('/' . $directory)); |
|
| 64 | - $this->assertEquals(0, $this->instance->filesize('/' . $directory)); |
|
| 65 | - $this->assertTrue($this->instance->isReadable('/' . $directory)); |
|
| 66 | - $this->assertTrue($this->instance->isUpdatable('/' . $directory)); |
|
| 67 | - |
|
| 68 | - $dh = $this->instance->opendir('/'); |
|
| 69 | - $content = []; |
|
| 70 | - while (($file = readdir($dh)) !== false) { |
|
| 71 | - if ($file !== '.' && $file !== '..') { |
|
| 72 | - $content[] = $file; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - $this->assertEquals([$directory], $content); |
|
| 76 | - |
|
| 77 | - $content = iterator_to_array($this->instance->getDirectoryContent('/')); |
|
| 78 | - |
|
| 79 | - $this->assertCount(1, $content); |
|
| 80 | - $dirEntry = $content[0]; |
|
| 81 | - unset($dirEntry['scan_permissions']); |
|
| 82 | - unset($dirEntry['etag']); |
|
| 83 | - $this->assertLessThanOrEqual(1, abs($dirEntry['mtime'] - $this->instance->filemtime($directory))); |
|
| 84 | - unset($dirEntry['mtime']); |
|
| 85 | - unset($dirEntry['storage_mtime']); |
|
| 86 | - $this->assertEquals([ |
|
| 87 | - 'name' => $directory, |
|
| 88 | - 'mimetype' => $this->instance->getMimeType($directory), |
|
| 89 | - 'size' => -1, |
|
| 90 | - 'permissions' => $this->instance->getPermissions($directory), |
|
| 91 | - ], $dirEntry); |
|
| 92 | - |
|
| 93 | - $this->assertFalse($this->instance->mkdir('/' . $directory)); //can't create existing folders |
|
| 94 | - $this->assertTrue($this->instance->rmdir('/' . $directory)); |
|
| 95 | - |
|
| 96 | - $this->wait(); |
|
| 97 | - $this->assertFalse($this->instance->file_exists('/' . $directory)); |
|
| 98 | - |
|
| 99 | - $this->assertFalse($this->instance->rmdir('/' . $directory)); //can't remove non existing folders |
|
| 100 | - |
|
| 101 | - $dh = $this->instance->opendir('/'); |
|
| 102 | - $content = []; |
|
| 103 | - while (($file = readdir($dh)) !== false) { |
|
| 104 | - if ($file != '.' && $file != '..') { |
|
| 105 | - $content[] = $file; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - $this->assertEquals([], $content); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public static function fileNameProvider(): array { |
|
| 112 | - return [ |
|
| 113 | - ['file.txt'], |
|
| 114 | - [' file.txt'], |
|
| 115 | - ['folder .txt'], |
|
| 116 | - ['file with space.txt'], |
|
| 117 | - ['spéciäl fäile'], |
|
| 118 | - ['test single\'quote.txt'], |
|
| 119 | - ]; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - public static function directoryProvider(): array { |
|
| 123 | - return [ |
|
| 124 | - ['folder'], |
|
| 125 | - [' folder'], |
|
| 126 | - ['folder '], |
|
| 127 | - ['folder with space'], |
|
| 128 | - ['spéciäl földer'], |
|
| 129 | - ['test single\'quote'], |
|
| 130 | - ]; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public static function loremFileProvider(): array { |
|
| 134 | - $root = \OC::$SERVERROOT . '/tests/data/'; |
|
| 135 | - return [ |
|
| 136 | - // small file |
|
| 137 | - [$root . 'lorem.txt'], |
|
| 138 | - // bigger file (> 8 KB which is the standard PHP block size) |
|
| 139 | - [$root . 'lorem-big.txt'] |
|
| 140 | - ]; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * test the various uses of file_get_contents and file_put_contents |
|
| 145 | - */ |
|
| 146 | - #[\PHPUnit\Framework\Attributes\DataProvider('loremFileProvider')] |
|
| 147 | - public function testGetPutContents($sourceFile): void { |
|
| 148 | - $sourceText = file_get_contents($sourceFile); |
|
| 149 | - |
|
| 150 | - //fill a file with string data |
|
| 151 | - $this->instance->file_put_contents('/lorem.txt', $sourceText); |
|
| 152 | - $this->assertFalse($this->instance->is_dir('/lorem.txt')); |
|
| 153 | - $this->assertEquals($sourceText, $this->instance->file_get_contents('/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); |
|
| 154 | - |
|
| 155 | - //empty the file |
|
| 156 | - $this->instance->file_put_contents('/lorem.txt', ''); |
|
| 157 | - $this->assertEquals('', $this->instance->file_get_contents('/lorem.txt'), 'file not emptied'); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * test various known mimetypes |
|
| 162 | - */ |
|
| 163 | - public function testMimeType(): void { |
|
| 164 | - $this->assertEquals('httpd/unix-directory', $this->instance->getMimeType('/')); |
|
| 165 | - $this->assertEquals(false, $this->instance->getMimeType('/non/existing/file')); |
|
| 166 | - |
|
| 167 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 168 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r')); |
|
| 169 | - $this->assertEquals('text/plain', $this->instance->getMimeType('/lorem.txt')); |
|
| 170 | - |
|
| 171 | - $pngFile = \OC::$SERVERROOT . '/tests/data/desktopapp.png'; |
|
| 172 | - $this->instance->file_put_contents('/desktopapp.png', file_get_contents($pngFile, 'r')); |
|
| 173 | - $this->assertEquals('image/png', $this->instance->getMimeType('/desktopapp.png')); |
|
| 174 | - |
|
| 175 | - $svgFile = \OC::$SERVERROOT . '/tests/data/desktopapp.svg'; |
|
| 176 | - $this->instance->file_put_contents('/desktopapp.svg', file_get_contents($svgFile, 'r')); |
|
| 177 | - $this->assertEquals('image/svg+xml', $this->instance->getMimeType('/desktopapp.svg')); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - public static function copyAndMoveProvider(): array { |
|
| 182 | - return [ |
|
| 183 | - ['/source.txt', '/target.txt'], |
|
| 184 | - ['/source.txt', '/target with space.txt'], |
|
| 185 | - ['/source with space.txt', '/target.txt'], |
|
| 186 | - ['/source with space.txt', '/target with space.txt'], |
|
| 187 | - ['/source.txt', '/tärgét.txt'], |
|
| 188 | - ['/sòurcē.txt', '/target.txt'], |
|
| 189 | - ['/sòurcē.txt', '/tärgét.txt'], |
|
| 190 | - ['/single \' quote.txt', '/tar\'get.txt'], |
|
| 191 | - ]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - public function initSourceAndTarget($source, $target = null) { |
|
| 195 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 196 | - $this->instance->file_put_contents($source, file_get_contents($textFile)); |
|
| 197 | - if ($target) { |
|
| 198 | - $testContents = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
| 199 | - $this->instance->file_put_contents($target, $testContents); |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - public function assertSameAsLorem($file) { |
|
| 204 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 205 | - $this->assertEquals( |
|
| 206 | - file_get_contents($textFile), |
|
| 207 | - $this->instance->file_get_contents($file), |
|
| 208 | - 'Expected ' . $file . ' to be a copy of ' . $textFile |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 213 | - public function testCopy($source, $target): void { |
|
| 214 | - $this->initSourceAndTarget($source); |
|
| 215 | - |
|
| 216 | - $this->instance->copy($source, $target); |
|
| 217 | - |
|
| 218 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 219 | - $this->assertSameAsLorem($target); |
|
| 220 | - $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 224 | - public function testMove($source, $target): void { |
|
| 225 | - $this->initSourceAndTarget($source); |
|
| 226 | - |
|
| 227 | - $this->instance->rename($source, $target); |
|
| 228 | - |
|
| 229 | - $this->wait(); |
|
| 230 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 231 | - $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); |
|
| 232 | - $this->assertSameAsLorem($target); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 236 | - public function testCopyOverwrite($source, $target): void { |
|
| 237 | - $this->initSourceAndTarget($source, $target); |
|
| 238 | - |
|
| 239 | - $this->instance->copy($source, $target); |
|
| 240 | - |
|
| 241 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 242 | - $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
| 243 | - $this->assertSameAsLorem($target); |
|
| 244 | - $this->assertSameAsLorem($source); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 248 | - public function testMoveOverwrite($source, $target): void { |
|
| 249 | - $this->initSourceAndTarget($source, $target); |
|
| 250 | - |
|
| 251 | - $this->instance->rename($source, $target); |
|
| 252 | - |
|
| 253 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 254 | - $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); |
|
| 255 | - $this->assertSameAsLorem($target); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - public function testLocal(): void { |
|
| 259 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 260 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
| 261 | - $localFile = $this->instance->getLocalFile('/lorem.txt'); |
|
| 262 | - $this->assertTrue(file_exists($localFile)); |
|
| 263 | - $this->assertEquals(file_get_contents($textFile), file_get_contents($localFile)); |
|
| 264 | - |
|
| 265 | - $this->instance->mkdir('/folder'); |
|
| 266 | - $this->instance->file_put_contents('/folder/lorem.txt', file_get_contents($textFile)); |
|
| 267 | - $this->instance->file_put_contents('/folder/bar.txt', 'asd'); |
|
| 268 | - $this->instance->mkdir('/folder/recursive'); |
|
| 269 | - $this->instance->file_put_contents('/folder/recursive/file.txt', 'foo'); |
|
| 270 | - |
|
| 271 | - // test below require to use instance->getLocalFile because the physical storage might be different |
|
| 272 | - $localFile = $this->instance->getLocalFile('/folder/lorem.txt'); |
|
| 273 | - $this->assertTrue(file_exists($localFile)); |
|
| 274 | - $this->assertEquals(file_get_contents($localFile), file_get_contents($textFile)); |
|
| 275 | - |
|
| 276 | - $localFile = $this->instance->getLocalFile('/folder/bar.txt'); |
|
| 277 | - $this->assertTrue(file_exists($localFile)); |
|
| 278 | - $this->assertEquals(file_get_contents($localFile), 'asd'); |
|
| 279 | - |
|
| 280 | - $localFile = $this->instance->getLocalFile('/folder/recursive/file.txt'); |
|
| 281 | - $this->assertTrue(file_exists($localFile)); |
|
| 282 | - $this->assertEquals(file_get_contents($localFile), 'foo'); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - public function testStat(): void { |
|
| 286 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 287 | - $ctimeStart = time(); |
|
| 288 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
| 289 | - $this->assertTrue($this->instance->isReadable('/lorem.txt')); |
|
| 290 | - $ctimeEnd = time(); |
|
| 291 | - $mTime = $this->instance->filemtime('/lorem.txt'); |
|
| 292 | - $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); |
|
| 293 | - $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5)); |
|
| 294 | - |
|
| 295 | - // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1) |
|
| 296 | - $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime); |
|
| 297 | - $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime); |
|
| 298 | - $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); |
|
| 299 | - |
|
| 300 | - $stat = $this->instance->stat('/lorem.txt'); |
|
| 301 | - //only size and mtime are required in the result |
|
| 302 | - $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); |
|
| 303 | - $this->assertEquals($stat['mtime'], $mTime); |
|
| 304 | - |
|
| 305 | - if ($this->instance->touch('/lorem.txt', 100) !== false) { |
|
| 306 | - $mTime = $this->instance->filemtime('/lorem.txt'); |
|
| 307 | - $this->assertEquals($mTime, 100); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - $mtimeStart = time(); |
|
| 311 | - |
|
| 312 | - $this->instance->unlink('/lorem.txt'); |
|
| 313 | - $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Test whether checkUpdate properly returns false when there was |
|
| 318 | - * no change. |
|
| 319 | - */ |
|
| 320 | - public function testCheckUpdate(): void { |
|
| 321 | - if ($this->instance instanceof Wrapper) { |
|
| 322 | - $this->markTestSkipped('Cannot test update check on wrappers'); |
|
| 323 | - } |
|
| 324 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 325 | - $watcher = $this->instance->getWatcher(); |
|
| 326 | - $watcher->setPolicy(Watcher::CHECK_ALWAYS); |
|
| 327 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
| 328 | - $this->assertTrue($watcher->checkUpdate('/lorem.txt'), 'Update detected'); |
|
| 329 | - $this->assertFalse($watcher->checkUpdate('/lorem.txt'), 'No update'); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - public function testUnlink(): void { |
|
| 333 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 334 | - $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
| 335 | - |
|
| 336 | - $this->assertTrue($this->instance->file_exists('/lorem.txt')); |
|
| 337 | - |
|
| 338 | - $this->assertTrue($this->instance->unlink('/lorem.txt')); |
|
| 339 | - $this->wait(); |
|
| 340 | - |
|
| 341 | - $this->assertFalse($this->instance->file_exists('/lorem.txt')); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - #[\PHPUnit\Framework\Attributes\DataProvider('fileNameProvider')] |
|
| 345 | - public function testFOpen($fileName): void { |
|
| 346 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 347 | - |
|
| 348 | - $fh = @$this->instance->fopen($fileName, 'r'); |
|
| 349 | - if ($fh) { |
|
| 350 | - fclose($fh); |
|
| 351 | - } |
|
| 352 | - $this->assertFalse($fh); |
|
| 353 | - $this->assertFalse($this->instance->file_exists($fileName)); |
|
| 354 | - |
|
| 355 | - $fh = $this->instance->fopen($fileName, 'w'); |
|
| 356 | - fwrite($fh, file_get_contents($textFile)); |
|
| 357 | - fclose($fh); |
|
| 358 | - $this->assertTrue($this->instance->file_exists($fileName)); |
|
| 359 | - |
|
| 360 | - $fh = $this->instance->fopen($fileName, 'r'); |
|
| 361 | - $this->assertTrue(is_resource($fh)); |
|
| 362 | - $content = stream_get_contents($fh); |
|
| 363 | - $this->assertEquals(file_get_contents($textFile), $content); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - public function testTouchCreateFile(): void { |
|
| 367 | - $this->assertFalse($this->instance->file_exists('touch')); |
|
| 368 | - // returns true on success |
|
| 369 | - $this->assertTrue($this->instance->touch('touch')); |
|
| 370 | - $this->assertTrue($this->instance->file_exists('touch')); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - public function testRecursiveRmdir(): void { |
|
| 374 | - $this->instance->mkdir('folder'); |
|
| 375 | - $this->instance->mkdir('folder/bar'); |
|
| 376 | - $this->wait(); |
|
| 377 | - $this->instance->file_put_contents('folder/asd.txt', 'foobar'); |
|
| 378 | - $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); |
|
| 379 | - $this->assertTrue($this->instance->rmdir('folder')); |
|
| 380 | - $this->wait(); |
|
| 381 | - $this->assertFalse($this->instance->file_exists('folder/asd.txt')); |
|
| 382 | - $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); |
|
| 383 | - $this->assertFalse($this->instance->file_exists('folder/bar')); |
|
| 384 | - $this->assertFalse($this->instance->file_exists('folder')); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - public function testRmdirEmptyFolder(): void { |
|
| 388 | - $this->assertTrue($this->instance->mkdir('empty')); |
|
| 389 | - $this->wait(); |
|
| 390 | - $this->assertTrue($this->instance->rmdir('empty')); |
|
| 391 | - $this->assertFalse($this->instance->file_exists('empty')); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - public function testRecursiveUnlink(): void { |
|
| 395 | - $this->instance->mkdir('folder'); |
|
| 396 | - $this->instance->mkdir('folder/bar'); |
|
| 397 | - $this->instance->file_put_contents('folder/asd.txt', 'foobar'); |
|
| 398 | - $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); |
|
| 399 | - $this->assertTrue($this->instance->unlink('folder')); |
|
| 400 | - $this->wait(); |
|
| 401 | - $this->assertFalse($this->instance->file_exists('folder/asd.txt')); |
|
| 402 | - $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); |
|
| 403 | - $this->assertFalse($this->instance->file_exists('folder/bar')); |
|
| 404 | - $this->assertFalse($this->instance->file_exists('folder')); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - public static function hashProvider(): array { |
|
| 408 | - return [ |
|
| 409 | - ['Foobar', 'md5'], |
|
| 410 | - ['Foobar', 'sha1'], |
|
| 411 | - ['Foobar', 'sha256'], |
|
| 412 | - ]; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - #[\PHPUnit\Framework\Attributes\DataProvider('hashProvider')] |
|
| 416 | - public function testHash($data, $type): void { |
|
| 417 | - $this->instance->file_put_contents('hash.txt', $data); |
|
| 418 | - $this->assertEquals(hash($type, $data), $this->instance->hash($type, 'hash.txt')); |
|
| 419 | - $this->assertEquals(hash($type, $data, true), $this->instance->hash($type, 'hash.txt', true)); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - public function testHashInFileName(): void { |
|
| 423 | - $this->instance->file_put_contents('#test.txt', 'data'); |
|
| 424 | - $this->assertEquals('data', $this->instance->file_get_contents('#test.txt')); |
|
| 425 | - |
|
| 426 | - $this->instance->mkdir('#foo'); |
|
| 427 | - $this->instance->file_put_contents('#foo/test.txt', 'data'); |
|
| 428 | - $this->assertEquals('data', $this->instance->file_get_contents('#foo/test.txt')); |
|
| 429 | - |
|
| 430 | - $dh = $this->instance->opendir('#foo'); |
|
| 431 | - $content = []; |
|
| 432 | - while ($file = readdir($dh)) { |
|
| 433 | - if ($file != '.' && $file != '..') { |
|
| 434 | - $content[] = $file; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $this->assertEquals(['test.txt'], $content); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - public function testCopyOverWriteFile(): void { |
|
| 442 | - $this->instance->file_put_contents('target.txt', 'foo'); |
|
| 443 | - $this->instance->file_put_contents('source.txt', 'bar'); |
|
| 444 | - $this->instance->copy('source.txt', 'target.txt'); |
|
| 445 | - $this->assertEquals('bar', $this->instance->file_get_contents('target.txt')); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - public function testRenameOverWriteFile(): void { |
|
| 449 | - $this->instance->file_put_contents('target.txt', 'foo'); |
|
| 450 | - $this->instance->file_put_contents('source.txt', 'bar'); |
|
| 451 | - $this->instance->rename('source.txt', 'target.txt'); |
|
| 452 | - $this->assertEquals('bar', $this->instance->file_get_contents('target.txt')); |
|
| 453 | - $this->assertFalse($this->instance->file_exists('source.txt')); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - public function testRenameDirectory(): void { |
|
| 457 | - $this->instance->mkdir('source'); |
|
| 458 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 459 | - $this->instance->file_put_contents('source/test2.txt', 'qwerty'); |
|
| 460 | - $this->instance->mkdir('source/subfolder'); |
|
| 461 | - $this->instance->file_put_contents('source/subfolder/test.txt', 'bar'); |
|
| 462 | - $this->instance->rename('source', 'target'); |
|
| 463 | - |
|
| 464 | - $this->assertFalse($this->instance->file_exists('source')); |
|
| 465 | - $this->assertFalse($this->instance->file_exists('source/test1.txt')); |
|
| 466 | - $this->assertFalse($this->instance->file_exists('source/test2.txt')); |
|
| 467 | - $this->assertFalse($this->instance->file_exists('source/subfolder')); |
|
| 468 | - $this->assertFalse($this->instance->file_exists('source/subfolder/test.txt')); |
|
| 469 | - |
|
| 470 | - $this->assertTrue($this->instance->file_exists('target')); |
|
| 471 | - $this->assertTrue($this->instance->file_exists('target/test1.txt')); |
|
| 472 | - $this->assertTrue($this->instance->file_exists('target/test2.txt')); |
|
| 473 | - $this->assertTrue($this->instance->file_exists('target/subfolder')); |
|
| 474 | - $this->assertTrue($this->instance->file_exists('target/subfolder/test.txt')); |
|
| 475 | - |
|
| 476 | - $contents = iterator_to_array($this->instance->getDirectoryContent('')); |
|
| 477 | - $this->assertCount(1, $contents); |
|
| 478 | - |
|
| 479 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 480 | - $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt')); |
|
| 481 | - $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt')); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - public function testRenameOverWriteDirectory(): void { |
|
| 485 | - $this->instance->mkdir('source'); |
|
| 486 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 487 | - |
|
| 488 | - $this->instance->mkdir('target'); |
|
| 489 | - $this->instance->file_put_contents('target/test1.txt', 'bar'); |
|
| 490 | - $this->instance->file_put_contents('target/test2.txt', 'bar'); |
|
| 491 | - |
|
| 492 | - $this->assertTrue($this->instance->rename('source', 'target'), 'rename must return true on success'); |
|
| 493 | - |
|
| 494 | - $this->assertFalse($this->instance->file_exists('source'), 'source has not been removed'); |
|
| 495 | - $this->assertFalse($this->instance->file_exists('source/test1.txt'), 'source/test1.txt has not been removed'); |
|
| 496 | - $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'target/test2.txt has not been removed'); |
|
| 497 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'), 'target/test1.txt has not been overwritten'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - public function testRenameOverWriteDirectoryOverFile(): void { |
|
| 501 | - $this->instance->mkdir('source'); |
|
| 502 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 503 | - |
|
| 504 | - $this->instance->file_put_contents('target', 'bar'); |
|
| 505 | - |
|
| 506 | - $this->assertTrue($this->instance->rename('source', 'target'), 'rename must return true on success'); |
|
| 507 | - |
|
| 508 | - $this->assertFalse($this->instance->file_exists('source')); |
|
| 509 | - $this->assertFalse($this->instance->file_exists('source/test1.txt')); |
|
| 510 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - public function testCopyDirectory(): void { |
|
| 514 | - $this->instance->mkdir('source'); |
|
| 515 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 516 | - $this->instance->file_put_contents('source/test2.txt', 'qwerty'); |
|
| 517 | - $this->instance->mkdir('source/subfolder'); |
|
| 518 | - $this->instance->file_put_contents('source/subfolder/test.txt', 'bar'); |
|
| 519 | - $this->instance->copy('source', 'target'); |
|
| 520 | - |
|
| 521 | - $this->assertTrue($this->instance->file_exists('source')); |
|
| 522 | - $this->assertTrue($this->instance->file_exists('source/test1.txt')); |
|
| 523 | - $this->assertTrue($this->instance->file_exists('source/test2.txt')); |
|
| 524 | - $this->assertTrue($this->instance->file_exists('source/subfolder')); |
|
| 525 | - $this->assertTrue($this->instance->file_exists('source/subfolder/test.txt')); |
|
| 526 | - |
|
| 527 | - $this->assertTrue($this->instance->file_exists('target')); |
|
| 528 | - $this->assertTrue($this->instance->file_exists('target/test1.txt')); |
|
| 529 | - $this->assertTrue($this->instance->file_exists('target/test2.txt')); |
|
| 530 | - $this->assertTrue($this->instance->file_exists('target/subfolder')); |
|
| 531 | - $this->assertTrue($this->instance->file_exists('target/subfolder/test.txt')); |
|
| 532 | - |
|
| 533 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 534 | - $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt')); |
|
| 535 | - $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt')); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - public function testCopyOverWriteDirectory(): void { |
|
| 539 | - $this->instance->mkdir('source'); |
|
| 540 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 541 | - |
|
| 542 | - $this->instance->mkdir('target'); |
|
| 543 | - $this->instance->file_put_contents('target/test1.txt', 'bar'); |
|
| 544 | - $this->instance->file_put_contents('target/test2.txt', 'bar'); |
|
| 545 | - |
|
| 546 | - $this->instance->copy('source', 'target'); |
|
| 547 | - |
|
| 548 | - $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'File target/test2.txt should no longer exist, but does'); |
|
| 549 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - public function testCopyOverWriteDirectoryOverFile(): void { |
|
| 553 | - $this->instance->mkdir('source'); |
|
| 554 | - $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 555 | - |
|
| 556 | - $this->instance->file_put_contents('target', 'bar'); |
|
| 557 | - |
|
| 558 | - $this->instance->copy('source', 'target'); |
|
| 559 | - |
|
| 560 | - $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - public function testInstanceOfStorage(): void { |
|
| 564 | - $this->assertTrue($this->instance->instanceOfStorage(IStorage::class)); |
|
| 565 | - $this->assertTrue($this->instance->instanceOfStorage(get_class($this->instance))); |
|
| 566 | - $this->assertFalse($this->instance->instanceOfStorage('\OC')); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 570 | - public function testCopyFromSameStorage($source, $target): void { |
|
| 571 | - $this->initSourceAndTarget($source); |
|
| 572 | - |
|
| 573 | - $this->instance->copyFromStorage($this->instance, $source, $target); |
|
| 574 | - |
|
| 575 | - $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 576 | - $this->assertSameAsLorem($target); |
|
| 577 | - $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - public function testIsCreatable(): void { |
|
| 581 | - $this->instance->mkdir('source'); |
|
| 582 | - $this->assertTrue($this->instance->isCreatable('source')); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - public function testIsReadable(): void { |
|
| 586 | - $this->instance->mkdir('source'); |
|
| 587 | - $this->assertTrue($this->instance->isReadable('source')); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - public function testIsUpdatable(): void { |
|
| 591 | - $this->instance->mkdir('source'); |
|
| 592 | - $this->assertTrue($this->instance->isUpdatable('source')); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - public function testIsDeletable(): void { |
|
| 596 | - $this->instance->mkdir('source'); |
|
| 597 | - $this->assertTrue($this->instance->isDeletable('source')); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - public function testIsShareable(): void { |
|
| 601 | - $this->instance->mkdir('source'); |
|
| 602 | - $this->assertTrue($this->instance->isSharable('source')); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - public function testStatAfterWrite(): void { |
|
| 606 | - $this->instance->file_put_contents('foo.txt', 'bar'); |
|
| 607 | - $stat = $this->instance->stat('foo.txt'); |
|
| 608 | - $this->assertEquals(3, $stat['size']); |
|
| 609 | - |
|
| 610 | - $fh = $this->instance->fopen('foo.txt', 'w'); |
|
| 611 | - fwrite($fh, 'qwerty'); |
|
| 612 | - fclose($fh); |
|
| 613 | - |
|
| 614 | - $stat = $this->instance->stat('foo.txt'); |
|
| 615 | - $this->assertEquals(6, $stat['size']); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - public function testPartFile(): void { |
|
| 619 | - $this->instance->file_put_contents('bar.txt.part', 'bar'); |
|
| 620 | - $this->instance->rename('bar.txt.part', 'bar.txt'); |
|
| 621 | - $this->assertEquals('bar', $this->instance->file_get_contents('bar.txt')); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - public function testWriteStream(): void { |
|
| 625 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 626 | - |
|
| 627 | - if (!$this->instance->instanceOfStorage(IWriteStreamStorage::class)) { |
|
| 628 | - $this->markTestSkipped('Not a WriteSteamStorage'); |
|
| 629 | - } |
|
| 630 | - /** @var IWriteStreamStorage $storage */ |
|
| 631 | - $storage = $this->instance; |
|
| 17 | + /** |
|
| 18 | + * @var \OC\Files\Storage\Storage instance |
|
| 19 | + */ |
|
| 20 | + protected $instance; |
|
| 21 | + protected $waitDelay = 0; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Sleep for the number of seconds specified in the |
|
| 25 | + * $waitDelay attribute |
|
| 26 | + */ |
|
| 27 | + protected function wait() { |
|
| 28 | + if ($this->waitDelay > 0) { |
|
| 29 | + sleep($this->waitDelay); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * the root folder of the storage should always exist, be readable and be recognized as a directory |
|
| 35 | + */ |
|
| 36 | + public function testRoot(): void { |
|
| 37 | + $this->assertTrue($this->instance->file_exists('/'), 'Root folder does not exist'); |
|
| 38 | + $this->assertTrue($this->instance->isReadable('/'), 'Root folder is not readable'); |
|
| 39 | + $this->assertTrue($this->instance->is_dir('/'), 'Root folder is not a directory'); |
|
| 40 | + $this->assertFalse($this->instance->is_file('/'), 'Root folder is a file'); |
|
| 41 | + $this->assertEquals('dir', $this->instance->filetype('/')); |
|
| 42 | + |
|
| 43 | + //without this, any further testing would be useless, not an actual requirement for filestorage though |
|
| 44 | + $this->assertTrue($this->instance->isUpdatable('/'), 'Root folder is not writable'); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Check that the test() function works |
|
| 49 | + */ |
|
| 50 | + public function testTestFunction(): void { |
|
| 51 | + $this->assertTrue($this->instance->test()); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + #[\PHPUnit\Framework\Attributes\DataProvider('directoryProvider')] |
|
| 55 | + public function testDirectories($directory): void { |
|
| 56 | + $this->assertFalse($this->instance->file_exists('/' . $directory)); |
|
| 57 | + |
|
| 58 | + $this->assertTrue($this->instance->mkdir('/' . $directory)); |
|
| 59 | + |
|
| 60 | + $this->assertTrue($this->instance->file_exists('/' . $directory)); |
|
| 61 | + $this->assertTrue($this->instance->is_dir('/' . $directory)); |
|
| 62 | + $this->assertFalse($this->instance->is_file('/' . $directory)); |
|
| 63 | + $this->assertEquals('dir', $this->instance->filetype('/' . $directory)); |
|
| 64 | + $this->assertEquals(0, $this->instance->filesize('/' . $directory)); |
|
| 65 | + $this->assertTrue($this->instance->isReadable('/' . $directory)); |
|
| 66 | + $this->assertTrue($this->instance->isUpdatable('/' . $directory)); |
|
| 67 | + |
|
| 68 | + $dh = $this->instance->opendir('/'); |
|
| 69 | + $content = []; |
|
| 70 | + while (($file = readdir($dh)) !== false) { |
|
| 71 | + if ($file !== '.' && $file !== '..') { |
|
| 72 | + $content[] = $file; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + $this->assertEquals([$directory], $content); |
|
| 76 | + |
|
| 77 | + $content = iterator_to_array($this->instance->getDirectoryContent('/')); |
|
| 78 | + |
|
| 79 | + $this->assertCount(1, $content); |
|
| 80 | + $dirEntry = $content[0]; |
|
| 81 | + unset($dirEntry['scan_permissions']); |
|
| 82 | + unset($dirEntry['etag']); |
|
| 83 | + $this->assertLessThanOrEqual(1, abs($dirEntry['mtime'] - $this->instance->filemtime($directory))); |
|
| 84 | + unset($dirEntry['mtime']); |
|
| 85 | + unset($dirEntry['storage_mtime']); |
|
| 86 | + $this->assertEquals([ |
|
| 87 | + 'name' => $directory, |
|
| 88 | + 'mimetype' => $this->instance->getMimeType($directory), |
|
| 89 | + 'size' => -1, |
|
| 90 | + 'permissions' => $this->instance->getPermissions($directory), |
|
| 91 | + ], $dirEntry); |
|
| 92 | + |
|
| 93 | + $this->assertFalse($this->instance->mkdir('/' . $directory)); //can't create existing folders |
|
| 94 | + $this->assertTrue($this->instance->rmdir('/' . $directory)); |
|
| 95 | + |
|
| 96 | + $this->wait(); |
|
| 97 | + $this->assertFalse($this->instance->file_exists('/' . $directory)); |
|
| 98 | + |
|
| 99 | + $this->assertFalse($this->instance->rmdir('/' . $directory)); //can't remove non existing folders |
|
| 100 | + |
|
| 101 | + $dh = $this->instance->opendir('/'); |
|
| 102 | + $content = []; |
|
| 103 | + while (($file = readdir($dh)) !== false) { |
|
| 104 | + if ($file != '.' && $file != '..') { |
|
| 105 | + $content[] = $file; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + $this->assertEquals([], $content); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public static function fileNameProvider(): array { |
|
| 112 | + return [ |
|
| 113 | + ['file.txt'], |
|
| 114 | + [' file.txt'], |
|
| 115 | + ['folder .txt'], |
|
| 116 | + ['file with space.txt'], |
|
| 117 | + ['spéciäl fäile'], |
|
| 118 | + ['test single\'quote.txt'], |
|
| 119 | + ]; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + public static function directoryProvider(): array { |
|
| 123 | + return [ |
|
| 124 | + ['folder'], |
|
| 125 | + [' folder'], |
|
| 126 | + ['folder '], |
|
| 127 | + ['folder with space'], |
|
| 128 | + ['spéciäl földer'], |
|
| 129 | + ['test single\'quote'], |
|
| 130 | + ]; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public static function loremFileProvider(): array { |
|
| 134 | + $root = \OC::$SERVERROOT . '/tests/data/'; |
|
| 135 | + return [ |
|
| 136 | + // small file |
|
| 137 | + [$root . 'lorem.txt'], |
|
| 138 | + // bigger file (> 8 KB which is the standard PHP block size) |
|
| 139 | + [$root . 'lorem-big.txt'] |
|
| 140 | + ]; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * test the various uses of file_get_contents and file_put_contents |
|
| 145 | + */ |
|
| 146 | + #[\PHPUnit\Framework\Attributes\DataProvider('loremFileProvider')] |
|
| 147 | + public function testGetPutContents($sourceFile): void { |
|
| 148 | + $sourceText = file_get_contents($sourceFile); |
|
| 149 | + |
|
| 150 | + //fill a file with string data |
|
| 151 | + $this->instance->file_put_contents('/lorem.txt', $sourceText); |
|
| 152 | + $this->assertFalse($this->instance->is_dir('/lorem.txt')); |
|
| 153 | + $this->assertEquals($sourceText, $this->instance->file_get_contents('/lorem.txt'), 'data returned from file_get_contents is not equal to the source data'); |
|
| 154 | + |
|
| 155 | + //empty the file |
|
| 156 | + $this->instance->file_put_contents('/lorem.txt', ''); |
|
| 157 | + $this->assertEquals('', $this->instance->file_get_contents('/lorem.txt'), 'file not emptied'); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * test various known mimetypes |
|
| 162 | + */ |
|
| 163 | + public function testMimeType(): void { |
|
| 164 | + $this->assertEquals('httpd/unix-directory', $this->instance->getMimeType('/')); |
|
| 165 | + $this->assertEquals(false, $this->instance->getMimeType('/non/existing/file')); |
|
| 166 | + |
|
| 167 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 168 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r')); |
|
| 169 | + $this->assertEquals('text/plain', $this->instance->getMimeType('/lorem.txt')); |
|
| 170 | + |
|
| 171 | + $pngFile = \OC::$SERVERROOT . '/tests/data/desktopapp.png'; |
|
| 172 | + $this->instance->file_put_contents('/desktopapp.png', file_get_contents($pngFile, 'r')); |
|
| 173 | + $this->assertEquals('image/png', $this->instance->getMimeType('/desktopapp.png')); |
|
| 174 | + |
|
| 175 | + $svgFile = \OC::$SERVERROOT . '/tests/data/desktopapp.svg'; |
|
| 176 | + $this->instance->file_put_contents('/desktopapp.svg', file_get_contents($svgFile, 'r')); |
|
| 177 | + $this->assertEquals('image/svg+xml', $this->instance->getMimeType('/desktopapp.svg')); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + public static function copyAndMoveProvider(): array { |
|
| 182 | + return [ |
|
| 183 | + ['/source.txt', '/target.txt'], |
|
| 184 | + ['/source.txt', '/target with space.txt'], |
|
| 185 | + ['/source with space.txt', '/target.txt'], |
|
| 186 | + ['/source with space.txt', '/target with space.txt'], |
|
| 187 | + ['/source.txt', '/tärgét.txt'], |
|
| 188 | + ['/sòurcē.txt', '/target.txt'], |
|
| 189 | + ['/sòurcē.txt', '/tärgét.txt'], |
|
| 190 | + ['/single \' quote.txt', '/tar\'get.txt'], |
|
| 191 | + ]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + public function initSourceAndTarget($source, $target = null) { |
|
| 195 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 196 | + $this->instance->file_put_contents($source, file_get_contents($textFile)); |
|
| 197 | + if ($target) { |
|
| 198 | + $testContents = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
| 199 | + $this->instance->file_put_contents($target, $testContents); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + public function assertSameAsLorem($file) { |
|
| 204 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 205 | + $this->assertEquals( |
|
| 206 | + file_get_contents($textFile), |
|
| 207 | + $this->instance->file_get_contents($file), |
|
| 208 | + 'Expected ' . $file . ' to be a copy of ' . $textFile |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 213 | + public function testCopy($source, $target): void { |
|
| 214 | + $this->initSourceAndTarget($source); |
|
| 215 | + |
|
| 216 | + $this->instance->copy($source, $target); |
|
| 217 | + |
|
| 218 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 219 | + $this->assertSameAsLorem($target); |
|
| 220 | + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 224 | + public function testMove($source, $target): void { |
|
| 225 | + $this->initSourceAndTarget($source); |
|
| 226 | + |
|
| 227 | + $this->instance->rename($source, $target); |
|
| 228 | + |
|
| 229 | + $this->wait(); |
|
| 230 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 231 | + $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); |
|
| 232 | + $this->assertSameAsLorem($target); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 236 | + public function testCopyOverwrite($source, $target): void { |
|
| 237 | + $this->initSourceAndTarget($source, $target); |
|
| 238 | + |
|
| 239 | + $this->instance->copy($source, $target); |
|
| 240 | + |
|
| 241 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 242 | + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
| 243 | + $this->assertSameAsLorem($target); |
|
| 244 | + $this->assertSameAsLorem($source); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 248 | + public function testMoveOverwrite($source, $target): void { |
|
| 249 | + $this->initSourceAndTarget($source, $target); |
|
| 250 | + |
|
| 251 | + $this->instance->rename($source, $target); |
|
| 252 | + |
|
| 253 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 254 | + $this->assertFalse($this->instance->file_exists($source), $source . ' still exists'); |
|
| 255 | + $this->assertSameAsLorem($target); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + public function testLocal(): void { |
|
| 259 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 260 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
| 261 | + $localFile = $this->instance->getLocalFile('/lorem.txt'); |
|
| 262 | + $this->assertTrue(file_exists($localFile)); |
|
| 263 | + $this->assertEquals(file_get_contents($textFile), file_get_contents($localFile)); |
|
| 264 | + |
|
| 265 | + $this->instance->mkdir('/folder'); |
|
| 266 | + $this->instance->file_put_contents('/folder/lorem.txt', file_get_contents($textFile)); |
|
| 267 | + $this->instance->file_put_contents('/folder/bar.txt', 'asd'); |
|
| 268 | + $this->instance->mkdir('/folder/recursive'); |
|
| 269 | + $this->instance->file_put_contents('/folder/recursive/file.txt', 'foo'); |
|
| 270 | + |
|
| 271 | + // test below require to use instance->getLocalFile because the physical storage might be different |
|
| 272 | + $localFile = $this->instance->getLocalFile('/folder/lorem.txt'); |
|
| 273 | + $this->assertTrue(file_exists($localFile)); |
|
| 274 | + $this->assertEquals(file_get_contents($localFile), file_get_contents($textFile)); |
|
| 275 | + |
|
| 276 | + $localFile = $this->instance->getLocalFile('/folder/bar.txt'); |
|
| 277 | + $this->assertTrue(file_exists($localFile)); |
|
| 278 | + $this->assertEquals(file_get_contents($localFile), 'asd'); |
|
| 279 | + |
|
| 280 | + $localFile = $this->instance->getLocalFile('/folder/recursive/file.txt'); |
|
| 281 | + $this->assertTrue(file_exists($localFile)); |
|
| 282 | + $this->assertEquals(file_get_contents($localFile), 'foo'); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + public function testStat(): void { |
|
| 286 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 287 | + $ctimeStart = time(); |
|
| 288 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
| 289 | + $this->assertTrue($this->instance->isReadable('/lorem.txt')); |
|
| 290 | + $ctimeEnd = time(); |
|
| 291 | + $mTime = $this->instance->filemtime('/lorem.txt'); |
|
| 292 | + $this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5)); |
|
| 293 | + $this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5)); |
|
| 294 | + |
|
| 295 | + // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1) |
|
| 296 | + $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime); |
|
| 297 | + $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime); |
|
| 298 | + $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt')); |
|
| 299 | + |
|
| 300 | + $stat = $this->instance->stat('/lorem.txt'); |
|
| 301 | + //only size and mtime are required in the result |
|
| 302 | + $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt')); |
|
| 303 | + $this->assertEquals($stat['mtime'], $mTime); |
|
| 304 | + |
|
| 305 | + if ($this->instance->touch('/lorem.txt', 100) !== false) { |
|
| 306 | + $mTime = $this->instance->filemtime('/lorem.txt'); |
|
| 307 | + $this->assertEquals($mTime, 100); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + $mtimeStart = time(); |
|
| 311 | + |
|
| 312 | + $this->instance->unlink('/lorem.txt'); |
|
| 313 | + $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Test whether checkUpdate properly returns false when there was |
|
| 318 | + * no change. |
|
| 319 | + */ |
|
| 320 | + public function testCheckUpdate(): void { |
|
| 321 | + if ($this->instance instanceof Wrapper) { |
|
| 322 | + $this->markTestSkipped('Cannot test update check on wrappers'); |
|
| 323 | + } |
|
| 324 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 325 | + $watcher = $this->instance->getWatcher(); |
|
| 326 | + $watcher->setPolicy(Watcher::CHECK_ALWAYS); |
|
| 327 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
| 328 | + $this->assertTrue($watcher->checkUpdate('/lorem.txt'), 'Update detected'); |
|
| 329 | + $this->assertFalse($watcher->checkUpdate('/lorem.txt'), 'No update'); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + public function testUnlink(): void { |
|
| 333 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 334 | + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); |
|
| 335 | + |
|
| 336 | + $this->assertTrue($this->instance->file_exists('/lorem.txt')); |
|
| 337 | + |
|
| 338 | + $this->assertTrue($this->instance->unlink('/lorem.txt')); |
|
| 339 | + $this->wait(); |
|
| 340 | + |
|
| 341 | + $this->assertFalse($this->instance->file_exists('/lorem.txt')); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + #[\PHPUnit\Framework\Attributes\DataProvider('fileNameProvider')] |
|
| 345 | + public function testFOpen($fileName): void { |
|
| 346 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 347 | + |
|
| 348 | + $fh = @$this->instance->fopen($fileName, 'r'); |
|
| 349 | + if ($fh) { |
|
| 350 | + fclose($fh); |
|
| 351 | + } |
|
| 352 | + $this->assertFalse($fh); |
|
| 353 | + $this->assertFalse($this->instance->file_exists($fileName)); |
|
| 354 | + |
|
| 355 | + $fh = $this->instance->fopen($fileName, 'w'); |
|
| 356 | + fwrite($fh, file_get_contents($textFile)); |
|
| 357 | + fclose($fh); |
|
| 358 | + $this->assertTrue($this->instance->file_exists($fileName)); |
|
| 359 | + |
|
| 360 | + $fh = $this->instance->fopen($fileName, 'r'); |
|
| 361 | + $this->assertTrue(is_resource($fh)); |
|
| 362 | + $content = stream_get_contents($fh); |
|
| 363 | + $this->assertEquals(file_get_contents($textFile), $content); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + public function testTouchCreateFile(): void { |
|
| 367 | + $this->assertFalse($this->instance->file_exists('touch')); |
|
| 368 | + // returns true on success |
|
| 369 | + $this->assertTrue($this->instance->touch('touch')); |
|
| 370 | + $this->assertTrue($this->instance->file_exists('touch')); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + public function testRecursiveRmdir(): void { |
|
| 374 | + $this->instance->mkdir('folder'); |
|
| 375 | + $this->instance->mkdir('folder/bar'); |
|
| 376 | + $this->wait(); |
|
| 377 | + $this->instance->file_put_contents('folder/asd.txt', 'foobar'); |
|
| 378 | + $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); |
|
| 379 | + $this->assertTrue($this->instance->rmdir('folder')); |
|
| 380 | + $this->wait(); |
|
| 381 | + $this->assertFalse($this->instance->file_exists('folder/asd.txt')); |
|
| 382 | + $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); |
|
| 383 | + $this->assertFalse($this->instance->file_exists('folder/bar')); |
|
| 384 | + $this->assertFalse($this->instance->file_exists('folder')); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + public function testRmdirEmptyFolder(): void { |
|
| 388 | + $this->assertTrue($this->instance->mkdir('empty')); |
|
| 389 | + $this->wait(); |
|
| 390 | + $this->assertTrue($this->instance->rmdir('empty')); |
|
| 391 | + $this->assertFalse($this->instance->file_exists('empty')); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + public function testRecursiveUnlink(): void { |
|
| 395 | + $this->instance->mkdir('folder'); |
|
| 396 | + $this->instance->mkdir('folder/bar'); |
|
| 397 | + $this->instance->file_put_contents('folder/asd.txt', 'foobar'); |
|
| 398 | + $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); |
|
| 399 | + $this->assertTrue($this->instance->unlink('folder')); |
|
| 400 | + $this->wait(); |
|
| 401 | + $this->assertFalse($this->instance->file_exists('folder/asd.txt')); |
|
| 402 | + $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); |
|
| 403 | + $this->assertFalse($this->instance->file_exists('folder/bar')); |
|
| 404 | + $this->assertFalse($this->instance->file_exists('folder')); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + public static function hashProvider(): array { |
|
| 408 | + return [ |
|
| 409 | + ['Foobar', 'md5'], |
|
| 410 | + ['Foobar', 'sha1'], |
|
| 411 | + ['Foobar', 'sha256'], |
|
| 412 | + ]; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + #[\PHPUnit\Framework\Attributes\DataProvider('hashProvider')] |
|
| 416 | + public function testHash($data, $type): void { |
|
| 417 | + $this->instance->file_put_contents('hash.txt', $data); |
|
| 418 | + $this->assertEquals(hash($type, $data), $this->instance->hash($type, 'hash.txt')); |
|
| 419 | + $this->assertEquals(hash($type, $data, true), $this->instance->hash($type, 'hash.txt', true)); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + public function testHashInFileName(): void { |
|
| 423 | + $this->instance->file_put_contents('#test.txt', 'data'); |
|
| 424 | + $this->assertEquals('data', $this->instance->file_get_contents('#test.txt')); |
|
| 425 | + |
|
| 426 | + $this->instance->mkdir('#foo'); |
|
| 427 | + $this->instance->file_put_contents('#foo/test.txt', 'data'); |
|
| 428 | + $this->assertEquals('data', $this->instance->file_get_contents('#foo/test.txt')); |
|
| 429 | + |
|
| 430 | + $dh = $this->instance->opendir('#foo'); |
|
| 431 | + $content = []; |
|
| 432 | + while ($file = readdir($dh)) { |
|
| 433 | + if ($file != '.' && $file != '..') { |
|
| 434 | + $content[] = $file; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $this->assertEquals(['test.txt'], $content); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + public function testCopyOverWriteFile(): void { |
|
| 442 | + $this->instance->file_put_contents('target.txt', 'foo'); |
|
| 443 | + $this->instance->file_put_contents('source.txt', 'bar'); |
|
| 444 | + $this->instance->copy('source.txt', 'target.txt'); |
|
| 445 | + $this->assertEquals('bar', $this->instance->file_get_contents('target.txt')); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + public function testRenameOverWriteFile(): void { |
|
| 449 | + $this->instance->file_put_contents('target.txt', 'foo'); |
|
| 450 | + $this->instance->file_put_contents('source.txt', 'bar'); |
|
| 451 | + $this->instance->rename('source.txt', 'target.txt'); |
|
| 452 | + $this->assertEquals('bar', $this->instance->file_get_contents('target.txt')); |
|
| 453 | + $this->assertFalse($this->instance->file_exists('source.txt')); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + public function testRenameDirectory(): void { |
|
| 457 | + $this->instance->mkdir('source'); |
|
| 458 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 459 | + $this->instance->file_put_contents('source/test2.txt', 'qwerty'); |
|
| 460 | + $this->instance->mkdir('source/subfolder'); |
|
| 461 | + $this->instance->file_put_contents('source/subfolder/test.txt', 'bar'); |
|
| 462 | + $this->instance->rename('source', 'target'); |
|
| 463 | + |
|
| 464 | + $this->assertFalse($this->instance->file_exists('source')); |
|
| 465 | + $this->assertFalse($this->instance->file_exists('source/test1.txt')); |
|
| 466 | + $this->assertFalse($this->instance->file_exists('source/test2.txt')); |
|
| 467 | + $this->assertFalse($this->instance->file_exists('source/subfolder')); |
|
| 468 | + $this->assertFalse($this->instance->file_exists('source/subfolder/test.txt')); |
|
| 469 | + |
|
| 470 | + $this->assertTrue($this->instance->file_exists('target')); |
|
| 471 | + $this->assertTrue($this->instance->file_exists('target/test1.txt')); |
|
| 472 | + $this->assertTrue($this->instance->file_exists('target/test2.txt')); |
|
| 473 | + $this->assertTrue($this->instance->file_exists('target/subfolder')); |
|
| 474 | + $this->assertTrue($this->instance->file_exists('target/subfolder/test.txt')); |
|
| 475 | + |
|
| 476 | + $contents = iterator_to_array($this->instance->getDirectoryContent('')); |
|
| 477 | + $this->assertCount(1, $contents); |
|
| 478 | + |
|
| 479 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 480 | + $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt')); |
|
| 481 | + $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt')); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + public function testRenameOverWriteDirectory(): void { |
|
| 485 | + $this->instance->mkdir('source'); |
|
| 486 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 487 | + |
|
| 488 | + $this->instance->mkdir('target'); |
|
| 489 | + $this->instance->file_put_contents('target/test1.txt', 'bar'); |
|
| 490 | + $this->instance->file_put_contents('target/test2.txt', 'bar'); |
|
| 491 | + |
|
| 492 | + $this->assertTrue($this->instance->rename('source', 'target'), 'rename must return true on success'); |
|
| 493 | + |
|
| 494 | + $this->assertFalse($this->instance->file_exists('source'), 'source has not been removed'); |
|
| 495 | + $this->assertFalse($this->instance->file_exists('source/test1.txt'), 'source/test1.txt has not been removed'); |
|
| 496 | + $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'target/test2.txt has not been removed'); |
|
| 497 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'), 'target/test1.txt has not been overwritten'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + public function testRenameOverWriteDirectoryOverFile(): void { |
|
| 501 | + $this->instance->mkdir('source'); |
|
| 502 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 503 | + |
|
| 504 | + $this->instance->file_put_contents('target', 'bar'); |
|
| 505 | + |
|
| 506 | + $this->assertTrue($this->instance->rename('source', 'target'), 'rename must return true on success'); |
|
| 507 | + |
|
| 508 | + $this->assertFalse($this->instance->file_exists('source')); |
|
| 509 | + $this->assertFalse($this->instance->file_exists('source/test1.txt')); |
|
| 510 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + public function testCopyDirectory(): void { |
|
| 514 | + $this->instance->mkdir('source'); |
|
| 515 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 516 | + $this->instance->file_put_contents('source/test2.txt', 'qwerty'); |
|
| 517 | + $this->instance->mkdir('source/subfolder'); |
|
| 518 | + $this->instance->file_put_contents('source/subfolder/test.txt', 'bar'); |
|
| 519 | + $this->instance->copy('source', 'target'); |
|
| 520 | + |
|
| 521 | + $this->assertTrue($this->instance->file_exists('source')); |
|
| 522 | + $this->assertTrue($this->instance->file_exists('source/test1.txt')); |
|
| 523 | + $this->assertTrue($this->instance->file_exists('source/test2.txt')); |
|
| 524 | + $this->assertTrue($this->instance->file_exists('source/subfolder')); |
|
| 525 | + $this->assertTrue($this->instance->file_exists('source/subfolder/test.txt')); |
|
| 526 | + |
|
| 527 | + $this->assertTrue($this->instance->file_exists('target')); |
|
| 528 | + $this->assertTrue($this->instance->file_exists('target/test1.txt')); |
|
| 529 | + $this->assertTrue($this->instance->file_exists('target/test2.txt')); |
|
| 530 | + $this->assertTrue($this->instance->file_exists('target/subfolder')); |
|
| 531 | + $this->assertTrue($this->instance->file_exists('target/subfolder/test.txt')); |
|
| 532 | + |
|
| 533 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 534 | + $this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt')); |
|
| 535 | + $this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt')); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + public function testCopyOverWriteDirectory(): void { |
|
| 539 | + $this->instance->mkdir('source'); |
|
| 540 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 541 | + |
|
| 542 | + $this->instance->mkdir('target'); |
|
| 543 | + $this->instance->file_put_contents('target/test1.txt', 'bar'); |
|
| 544 | + $this->instance->file_put_contents('target/test2.txt', 'bar'); |
|
| 545 | + |
|
| 546 | + $this->instance->copy('source', 'target'); |
|
| 547 | + |
|
| 548 | + $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'File target/test2.txt should no longer exist, but does'); |
|
| 549 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + public function testCopyOverWriteDirectoryOverFile(): void { |
|
| 553 | + $this->instance->mkdir('source'); |
|
| 554 | + $this->instance->file_put_contents('source/test1.txt', 'foo'); |
|
| 555 | + |
|
| 556 | + $this->instance->file_put_contents('target', 'bar'); |
|
| 557 | + |
|
| 558 | + $this->instance->copy('source', 'target'); |
|
| 559 | + |
|
| 560 | + $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + public function testInstanceOfStorage(): void { |
|
| 564 | + $this->assertTrue($this->instance->instanceOfStorage(IStorage::class)); |
|
| 565 | + $this->assertTrue($this->instance->instanceOfStorage(get_class($this->instance))); |
|
| 566 | + $this->assertFalse($this->instance->instanceOfStorage('\OC')); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] |
|
| 570 | + public function testCopyFromSameStorage($source, $target): void { |
|
| 571 | + $this->initSourceAndTarget($source); |
|
| 572 | + |
|
| 573 | + $this->instance->copyFromStorage($this->instance, $source, $target); |
|
| 574 | + |
|
| 575 | + $this->assertTrue($this->instance->file_exists($target), $target . ' was not created'); |
|
| 576 | + $this->assertSameAsLorem($target); |
|
| 577 | + $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + public function testIsCreatable(): void { |
|
| 581 | + $this->instance->mkdir('source'); |
|
| 582 | + $this->assertTrue($this->instance->isCreatable('source')); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + public function testIsReadable(): void { |
|
| 586 | + $this->instance->mkdir('source'); |
|
| 587 | + $this->assertTrue($this->instance->isReadable('source')); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + public function testIsUpdatable(): void { |
|
| 591 | + $this->instance->mkdir('source'); |
|
| 592 | + $this->assertTrue($this->instance->isUpdatable('source')); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + public function testIsDeletable(): void { |
|
| 596 | + $this->instance->mkdir('source'); |
|
| 597 | + $this->assertTrue($this->instance->isDeletable('source')); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + public function testIsShareable(): void { |
|
| 601 | + $this->instance->mkdir('source'); |
|
| 602 | + $this->assertTrue($this->instance->isSharable('source')); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + public function testStatAfterWrite(): void { |
|
| 606 | + $this->instance->file_put_contents('foo.txt', 'bar'); |
|
| 607 | + $stat = $this->instance->stat('foo.txt'); |
|
| 608 | + $this->assertEquals(3, $stat['size']); |
|
| 609 | + |
|
| 610 | + $fh = $this->instance->fopen('foo.txt', 'w'); |
|
| 611 | + fwrite($fh, 'qwerty'); |
|
| 612 | + fclose($fh); |
|
| 613 | + |
|
| 614 | + $stat = $this->instance->stat('foo.txt'); |
|
| 615 | + $this->assertEquals(6, $stat['size']); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + public function testPartFile(): void { |
|
| 619 | + $this->instance->file_put_contents('bar.txt.part', 'bar'); |
|
| 620 | + $this->instance->rename('bar.txt.part', 'bar.txt'); |
|
| 621 | + $this->assertEquals('bar', $this->instance->file_get_contents('bar.txt')); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + public function testWriteStream(): void { |
|
| 625 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 626 | + |
|
| 627 | + if (!$this->instance->instanceOfStorage(IWriteStreamStorage::class)) { |
|
| 628 | + $this->markTestSkipped('Not a WriteSteamStorage'); |
|
| 629 | + } |
|
| 630 | + /** @var IWriteStreamStorage $storage */ |
|
| 631 | + $storage = $this->instance; |
|
| 632 | 632 | |
| 633 | - $source = fopen($textFile, 'r'); |
|
| 634 | - |
|
| 635 | - $storage->writeStream('test.txt', $source); |
|
| 636 | - $this->assertTrue($storage->file_exists('test.txt')); |
|
| 637 | - $this->assertStringEqualsFile($textFile, $storage->file_get_contents('test.txt')); |
|
| 638 | - $this->assertEquals('resource (closed)', gettype($source)); |
|
| 639 | - } |
|
| 633 | + $source = fopen($textFile, 'r'); |
|
| 634 | + |
|
| 635 | + $storage->writeStream('test.txt', $source); |
|
| 636 | + $this->assertTrue($storage->file_exists('test.txt')); |
|
| 637 | + $this->assertStringEqualsFile($textFile, $storage->file_get_contents('test.txt')); |
|
| 638 | + $this->assertEquals('resource (closed)', gettype($source)); |
|
| 639 | + } |
|
| 640 | 640 | |
| 641 | - public function testFseekSize(): void { |
|
| 642 | - $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 643 | - $this->instance->file_put_contents('bar.txt', file_get_contents($textFile)); |
|
| 641 | + public function testFseekSize(): void { |
|
| 642 | + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; |
|
| 643 | + $this->instance->file_put_contents('bar.txt', file_get_contents($textFile)); |
|
| 644 | 644 | |
| 645 | - $size = $this->instance->filesize('bar.txt'); |
|
| 646 | - $this->assertEquals(filesize($textFile), $size); |
|
| 647 | - $fh = $this->instance->fopen('bar.txt', 'r'); |
|
| 648 | - |
|
| 649 | - fseek($fh, 0, SEEK_END); |
|
| 650 | - $pos = ftell($fh); |
|
| 645 | + $size = $this->instance->filesize('bar.txt'); |
|
| 646 | + $this->assertEquals(filesize($textFile), $size); |
|
| 647 | + $fh = $this->instance->fopen('bar.txt', 'r'); |
|
| 648 | + |
|
| 649 | + fseek($fh, 0, SEEK_END); |
|
| 650 | + $pos = ftell($fh); |
|
| 651 | 651 | |
| 652 | - $this->assertEquals($size, $pos); |
|
| 653 | - } |
|
| 652 | + $this->assertEquals($size, $pos); |
|
| 653 | + } |
|
| 654 | 654 | } |
@@ -28,234 +28,234 @@ |
||
| 28 | 28 | use Symfony\Component\Console\Output\OutputInterface; |
| 29 | 29 | |
| 30 | 30 | class ScanAppData extends Base { |
| 31 | - protected float $execTime = 0; |
|
| 32 | - |
|
| 33 | - protected int $foldersCounter = 0; |
|
| 34 | - |
|
| 35 | - protected int $filesCounter = 0; |
|
| 36 | - protected int $previewsCounter = -1; |
|
| 37 | - |
|
| 38 | - public function __construct( |
|
| 39 | - protected IRootFolder $rootFolder, |
|
| 40 | - protected IConfig $config, |
|
| 41 | - private StorageFactory $previewStorage, |
|
| 42 | - ) { |
|
| 43 | - parent::__construct(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - protected function configure(): void { |
|
| 47 | - parent::configure(); |
|
| 48 | - |
|
| 49 | - $this |
|
| 50 | - ->setName('files:scan-app-data') |
|
| 51 | - ->setDescription('rescan the AppData folder'); |
|
| 52 | - |
|
| 53 | - $this->addArgument('folder', InputArgument::OPTIONAL, 'The appdata subfolder to scan', ''); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - protected function scanFiles(OutputInterface $output, string $folder): int { |
|
| 57 | - if ($folder === 'preview' || $folder === '') { |
|
| 58 | - $this->previewsCounter = $this->previewStorage->scan(); |
|
| 59 | - |
|
| 60 | - if ($folder === 'preview') { |
|
| 61 | - return self::SUCCESS; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - try { |
|
| 66 | - /** @var Folder $appData */ |
|
| 67 | - $appData = $this->getAppDataFolder(); |
|
| 68 | - } catch (NotFoundException $e) { |
|
| 69 | - $output->writeln('<error>NoAppData folder found</error>'); |
|
| 70 | - return self::FAILURE; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - if ($folder !== '') { |
|
| 74 | - try { |
|
| 75 | - $appData = $appData->get($folder); |
|
| 76 | - } catch (NotFoundException $e) { |
|
| 77 | - $output->writeln('<error>Could not find folder: ' . $folder . '</error>'); |
|
| 78 | - return self::FAILURE; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $connection = $this->reconnectToDatabase($output); |
|
| 83 | - $scanner = new Scanner( |
|
| 84 | - null, |
|
| 85 | - new ConnectionAdapter($connection), |
|
| 86 | - Server::get(IEventDispatcher::class), |
|
| 87 | - Server::get(LoggerInterface::class) |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
| 91 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output): void { |
|
| 92 | - $output->writeln("\tFile <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
| 93 | - ++$this->filesCounter; |
|
| 94 | - $this->abortIfInterrupted(); |
|
| 95 | - }); |
|
| 96 | - |
|
| 97 | - $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output): void { |
|
| 98 | - $output->writeln("\tFolder <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
| 99 | - ++$this->foldersCounter; |
|
| 100 | - $this->abortIfInterrupted(); |
|
| 101 | - }); |
|
| 102 | - |
|
| 103 | - $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output): void { |
|
| 104 | - $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE); |
|
| 105 | - }); |
|
| 106 | - |
|
| 107 | - $scanner->listen('\OC\Files\Utils\Scanner', 'normalizedNameMismatch', function ($fullPath) use ($output): void { |
|
| 108 | - $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 109 | - }); |
|
| 110 | - |
|
| 111 | - try { |
|
| 112 | - $scanner->scan($appData->getPath()); |
|
| 113 | - } catch (ForbiddenException $e) { |
|
| 114 | - $output->writeln('<error>Storage not writable</error>'); |
|
| 115 | - $output->writeln('<info>Make sure you\'re running the scan command only as the user the web server runs as</info>'); |
|
| 116 | - return self::FAILURE; |
|
| 117 | - } catch (InterruptedException $e) { |
|
| 118 | - # exit the function if ctrl-c has been pressed |
|
| 119 | - $output->writeln('<info>Interrupted by user</info>'); |
|
| 120 | - return self::FAILURE; |
|
| 121 | - } catch (NotFoundException $e) { |
|
| 122 | - $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 123 | - return self::FAILURE; |
|
| 124 | - } catch (\Exception $e) { |
|
| 125 | - $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 126 | - $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 127 | - return self::FAILURE; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return self::SUCCESS; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 135 | - # restrict the verbosity level to VERBOSITY_VERBOSE |
|
| 136 | - if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
| 137 | - $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - $output->writeln('Scanning AppData for files'); |
|
| 141 | - $output->writeln(''); |
|
| 142 | - |
|
| 143 | - $folder = $input->getArgument('folder'); |
|
| 144 | - |
|
| 145 | - $this->initTools(); |
|
| 146 | - |
|
| 147 | - $exitCode = $this->scanFiles($output, $folder); |
|
| 148 | - if ($exitCode === self::SUCCESS) { |
|
| 149 | - $this->presentStats($output); |
|
| 150 | - } |
|
| 151 | - return $exitCode; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Initialises some useful tools for the Command |
|
| 156 | - */ |
|
| 157 | - protected function initTools(): void { |
|
| 158 | - // Start the timer |
|
| 159 | - $this->execTime = -microtime(true); |
|
| 160 | - // Convert PHP errors to exceptions |
|
| 161 | - set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
| 166 | - * |
|
| 167 | - * @see https://www.php.net/manual/en/function.set-error-handler.php |
|
| 168 | - * |
|
| 169 | - * @param int $severity the level of the error raised |
|
| 170 | - * @param string $message |
|
| 171 | - * @param string $file the filename that the error was raised in |
|
| 172 | - * @param int $line the line number the error was raised |
|
| 173 | - * |
|
| 174 | - * @throws \ErrorException |
|
| 175 | - */ |
|
| 176 | - public function exceptionErrorHandler(int $severity, string $message, string $file, int $line): void { |
|
| 177 | - if (!(error_reporting() & $severity)) { |
|
| 178 | - // This error code is not included in error_reporting |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - throw new \ErrorException($message, 0, $severity, $file, $line); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - protected function presentStats(OutputInterface $output): void { |
|
| 185 | - // Stop the timer |
|
| 186 | - $this->execTime += microtime(true); |
|
| 187 | - if ($this->previewsCounter !== -1) { |
|
| 188 | - $headers[] = 'Previews'; |
|
| 189 | - } |
|
| 190 | - $headers[] = 'Folders'; |
|
| 191 | - $headers[] = 'Files'; |
|
| 192 | - $headers[] = 'Elapsed time'; |
|
| 193 | - |
|
| 194 | - $this->showSummary($headers, null, $output); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Shows a summary of operations |
|
| 199 | - * |
|
| 200 | - * @param string[] $headers |
|
| 201 | - * @param string[] $rows |
|
| 202 | - */ |
|
| 203 | - protected function showSummary(array $headers, ?array $rows, OutputInterface $output): void { |
|
| 204 | - $niceDate = $this->formatExecTime(); |
|
| 205 | - if (!$rows) { |
|
| 206 | - if ($this->previewsCounter !== -1) { |
|
| 207 | - $rows[] = $this->previewsCounter; |
|
| 208 | - } |
|
| 209 | - $rows[] = $this->foldersCounter; |
|
| 210 | - $rows[] = $this->filesCounter; |
|
| 211 | - $rows[] = $niceDate; |
|
| 212 | - } |
|
| 213 | - $table = new Table($output); |
|
| 214 | - $table |
|
| 215 | - ->setHeaders($headers) |
|
| 216 | - ->setRows([$rows]); |
|
| 217 | - $table->render(); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Formats microtime into a human-readable format |
|
| 223 | - */ |
|
| 224 | - protected function formatExecTime(): string { |
|
| 225 | - $secs = round($this->execTime); |
|
| 226 | - # convert seconds into HH:MM:SS form |
|
| 227 | - return sprintf('%02d:%02d:%02d', (int)($secs / 3600), ((int)($secs / 60) % 60), (int)$secs % 60); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - protected function reconnectToDatabase(OutputInterface $output): Connection { |
|
| 231 | - /** @var Connection $connection */ |
|
| 232 | - $connection = Server::get(Connection::class); |
|
| 233 | - try { |
|
| 234 | - $connection->close(); |
|
| 235 | - } catch (\Exception $ex) { |
|
| 236 | - $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
| 237 | - } |
|
| 238 | - while (!$connection->isConnected()) { |
|
| 239 | - try { |
|
| 240 | - $connection->connect(); |
|
| 241 | - } catch (\Exception $ex) { |
|
| 242 | - $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
| 243 | - sleep(60); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - return $connection; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @throws NotFoundException |
|
| 251 | - */ |
|
| 252 | - private function getAppDataFolder(): Node { |
|
| 253 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
| 254 | - |
|
| 255 | - if ($instanceId === null) { |
|
| 256 | - throw new NotFoundException(); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return $this->rootFolder->get('appdata_' . $instanceId); |
|
| 260 | - } |
|
| 31 | + protected float $execTime = 0; |
|
| 32 | + |
|
| 33 | + protected int $foldersCounter = 0; |
|
| 34 | + |
|
| 35 | + protected int $filesCounter = 0; |
|
| 36 | + protected int $previewsCounter = -1; |
|
| 37 | + |
|
| 38 | + public function __construct( |
|
| 39 | + protected IRootFolder $rootFolder, |
|
| 40 | + protected IConfig $config, |
|
| 41 | + private StorageFactory $previewStorage, |
|
| 42 | + ) { |
|
| 43 | + parent::__construct(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + protected function configure(): void { |
|
| 47 | + parent::configure(); |
|
| 48 | + |
|
| 49 | + $this |
|
| 50 | + ->setName('files:scan-app-data') |
|
| 51 | + ->setDescription('rescan the AppData folder'); |
|
| 52 | + |
|
| 53 | + $this->addArgument('folder', InputArgument::OPTIONAL, 'The appdata subfolder to scan', ''); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + protected function scanFiles(OutputInterface $output, string $folder): int { |
|
| 57 | + if ($folder === 'preview' || $folder === '') { |
|
| 58 | + $this->previewsCounter = $this->previewStorage->scan(); |
|
| 59 | + |
|
| 60 | + if ($folder === 'preview') { |
|
| 61 | + return self::SUCCESS; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + try { |
|
| 66 | + /** @var Folder $appData */ |
|
| 67 | + $appData = $this->getAppDataFolder(); |
|
| 68 | + } catch (NotFoundException $e) { |
|
| 69 | + $output->writeln('<error>NoAppData folder found</error>'); |
|
| 70 | + return self::FAILURE; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + if ($folder !== '') { |
|
| 74 | + try { |
|
| 75 | + $appData = $appData->get($folder); |
|
| 76 | + } catch (NotFoundException $e) { |
|
| 77 | + $output->writeln('<error>Could not find folder: ' . $folder . '</error>'); |
|
| 78 | + return self::FAILURE; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $connection = $this->reconnectToDatabase($output); |
|
| 83 | + $scanner = new Scanner( |
|
| 84 | + null, |
|
| 85 | + new ConnectionAdapter($connection), |
|
| 86 | + Server::get(IEventDispatcher::class), |
|
| 87 | + Server::get(LoggerInterface::class) |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + # check on each file/folder if there was a user interrupt (ctrl-c) and throw an exception |
|
| 91 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFile', function ($path) use ($output): void { |
|
| 92 | + $output->writeln("\tFile <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
| 93 | + ++$this->filesCounter; |
|
| 94 | + $this->abortIfInterrupted(); |
|
| 95 | + }); |
|
| 96 | + |
|
| 97 | + $scanner->listen('\OC\Files\Utils\Scanner', 'scanFolder', function ($path) use ($output): void { |
|
| 98 | + $output->writeln("\tFolder <info>$path</info>", OutputInterface::VERBOSITY_VERBOSE); |
|
| 99 | + ++$this->foldersCounter; |
|
| 100 | + $this->abortIfInterrupted(); |
|
| 101 | + }); |
|
| 102 | + |
|
| 103 | + $scanner->listen('\OC\Files\Utils\Scanner', 'StorageNotAvailable', function (StorageNotAvailableException $e) use ($output): void { |
|
| 104 | + $output->writeln('Error while scanning, storage not available (' . $e->getMessage() . ')', OutputInterface::VERBOSITY_VERBOSE); |
|
| 105 | + }); |
|
| 106 | + |
|
| 107 | + $scanner->listen('\OC\Files\Utils\Scanner', 'normalizedNameMismatch', function ($fullPath) use ($output): void { |
|
| 108 | + $output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>'); |
|
| 109 | + }); |
|
| 110 | + |
|
| 111 | + try { |
|
| 112 | + $scanner->scan($appData->getPath()); |
|
| 113 | + } catch (ForbiddenException $e) { |
|
| 114 | + $output->writeln('<error>Storage not writable</error>'); |
|
| 115 | + $output->writeln('<info>Make sure you\'re running the scan command only as the user the web server runs as</info>'); |
|
| 116 | + return self::FAILURE; |
|
| 117 | + } catch (InterruptedException $e) { |
|
| 118 | + # exit the function if ctrl-c has been pressed |
|
| 119 | + $output->writeln('<info>Interrupted by user</info>'); |
|
| 120 | + return self::FAILURE; |
|
| 121 | + } catch (NotFoundException $e) { |
|
| 122 | + $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); |
|
| 123 | + return self::FAILURE; |
|
| 124 | + } catch (\Exception $e) { |
|
| 125 | + $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); |
|
| 126 | + $output->writeln('<error>' . $e->getTraceAsString() . '</error>'); |
|
| 127 | + return self::FAILURE; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return self::SUCCESS; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 135 | + # restrict the verbosity level to VERBOSITY_VERBOSE |
|
| 136 | + if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { |
|
| 137 | + $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + $output->writeln('Scanning AppData for files'); |
|
| 141 | + $output->writeln(''); |
|
| 142 | + |
|
| 143 | + $folder = $input->getArgument('folder'); |
|
| 144 | + |
|
| 145 | + $this->initTools(); |
|
| 146 | + |
|
| 147 | + $exitCode = $this->scanFiles($output, $folder); |
|
| 148 | + if ($exitCode === self::SUCCESS) { |
|
| 149 | + $this->presentStats($output); |
|
| 150 | + } |
|
| 151 | + return $exitCode; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Initialises some useful tools for the Command |
|
| 156 | + */ |
|
| 157 | + protected function initTools(): void { |
|
| 158 | + // Start the timer |
|
| 159 | + $this->execTime = -microtime(true); |
|
| 160 | + // Convert PHP errors to exceptions |
|
| 161 | + set_error_handler([$this, 'exceptionErrorHandler'], E_ALL); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Processes PHP errors as exceptions in order to be able to keep track of problems |
|
| 166 | + * |
|
| 167 | + * @see https://www.php.net/manual/en/function.set-error-handler.php |
|
| 168 | + * |
|
| 169 | + * @param int $severity the level of the error raised |
|
| 170 | + * @param string $message |
|
| 171 | + * @param string $file the filename that the error was raised in |
|
| 172 | + * @param int $line the line number the error was raised |
|
| 173 | + * |
|
| 174 | + * @throws \ErrorException |
|
| 175 | + */ |
|
| 176 | + public function exceptionErrorHandler(int $severity, string $message, string $file, int $line): void { |
|
| 177 | + if (!(error_reporting() & $severity)) { |
|
| 178 | + // This error code is not included in error_reporting |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + throw new \ErrorException($message, 0, $severity, $file, $line); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + protected function presentStats(OutputInterface $output): void { |
|
| 185 | + // Stop the timer |
|
| 186 | + $this->execTime += microtime(true); |
|
| 187 | + if ($this->previewsCounter !== -1) { |
|
| 188 | + $headers[] = 'Previews'; |
|
| 189 | + } |
|
| 190 | + $headers[] = 'Folders'; |
|
| 191 | + $headers[] = 'Files'; |
|
| 192 | + $headers[] = 'Elapsed time'; |
|
| 193 | + |
|
| 194 | + $this->showSummary($headers, null, $output); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Shows a summary of operations |
|
| 199 | + * |
|
| 200 | + * @param string[] $headers |
|
| 201 | + * @param string[] $rows |
|
| 202 | + */ |
|
| 203 | + protected function showSummary(array $headers, ?array $rows, OutputInterface $output): void { |
|
| 204 | + $niceDate = $this->formatExecTime(); |
|
| 205 | + if (!$rows) { |
|
| 206 | + if ($this->previewsCounter !== -1) { |
|
| 207 | + $rows[] = $this->previewsCounter; |
|
| 208 | + } |
|
| 209 | + $rows[] = $this->foldersCounter; |
|
| 210 | + $rows[] = $this->filesCounter; |
|
| 211 | + $rows[] = $niceDate; |
|
| 212 | + } |
|
| 213 | + $table = new Table($output); |
|
| 214 | + $table |
|
| 215 | + ->setHeaders($headers) |
|
| 216 | + ->setRows([$rows]); |
|
| 217 | + $table->render(); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Formats microtime into a human-readable format |
|
| 223 | + */ |
|
| 224 | + protected function formatExecTime(): string { |
|
| 225 | + $secs = round($this->execTime); |
|
| 226 | + # convert seconds into HH:MM:SS form |
|
| 227 | + return sprintf('%02d:%02d:%02d', (int)($secs / 3600), ((int)($secs / 60) % 60), (int)$secs % 60); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + protected function reconnectToDatabase(OutputInterface $output): Connection { |
|
| 231 | + /** @var Connection $connection */ |
|
| 232 | + $connection = Server::get(Connection::class); |
|
| 233 | + try { |
|
| 234 | + $connection->close(); |
|
| 235 | + } catch (\Exception $ex) { |
|
| 236 | + $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
| 237 | + } |
|
| 238 | + while (!$connection->isConnected()) { |
|
| 239 | + try { |
|
| 240 | + $connection->connect(); |
|
| 241 | + } catch (\Exception $ex) { |
|
| 242 | + $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
| 243 | + sleep(60); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + return $connection; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @throws NotFoundException |
|
| 251 | + */ |
|
| 252 | + private function getAppDataFolder(): Node { |
|
| 253 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
| 254 | + |
|
| 255 | + if ($instanceId === null) { |
|
| 256 | + throw new NotFoundException(); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return $this->rootFolder->get('appdata_' . $instanceId); |
|
| 260 | + } |
|
| 261 | 261 | } |
@@ -249,1412 +249,1412 @@ |
||
| 249 | 249 | * TODO: hookup all manager classes |
| 250 | 250 | */ |
| 251 | 251 | class Server extends ServerContainer implements IServerContainer { |
| 252 | - /** @var string */ |
|
| 253 | - private $webRoot; |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @param string $webRoot |
|
| 257 | - * @param \OC\Config $config |
|
| 258 | - */ |
|
| 259 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 260 | - parent::__construct(); |
|
| 261 | - $this->webRoot = $webRoot; |
|
| 262 | - |
|
| 263 | - // To find out if we are running from CLI or not |
|
| 264 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 265 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 266 | - |
|
| 267 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 268 | - return $c; |
|
| 269 | - }); |
|
| 270 | - $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class); |
|
| 271 | - |
|
| 272 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 273 | - |
|
| 274 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 275 | - |
|
| 276 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 277 | - |
|
| 278 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 279 | - |
|
| 280 | - $this->registerAlias(\OCP\ContextChat\IContentManager::class, \OC\ContextChat\ContentManager::class); |
|
| 281 | - |
|
| 282 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 283 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 284 | - $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 285 | - |
|
| 286 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 287 | - |
|
| 288 | - $this->registerService(View::class, function (Server $c) { |
|
| 289 | - return new View(); |
|
| 290 | - }, false); |
|
| 291 | - |
|
| 292 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 293 | - return new PreviewManager( |
|
| 294 | - $c->get(\OCP\IConfig::class), |
|
| 295 | - $c->get(IRootFolder::class), |
|
| 296 | - $c->get(IEventDispatcher::class), |
|
| 297 | - $c->get(GeneratorHelper::class), |
|
| 298 | - $c->get(ISession::class)->get('user_id'), |
|
| 299 | - $c->get(Coordinator::class), |
|
| 300 | - $c->get(IServerContainer::class), |
|
| 301 | - $c->get(IBinaryFinder::class), |
|
| 302 | - $c->get(IMagickSupport::class) |
|
| 303 | - ); |
|
| 304 | - }); |
|
| 305 | - $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 306 | - |
|
| 307 | - $this->registerService(Watcher::class, function (ContainerInterface $c): Watcher { |
|
| 308 | - return new Watcher( |
|
| 309 | - $c->get(\OC\Preview\Storage\StorageFactory::class), |
|
| 310 | - $c->get(PreviewMapper::class), |
|
| 311 | - $c->get(IDBConnection::class), |
|
| 312 | - ); |
|
| 313 | - }); |
|
| 314 | - |
|
| 315 | - $this->registerService(IProfiler::class, function (Server $c) { |
|
| 316 | - return new Profiler($c->get(SystemConfig::class)); |
|
| 317 | - }); |
|
| 318 | - |
|
| 319 | - $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { |
|
| 320 | - $view = new View(); |
|
| 321 | - $util = new Encryption\Util( |
|
| 322 | - $view, |
|
| 323 | - $c->get(IUserManager::class), |
|
| 324 | - $c->get(IGroupManager::class), |
|
| 325 | - $c->get(\OCP\IConfig::class) |
|
| 326 | - ); |
|
| 327 | - return new Encryption\Manager( |
|
| 328 | - $c->get(\OCP\IConfig::class), |
|
| 329 | - $c->get(LoggerInterface::class), |
|
| 330 | - $c->getL10N('core'), |
|
| 331 | - new View(), |
|
| 332 | - $util, |
|
| 333 | - new ArrayCache() |
|
| 334 | - ); |
|
| 335 | - }); |
|
| 336 | - $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); |
|
| 337 | - |
|
| 338 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 339 | - $util = new Encryption\Util( |
|
| 340 | - new View(), |
|
| 341 | - $c->get(IUserManager::class), |
|
| 342 | - $c->get(IGroupManager::class), |
|
| 343 | - $c->get(\OCP\IConfig::class) |
|
| 344 | - ); |
|
| 345 | - return new Encryption\File( |
|
| 346 | - $util, |
|
| 347 | - $c->get(IRootFolder::class), |
|
| 348 | - $c->get(\OCP\Share\IManager::class) |
|
| 349 | - ); |
|
| 350 | - }); |
|
| 351 | - |
|
| 352 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 353 | - $view = new View(); |
|
| 354 | - $util = new Encryption\Util( |
|
| 355 | - $view, |
|
| 356 | - $c->get(IUserManager::class), |
|
| 357 | - $c->get(IGroupManager::class), |
|
| 358 | - $c->get(\OCP\IConfig::class) |
|
| 359 | - ); |
|
| 360 | - |
|
| 361 | - return new Encryption\Keys\Storage( |
|
| 362 | - $view, |
|
| 363 | - $util, |
|
| 364 | - $c->get(ICrypto::class), |
|
| 365 | - $c->get(\OCP\IConfig::class) |
|
| 366 | - ); |
|
| 367 | - }); |
|
| 368 | - |
|
| 369 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 370 | - |
|
| 371 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 372 | - /** @var \OCP\IConfig $config */ |
|
| 373 | - $config = $c->get(\OCP\IConfig::class); |
|
| 374 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 375 | - return new $factoryClass($this); |
|
| 376 | - }); |
|
| 377 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 378 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 379 | - }); |
|
| 380 | - /** @deprecated 19.0.0 */ |
|
| 381 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 382 | - |
|
| 383 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 384 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 385 | - }); |
|
| 386 | - $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 387 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 388 | - $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 389 | - $view = new View(); |
|
| 390 | - /** @var IUserSession $userSession */ |
|
| 391 | - $userSession = $c->get(IUserSession::class); |
|
| 392 | - $root = new Root( |
|
| 393 | - $manager, |
|
| 394 | - $view, |
|
| 395 | - $userSession->getUser(), |
|
| 396 | - $c->get(IUserMountCache::class), |
|
| 397 | - $this->get(LoggerInterface::class), |
|
| 398 | - $this->get(IUserManager::class), |
|
| 399 | - $this->get(IEventDispatcher::class), |
|
| 400 | - $this->get(ICacheFactory::class), |
|
| 401 | - $this->get(IAppConfig::class), |
|
| 402 | - ); |
|
| 403 | - |
|
| 404 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 405 | - $root, |
|
| 406 | - $c->get(SystemConfig::class), |
|
| 407 | - $this->get(IEventDispatcher::class) |
|
| 408 | - ); |
|
| 409 | - $previewConnector->connectWatcher(); |
|
| 410 | - |
|
| 411 | - return $root; |
|
| 412 | - }); |
|
| 413 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 414 | - return new HookConnector( |
|
| 415 | - $c->get(IRootFolder::class), |
|
| 416 | - new View(), |
|
| 417 | - $c->get(IEventDispatcher::class), |
|
| 418 | - $c->get(LoggerInterface::class) |
|
| 419 | - ); |
|
| 420 | - }); |
|
| 421 | - |
|
| 422 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 423 | - return new LazyRoot(function () use ($c) { |
|
| 424 | - return $c->get('RootFolder'); |
|
| 425 | - }); |
|
| 426 | - }); |
|
| 427 | - |
|
| 428 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 429 | - |
|
| 430 | - $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 431 | - return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 432 | - }); |
|
| 433 | - |
|
| 434 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 435 | - $groupManager = new \OC\Group\Manager( |
|
| 436 | - $this->get(IUserManager::class), |
|
| 437 | - $this->get(IEventDispatcher::class), |
|
| 438 | - $this->get(LoggerInterface::class), |
|
| 439 | - $this->get(ICacheFactory::class), |
|
| 440 | - $this->get(IRemoteAddress::class), |
|
| 441 | - ); |
|
| 442 | - return $groupManager; |
|
| 443 | - }); |
|
| 444 | - |
|
| 445 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 446 | - $session = $c->get(ISession::class); |
|
| 447 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 448 | - $tokenProvider = $c->get(IProvider::class); |
|
| 449 | - } else { |
|
| 450 | - $tokenProvider = null; |
|
| 451 | - } |
|
| 452 | - $logger = $c->get(LoggerInterface::class); |
|
| 453 | - $crypto = $c->get(ICrypto::class); |
|
| 454 | - return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 455 | - }); |
|
| 456 | - $this->registerAlias(IStore::class, Store::class); |
|
| 457 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 458 | - $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 459 | - |
|
| 460 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 461 | - $manager = $c->get(IUserManager::class); |
|
| 462 | - $session = new \OC\Session\Memory(); |
|
| 463 | - $timeFactory = new TimeFactory(); |
|
| 464 | - // Token providers might require a working database. This code |
|
| 465 | - // might however be called when Nextcloud is not yet setup. |
|
| 466 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 467 | - $provider = $c->get(IProvider::class); |
|
| 468 | - } else { |
|
| 469 | - $provider = null; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - $userSession = new \OC\User\Session( |
|
| 473 | - $manager, |
|
| 474 | - $session, |
|
| 475 | - $timeFactory, |
|
| 476 | - $provider, |
|
| 477 | - $c->get(\OCP\IConfig::class), |
|
| 478 | - $c->get(ISecureRandom::class), |
|
| 479 | - $c->get('LockdownManager'), |
|
| 480 | - $c->get(LoggerInterface::class), |
|
| 481 | - $c->get(IEventDispatcher::class), |
|
| 482 | - ); |
|
| 483 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 484 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 485 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 486 | - }); |
|
| 487 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 488 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 489 | - /** @var \OC\User\User $user */ |
|
| 490 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 491 | - }); |
|
| 492 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 493 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 494 | - /** @var \OC\User\User $user */ |
|
| 495 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 496 | - }); |
|
| 497 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 498 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 499 | - /** @var \OC\User\User $user */ |
|
| 500 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 501 | - }); |
|
| 502 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 503 | - /** @var \OC\User\User $user */ |
|
| 504 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 505 | - }); |
|
| 506 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 507 | - /** @var \OC\User\User $user */ |
|
| 508 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 509 | - }); |
|
| 510 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 511 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 512 | - |
|
| 513 | - /** @var IEventDispatcher $dispatcher */ |
|
| 514 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 515 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 516 | - }); |
|
| 517 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 518 | - /** @var \OC\User\User $user */ |
|
| 519 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 520 | - |
|
| 521 | - /** @var IEventDispatcher $dispatcher */ |
|
| 522 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 523 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 524 | - }); |
|
| 525 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 526 | - /** @var IEventDispatcher $dispatcher */ |
|
| 527 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 528 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 529 | - }); |
|
| 530 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 531 | - /** @var \OC\User\User $user */ |
|
| 532 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 533 | - |
|
| 534 | - /** @var IEventDispatcher $dispatcher */ |
|
| 535 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 536 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 537 | - }); |
|
| 538 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 539 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 540 | - |
|
| 541 | - /** @var IEventDispatcher $dispatcher */ |
|
| 542 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 543 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 544 | - }); |
|
| 545 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 546 | - /** @var IEventDispatcher $dispatcher */ |
|
| 547 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 548 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 549 | - }); |
|
| 550 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 551 | - /** @var \OC\User\User $user */ |
|
| 552 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 553 | - }); |
|
| 554 | - return $userSession; |
|
| 555 | - }); |
|
| 556 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 557 | - |
|
| 558 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 559 | - |
|
| 560 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 561 | - |
|
| 562 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 563 | - |
|
| 564 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 565 | - return new \OC\SystemConfig($config); |
|
| 566 | - }); |
|
| 567 | - |
|
| 568 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 569 | - $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 570 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 571 | - |
|
| 572 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 573 | - return new \OC\L10N\Factory( |
|
| 574 | - $c->get(\OCP\IConfig::class), |
|
| 575 | - $c->getRequest(), |
|
| 576 | - $c->get(IUserSession::class), |
|
| 577 | - $c->get(ICacheFactory::class), |
|
| 578 | - \OC::$SERVERROOT, |
|
| 579 | - $c->get(IAppManager::class), |
|
| 580 | - ); |
|
| 581 | - }); |
|
| 582 | - |
|
| 583 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 584 | - |
|
| 585 | - $this->registerAlias(ICache::class, Cache\File::class); |
|
| 586 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 587 | - $profiler = $c->get(IProfiler::class); |
|
| 588 | - $logger = $c->get(LoggerInterface::class); |
|
| 589 | - $serverVersion = $c->get(ServerVersion::class); |
|
| 590 | - /** @var SystemConfig $config */ |
|
| 591 | - $config = $c->get(SystemConfig::class); |
|
| 592 | - if (!$config->getValue('installed', false) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 593 | - return new \OC\Memcache\Factory( |
|
| 594 | - $logger, |
|
| 595 | - $profiler, |
|
| 596 | - $serverVersion, |
|
| 597 | - ArrayCache::class, |
|
| 598 | - ArrayCache::class, |
|
| 599 | - ArrayCache::class |
|
| 600 | - ); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - return new \OC\Memcache\Factory( |
|
| 604 | - $logger, |
|
| 605 | - $profiler, |
|
| 606 | - $serverVersion, |
|
| 607 | - /** @psalm-taint-escape callable */ |
|
| 608 | - $config->getValue('memcache.local', null), |
|
| 609 | - /** @psalm-taint-escape callable */ |
|
| 610 | - $config->getValue('memcache.distributed', null), |
|
| 611 | - /** @psalm-taint-escape callable */ |
|
| 612 | - $config->getValue('memcache.locking', null), |
|
| 613 | - /** @psalm-taint-escape callable */ |
|
| 614 | - $config->getValue('redis_log_file') |
|
| 615 | - ); |
|
| 616 | - }); |
|
| 617 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 618 | - |
|
| 619 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 620 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 621 | - return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 622 | - }); |
|
| 623 | - |
|
| 624 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 625 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 626 | - return new \OC\Activity\Manager( |
|
| 627 | - $c->getRequest(), |
|
| 628 | - $c->get(IUserSession::class), |
|
| 629 | - $c->get(\OCP\IConfig::class), |
|
| 630 | - $c->get(IValidator::class), |
|
| 631 | - $c->get(IRichTextFormatter::class), |
|
| 632 | - $l10n, |
|
| 633 | - $c->get(ITimeFactory::class), |
|
| 634 | - ); |
|
| 635 | - }); |
|
| 636 | - |
|
| 637 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 638 | - return new \OC\Activity\EventMerger( |
|
| 639 | - $c->getL10N('lib') |
|
| 640 | - ); |
|
| 641 | - }); |
|
| 642 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 643 | - |
|
| 644 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 645 | - return new AvatarManager( |
|
| 646 | - $c->get(IUserSession::class), |
|
| 647 | - $c->get(\OC\User\Manager::class), |
|
| 648 | - $c->getAppDataDir('avatar'), |
|
| 649 | - $c->getL10N('lib'), |
|
| 650 | - $c->get(LoggerInterface::class), |
|
| 651 | - $c->get(\OCP\IConfig::class), |
|
| 652 | - $c->get(IAccountManager::class), |
|
| 653 | - $c->get(KnownUserService::class) |
|
| 654 | - ); |
|
| 655 | - }); |
|
| 656 | - |
|
| 657 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 658 | - |
|
| 659 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 660 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 661 | - $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 662 | - |
|
| 663 | - /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 664 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 665 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 666 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 667 | - $logger = $factory->get($logType); |
|
| 668 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 669 | - |
|
| 670 | - return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 671 | - }); |
|
| 672 | - // PSR-3 logger |
|
| 673 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 674 | - |
|
| 675 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 676 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 677 | - }); |
|
| 678 | - |
|
| 679 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 680 | - |
|
| 681 | - $this->registerService(Router::class, function (Server $c) { |
|
| 682 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 683 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 684 | - $router = $c->resolve(CachingRouter::class); |
|
| 685 | - } else { |
|
| 686 | - $router = $c->resolve(Router::class); |
|
| 687 | - } |
|
| 688 | - return $router; |
|
| 689 | - }); |
|
| 690 | - $this->registerAlias(IRouter::class, Router::class); |
|
| 691 | - |
|
| 692 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 693 | - $config = $c->get(\OCP\IConfig::class); |
|
| 694 | - if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 695 | - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 696 | - $c->get(AllConfig::class), |
|
| 697 | - $this->get(ICacheFactory::class), |
|
| 698 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 699 | - ); |
|
| 700 | - } else { |
|
| 701 | - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 702 | - $c->get(AllConfig::class), |
|
| 703 | - $c->get(IDBConnection::class), |
|
| 704 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 705 | - ); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - return $backend; |
|
| 709 | - }); |
|
| 710 | - |
|
| 711 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 712 | - $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 713 | - $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 714 | - |
|
| 715 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 716 | - |
|
| 717 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
| 718 | - |
|
| 719 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 720 | - |
|
| 721 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 722 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 723 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 724 | - $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 725 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 726 | - if (!$factory->isValidType($type)) { |
|
| 727 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 728 | - } |
|
| 729 | - $connection = $factory->getConnection($type, []); |
|
| 730 | - return $connection; |
|
| 731 | - }); |
|
| 732 | - |
|
| 733 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 734 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
| 735 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 736 | - return new NegativeDnsCache( |
|
| 737 | - $c->get(ICacheFactory::class), |
|
| 738 | - ); |
|
| 739 | - }); |
|
| 740 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 741 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 742 | - return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 743 | - }); |
|
| 744 | - |
|
| 745 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 746 | - $queryLogger = new QueryLogger(); |
|
| 747 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 748 | - // In debug mode, module is being activated by default |
|
| 749 | - $queryLogger->activate(); |
|
| 750 | - } |
|
| 751 | - return $queryLogger; |
|
| 752 | - }); |
|
| 753 | - |
|
| 754 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 755 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 756 | - |
|
| 757 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 758 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 759 | - |
|
| 760 | - return new DateTimeFormatter( |
|
| 761 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 762 | - $c->getL10N('lib', $language) |
|
| 763 | - ); |
|
| 764 | - }); |
|
| 765 | - |
|
| 766 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 767 | - $mountCache = $c->get(UserMountCache::class); |
|
| 768 | - $listener = new UserMountCacheListener($mountCache); |
|
| 769 | - $listener->listen($c->get(IUserManager::class)); |
|
| 770 | - return $mountCache; |
|
| 771 | - }); |
|
| 772 | - |
|
| 773 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 774 | - $loader = $c->get(IStorageFactory::class); |
|
| 775 | - $mountCache = $c->get(IUserMountCache::class); |
|
| 776 | - $eventLogger = $c->get(IEventLogger::class); |
|
| 777 | - $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 778 | - |
|
| 779 | - // builtin providers |
|
| 780 | - |
|
| 781 | - $config = $c->get(\OCP\IConfig::class); |
|
| 782 | - $logger = $c->get(LoggerInterface::class); |
|
| 783 | - $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); |
|
| 784 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 785 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 786 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig)); |
|
| 787 | - $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 788 | - |
|
| 789 | - return $manager; |
|
| 790 | - }); |
|
| 791 | - |
|
| 792 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 793 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 794 | - if ($busClass) { |
|
| 795 | - [$app, $class] = explode('::', $busClass, 2); |
|
| 796 | - if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 797 | - $c->get(IAppManager::class)->loadApp($app); |
|
| 798 | - return $c->get($class); |
|
| 799 | - } else { |
|
| 800 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 801 | - } |
|
| 802 | - } else { |
|
| 803 | - $jobList = $c->get(IJobList::class); |
|
| 804 | - return new CronBus($jobList); |
|
| 805 | - } |
|
| 806 | - }); |
|
| 807 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 808 | - $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 809 | - $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 810 | - |
|
| 811 | - $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 812 | - $config = $c->get(\OCP\IConfig::class); |
|
| 813 | - if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 814 | - && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 815 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 816 | - } else { |
|
| 817 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - return $backend; |
|
| 821 | - }); |
|
| 822 | - |
|
| 823 | - $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 824 | - $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 825 | - // IConfig requires a working database. This code |
|
| 826 | - // might however be called when Nextcloud is not yet setup. |
|
| 827 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 828 | - $config = $c->get(\OCP\IConfig::class); |
|
| 829 | - $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 830 | - } else { |
|
| 831 | - $config = null; |
|
| 832 | - $appConfig = null; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - return new Checker( |
|
| 836 | - $c->get(ServerVersion::class), |
|
| 837 | - $c->get(EnvironmentHelper::class), |
|
| 838 | - new FileAccessHelper(), |
|
| 839 | - $config, |
|
| 840 | - $appConfig, |
|
| 841 | - $c->get(ICacheFactory::class), |
|
| 842 | - $c->get(IAppManager::class), |
|
| 843 | - $c->get(IMimeTypeDetector::class) |
|
| 844 | - ); |
|
| 845 | - }); |
|
| 846 | - $this->registerService(Request::class, function (ContainerInterface $c) { |
|
| 847 | - if (isset($this['urlParams'])) { |
|
| 848 | - $urlParams = $this['urlParams']; |
|
| 849 | - } else { |
|
| 850 | - $urlParams = []; |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 854 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 855 | - ) { |
|
| 856 | - $stream = 'fakeinput://data'; |
|
| 857 | - } else { |
|
| 858 | - $stream = 'php://input'; |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - return new Request( |
|
| 862 | - [ |
|
| 863 | - 'get' => $_GET, |
|
| 864 | - 'post' => $_POST, |
|
| 865 | - 'files' => $_FILES, |
|
| 866 | - 'server' => $_SERVER, |
|
| 867 | - 'env' => $_ENV, |
|
| 868 | - 'cookies' => $_COOKIE, |
|
| 869 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 870 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 871 | - : '', |
|
| 872 | - 'urlParams' => $urlParams, |
|
| 873 | - ], |
|
| 874 | - $this->get(IRequestId::class), |
|
| 875 | - $this->get(\OCP\IConfig::class), |
|
| 876 | - $this->get(CsrfTokenManager::class), |
|
| 877 | - $stream |
|
| 878 | - ); |
|
| 879 | - }); |
|
| 880 | - $this->registerAlias(\OCP\IRequest::class, Request::class); |
|
| 881 | - |
|
| 882 | - $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 883 | - return new RequestId( |
|
| 884 | - $_SERVER['UNIQUE_ID'] ?? '', |
|
| 885 | - $this->get(ISecureRandom::class) |
|
| 886 | - ); |
|
| 887 | - }); |
|
| 888 | - |
|
| 889 | - /** @since 32.0.0 */ |
|
| 890 | - $this->registerAlias(IEmailValidator::class, EmailValidator::class); |
|
| 891 | - |
|
| 892 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 893 | - return new Mailer( |
|
| 894 | - $c->get(\OCP\IConfig::class), |
|
| 895 | - $c->get(LoggerInterface::class), |
|
| 896 | - $c->get(Defaults::class), |
|
| 897 | - $c->get(IURLGenerator::class), |
|
| 898 | - $c->getL10N('lib'), |
|
| 899 | - $c->get(IEventDispatcher::class), |
|
| 900 | - $c->get(IFactory::class), |
|
| 901 | - $c->get(IEmailValidator::class), |
|
| 902 | - ); |
|
| 903 | - }); |
|
| 904 | - |
|
| 905 | - /** @since 30.0.0 */ |
|
| 906 | - $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 907 | - |
|
| 908 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 909 | - $config = $c->get(\OCP\IConfig::class); |
|
| 910 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 911 | - if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 912 | - return new NullLDAPProviderFactory($this); |
|
| 913 | - } |
|
| 914 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 915 | - return new $factoryClass($this); |
|
| 916 | - }); |
|
| 917 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 918 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
| 919 | - return $factory->getLDAPProvider(); |
|
| 920 | - }); |
|
| 921 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 922 | - $ini = $c->get(IniGetWrapper::class); |
|
| 923 | - $config = $c->get(\OCP\IConfig::class); |
|
| 924 | - $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 925 | - if ($config->getSystemValueBool('filelocking.enabled', true) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 926 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 927 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 928 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 929 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 930 | - $timeFactory = $c->get(ITimeFactory::class); |
|
| 931 | - return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 932 | - } |
|
| 933 | - return new DBLockingProvider( |
|
| 934 | - $c->get(IDBConnection::class), |
|
| 935 | - new TimeFactory(), |
|
| 936 | - $ttl, |
|
| 937 | - !\OC::$CLI |
|
| 938 | - ); |
|
| 939 | - } |
|
| 940 | - return new NoopLockingProvider(); |
|
| 941 | - }); |
|
| 942 | - |
|
| 943 | - $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 944 | - return new LockManager(); |
|
| 945 | - }); |
|
| 946 | - |
|
| 947 | - $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 948 | - $this->registerService(SetupManager::class, function ($c) { |
|
| 949 | - // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 950 | - return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 951 | - }); |
|
| 952 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 953 | - |
|
| 954 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 955 | - return new \OC\Files\Type\Detection( |
|
| 956 | - $c->get(IURLGenerator::class), |
|
| 957 | - $c->get(LoggerInterface::class), |
|
| 958 | - \OC::$configDir, |
|
| 959 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 960 | - ); |
|
| 961 | - }); |
|
| 962 | - |
|
| 963 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 964 | - $this->registerService(BundleFetcher::class, function () { |
|
| 965 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 966 | - }); |
|
| 967 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 968 | - |
|
| 969 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 970 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 971 | - $manager->registerCapability(function () use ($c) { |
|
| 972 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 973 | - }); |
|
| 974 | - $manager->registerCapability(function () use ($c) { |
|
| 975 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 976 | - }); |
|
| 977 | - return $manager; |
|
| 978 | - }); |
|
| 979 | - |
|
| 980 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 981 | - $config = $c->get(\OCP\IConfig::class); |
|
| 982 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 983 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 984 | - $factory = new $factoryClass($this); |
|
| 985 | - $manager = $factory->getManager(); |
|
| 986 | - |
|
| 987 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 988 | - $manager = $c->get(IUserManager::class); |
|
| 989 | - $userDisplayName = $manager->getDisplayName($id); |
|
| 990 | - if ($userDisplayName === null) { |
|
| 991 | - $l = $c->get(IFactory::class)->get('core'); |
|
| 992 | - return $l->t('Unknown account'); |
|
| 993 | - } |
|
| 994 | - return $userDisplayName; |
|
| 995 | - }); |
|
| 996 | - |
|
| 997 | - return $manager; |
|
| 998 | - }); |
|
| 999 | - |
|
| 1000 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1001 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1002 | - try { |
|
| 1003 | - $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1004 | - } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1005 | - // App disabled or in maintenance mode |
|
| 1006 | - $classExists = false; |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1010 | - $backgroundService = new BackgroundService( |
|
| 1011 | - $c->get(IRootFolder::class), |
|
| 1012 | - $c->getAppDataDir('theming'), |
|
| 1013 | - $c->get(IAppConfig::class), |
|
| 1014 | - $c->get(\OCP\IConfig::class), |
|
| 1015 | - $c->get(ISession::class)->get('user_id'), |
|
| 1016 | - ); |
|
| 1017 | - $imageManager = new ImageManager( |
|
| 1018 | - $c->get(\OCP\IConfig::class), |
|
| 1019 | - $c->getAppDataDir('theming'), |
|
| 1020 | - $c->get(IURLGenerator::class), |
|
| 1021 | - $c->get(ICacheFactory::class), |
|
| 1022 | - $c->get(LoggerInterface::class), |
|
| 1023 | - $c->get(ITempManager::class), |
|
| 1024 | - $backgroundService, |
|
| 1025 | - ); |
|
| 1026 | - return new ThemingDefaults( |
|
| 1027 | - $c->get(\OCP\IConfig::class), |
|
| 1028 | - $c->get(\OCP\IAppConfig::class), |
|
| 1029 | - $c->getL10N('theming'), |
|
| 1030 | - $c->get(IUserSession::class), |
|
| 1031 | - $c->get(IURLGenerator::class), |
|
| 1032 | - $c->get(ICacheFactory::class), |
|
| 1033 | - new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1034 | - $imageManager, |
|
| 1035 | - $c->get(IAppManager::class), |
|
| 1036 | - $c->get(INavigationManager::class), |
|
| 1037 | - $backgroundService, |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - return new \OC_Defaults(); |
|
| 1041 | - }); |
|
| 1042 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1043 | - return new JSCombiner( |
|
| 1044 | - $c->getAppDataDir('js'), |
|
| 1045 | - $c->get(IURLGenerator::class), |
|
| 1046 | - $this->get(ICacheFactory::class), |
|
| 1047 | - $c->get(\OCP\IConfig::class), |
|
| 1048 | - $c->get(LoggerInterface::class) |
|
| 1049 | - ); |
|
| 1050 | - }); |
|
| 1051 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1052 | - |
|
| 1053 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1054 | - // FIXME: Instantiated here due to cyclic dependency |
|
| 1055 | - $request = new Request( |
|
| 1056 | - [ |
|
| 1057 | - 'get' => $_GET, |
|
| 1058 | - 'post' => $_POST, |
|
| 1059 | - 'files' => $_FILES, |
|
| 1060 | - 'server' => $_SERVER, |
|
| 1061 | - 'env' => $_ENV, |
|
| 1062 | - 'cookies' => $_COOKIE, |
|
| 1063 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1064 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1065 | - : null, |
|
| 1066 | - ], |
|
| 1067 | - $c->get(IRequestId::class), |
|
| 1068 | - $c->get(\OCP\IConfig::class) |
|
| 1069 | - ); |
|
| 1070 | - |
|
| 1071 | - return new CryptoWrapper( |
|
| 1072 | - $c->get(ICrypto::class), |
|
| 1073 | - $c->get(ISecureRandom::class), |
|
| 1074 | - $request |
|
| 1075 | - ); |
|
| 1076 | - }); |
|
| 1077 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1078 | - return new SessionStorage($c->get(ISession::class)); |
|
| 1079 | - }); |
|
| 1080 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1081 | - |
|
| 1082 | - $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1083 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1084 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1085 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1086 | - return $c->get($factoryClass); |
|
| 1087 | - }); |
|
| 1088 | - |
|
| 1089 | - $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1090 | - |
|
| 1091 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1092 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1093 | - |
|
| 1094 | - // register default plugins |
|
| 1095 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1096 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1097 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1098 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1099 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1100 | - |
|
| 1101 | - return $instance; |
|
| 1102 | - }); |
|
| 1103 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1104 | - |
|
| 1105 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1106 | - |
|
| 1107 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1108 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1109 | - |
|
| 1110 | - $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1111 | - $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1112 | - |
|
| 1113 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1114 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1115 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1116 | - return new \OC\Files\AppData\Factory( |
|
| 1117 | - $c->get(IRootFolder::class), |
|
| 1118 | - $c->get(SystemConfig::class) |
|
| 1119 | - ); |
|
| 1120 | - }); |
|
| 1121 | - |
|
| 1122 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1123 | - return new LockdownManager(function () use ($c) { |
|
| 1124 | - return $c->get(ISession::class); |
|
| 1125 | - }); |
|
| 1126 | - }); |
|
| 1127 | - |
|
| 1128 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1129 | - return new DiscoveryService( |
|
| 1130 | - $c->get(ICacheFactory::class), |
|
| 1131 | - $c->get(IClientService::class) |
|
| 1132 | - ); |
|
| 1133 | - }); |
|
| 1134 | - $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1135 | - |
|
| 1136 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1137 | - return new CloudIdManager( |
|
| 1138 | - $c->get(ICacheFactory::class), |
|
| 1139 | - $c->get(IEventDispatcher::class), |
|
| 1140 | - $c->get(\OCP\Contacts\IManager::class), |
|
| 1141 | - $c->get(IURLGenerator::class), |
|
| 1142 | - $c->get(IUserManager::class), |
|
| 1143 | - ); |
|
| 1144 | - }); |
|
| 252 | + /** @var string */ |
|
| 253 | + private $webRoot; |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @param string $webRoot |
|
| 257 | + * @param \OC\Config $config |
|
| 258 | + */ |
|
| 259 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 260 | + parent::__construct(); |
|
| 261 | + $this->webRoot = $webRoot; |
|
| 262 | + |
|
| 263 | + // To find out if we are running from CLI or not |
|
| 264 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 265 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 266 | + |
|
| 267 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 268 | + return $c; |
|
| 269 | + }); |
|
| 270 | + $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class); |
|
| 271 | + |
|
| 272 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 273 | + |
|
| 274 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 275 | + |
|
| 276 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 277 | + |
|
| 278 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 279 | + |
|
| 280 | + $this->registerAlias(\OCP\ContextChat\IContentManager::class, \OC\ContextChat\ContentManager::class); |
|
| 281 | + |
|
| 282 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 283 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 284 | + $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 285 | + |
|
| 286 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 287 | + |
|
| 288 | + $this->registerService(View::class, function (Server $c) { |
|
| 289 | + return new View(); |
|
| 290 | + }, false); |
|
| 291 | + |
|
| 292 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 293 | + return new PreviewManager( |
|
| 294 | + $c->get(\OCP\IConfig::class), |
|
| 295 | + $c->get(IRootFolder::class), |
|
| 296 | + $c->get(IEventDispatcher::class), |
|
| 297 | + $c->get(GeneratorHelper::class), |
|
| 298 | + $c->get(ISession::class)->get('user_id'), |
|
| 299 | + $c->get(Coordinator::class), |
|
| 300 | + $c->get(IServerContainer::class), |
|
| 301 | + $c->get(IBinaryFinder::class), |
|
| 302 | + $c->get(IMagickSupport::class) |
|
| 303 | + ); |
|
| 304 | + }); |
|
| 305 | + $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 306 | + |
|
| 307 | + $this->registerService(Watcher::class, function (ContainerInterface $c): Watcher { |
|
| 308 | + return new Watcher( |
|
| 309 | + $c->get(\OC\Preview\Storage\StorageFactory::class), |
|
| 310 | + $c->get(PreviewMapper::class), |
|
| 311 | + $c->get(IDBConnection::class), |
|
| 312 | + ); |
|
| 313 | + }); |
|
| 314 | + |
|
| 315 | + $this->registerService(IProfiler::class, function (Server $c) { |
|
| 316 | + return new Profiler($c->get(SystemConfig::class)); |
|
| 317 | + }); |
|
| 318 | + |
|
| 319 | + $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { |
|
| 320 | + $view = new View(); |
|
| 321 | + $util = new Encryption\Util( |
|
| 322 | + $view, |
|
| 323 | + $c->get(IUserManager::class), |
|
| 324 | + $c->get(IGroupManager::class), |
|
| 325 | + $c->get(\OCP\IConfig::class) |
|
| 326 | + ); |
|
| 327 | + return new Encryption\Manager( |
|
| 328 | + $c->get(\OCP\IConfig::class), |
|
| 329 | + $c->get(LoggerInterface::class), |
|
| 330 | + $c->getL10N('core'), |
|
| 331 | + new View(), |
|
| 332 | + $util, |
|
| 333 | + new ArrayCache() |
|
| 334 | + ); |
|
| 335 | + }); |
|
| 336 | + $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); |
|
| 337 | + |
|
| 338 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 339 | + $util = new Encryption\Util( |
|
| 340 | + new View(), |
|
| 341 | + $c->get(IUserManager::class), |
|
| 342 | + $c->get(IGroupManager::class), |
|
| 343 | + $c->get(\OCP\IConfig::class) |
|
| 344 | + ); |
|
| 345 | + return new Encryption\File( |
|
| 346 | + $util, |
|
| 347 | + $c->get(IRootFolder::class), |
|
| 348 | + $c->get(\OCP\Share\IManager::class) |
|
| 349 | + ); |
|
| 350 | + }); |
|
| 351 | + |
|
| 352 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 353 | + $view = new View(); |
|
| 354 | + $util = new Encryption\Util( |
|
| 355 | + $view, |
|
| 356 | + $c->get(IUserManager::class), |
|
| 357 | + $c->get(IGroupManager::class), |
|
| 358 | + $c->get(\OCP\IConfig::class) |
|
| 359 | + ); |
|
| 360 | + |
|
| 361 | + return new Encryption\Keys\Storage( |
|
| 362 | + $view, |
|
| 363 | + $util, |
|
| 364 | + $c->get(ICrypto::class), |
|
| 365 | + $c->get(\OCP\IConfig::class) |
|
| 366 | + ); |
|
| 367 | + }); |
|
| 368 | + |
|
| 369 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 370 | + |
|
| 371 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 372 | + /** @var \OCP\IConfig $config */ |
|
| 373 | + $config = $c->get(\OCP\IConfig::class); |
|
| 374 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 375 | + return new $factoryClass($this); |
|
| 376 | + }); |
|
| 377 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 378 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 379 | + }); |
|
| 380 | + /** @deprecated 19.0.0 */ |
|
| 381 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 382 | + |
|
| 383 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 384 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 385 | + }); |
|
| 386 | + $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 387 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 388 | + $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 389 | + $view = new View(); |
|
| 390 | + /** @var IUserSession $userSession */ |
|
| 391 | + $userSession = $c->get(IUserSession::class); |
|
| 392 | + $root = new Root( |
|
| 393 | + $manager, |
|
| 394 | + $view, |
|
| 395 | + $userSession->getUser(), |
|
| 396 | + $c->get(IUserMountCache::class), |
|
| 397 | + $this->get(LoggerInterface::class), |
|
| 398 | + $this->get(IUserManager::class), |
|
| 399 | + $this->get(IEventDispatcher::class), |
|
| 400 | + $this->get(ICacheFactory::class), |
|
| 401 | + $this->get(IAppConfig::class), |
|
| 402 | + ); |
|
| 403 | + |
|
| 404 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 405 | + $root, |
|
| 406 | + $c->get(SystemConfig::class), |
|
| 407 | + $this->get(IEventDispatcher::class) |
|
| 408 | + ); |
|
| 409 | + $previewConnector->connectWatcher(); |
|
| 410 | + |
|
| 411 | + return $root; |
|
| 412 | + }); |
|
| 413 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 414 | + return new HookConnector( |
|
| 415 | + $c->get(IRootFolder::class), |
|
| 416 | + new View(), |
|
| 417 | + $c->get(IEventDispatcher::class), |
|
| 418 | + $c->get(LoggerInterface::class) |
|
| 419 | + ); |
|
| 420 | + }); |
|
| 421 | + |
|
| 422 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 423 | + return new LazyRoot(function () use ($c) { |
|
| 424 | + return $c->get('RootFolder'); |
|
| 425 | + }); |
|
| 426 | + }); |
|
| 427 | + |
|
| 428 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 429 | + |
|
| 430 | + $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 431 | + return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 432 | + }); |
|
| 433 | + |
|
| 434 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 435 | + $groupManager = new \OC\Group\Manager( |
|
| 436 | + $this->get(IUserManager::class), |
|
| 437 | + $this->get(IEventDispatcher::class), |
|
| 438 | + $this->get(LoggerInterface::class), |
|
| 439 | + $this->get(ICacheFactory::class), |
|
| 440 | + $this->get(IRemoteAddress::class), |
|
| 441 | + ); |
|
| 442 | + return $groupManager; |
|
| 443 | + }); |
|
| 444 | + |
|
| 445 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 446 | + $session = $c->get(ISession::class); |
|
| 447 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 448 | + $tokenProvider = $c->get(IProvider::class); |
|
| 449 | + } else { |
|
| 450 | + $tokenProvider = null; |
|
| 451 | + } |
|
| 452 | + $logger = $c->get(LoggerInterface::class); |
|
| 453 | + $crypto = $c->get(ICrypto::class); |
|
| 454 | + return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 455 | + }); |
|
| 456 | + $this->registerAlias(IStore::class, Store::class); |
|
| 457 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 458 | + $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 459 | + |
|
| 460 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 461 | + $manager = $c->get(IUserManager::class); |
|
| 462 | + $session = new \OC\Session\Memory(); |
|
| 463 | + $timeFactory = new TimeFactory(); |
|
| 464 | + // Token providers might require a working database. This code |
|
| 465 | + // might however be called when Nextcloud is not yet setup. |
|
| 466 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 467 | + $provider = $c->get(IProvider::class); |
|
| 468 | + } else { |
|
| 469 | + $provider = null; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + $userSession = new \OC\User\Session( |
|
| 473 | + $manager, |
|
| 474 | + $session, |
|
| 475 | + $timeFactory, |
|
| 476 | + $provider, |
|
| 477 | + $c->get(\OCP\IConfig::class), |
|
| 478 | + $c->get(ISecureRandom::class), |
|
| 479 | + $c->get('LockdownManager'), |
|
| 480 | + $c->get(LoggerInterface::class), |
|
| 481 | + $c->get(IEventDispatcher::class), |
|
| 482 | + ); |
|
| 483 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 484 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 485 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 486 | + }); |
|
| 487 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 488 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 489 | + /** @var \OC\User\User $user */ |
|
| 490 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 491 | + }); |
|
| 492 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 493 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 494 | + /** @var \OC\User\User $user */ |
|
| 495 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 496 | + }); |
|
| 497 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 498 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 499 | + /** @var \OC\User\User $user */ |
|
| 500 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 501 | + }); |
|
| 502 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 503 | + /** @var \OC\User\User $user */ |
|
| 504 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 505 | + }); |
|
| 506 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 507 | + /** @var \OC\User\User $user */ |
|
| 508 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 509 | + }); |
|
| 510 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 511 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 512 | + |
|
| 513 | + /** @var IEventDispatcher $dispatcher */ |
|
| 514 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 515 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 516 | + }); |
|
| 517 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 518 | + /** @var \OC\User\User $user */ |
|
| 519 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 520 | + |
|
| 521 | + /** @var IEventDispatcher $dispatcher */ |
|
| 522 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 523 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 524 | + }); |
|
| 525 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 526 | + /** @var IEventDispatcher $dispatcher */ |
|
| 527 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 528 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 529 | + }); |
|
| 530 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 531 | + /** @var \OC\User\User $user */ |
|
| 532 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 533 | + |
|
| 534 | + /** @var IEventDispatcher $dispatcher */ |
|
| 535 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 536 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 537 | + }); |
|
| 538 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 539 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 540 | + |
|
| 541 | + /** @var IEventDispatcher $dispatcher */ |
|
| 542 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 543 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 544 | + }); |
|
| 545 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 546 | + /** @var IEventDispatcher $dispatcher */ |
|
| 547 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 548 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 549 | + }); |
|
| 550 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 551 | + /** @var \OC\User\User $user */ |
|
| 552 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 553 | + }); |
|
| 554 | + return $userSession; |
|
| 555 | + }); |
|
| 556 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 557 | + |
|
| 558 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 559 | + |
|
| 560 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 561 | + |
|
| 562 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 563 | + |
|
| 564 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 565 | + return new \OC\SystemConfig($config); |
|
| 566 | + }); |
|
| 567 | + |
|
| 568 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 569 | + $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 570 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 571 | + |
|
| 572 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 573 | + return new \OC\L10N\Factory( |
|
| 574 | + $c->get(\OCP\IConfig::class), |
|
| 575 | + $c->getRequest(), |
|
| 576 | + $c->get(IUserSession::class), |
|
| 577 | + $c->get(ICacheFactory::class), |
|
| 578 | + \OC::$SERVERROOT, |
|
| 579 | + $c->get(IAppManager::class), |
|
| 580 | + ); |
|
| 581 | + }); |
|
| 582 | + |
|
| 583 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 584 | + |
|
| 585 | + $this->registerAlias(ICache::class, Cache\File::class); |
|
| 586 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 587 | + $profiler = $c->get(IProfiler::class); |
|
| 588 | + $logger = $c->get(LoggerInterface::class); |
|
| 589 | + $serverVersion = $c->get(ServerVersion::class); |
|
| 590 | + /** @var SystemConfig $config */ |
|
| 591 | + $config = $c->get(SystemConfig::class); |
|
| 592 | + if (!$config->getValue('installed', false) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 593 | + return new \OC\Memcache\Factory( |
|
| 594 | + $logger, |
|
| 595 | + $profiler, |
|
| 596 | + $serverVersion, |
|
| 597 | + ArrayCache::class, |
|
| 598 | + ArrayCache::class, |
|
| 599 | + ArrayCache::class |
|
| 600 | + ); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + return new \OC\Memcache\Factory( |
|
| 604 | + $logger, |
|
| 605 | + $profiler, |
|
| 606 | + $serverVersion, |
|
| 607 | + /** @psalm-taint-escape callable */ |
|
| 608 | + $config->getValue('memcache.local', null), |
|
| 609 | + /** @psalm-taint-escape callable */ |
|
| 610 | + $config->getValue('memcache.distributed', null), |
|
| 611 | + /** @psalm-taint-escape callable */ |
|
| 612 | + $config->getValue('memcache.locking', null), |
|
| 613 | + /** @psalm-taint-escape callable */ |
|
| 614 | + $config->getValue('redis_log_file') |
|
| 615 | + ); |
|
| 616 | + }); |
|
| 617 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 618 | + |
|
| 619 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 620 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 621 | + return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 622 | + }); |
|
| 623 | + |
|
| 624 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 625 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 626 | + return new \OC\Activity\Manager( |
|
| 627 | + $c->getRequest(), |
|
| 628 | + $c->get(IUserSession::class), |
|
| 629 | + $c->get(\OCP\IConfig::class), |
|
| 630 | + $c->get(IValidator::class), |
|
| 631 | + $c->get(IRichTextFormatter::class), |
|
| 632 | + $l10n, |
|
| 633 | + $c->get(ITimeFactory::class), |
|
| 634 | + ); |
|
| 635 | + }); |
|
| 636 | + |
|
| 637 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 638 | + return new \OC\Activity\EventMerger( |
|
| 639 | + $c->getL10N('lib') |
|
| 640 | + ); |
|
| 641 | + }); |
|
| 642 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 643 | + |
|
| 644 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 645 | + return new AvatarManager( |
|
| 646 | + $c->get(IUserSession::class), |
|
| 647 | + $c->get(\OC\User\Manager::class), |
|
| 648 | + $c->getAppDataDir('avatar'), |
|
| 649 | + $c->getL10N('lib'), |
|
| 650 | + $c->get(LoggerInterface::class), |
|
| 651 | + $c->get(\OCP\IConfig::class), |
|
| 652 | + $c->get(IAccountManager::class), |
|
| 653 | + $c->get(KnownUserService::class) |
|
| 654 | + ); |
|
| 655 | + }); |
|
| 656 | + |
|
| 657 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 658 | + |
|
| 659 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 660 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 661 | + $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 662 | + |
|
| 663 | + /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 664 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 665 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 666 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 667 | + $logger = $factory->get($logType); |
|
| 668 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 669 | + |
|
| 670 | + return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 671 | + }); |
|
| 672 | + // PSR-3 logger |
|
| 673 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 674 | + |
|
| 675 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 676 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 677 | + }); |
|
| 678 | + |
|
| 679 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 680 | + |
|
| 681 | + $this->registerService(Router::class, function (Server $c) { |
|
| 682 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 683 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 684 | + $router = $c->resolve(CachingRouter::class); |
|
| 685 | + } else { |
|
| 686 | + $router = $c->resolve(Router::class); |
|
| 687 | + } |
|
| 688 | + return $router; |
|
| 689 | + }); |
|
| 690 | + $this->registerAlias(IRouter::class, Router::class); |
|
| 691 | + |
|
| 692 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 693 | + $config = $c->get(\OCP\IConfig::class); |
|
| 694 | + if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 695 | + $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 696 | + $c->get(AllConfig::class), |
|
| 697 | + $this->get(ICacheFactory::class), |
|
| 698 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 699 | + ); |
|
| 700 | + } else { |
|
| 701 | + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 702 | + $c->get(AllConfig::class), |
|
| 703 | + $c->get(IDBConnection::class), |
|
| 704 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 705 | + ); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + return $backend; |
|
| 709 | + }); |
|
| 710 | + |
|
| 711 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 712 | + $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 713 | + $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 714 | + |
|
| 715 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 716 | + |
|
| 717 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
| 718 | + |
|
| 719 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 720 | + |
|
| 721 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 722 | + $this->registerService(Connection::class, function (Server $c) { |
|
| 723 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 724 | + $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 725 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 726 | + if (!$factory->isValidType($type)) { |
|
| 727 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 728 | + } |
|
| 729 | + $connection = $factory->getConnection($type, []); |
|
| 730 | + return $connection; |
|
| 731 | + }); |
|
| 732 | + |
|
| 733 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 734 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
| 735 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 736 | + return new NegativeDnsCache( |
|
| 737 | + $c->get(ICacheFactory::class), |
|
| 738 | + ); |
|
| 739 | + }); |
|
| 740 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 741 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 742 | + return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 743 | + }); |
|
| 744 | + |
|
| 745 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 746 | + $queryLogger = new QueryLogger(); |
|
| 747 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 748 | + // In debug mode, module is being activated by default |
|
| 749 | + $queryLogger->activate(); |
|
| 750 | + } |
|
| 751 | + return $queryLogger; |
|
| 752 | + }); |
|
| 753 | + |
|
| 754 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 755 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 756 | + |
|
| 757 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 758 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 759 | + |
|
| 760 | + return new DateTimeFormatter( |
|
| 761 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 762 | + $c->getL10N('lib', $language) |
|
| 763 | + ); |
|
| 764 | + }); |
|
| 765 | + |
|
| 766 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 767 | + $mountCache = $c->get(UserMountCache::class); |
|
| 768 | + $listener = new UserMountCacheListener($mountCache); |
|
| 769 | + $listener->listen($c->get(IUserManager::class)); |
|
| 770 | + return $mountCache; |
|
| 771 | + }); |
|
| 772 | + |
|
| 773 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 774 | + $loader = $c->get(IStorageFactory::class); |
|
| 775 | + $mountCache = $c->get(IUserMountCache::class); |
|
| 776 | + $eventLogger = $c->get(IEventLogger::class); |
|
| 777 | + $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 778 | + |
|
| 779 | + // builtin providers |
|
| 780 | + |
|
| 781 | + $config = $c->get(\OCP\IConfig::class); |
|
| 782 | + $logger = $c->get(LoggerInterface::class); |
|
| 783 | + $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); |
|
| 784 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 785 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 786 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig)); |
|
| 787 | + $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 788 | + |
|
| 789 | + return $manager; |
|
| 790 | + }); |
|
| 791 | + |
|
| 792 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 793 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 794 | + if ($busClass) { |
|
| 795 | + [$app, $class] = explode('::', $busClass, 2); |
|
| 796 | + if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 797 | + $c->get(IAppManager::class)->loadApp($app); |
|
| 798 | + return $c->get($class); |
|
| 799 | + } else { |
|
| 800 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 801 | + } |
|
| 802 | + } else { |
|
| 803 | + $jobList = $c->get(IJobList::class); |
|
| 804 | + return new CronBus($jobList); |
|
| 805 | + } |
|
| 806 | + }); |
|
| 807 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 808 | + $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 809 | + $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 810 | + |
|
| 811 | + $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 812 | + $config = $c->get(\OCP\IConfig::class); |
|
| 813 | + if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 814 | + && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 815 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 816 | + } else { |
|
| 817 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + return $backend; |
|
| 821 | + }); |
|
| 822 | + |
|
| 823 | + $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 824 | + $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 825 | + // IConfig requires a working database. This code |
|
| 826 | + // might however be called when Nextcloud is not yet setup. |
|
| 827 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 828 | + $config = $c->get(\OCP\IConfig::class); |
|
| 829 | + $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 830 | + } else { |
|
| 831 | + $config = null; |
|
| 832 | + $appConfig = null; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + return new Checker( |
|
| 836 | + $c->get(ServerVersion::class), |
|
| 837 | + $c->get(EnvironmentHelper::class), |
|
| 838 | + new FileAccessHelper(), |
|
| 839 | + $config, |
|
| 840 | + $appConfig, |
|
| 841 | + $c->get(ICacheFactory::class), |
|
| 842 | + $c->get(IAppManager::class), |
|
| 843 | + $c->get(IMimeTypeDetector::class) |
|
| 844 | + ); |
|
| 845 | + }); |
|
| 846 | + $this->registerService(Request::class, function (ContainerInterface $c) { |
|
| 847 | + if (isset($this['urlParams'])) { |
|
| 848 | + $urlParams = $this['urlParams']; |
|
| 849 | + } else { |
|
| 850 | + $urlParams = []; |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 854 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 855 | + ) { |
|
| 856 | + $stream = 'fakeinput://data'; |
|
| 857 | + } else { |
|
| 858 | + $stream = 'php://input'; |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + return new Request( |
|
| 862 | + [ |
|
| 863 | + 'get' => $_GET, |
|
| 864 | + 'post' => $_POST, |
|
| 865 | + 'files' => $_FILES, |
|
| 866 | + 'server' => $_SERVER, |
|
| 867 | + 'env' => $_ENV, |
|
| 868 | + 'cookies' => $_COOKIE, |
|
| 869 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 870 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 871 | + : '', |
|
| 872 | + 'urlParams' => $urlParams, |
|
| 873 | + ], |
|
| 874 | + $this->get(IRequestId::class), |
|
| 875 | + $this->get(\OCP\IConfig::class), |
|
| 876 | + $this->get(CsrfTokenManager::class), |
|
| 877 | + $stream |
|
| 878 | + ); |
|
| 879 | + }); |
|
| 880 | + $this->registerAlias(\OCP\IRequest::class, Request::class); |
|
| 881 | + |
|
| 882 | + $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 883 | + return new RequestId( |
|
| 884 | + $_SERVER['UNIQUE_ID'] ?? '', |
|
| 885 | + $this->get(ISecureRandom::class) |
|
| 886 | + ); |
|
| 887 | + }); |
|
| 888 | + |
|
| 889 | + /** @since 32.0.0 */ |
|
| 890 | + $this->registerAlias(IEmailValidator::class, EmailValidator::class); |
|
| 891 | + |
|
| 892 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 893 | + return new Mailer( |
|
| 894 | + $c->get(\OCP\IConfig::class), |
|
| 895 | + $c->get(LoggerInterface::class), |
|
| 896 | + $c->get(Defaults::class), |
|
| 897 | + $c->get(IURLGenerator::class), |
|
| 898 | + $c->getL10N('lib'), |
|
| 899 | + $c->get(IEventDispatcher::class), |
|
| 900 | + $c->get(IFactory::class), |
|
| 901 | + $c->get(IEmailValidator::class), |
|
| 902 | + ); |
|
| 903 | + }); |
|
| 904 | + |
|
| 905 | + /** @since 30.0.0 */ |
|
| 906 | + $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 907 | + |
|
| 908 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 909 | + $config = $c->get(\OCP\IConfig::class); |
|
| 910 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 911 | + if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 912 | + return new NullLDAPProviderFactory($this); |
|
| 913 | + } |
|
| 914 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 915 | + return new $factoryClass($this); |
|
| 916 | + }); |
|
| 917 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 918 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
| 919 | + return $factory->getLDAPProvider(); |
|
| 920 | + }); |
|
| 921 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 922 | + $ini = $c->get(IniGetWrapper::class); |
|
| 923 | + $config = $c->get(\OCP\IConfig::class); |
|
| 924 | + $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 925 | + if ($config->getSystemValueBool('filelocking.enabled', true) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 926 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 927 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 928 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 929 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 930 | + $timeFactory = $c->get(ITimeFactory::class); |
|
| 931 | + return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 932 | + } |
|
| 933 | + return new DBLockingProvider( |
|
| 934 | + $c->get(IDBConnection::class), |
|
| 935 | + new TimeFactory(), |
|
| 936 | + $ttl, |
|
| 937 | + !\OC::$CLI |
|
| 938 | + ); |
|
| 939 | + } |
|
| 940 | + return new NoopLockingProvider(); |
|
| 941 | + }); |
|
| 942 | + |
|
| 943 | + $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 944 | + return new LockManager(); |
|
| 945 | + }); |
|
| 946 | + |
|
| 947 | + $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 948 | + $this->registerService(SetupManager::class, function ($c) { |
|
| 949 | + // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 950 | + return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 951 | + }); |
|
| 952 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 953 | + |
|
| 954 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 955 | + return new \OC\Files\Type\Detection( |
|
| 956 | + $c->get(IURLGenerator::class), |
|
| 957 | + $c->get(LoggerInterface::class), |
|
| 958 | + \OC::$configDir, |
|
| 959 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 960 | + ); |
|
| 961 | + }); |
|
| 962 | + |
|
| 963 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 964 | + $this->registerService(BundleFetcher::class, function () { |
|
| 965 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 966 | + }); |
|
| 967 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 968 | + |
|
| 969 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 970 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 971 | + $manager->registerCapability(function () use ($c) { |
|
| 972 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 973 | + }); |
|
| 974 | + $manager->registerCapability(function () use ($c) { |
|
| 975 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 976 | + }); |
|
| 977 | + return $manager; |
|
| 978 | + }); |
|
| 979 | + |
|
| 980 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 981 | + $config = $c->get(\OCP\IConfig::class); |
|
| 982 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 983 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 984 | + $factory = new $factoryClass($this); |
|
| 985 | + $manager = $factory->getManager(); |
|
| 986 | + |
|
| 987 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 988 | + $manager = $c->get(IUserManager::class); |
|
| 989 | + $userDisplayName = $manager->getDisplayName($id); |
|
| 990 | + if ($userDisplayName === null) { |
|
| 991 | + $l = $c->get(IFactory::class)->get('core'); |
|
| 992 | + return $l->t('Unknown account'); |
|
| 993 | + } |
|
| 994 | + return $userDisplayName; |
|
| 995 | + }); |
|
| 996 | + |
|
| 997 | + return $manager; |
|
| 998 | + }); |
|
| 999 | + |
|
| 1000 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1001 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1002 | + try { |
|
| 1003 | + $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1004 | + } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1005 | + // App disabled or in maintenance mode |
|
| 1006 | + $classExists = false; |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1010 | + $backgroundService = new BackgroundService( |
|
| 1011 | + $c->get(IRootFolder::class), |
|
| 1012 | + $c->getAppDataDir('theming'), |
|
| 1013 | + $c->get(IAppConfig::class), |
|
| 1014 | + $c->get(\OCP\IConfig::class), |
|
| 1015 | + $c->get(ISession::class)->get('user_id'), |
|
| 1016 | + ); |
|
| 1017 | + $imageManager = new ImageManager( |
|
| 1018 | + $c->get(\OCP\IConfig::class), |
|
| 1019 | + $c->getAppDataDir('theming'), |
|
| 1020 | + $c->get(IURLGenerator::class), |
|
| 1021 | + $c->get(ICacheFactory::class), |
|
| 1022 | + $c->get(LoggerInterface::class), |
|
| 1023 | + $c->get(ITempManager::class), |
|
| 1024 | + $backgroundService, |
|
| 1025 | + ); |
|
| 1026 | + return new ThemingDefaults( |
|
| 1027 | + $c->get(\OCP\IConfig::class), |
|
| 1028 | + $c->get(\OCP\IAppConfig::class), |
|
| 1029 | + $c->getL10N('theming'), |
|
| 1030 | + $c->get(IUserSession::class), |
|
| 1031 | + $c->get(IURLGenerator::class), |
|
| 1032 | + $c->get(ICacheFactory::class), |
|
| 1033 | + new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1034 | + $imageManager, |
|
| 1035 | + $c->get(IAppManager::class), |
|
| 1036 | + $c->get(INavigationManager::class), |
|
| 1037 | + $backgroundService, |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + return new \OC_Defaults(); |
|
| 1041 | + }); |
|
| 1042 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1043 | + return new JSCombiner( |
|
| 1044 | + $c->getAppDataDir('js'), |
|
| 1045 | + $c->get(IURLGenerator::class), |
|
| 1046 | + $this->get(ICacheFactory::class), |
|
| 1047 | + $c->get(\OCP\IConfig::class), |
|
| 1048 | + $c->get(LoggerInterface::class) |
|
| 1049 | + ); |
|
| 1050 | + }); |
|
| 1051 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1052 | + |
|
| 1053 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1054 | + // FIXME: Instantiated here due to cyclic dependency |
|
| 1055 | + $request = new Request( |
|
| 1056 | + [ |
|
| 1057 | + 'get' => $_GET, |
|
| 1058 | + 'post' => $_POST, |
|
| 1059 | + 'files' => $_FILES, |
|
| 1060 | + 'server' => $_SERVER, |
|
| 1061 | + 'env' => $_ENV, |
|
| 1062 | + 'cookies' => $_COOKIE, |
|
| 1063 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1064 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1065 | + : null, |
|
| 1066 | + ], |
|
| 1067 | + $c->get(IRequestId::class), |
|
| 1068 | + $c->get(\OCP\IConfig::class) |
|
| 1069 | + ); |
|
| 1070 | + |
|
| 1071 | + return new CryptoWrapper( |
|
| 1072 | + $c->get(ICrypto::class), |
|
| 1073 | + $c->get(ISecureRandom::class), |
|
| 1074 | + $request |
|
| 1075 | + ); |
|
| 1076 | + }); |
|
| 1077 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1078 | + return new SessionStorage($c->get(ISession::class)); |
|
| 1079 | + }); |
|
| 1080 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1081 | + |
|
| 1082 | + $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1083 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1084 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1085 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1086 | + return $c->get($factoryClass); |
|
| 1087 | + }); |
|
| 1088 | + |
|
| 1089 | + $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1090 | + |
|
| 1091 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1092 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1093 | + |
|
| 1094 | + // register default plugins |
|
| 1095 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1096 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1097 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1098 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1099 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1100 | + |
|
| 1101 | + return $instance; |
|
| 1102 | + }); |
|
| 1103 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1104 | + |
|
| 1105 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1106 | + |
|
| 1107 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1108 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1109 | + |
|
| 1110 | + $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1111 | + $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1112 | + |
|
| 1113 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1114 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1115 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1116 | + return new \OC\Files\AppData\Factory( |
|
| 1117 | + $c->get(IRootFolder::class), |
|
| 1118 | + $c->get(SystemConfig::class) |
|
| 1119 | + ); |
|
| 1120 | + }); |
|
| 1121 | + |
|
| 1122 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1123 | + return new LockdownManager(function () use ($c) { |
|
| 1124 | + return $c->get(ISession::class); |
|
| 1125 | + }); |
|
| 1126 | + }); |
|
| 1127 | + |
|
| 1128 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1129 | + return new DiscoveryService( |
|
| 1130 | + $c->get(ICacheFactory::class), |
|
| 1131 | + $c->get(IClientService::class) |
|
| 1132 | + ); |
|
| 1133 | + }); |
|
| 1134 | + $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1135 | + |
|
| 1136 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1137 | + return new CloudIdManager( |
|
| 1138 | + $c->get(ICacheFactory::class), |
|
| 1139 | + $c->get(IEventDispatcher::class), |
|
| 1140 | + $c->get(\OCP\Contacts\IManager::class), |
|
| 1141 | + $c->get(IURLGenerator::class), |
|
| 1142 | + $c->get(IUserManager::class), |
|
| 1143 | + ); |
|
| 1144 | + }); |
|
| 1145 | 1145 | |
| 1146 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1147 | - $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1148 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1149 | - return new CloudFederationFactory(); |
|
| 1150 | - }); |
|
| 1146 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1147 | + $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1148 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1149 | + return new CloudFederationFactory(); |
|
| 1150 | + }); |
|
| 1151 | 1151 | |
| 1152 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1152 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1153 | 1153 | |
| 1154 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1155 | - $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1154 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1155 | + $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1156 | 1156 | |
| 1157 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1158 | - return new Defaults( |
|
| 1159 | - $c->get('ThemingDefaults') |
|
| 1160 | - ); |
|
| 1161 | - }); |
|
| 1157 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1158 | + return new Defaults( |
|
| 1159 | + $c->get('ThemingDefaults') |
|
| 1160 | + ); |
|
| 1161 | + }); |
|
| 1162 | 1162 | |
| 1163 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1164 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1165 | - }, false); |
|
| 1163 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1164 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1165 | + }, false); |
|
| 1166 | 1166 | |
| 1167 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1168 | - return new ShareHelper( |
|
| 1169 | - $c->get(\OCP\Share\IManager::class) |
|
| 1170 | - ); |
|
| 1171 | - }); |
|
| 1167 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1168 | + return new ShareHelper( |
|
| 1169 | + $c->get(\OCP\Share\IManager::class) |
|
| 1170 | + ); |
|
| 1171 | + }); |
|
| 1172 | 1172 | |
| 1173 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1174 | - return new ApiFactory($c->get(IClientService::class)); |
|
| 1175 | - }); |
|
| 1173 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1174 | + return new ApiFactory($c->get(IClientService::class)); |
|
| 1175 | + }); |
|
| 1176 | 1176 | |
| 1177 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1178 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1179 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1180 | - }); |
|
| 1177 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1178 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1179 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1180 | + }); |
|
| 1181 | 1181 | |
| 1182 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1183 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1182 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1183 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1184 | 1184 | |
| 1185 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1185 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1186 | 1186 | |
| 1187 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1187 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1188 | 1188 | |
| 1189 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1190 | - $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1189 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1190 | + $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1191 | 1191 | |
| 1192 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1192 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1193 | 1193 | |
| 1194 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1194 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1195 | 1195 | |
| 1196 | - $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1196 | + $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1197 | 1197 | |
| 1198 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1198 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1199 | 1199 | |
| 1200 | - $this->registerAlias(IBroker::class, Broker::class); |
|
| 1200 | + $this->registerAlias(IBroker::class, Broker::class); |
|
| 1201 | 1201 | |
| 1202 | - $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1202 | + $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1203 | 1203 | |
| 1204 | - $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1204 | + $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1205 | 1205 | |
| 1206 | - $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1206 | + $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1207 | 1207 | |
| 1208 | - $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1208 | + $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1209 | 1209 | |
| 1210 | - $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1210 | + $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1211 | 1211 | |
| 1212 | - $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1212 | + $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1213 | 1213 | |
| 1214 | - $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1214 | + $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1215 | 1215 | |
| 1216 | - $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1216 | + $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1217 | 1217 | |
| 1218 | - $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1218 | + $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1219 | 1219 | |
| 1220 | - $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1220 | + $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1221 | 1221 | |
| 1222 | - $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1222 | + $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1223 | 1223 | |
| 1224 | - $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1224 | + $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1225 | 1225 | |
| 1226 | - // there is no reason for having OCMProvider as a Service |
|
| 1227 | - $this->registerDeprecatedAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class); |
|
| 1228 | - $this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1226 | + // there is no reason for having OCMProvider as a Service |
|
| 1227 | + $this->registerDeprecatedAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class); |
|
| 1228 | + $this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1229 | 1229 | |
| 1230 | - $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1230 | + $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1231 | 1231 | |
| 1232 | - $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1232 | + $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1233 | 1233 | |
| 1234 | - $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1234 | + $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1235 | 1235 | |
| 1236 | - $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1236 | + $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1237 | 1237 | |
| 1238 | - $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1238 | + $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1239 | 1239 | |
| 1240 | - $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1240 | + $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1241 | 1241 | |
| 1242 | - $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1242 | + $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1243 | 1243 | |
| 1244 | - $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1244 | + $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1245 | 1245 | |
| 1246 | - $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1246 | + $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1247 | 1247 | |
| 1248 | - $this->connectDispatcher(); |
|
| 1249 | - } |
|
| 1248 | + $this->connectDispatcher(); |
|
| 1249 | + } |
|
| 1250 | 1250 | |
| 1251 | - public function boot() { |
|
| 1252 | - /** @var HookConnector $hookConnector */ |
|
| 1253 | - $hookConnector = $this->get(HookConnector::class); |
|
| 1254 | - $hookConnector->viewToNode(); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - private function connectDispatcher(): void { |
|
| 1258 | - /** @var IEventDispatcher $eventDispatcher */ |
|
| 1259 | - $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1260 | - $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1261 | - $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1262 | - $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1263 | - $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1264 | - |
|
| 1265 | - FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1266 | - GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * @return \OCP\Contacts\IManager |
|
| 1271 | - * @deprecated 20.0.0 |
|
| 1272 | - */ |
|
| 1273 | - public function getContactsManager() { |
|
| 1274 | - return $this->get(\OCP\Contacts\IManager::class); |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - /** |
|
| 1278 | - * @return \OC\Encryption\Manager |
|
| 1279 | - * @deprecated 20.0.0 |
|
| 1280 | - */ |
|
| 1281 | - public function getEncryptionManager() { |
|
| 1282 | - return $this->get(\OCP\Encryption\IManager::class); |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * @return \OC\Encryption\File |
|
| 1287 | - * @deprecated 20.0.0 |
|
| 1288 | - */ |
|
| 1289 | - public function getEncryptionFilesHelper() { |
|
| 1290 | - return $this->get(IFile::class); |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - /** |
|
| 1294 | - * The current request object holding all information about the request |
|
| 1295 | - * currently being processed is returned from this method. |
|
| 1296 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1297 | - * |
|
| 1298 | - * @return \OCP\IRequest |
|
| 1299 | - * @deprecated 20.0.0 |
|
| 1300 | - */ |
|
| 1301 | - public function getRequest() { |
|
| 1302 | - return $this->get(IRequest::class); |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - /** |
|
| 1306 | - * Returns the root folder of ownCloud's data directory |
|
| 1307 | - * |
|
| 1308 | - * @return IRootFolder |
|
| 1309 | - * @deprecated 20.0.0 |
|
| 1310 | - */ |
|
| 1311 | - public function getRootFolder() { |
|
| 1312 | - return $this->get(IRootFolder::class); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * Returns the root folder of ownCloud's data directory |
|
| 1317 | - * This is the lazy variant so this gets only initialized once it |
|
| 1318 | - * is actually used. |
|
| 1319 | - * |
|
| 1320 | - * @return IRootFolder |
|
| 1321 | - * @deprecated 20.0.0 |
|
| 1322 | - */ |
|
| 1323 | - public function getLazyRootFolder() { |
|
| 1324 | - return $this->get(IRootFolder::class); |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - /** |
|
| 1328 | - * Returns a view to ownCloud's files folder |
|
| 1329 | - * |
|
| 1330 | - * @param string $userId user ID |
|
| 1331 | - * @return \OCP\Files\Folder|null |
|
| 1332 | - * @deprecated 20.0.0 |
|
| 1333 | - */ |
|
| 1334 | - public function getUserFolder($userId = null) { |
|
| 1335 | - if ($userId === null) { |
|
| 1336 | - $user = $this->get(IUserSession::class)->getUser(); |
|
| 1337 | - if (!$user) { |
|
| 1338 | - return null; |
|
| 1339 | - } |
|
| 1340 | - $userId = $user->getUID(); |
|
| 1341 | - } |
|
| 1342 | - $root = $this->get(IRootFolder::class); |
|
| 1343 | - return $root->getUserFolder($userId); |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - /** |
|
| 1347 | - * @return \OC\User\Manager |
|
| 1348 | - * @deprecated 20.0.0 |
|
| 1349 | - */ |
|
| 1350 | - public function getUserManager() { |
|
| 1351 | - return $this->get(IUserManager::class); |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - /** |
|
| 1355 | - * @return \OC\Group\Manager |
|
| 1356 | - * @deprecated 20.0.0 |
|
| 1357 | - */ |
|
| 1358 | - public function getGroupManager() { |
|
| 1359 | - return $this->get(IGroupManager::class); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * @return \OC\User\Session |
|
| 1364 | - * @deprecated 20.0.0 |
|
| 1365 | - */ |
|
| 1366 | - public function getUserSession() { |
|
| 1367 | - return $this->get(IUserSession::class); |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - /** |
|
| 1371 | - * @return \OCP\ISession |
|
| 1372 | - * @deprecated 20.0.0 |
|
| 1373 | - */ |
|
| 1374 | - public function getSession() { |
|
| 1375 | - return $this->get(Session::class)->getSession(); |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * @param \OCP\ISession $session |
|
| 1380 | - * @return void |
|
| 1381 | - */ |
|
| 1382 | - public function setSession(\OCP\ISession $session) { |
|
| 1383 | - $this->get(SessionStorage::class)->setSession($session); |
|
| 1384 | - $this->get(Session::class)->setSession($session); |
|
| 1385 | - $this->get(Store::class)->setSession($session); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * @return \OCP\IConfig |
|
| 1390 | - * @deprecated 20.0.0 |
|
| 1391 | - */ |
|
| 1392 | - public function getConfig() { |
|
| 1393 | - return $this->get(AllConfig::class); |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - /** |
|
| 1397 | - * @return \OC\SystemConfig |
|
| 1398 | - * @deprecated 20.0.0 |
|
| 1399 | - */ |
|
| 1400 | - public function getSystemConfig() { |
|
| 1401 | - return $this->get(SystemConfig::class); |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - /** |
|
| 1405 | - * @return IFactory |
|
| 1406 | - * @deprecated 20.0.0 |
|
| 1407 | - */ |
|
| 1408 | - public function getL10NFactory() { |
|
| 1409 | - return $this->get(IFactory::class); |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - /** |
|
| 1413 | - * get an L10N instance |
|
| 1414 | - * |
|
| 1415 | - * @param string $app appid |
|
| 1416 | - * @param string $lang |
|
| 1417 | - * @return IL10N |
|
| 1418 | - * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1419 | - */ |
|
| 1420 | - public function getL10N($app, $lang = null) { |
|
| 1421 | - return $this->get(IFactory::class)->get($app, $lang); |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - /** |
|
| 1425 | - * @return IURLGenerator |
|
| 1426 | - * @deprecated 20.0.0 |
|
| 1427 | - */ |
|
| 1428 | - public function getURLGenerator() { |
|
| 1429 | - return $this->get(IURLGenerator::class); |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - /** |
|
| 1433 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1434 | - * getMemCacheFactory() instead. |
|
| 1435 | - * |
|
| 1436 | - * @return ICache |
|
| 1437 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1438 | - */ |
|
| 1439 | - public function getCache() { |
|
| 1440 | - return $this->get(ICache::class); |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - /** |
|
| 1444 | - * Returns an \OCP\CacheFactory instance |
|
| 1445 | - * |
|
| 1446 | - * @return \OCP\ICacheFactory |
|
| 1447 | - * @deprecated 20.0.0 |
|
| 1448 | - */ |
|
| 1449 | - public function getMemCacheFactory() { |
|
| 1450 | - return $this->get(ICacheFactory::class); |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * Returns the current session |
|
| 1455 | - * |
|
| 1456 | - * @return \OCP\IDBConnection |
|
| 1457 | - * @deprecated 20.0.0 |
|
| 1458 | - */ |
|
| 1459 | - public function getDatabaseConnection() { |
|
| 1460 | - return $this->get(IDBConnection::class); |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - /** |
|
| 1464 | - * Returns the activity manager |
|
| 1465 | - * |
|
| 1466 | - * @return \OCP\Activity\IManager |
|
| 1467 | - * @deprecated 20.0.0 |
|
| 1468 | - */ |
|
| 1469 | - public function getActivityManager() { |
|
| 1470 | - return $this->get(\OCP\Activity\IManager::class); |
|
| 1471 | - } |
|
| 1472 | - |
|
| 1473 | - /** |
|
| 1474 | - * Returns an job list for controlling background jobs |
|
| 1475 | - * |
|
| 1476 | - * @return IJobList |
|
| 1477 | - * @deprecated 20.0.0 |
|
| 1478 | - */ |
|
| 1479 | - public function getJobList() { |
|
| 1480 | - return $this->get(IJobList::class); |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - /** |
|
| 1484 | - * Returns a SecureRandom instance |
|
| 1485 | - * |
|
| 1486 | - * @return \OCP\Security\ISecureRandom |
|
| 1487 | - * @deprecated 20.0.0 |
|
| 1488 | - */ |
|
| 1489 | - public function getSecureRandom() { |
|
| 1490 | - return $this->get(ISecureRandom::class); |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * Returns a Crypto instance |
|
| 1495 | - * |
|
| 1496 | - * @return ICrypto |
|
| 1497 | - * @deprecated 20.0.0 |
|
| 1498 | - */ |
|
| 1499 | - public function getCrypto() { |
|
| 1500 | - return $this->get(ICrypto::class); |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * Returns a Hasher instance |
|
| 1505 | - * |
|
| 1506 | - * @return IHasher |
|
| 1507 | - * @deprecated 20.0.0 |
|
| 1508 | - */ |
|
| 1509 | - public function getHasher() { |
|
| 1510 | - return $this->get(IHasher::class); |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * Get the certificate manager |
|
| 1515 | - * |
|
| 1516 | - * @return \OCP\ICertificateManager |
|
| 1517 | - */ |
|
| 1518 | - public function getCertificateManager() { |
|
| 1519 | - return $this->get(ICertificateManager::class); |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - /** |
|
| 1523 | - * Get the manager for temporary files and folders |
|
| 1524 | - * |
|
| 1525 | - * @return \OCP\ITempManager |
|
| 1526 | - * @deprecated 20.0.0 |
|
| 1527 | - */ |
|
| 1528 | - public function getTempManager() { |
|
| 1529 | - return $this->get(ITempManager::class); |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - /** |
|
| 1533 | - * Get the app manager |
|
| 1534 | - * |
|
| 1535 | - * @return \OCP\App\IAppManager |
|
| 1536 | - * @deprecated 20.0.0 |
|
| 1537 | - */ |
|
| 1538 | - public function getAppManager() { |
|
| 1539 | - return $this->get(IAppManager::class); |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - /** |
|
| 1543 | - * Creates a new mailer |
|
| 1544 | - * |
|
| 1545 | - * @return IMailer |
|
| 1546 | - * @deprecated 20.0.0 |
|
| 1547 | - */ |
|
| 1548 | - public function getMailer() { |
|
| 1549 | - return $this->get(IMailer::class); |
|
| 1550 | - } |
|
| 1551 | - |
|
| 1552 | - /** |
|
| 1553 | - * Get the webroot |
|
| 1554 | - * |
|
| 1555 | - * @return string |
|
| 1556 | - * @deprecated 20.0.0 |
|
| 1557 | - */ |
|
| 1558 | - public function getWebRoot() { |
|
| 1559 | - return $this->webRoot; |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - /** |
|
| 1563 | - * Get the locking provider |
|
| 1564 | - * |
|
| 1565 | - * @return ILockingProvider |
|
| 1566 | - * @since 8.1.0 |
|
| 1567 | - * @deprecated 20.0.0 |
|
| 1568 | - */ |
|
| 1569 | - public function getLockingProvider() { |
|
| 1570 | - return $this->get(ILockingProvider::class); |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - /** |
|
| 1574 | - * Get the MimeTypeDetector |
|
| 1575 | - * |
|
| 1576 | - * @return IMimeTypeDetector |
|
| 1577 | - * @deprecated 20.0.0 |
|
| 1578 | - */ |
|
| 1579 | - public function getMimeTypeDetector() { |
|
| 1580 | - return $this->get(IMimeTypeDetector::class); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - /** |
|
| 1584 | - * Get the MimeTypeLoader |
|
| 1585 | - * |
|
| 1586 | - * @return IMimeTypeLoader |
|
| 1587 | - * @deprecated 20.0.0 |
|
| 1588 | - */ |
|
| 1589 | - public function getMimeTypeLoader() { |
|
| 1590 | - return $this->get(IMimeTypeLoader::class); |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - /** |
|
| 1594 | - * Get the Notification Manager |
|
| 1595 | - * |
|
| 1596 | - * @return \OCP\Notification\IManager |
|
| 1597 | - * @since 8.2.0 |
|
| 1598 | - * @deprecated 20.0.0 |
|
| 1599 | - */ |
|
| 1600 | - public function getNotificationManager() { |
|
| 1601 | - return $this->get(\OCP\Notification\IManager::class); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1606 | - * @deprecated 20.0.0 |
|
| 1607 | - */ |
|
| 1608 | - public function getThemingDefaults() { |
|
| 1609 | - return $this->get('ThemingDefaults'); |
|
| 1610 | - } |
|
| 1611 | - |
|
| 1612 | - /** |
|
| 1613 | - * @return \OC\IntegrityCheck\Checker |
|
| 1614 | - * @deprecated 20.0.0 |
|
| 1615 | - */ |
|
| 1616 | - public function getIntegrityCodeChecker() { |
|
| 1617 | - return $this->get('IntegrityCodeChecker'); |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - /** |
|
| 1621 | - * @return CsrfTokenManager |
|
| 1622 | - * @deprecated 20.0.0 |
|
| 1623 | - */ |
|
| 1624 | - public function getCsrfTokenManager() { |
|
| 1625 | - return $this->get(CsrfTokenManager::class); |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - /** |
|
| 1629 | - * @return ContentSecurityPolicyNonceManager |
|
| 1630 | - * @deprecated 20.0.0 |
|
| 1631 | - */ |
|
| 1632 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1633 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1634 | - } |
|
| 1635 | - |
|
| 1636 | - /** |
|
| 1637 | - * @return \OCP\Settings\IManager |
|
| 1638 | - * @deprecated 20.0.0 |
|
| 1639 | - */ |
|
| 1640 | - public function getSettingsManager() { |
|
| 1641 | - return $this->get(\OC\Settings\Manager::class); |
|
| 1642 | - } |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * @return \OCP\Files\IAppData |
|
| 1646 | - * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 1647 | - */ |
|
| 1648 | - public function getAppDataDir($app) { |
|
| 1649 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 1650 | - return $factory->get($app); |
|
| 1651 | - } |
|
| 1652 | - |
|
| 1653 | - /** |
|
| 1654 | - * @return \OCP\Federation\ICloudIdManager |
|
| 1655 | - * @deprecated 20.0.0 |
|
| 1656 | - */ |
|
| 1657 | - public function getCloudIdManager() { |
|
| 1658 | - return $this->get(ICloudIdManager::class); |
|
| 1659 | - } |
|
| 1251 | + public function boot() { |
|
| 1252 | + /** @var HookConnector $hookConnector */ |
|
| 1253 | + $hookConnector = $this->get(HookConnector::class); |
|
| 1254 | + $hookConnector->viewToNode(); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + private function connectDispatcher(): void { |
|
| 1258 | + /** @var IEventDispatcher $eventDispatcher */ |
|
| 1259 | + $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1260 | + $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1261 | + $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1262 | + $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1263 | + $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1264 | + |
|
| 1265 | + FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1266 | + GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * @return \OCP\Contacts\IManager |
|
| 1271 | + * @deprecated 20.0.0 |
|
| 1272 | + */ |
|
| 1273 | + public function getContactsManager() { |
|
| 1274 | + return $this->get(\OCP\Contacts\IManager::class); |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + /** |
|
| 1278 | + * @return \OC\Encryption\Manager |
|
| 1279 | + * @deprecated 20.0.0 |
|
| 1280 | + */ |
|
| 1281 | + public function getEncryptionManager() { |
|
| 1282 | + return $this->get(\OCP\Encryption\IManager::class); |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * @return \OC\Encryption\File |
|
| 1287 | + * @deprecated 20.0.0 |
|
| 1288 | + */ |
|
| 1289 | + public function getEncryptionFilesHelper() { |
|
| 1290 | + return $this->get(IFile::class); |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + /** |
|
| 1294 | + * The current request object holding all information about the request |
|
| 1295 | + * currently being processed is returned from this method. |
|
| 1296 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1297 | + * |
|
| 1298 | + * @return \OCP\IRequest |
|
| 1299 | + * @deprecated 20.0.0 |
|
| 1300 | + */ |
|
| 1301 | + public function getRequest() { |
|
| 1302 | + return $this->get(IRequest::class); |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + /** |
|
| 1306 | + * Returns the root folder of ownCloud's data directory |
|
| 1307 | + * |
|
| 1308 | + * @return IRootFolder |
|
| 1309 | + * @deprecated 20.0.0 |
|
| 1310 | + */ |
|
| 1311 | + public function getRootFolder() { |
|
| 1312 | + return $this->get(IRootFolder::class); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * Returns the root folder of ownCloud's data directory |
|
| 1317 | + * This is the lazy variant so this gets only initialized once it |
|
| 1318 | + * is actually used. |
|
| 1319 | + * |
|
| 1320 | + * @return IRootFolder |
|
| 1321 | + * @deprecated 20.0.0 |
|
| 1322 | + */ |
|
| 1323 | + public function getLazyRootFolder() { |
|
| 1324 | + return $this->get(IRootFolder::class); |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + /** |
|
| 1328 | + * Returns a view to ownCloud's files folder |
|
| 1329 | + * |
|
| 1330 | + * @param string $userId user ID |
|
| 1331 | + * @return \OCP\Files\Folder|null |
|
| 1332 | + * @deprecated 20.0.0 |
|
| 1333 | + */ |
|
| 1334 | + public function getUserFolder($userId = null) { |
|
| 1335 | + if ($userId === null) { |
|
| 1336 | + $user = $this->get(IUserSession::class)->getUser(); |
|
| 1337 | + if (!$user) { |
|
| 1338 | + return null; |
|
| 1339 | + } |
|
| 1340 | + $userId = $user->getUID(); |
|
| 1341 | + } |
|
| 1342 | + $root = $this->get(IRootFolder::class); |
|
| 1343 | + return $root->getUserFolder($userId); |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + /** |
|
| 1347 | + * @return \OC\User\Manager |
|
| 1348 | + * @deprecated 20.0.0 |
|
| 1349 | + */ |
|
| 1350 | + public function getUserManager() { |
|
| 1351 | + return $this->get(IUserManager::class); |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + /** |
|
| 1355 | + * @return \OC\Group\Manager |
|
| 1356 | + * @deprecated 20.0.0 |
|
| 1357 | + */ |
|
| 1358 | + public function getGroupManager() { |
|
| 1359 | + return $this->get(IGroupManager::class); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * @return \OC\User\Session |
|
| 1364 | + * @deprecated 20.0.0 |
|
| 1365 | + */ |
|
| 1366 | + public function getUserSession() { |
|
| 1367 | + return $this->get(IUserSession::class); |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + /** |
|
| 1371 | + * @return \OCP\ISession |
|
| 1372 | + * @deprecated 20.0.0 |
|
| 1373 | + */ |
|
| 1374 | + public function getSession() { |
|
| 1375 | + return $this->get(Session::class)->getSession(); |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * @param \OCP\ISession $session |
|
| 1380 | + * @return void |
|
| 1381 | + */ |
|
| 1382 | + public function setSession(\OCP\ISession $session) { |
|
| 1383 | + $this->get(SessionStorage::class)->setSession($session); |
|
| 1384 | + $this->get(Session::class)->setSession($session); |
|
| 1385 | + $this->get(Store::class)->setSession($session); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * @return \OCP\IConfig |
|
| 1390 | + * @deprecated 20.0.0 |
|
| 1391 | + */ |
|
| 1392 | + public function getConfig() { |
|
| 1393 | + return $this->get(AllConfig::class); |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + /** |
|
| 1397 | + * @return \OC\SystemConfig |
|
| 1398 | + * @deprecated 20.0.0 |
|
| 1399 | + */ |
|
| 1400 | + public function getSystemConfig() { |
|
| 1401 | + return $this->get(SystemConfig::class); |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + /** |
|
| 1405 | + * @return IFactory |
|
| 1406 | + * @deprecated 20.0.0 |
|
| 1407 | + */ |
|
| 1408 | + public function getL10NFactory() { |
|
| 1409 | + return $this->get(IFactory::class); |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + /** |
|
| 1413 | + * get an L10N instance |
|
| 1414 | + * |
|
| 1415 | + * @param string $app appid |
|
| 1416 | + * @param string $lang |
|
| 1417 | + * @return IL10N |
|
| 1418 | + * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1419 | + */ |
|
| 1420 | + public function getL10N($app, $lang = null) { |
|
| 1421 | + return $this->get(IFactory::class)->get($app, $lang); |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + /** |
|
| 1425 | + * @return IURLGenerator |
|
| 1426 | + * @deprecated 20.0.0 |
|
| 1427 | + */ |
|
| 1428 | + public function getURLGenerator() { |
|
| 1429 | + return $this->get(IURLGenerator::class); |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + /** |
|
| 1433 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1434 | + * getMemCacheFactory() instead. |
|
| 1435 | + * |
|
| 1436 | + * @return ICache |
|
| 1437 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1438 | + */ |
|
| 1439 | + public function getCache() { |
|
| 1440 | + return $this->get(ICache::class); |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + /** |
|
| 1444 | + * Returns an \OCP\CacheFactory instance |
|
| 1445 | + * |
|
| 1446 | + * @return \OCP\ICacheFactory |
|
| 1447 | + * @deprecated 20.0.0 |
|
| 1448 | + */ |
|
| 1449 | + public function getMemCacheFactory() { |
|
| 1450 | + return $this->get(ICacheFactory::class); |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * Returns the current session |
|
| 1455 | + * |
|
| 1456 | + * @return \OCP\IDBConnection |
|
| 1457 | + * @deprecated 20.0.0 |
|
| 1458 | + */ |
|
| 1459 | + public function getDatabaseConnection() { |
|
| 1460 | + return $this->get(IDBConnection::class); |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + /** |
|
| 1464 | + * Returns the activity manager |
|
| 1465 | + * |
|
| 1466 | + * @return \OCP\Activity\IManager |
|
| 1467 | + * @deprecated 20.0.0 |
|
| 1468 | + */ |
|
| 1469 | + public function getActivityManager() { |
|
| 1470 | + return $this->get(\OCP\Activity\IManager::class); |
|
| 1471 | + } |
|
| 1472 | + |
|
| 1473 | + /** |
|
| 1474 | + * Returns an job list for controlling background jobs |
|
| 1475 | + * |
|
| 1476 | + * @return IJobList |
|
| 1477 | + * @deprecated 20.0.0 |
|
| 1478 | + */ |
|
| 1479 | + public function getJobList() { |
|
| 1480 | + return $this->get(IJobList::class); |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + /** |
|
| 1484 | + * Returns a SecureRandom instance |
|
| 1485 | + * |
|
| 1486 | + * @return \OCP\Security\ISecureRandom |
|
| 1487 | + * @deprecated 20.0.0 |
|
| 1488 | + */ |
|
| 1489 | + public function getSecureRandom() { |
|
| 1490 | + return $this->get(ISecureRandom::class); |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * Returns a Crypto instance |
|
| 1495 | + * |
|
| 1496 | + * @return ICrypto |
|
| 1497 | + * @deprecated 20.0.0 |
|
| 1498 | + */ |
|
| 1499 | + public function getCrypto() { |
|
| 1500 | + return $this->get(ICrypto::class); |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * Returns a Hasher instance |
|
| 1505 | + * |
|
| 1506 | + * @return IHasher |
|
| 1507 | + * @deprecated 20.0.0 |
|
| 1508 | + */ |
|
| 1509 | + public function getHasher() { |
|
| 1510 | + return $this->get(IHasher::class); |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * Get the certificate manager |
|
| 1515 | + * |
|
| 1516 | + * @return \OCP\ICertificateManager |
|
| 1517 | + */ |
|
| 1518 | + public function getCertificateManager() { |
|
| 1519 | + return $this->get(ICertificateManager::class); |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + /** |
|
| 1523 | + * Get the manager for temporary files and folders |
|
| 1524 | + * |
|
| 1525 | + * @return \OCP\ITempManager |
|
| 1526 | + * @deprecated 20.0.0 |
|
| 1527 | + */ |
|
| 1528 | + public function getTempManager() { |
|
| 1529 | + return $this->get(ITempManager::class); |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + /** |
|
| 1533 | + * Get the app manager |
|
| 1534 | + * |
|
| 1535 | + * @return \OCP\App\IAppManager |
|
| 1536 | + * @deprecated 20.0.0 |
|
| 1537 | + */ |
|
| 1538 | + public function getAppManager() { |
|
| 1539 | + return $this->get(IAppManager::class); |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + /** |
|
| 1543 | + * Creates a new mailer |
|
| 1544 | + * |
|
| 1545 | + * @return IMailer |
|
| 1546 | + * @deprecated 20.0.0 |
|
| 1547 | + */ |
|
| 1548 | + public function getMailer() { |
|
| 1549 | + return $this->get(IMailer::class); |
|
| 1550 | + } |
|
| 1551 | + |
|
| 1552 | + /** |
|
| 1553 | + * Get the webroot |
|
| 1554 | + * |
|
| 1555 | + * @return string |
|
| 1556 | + * @deprecated 20.0.0 |
|
| 1557 | + */ |
|
| 1558 | + public function getWebRoot() { |
|
| 1559 | + return $this->webRoot; |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + /** |
|
| 1563 | + * Get the locking provider |
|
| 1564 | + * |
|
| 1565 | + * @return ILockingProvider |
|
| 1566 | + * @since 8.1.0 |
|
| 1567 | + * @deprecated 20.0.0 |
|
| 1568 | + */ |
|
| 1569 | + public function getLockingProvider() { |
|
| 1570 | + return $this->get(ILockingProvider::class); |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + /** |
|
| 1574 | + * Get the MimeTypeDetector |
|
| 1575 | + * |
|
| 1576 | + * @return IMimeTypeDetector |
|
| 1577 | + * @deprecated 20.0.0 |
|
| 1578 | + */ |
|
| 1579 | + public function getMimeTypeDetector() { |
|
| 1580 | + return $this->get(IMimeTypeDetector::class); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + /** |
|
| 1584 | + * Get the MimeTypeLoader |
|
| 1585 | + * |
|
| 1586 | + * @return IMimeTypeLoader |
|
| 1587 | + * @deprecated 20.0.0 |
|
| 1588 | + */ |
|
| 1589 | + public function getMimeTypeLoader() { |
|
| 1590 | + return $this->get(IMimeTypeLoader::class); |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + /** |
|
| 1594 | + * Get the Notification Manager |
|
| 1595 | + * |
|
| 1596 | + * @return \OCP\Notification\IManager |
|
| 1597 | + * @since 8.2.0 |
|
| 1598 | + * @deprecated 20.0.0 |
|
| 1599 | + */ |
|
| 1600 | + public function getNotificationManager() { |
|
| 1601 | + return $this->get(\OCP\Notification\IManager::class); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1606 | + * @deprecated 20.0.0 |
|
| 1607 | + */ |
|
| 1608 | + public function getThemingDefaults() { |
|
| 1609 | + return $this->get('ThemingDefaults'); |
|
| 1610 | + } |
|
| 1611 | + |
|
| 1612 | + /** |
|
| 1613 | + * @return \OC\IntegrityCheck\Checker |
|
| 1614 | + * @deprecated 20.0.0 |
|
| 1615 | + */ |
|
| 1616 | + public function getIntegrityCodeChecker() { |
|
| 1617 | + return $this->get('IntegrityCodeChecker'); |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + /** |
|
| 1621 | + * @return CsrfTokenManager |
|
| 1622 | + * @deprecated 20.0.0 |
|
| 1623 | + */ |
|
| 1624 | + public function getCsrfTokenManager() { |
|
| 1625 | + return $this->get(CsrfTokenManager::class); |
|
| 1626 | + } |
|
| 1627 | + |
|
| 1628 | + /** |
|
| 1629 | + * @return ContentSecurityPolicyNonceManager |
|
| 1630 | + * @deprecated 20.0.0 |
|
| 1631 | + */ |
|
| 1632 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1633 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1634 | + } |
|
| 1635 | + |
|
| 1636 | + /** |
|
| 1637 | + * @return \OCP\Settings\IManager |
|
| 1638 | + * @deprecated 20.0.0 |
|
| 1639 | + */ |
|
| 1640 | + public function getSettingsManager() { |
|
| 1641 | + return $this->get(\OC\Settings\Manager::class); |
|
| 1642 | + } |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * @return \OCP\Files\IAppData |
|
| 1646 | + * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 1647 | + */ |
|
| 1648 | + public function getAppDataDir($app) { |
|
| 1649 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 1650 | + return $factory->get($app); |
|
| 1651 | + } |
|
| 1652 | + |
|
| 1653 | + /** |
|
| 1654 | + * @return \OCP\Federation\ICloudIdManager |
|
| 1655 | + * @deprecated 20.0.0 |
|
| 1656 | + */ |
|
| 1657 | + public function getCloudIdManager() { |
|
| 1658 | + return $this->get(ICloudIdManager::class); |
|
| 1659 | + } |
|
| 1660 | 1660 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | $this->registerParameter('isCLI', \OC::$CLI); |
| 265 | 265 | $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
| 266 | 266 | |
| 267 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 267 | + $this->registerService(ContainerInterface::class, function(ContainerInterface $c) { |
|
| 268 | 268 | return $c; |
| 269 | 269 | }); |
| 270 | 270 | $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class); |
@@ -285,11 +285,11 @@ discard block |
||
| 285 | 285 | |
| 286 | 286 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
| 287 | 287 | |
| 288 | - $this->registerService(View::class, function (Server $c) { |
|
| 288 | + $this->registerService(View::class, function(Server $c) { |
|
| 289 | 289 | return new View(); |
| 290 | 290 | }, false); |
| 291 | 291 | |
| 292 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 292 | + $this->registerService(IPreview::class, function(ContainerInterface $c) { |
|
| 293 | 293 | return new PreviewManager( |
| 294 | 294 | $c->get(\OCP\IConfig::class), |
| 295 | 295 | $c->get(IRootFolder::class), |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | }); |
| 305 | 305 | $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
| 306 | 306 | |
| 307 | - $this->registerService(Watcher::class, function (ContainerInterface $c): Watcher { |
|
| 307 | + $this->registerService(Watcher::class, function(ContainerInterface $c): Watcher { |
|
| 308 | 308 | return new Watcher( |
| 309 | 309 | $c->get(\OC\Preview\Storage\StorageFactory::class), |
| 310 | 310 | $c->get(PreviewMapper::class), |
@@ -312,11 +312,11 @@ discard block |
||
| 312 | 312 | ); |
| 313 | 313 | }); |
| 314 | 314 | |
| 315 | - $this->registerService(IProfiler::class, function (Server $c) { |
|
| 315 | + $this->registerService(IProfiler::class, function(Server $c) { |
|
| 316 | 316 | return new Profiler($c->get(SystemConfig::class)); |
| 317 | 317 | }); |
| 318 | 318 | |
| 319 | - $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { |
|
| 319 | + $this->registerService(Encryption\Manager::class, function(Server $c): Encryption\Manager { |
|
| 320 | 320 | $view = new View(); |
| 321 | 321 | $util = new Encryption\Util( |
| 322 | 322 | $view, |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | }); |
| 336 | 336 | $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); |
| 337 | 337 | |
| 338 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 338 | + $this->registerService(IFile::class, function(ContainerInterface $c) { |
|
| 339 | 339 | $util = new Encryption\Util( |
| 340 | 340 | new View(), |
| 341 | 341 | $c->get(IUserManager::class), |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | ); |
| 350 | 350 | }); |
| 351 | 351 | |
| 352 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 352 | + $this->registerService(IStorage::class, function(ContainerInterface $c) { |
|
| 353 | 353 | $view = new View(); |
| 354 | 354 | $util = new Encryption\Util( |
| 355 | 355 | $view, |
@@ -368,23 +368,23 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
| 370 | 370 | |
| 371 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 371 | + $this->registerService('SystemTagManagerFactory', function(ContainerInterface $c) { |
|
| 372 | 372 | /** @var \OCP\IConfig $config */ |
| 373 | 373 | $config = $c->get(\OCP\IConfig::class); |
| 374 | 374 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
| 375 | 375 | return new $factoryClass($this); |
| 376 | 376 | }); |
| 377 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 377 | + $this->registerService(ISystemTagManager::class, function(ContainerInterface $c) { |
|
| 378 | 378 | return $c->get('SystemTagManagerFactory')->getManager(); |
| 379 | 379 | }); |
| 380 | 380 | /** @deprecated 19.0.0 */ |
| 381 | 381 | $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
| 382 | 382 | |
| 383 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 383 | + $this->registerService(ISystemTagObjectMapper::class, function(ContainerInterface $c) { |
|
| 384 | 384 | return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
| 385 | 385 | }); |
| 386 | 386 | $this->registerAlias(IFileAccess::class, FileAccess::class); |
| 387 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 387 | + $this->registerService('RootFolder', function(ContainerInterface $c) { |
|
| 388 | 388 | $manager = \OC\Files\Filesystem::getMountManager(); |
| 389 | 389 | $view = new View(); |
| 390 | 390 | /** @var IUserSession $userSession */ |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | |
| 411 | 411 | return $root; |
| 412 | 412 | }); |
| 413 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 413 | + $this->registerService(HookConnector::class, function(ContainerInterface $c) { |
|
| 414 | 414 | return new HookConnector( |
| 415 | 415 | $c->get(IRootFolder::class), |
| 416 | 416 | new View(), |
@@ -419,19 +419,19 @@ discard block |
||
| 419 | 419 | ); |
| 420 | 420 | }); |
| 421 | 421 | |
| 422 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 423 | - return new LazyRoot(function () use ($c) { |
|
| 422 | + $this->registerService(IRootFolder::class, function(ContainerInterface $c) { |
|
| 423 | + return new LazyRoot(function() use ($c) { |
|
| 424 | 424 | return $c->get('RootFolder'); |
| 425 | 425 | }); |
| 426 | 426 | }); |
| 427 | 427 | |
| 428 | 428 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
| 429 | 429 | |
| 430 | - $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 430 | + $this->registerService(DisplayNameCache::class, function(ContainerInterface $c) { |
|
| 431 | 431 | return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
| 432 | 432 | }); |
| 433 | 433 | |
| 434 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 434 | + $this->registerService(\OCP\IGroupManager::class, function(ContainerInterface $c) { |
|
| 435 | 435 | $groupManager = new \OC\Group\Manager( |
| 436 | 436 | $this->get(IUserManager::class), |
| 437 | 437 | $this->get(IEventDispatcher::class), |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | return $groupManager; |
| 443 | 443 | }); |
| 444 | 444 | |
| 445 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 445 | + $this->registerService(Store::class, function(ContainerInterface $c) { |
|
| 446 | 446 | $session = $c->get(ISession::class); |
| 447 | 447 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
| 448 | 448 | $tokenProvider = $c->get(IProvider::class); |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
| 458 | 458 | $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
| 459 | 459 | |
| 460 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 460 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
| 461 | 461 | $manager = $c->get(IUserManager::class); |
| 462 | 462 | $session = new \OC\Session\Memory(); |
| 463 | 463 | $timeFactory = new TimeFactory(); |
@@ -481,40 +481,40 @@ discard block |
||
| 481 | 481 | $c->get(IEventDispatcher::class), |
| 482 | 482 | ); |
| 483 | 483 | /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
| 484 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 484 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 485 | 485 | \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
| 486 | 486 | }); |
| 487 | 487 | /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
| 488 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 488 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 489 | 489 | /** @var \OC\User\User $user */ |
| 490 | 490 | \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
| 491 | 491 | }); |
| 492 | 492 | /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
| 493 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 493 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
| 494 | 494 | /** @var \OC\User\User $user */ |
| 495 | 495 | \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
| 496 | 496 | }); |
| 497 | 497 | /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
| 498 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 498 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 499 | 499 | /** @var \OC\User\User $user */ |
| 500 | 500 | \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
| 501 | 501 | }); |
| 502 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 502 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 503 | 503 | /** @var \OC\User\User $user */ |
| 504 | 504 | \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
| 505 | 505 | }); |
| 506 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 506 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 507 | 507 | /** @var \OC\User\User $user */ |
| 508 | 508 | \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
| 509 | 509 | }); |
| 510 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 510 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 511 | 511 | \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
| 512 | 512 | |
| 513 | 513 | /** @var IEventDispatcher $dispatcher */ |
| 514 | 514 | $dispatcher = $this->get(IEventDispatcher::class); |
| 515 | 515 | $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
| 516 | 516 | }); |
| 517 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 517 | + $userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) { |
|
| 518 | 518 | /** @var \OC\User\User $user */ |
| 519 | 519 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
| 520 | 520 | |
@@ -522,12 +522,12 @@ discard block |
||
| 522 | 522 | $dispatcher = $this->get(IEventDispatcher::class); |
| 523 | 523 | $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
| 524 | 524 | }); |
| 525 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 525 | + $userSession->listen('\OC\User', 'preRememberedLogin', function($uid) { |
|
| 526 | 526 | /** @var IEventDispatcher $dispatcher */ |
| 527 | 527 | $dispatcher = $this->get(IEventDispatcher::class); |
| 528 | 528 | $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
| 529 | 529 | }); |
| 530 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 530 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
| 531 | 531 | /** @var \OC\User\User $user */ |
| 532 | 532 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
| 533 | 533 | |
@@ -535,19 +535,19 @@ discard block |
||
| 535 | 535 | $dispatcher = $this->get(IEventDispatcher::class); |
| 536 | 536 | $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
| 537 | 537 | }); |
| 538 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 538 | + $userSession->listen('\OC\User', 'logout', function($user) { |
|
| 539 | 539 | \OC_Hook::emit('OC_User', 'logout', []); |
| 540 | 540 | |
| 541 | 541 | /** @var IEventDispatcher $dispatcher */ |
| 542 | 542 | $dispatcher = $this->get(IEventDispatcher::class); |
| 543 | 543 | $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
| 544 | 544 | }); |
| 545 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 545 | + $userSession->listen('\OC\User', 'postLogout', function($user) { |
|
| 546 | 546 | /** @var IEventDispatcher $dispatcher */ |
| 547 | 547 | $dispatcher = $this->get(IEventDispatcher::class); |
| 548 | 548 | $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
| 549 | 549 | }); |
| 550 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 550 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
| 551 | 551 | /** @var \OC\User\User $user */ |
| 552 | 552 | \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
| 553 | 553 | }); |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | |
| 562 | 562 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 563 | 563 | |
| 564 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 564 | + $this->registerService(\OC\SystemConfig::class, function($c) use ($config) { |
|
| 565 | 565 | return new \OC\SystemConfig($config); |
| 566 | 566 | }); |
| 567 | 567 | |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
| 570 | 570 | $this->registerAlias(IAppManager::class, AppManager::class); |
| 571 | 571 | |
| 572 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 572 | + $this->registerService(IFactory::class, function(Server $c) { |
|
| 573 | 573 | return new \OC\L10N\Factory( |
| 574 | 574 | $c->get(\OCP\IConfig::class), |
| 575 | 575 | $c->getRequest(), |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
| 584 | 584 | |
| 585 | 585 | $this->registerAlias(ICache::class, Cache\File::class); |
| 586 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 586 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 587 | 587 | $profiler = $c->get(IProfiler::class); |
| 588 | 588 | $logger = $c->get(LoggerInterface::class); |
| 589 | 589 | $serverVersion = $c->get(ServerVersion::class); |
@@ -616,12 +616,12 @@ discard block |
||
| 616 | 616 | }); |
| 617 | 617 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 618 | 618 | |
| 619 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 619 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 620 | 620 | $systemConfig = $c->get(SystemConfig::class); |
| 621 | 621 | return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
| 622 | 622 | }); |
| 623 | 623 | |
| 624 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 624 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 625 | 625 | $l10n = $this->get(IFactory::class)->get('lib'); |
| 626 | 626 | return new \OC\Activity\Manager( |
| 627 | 627 | $c->getRequest(), |
@@ -634,14 +634,14 @@ discard block |
||
| 634 | 634 | ); |
| 635 | 635 | }); |
| 636 | 636 | |
| 637 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 637 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 638 | 638 | return new \OC\Activity\EventMerger( |
| 639 | 639 | $c->getL10N('lib') |
| 640 | 640 | ); |
| 641 | 641 | }); |
| 642 | 642 | $this->registerAlias(IValidator::class, Validator::class); |
| 643 | 643 | |
| 644 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 644 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
| 645 | 645 | return new AvatarManager( |
| 646 | 646 | $c->get(IUserSession::class), |
| 647 | 647 | $c->get(\OC\User\Manager::class), |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
| 662 | 662 | |
| 663 | 663 | /** Only used by the PsrLoggerAdapter should not be used by apps */ |
| 664 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 664 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
| 665 | 665 | $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
| 666 | 666 | $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
| 667 | 667 | $logger = $factory->get($logType); |
@@ -672,13 +672,13 @@ discard block |
||
| 672 | 672 | // PSR-3 logger |
| 673 | 673 | $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
| 674 | 674 | |
| 675 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 675 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
| 676 | 676 | return new LogFactory($c, $this->get(SystemConfig::class)); |
| 677 | 677 | }); |
| 678 | 678 | |
| 679 | 679 | $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
| 680 | 680 | |
| 681 | - $this->registerService(Router::class, function (Server $c) { |
|
| 681 | + $this->registerService(Router::class, function(Server $c) { |
|
| 682 | 682 | $cacheFactory = $c->get(ICacheFactory::class); |
| 683 | 683 | if ($cacheFactory->isLocalCacheAvailable()) { |
| 684 | 684 | $router = $c->resolve(CachingRouter::class); |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | }); |
| 690 | 690 | $this->registerAlias(IRouter::class, Router::class); |
| 691 | 691 | |
| 692 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 692 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 693 | 693 | $config = $c->get(\OCP\IConfig::class); |
| 694 | 694 | if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
| 695 | 695 | $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
| 720 | 720 | |
| 721 | 721 | $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
| 722 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 722 | + $this->registerService(Connection::class, function(Server $c) { |
|
| 723 | 723 | $systemConfig = $c->get(SystemConfig::class); |
| 724 | 724 | $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
| 725 | 725 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -732,17 +732,17 @@ discard block |
||
| 732 | 732 | |
| 733 | 733 | $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
| 734 | 734 | $this->registerAlias(IClientService::class, ClientService::class); |
| 735 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 735 | + $this->registerService(NegativeDnsCache::class, function(ContainerInterface $c) { |
|
| 736 | 736 | return new NegativeDnsCache( |
| 737 | 737 | $c->get(ICacheFactory::class), |
| 738 | 738 | ); |
| 739 | 739 | }); |
| 740 | 740 | $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
| 741 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 741 | + $this->registerService(IEventLogger::class, function(ContainerInterface $c) { |
|
| 742 | 742 | return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
| 743 | 743 | }); |
| 744 | 744 | |
| 745 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 745 | + $this->registerService(IQueryLogger::class, function(ContainerInterface $c) { |
|
| 746 | 746 | $queryLogger = new QueryLogger(); |
| 747 | 747 | if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
| 748 | 748 | // In debug mode, module is being activated by default |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 755 | 755 | $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
| 756 | 756 | |
| 757 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 757 | + $this->registerService(IDateTimeFormatter::class, function(Server $c) { |
|
| 758 | 758 | $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
| 759 | 759 | |
| 760 | 760 | return new DateTimeFormatter( |
@@ -763,14 +763,14 @@ discard block |
||
| 763 | 763 | ); |
| 764 | 764 | }); |
| 765 | 765 | |
| 766 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 766 | + $this->registerService(IUserMountCache::class, function(ContainerInterface $c) { |
|
| 767 | 767 | $mountCache = $c->get(UserMountCache::class); |
| 768 | 768 | $listener = new UserMountCacheListener($mountCache); |
| 769 | 769 | $listener->listen($c->get(IUserManager::class)); |
| 770 | 770 | return $mountCache; |
| 771 | 771 | }); |
| 772 | 772 | |
| 773 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 773 | + $this->registerService(IMountProviderCollection::class, function(ContainerInterface $c) { |
|
| 774 | 774 | $loader = $c->get(IStorageFactory::class); |
| 775 | 775 | $mountCache = $c->get(IUserMountCache::class); |
| 776 | 776 | $eventLogger = $c->get(IEventLogger::class); |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | return $manager; |
| 790 | 790 | }); |
| 791 | 791 | |
| 792 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 792 | + $this->registerService(IBus::class, function(ContainerInterface $c) { |
|
| 793 | 793 | $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
| 794 | 794 | if ($busClass) { |
| 795 | 795 | [$app, $class] = explode('::', $busClass, 2); |
@@ -808,7 +808,7 @@ discard block |
||
| 808 | 808 | $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
| 809 | 809 | $this->registerAlias(IThrottler::class, Throttler::class); |
| 810 | 810 | |
| 811 | - $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 811 | + $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function($c) { |
|
| 812 | 812 | $config = $c->get(\OCP\IConfig::class); |
| 813 | 813 | if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
| 814 | 814 | && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | }); |
| 822 | 822 | |
| 823 | 823 | $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
| 824 | - $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 824 | + $this->registerService(Checker::class, function(ContainerInterface $c) { |
|
| 825 | 825 | // IConfig requires a working database. This code |
| 826 | 826 | // might however be called when Nextcloud is not yet setup. |
| 827 | 827 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | $c->get(IMimeTypeDetector::class) |
| 844 | 844 | ); |
| 845 | 845 | }); |
| 846 | - $this->registerService(Request::class, function (ContainerInterface $c) { |
|
| 846 | + $this->registerService(Request::class, function(ContainerInterface $c) { |
|
| 847 | 847 | if (isset($this['urlParams'])) { |
| 848 | 848 | $urlParams = $this['urlParams']; |
| 849 | 849 | } else { |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | }); |
| 880 | 880 | $this->registerAlias(\OCP\IRequest::class, Request::class); |
| 881 | 881 | |
| 882 | - $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 882 | + $this->registerService(IRequestId::class, function(ContainerInterface $c): IRequestId { |
|
| 883 | 883 | return new RequestId( |
| 884 | 884 | $_SERVER['UNIQUE_ID'] ?? '', |
| 885 | 885 | $this->get(ISecureRandom::class) |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | /** @since 32.0.0 */ |
| 890 | 890 | $this->registerAlias(IEmailValidator::class, EmailValidator::class); |
| 891 | 891 | |
| 892 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 892 | + $this->registerService(IMailer::class, function(Server $c) { |
|
| 893 | 893 | return new Mailer( |
| 894 | 894 | $c->get(\OCP\IConfig::class), |
| 895 | 895 | $c->get(LoggerInterface::class), |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | /** @since 30.0.0 */ |
| 906 | 906 | $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
| 907 | 907 | |
| 908 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 908 | + $this->registerService(ILDAPProviderFactory::class, function(ContainerInterface $c) { |
|
| 909 | 909 | $config = $c->get(\OCP\IConfig::class); |
| 910 | 910 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 911 | 911 | if (is_null($factoryClass) || !class_exists($factoryClass)) { |
@@ -914,11 +914,11 @@ discard block |
||
| 914 | 914 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
| 915 | 915 | return new $factoryClass($this); |
| 916 | 916 | }); |
| 917 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 917 | + $this->registerService(ILDAPProvider::class, function(ContainerInterface $c) { |
|
| 918 | 918 | $factory = $c->get(ILDAPProviderFactory::class); |
| 919 | 919 | return $factory->getLDAPProvider(); |
| 920 | 920 | }); |
| 921 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 921 | + $this->registerService(ILockingProvider::class, function(ContainerInterface $c) { |
|
| 922 | 922 | $ini = $c->get(IniGetWrapper::class); |
| 923 | 923 | $config = $c->get(\OCP\IConfig::class); |
| 924 | 924 | $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -940,51 +940,51 @@ discard block |
||
| 940 | 940 | return new NoopLockingProvider(); |
| 941 | 941 | }); |
| 942 | 942 | |
| 943 | - $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 943 | + $this->registerService(ILockManager::class, function(Server $c): LockManager { |
|
| 944 | 944 | return new LockManager(); |
| 945 | 945 | }); |
| 946 | 946 | |
| 947 | 947 | $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
| 948 | - $this->registerService(SetupManager::class, function ($c) { |
|
| 948 | + $this->registerService(SetupManager::class, function($c) { |
|
| 949 | 949 | // create the setupmanager through the mount manager to resolve the cyclic dependency |
| 950 | 950 | return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
| 951 | 951 | }); |
| 952 | 952 | $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
| 953 | 953 | |
| 954 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 954 | + $this->registerService(IMimeTypeDetector::class, function(ContainerInterface $c) { |
|
| 955 | 955 | return new \OC\Files\Type\Detection( |
| 956 | 956 | $c->get(IURLGenerator::class), |
| 957 | 957 | $c->get(LoggerInterface::class), |
| 958 | 958 | \OC::$configDir, |
| 959 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 959 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 960 | 960 | ); |
| 961 | 961 | }); |
| 962 | 962 | |
| 963 | 963 | $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
| 964 | - $this->registerService(BundleFetcher::class, function () { |
|
| 964 | + $this->registerService(BundleFetcher::class, function() { |
|
| 965 | 965 | return new BundleFetcher($this->getL10N('lib')); |
| 966 | 966 | }); |
| 967 | 967 | $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
| 968 | 968 | |
| 969 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 969 | + $this->registerService(CapabilitiesManager::class, function(ContainerInterface $c) { |
|
| 970 | 970 | $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
| 971 | - $manager->registerCapability(function () use ($c) { |
|
| 971 | + $manager->registerCapability(function() use ($c) { |
|
| 972 | 972 | return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
| 973 | 973 | }); |
| 974 | - $manager->registerCapability(function () use ($c) { |
|
| 974 | + $manager->registerCapability(function() use ($c) { |
|
| 975 | 975 | return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
| 976 | 976 | }); |
| 977 | 977 | return $manager; |
| 978 | 978 | }); |
| 979 | 979 | |
| 980 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 980 | + $this->registerService(ICommentsManager::class, function(Server $c) { |
|
| 981 | 981 | $config = $c->get(\OCP\IConfig::class); |
| 982 | 982 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
| 983 | 983 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
| 984 | 984 | $factory = new $factoryClass($this); |
| 985 | 985 | $manager = $factory->getManager(); |
| 986 | 986 | |
| 987 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 987 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
| 988 | 988 | $manager = $c->get(IUserManager::class); |
| 989 | 989 | $userDisplayName = $manager->getDisplayName($id); |
| 990 | 990 | if ($userDisplayName === null) { |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | }); |
| 999 | 999 | |
| 1000 | 1000 | $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
| 1001 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1001 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 1002 | 1002 | try { |
| 1003 | 1003 | $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
| 1004 | 1004 | } catch (\OCP\AutoloadNotAllowedException $e) { |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | } |
| 1040 | 1040 | return new \OC_Defaults(); |
| 1041 | 1041 | }); |
| 1042 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1042 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
| 1043 | 1043 | return new JSCombiner( |
| 1044 | 1044 | $c->getAppDataDir('js'), |
| 1045 | 1045 | $c->get(IURLGenerator::class), |
@@ -1050,7 +1050,7 @@ discard block |
||
| 1050 | 1050 | }); |
| 1051 | 1051 | $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
| 1052 | 1052 | |
| 1053 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1053 | + $this->registerService('CryptoWrapper', function(ContainerInterface $c) { |
|
| 1054 | 1054 | // FIXME: Instantiated here due to cyclic dependency |
| 1055 | 1055 | $request = new Request( |
| 1056 | 1056 | [ |
@@ -1074,12 +1074,12 @@ discard block |
||
| 1074 | 1074 | $request |
| 1075 | 1075 | ); |
| 1076 | 1076 | }); |
| 1077 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1077 | + $this->registerService(SessionStorage::class, function(ContainerInterface $c) { |
|
| 1078 | 1078 | return new SessionStorage($c->get(ISession::class)); |
| 1079 | 1079 | }); |
| 1080 | 1080 | $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
| 1081 | 1081 | |
| 1082 | - $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1082 | + $this->registerService(IProviderFactory::class, function(ContainerInterface $c) { |
|
| 1083 | 1083 | $config = $c->get(\OCP\IConfig::class); |
| 1084 | 1084 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
| 1085 | 1085 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1088,7 +1088,7 @@ discard block |
||
| 1088 | 1088 | |
| 1089 | 1089 | $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
| 1090 | 1090 | |
| 1091 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1091 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
| 1092 | 1092 | $instance = new Collaboration\Collaborators\Search($c); |
| 1093 | 1093 | |
| 1094 | 1094 | // register default plugins |
@@ -1112,20 +1112,20 @@ discard block |
||
| 1112 | 1112 | |
| 1113 | 1113 | $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
| 1114 | 1114 | $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
| 1115 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1115 | + $this->registerService(\OC\Files\AppData\Factory::class, function(ContainerInterface $c) { |
|
| 1116 | 1116 | return new \OC\Files\AppData\Factory( |
| 1117 | 1117 | $c->get(IRootFolder::class), |
| 1118 | 1118 | $c->get(SystemConfig::class) |
| 1119 | 1119 | ); |
| 1120 | 1120 | }); |
| 1121 | 1121 | |
| 1122 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1123 | - return new LockdownManager(function () use ($c) { |
|
| 1122 | + $this->registerService('LockdownManager', function(ContainerInterface $c) { |
|
| 1123 | + return new LockdownManager(function() use ($c) { |
|
| 1124 | 1124 | return $c->get(ISession::class); |
| 1125 | 1125 | }); |
| 1126 | 1126 | }); |
| 1127 | 1127 | |
| 1128 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1128 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(ContainerInterface $c) { |
|
| 1129 | 1129 | return new DiscoveryService( |
| 1130 | 1130 | $c->get(ICacheFactory::class), |
| 1131 | 1131 | $c->get(IClientService::class) |
@@ -1133,7 +1133,7 @@ discard block |
||
| 1133 | 1133 | }); |
| 1134 | 1134 | $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
| 1135 | 1135 | |
| 1136 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1136 | + $this->registerService(ICloudIdManager::class, function(ContainerInterface $c) { |
|
| 1137 | 1137 | return new CloudIdManager( |
| 1138 | 1138 | $c->get(ICacheFactory::class), |
| 1139 | 1139 | $c->get(IEventDispatcher::class), |
@@ -1145,7 +1145,7 @@ discard block |
||
| 1145 | 1145 | |
| 1146 | 1146 | $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
| 1147 | 1147 | $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
| 1148 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1148 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
| 1149 | 1149 | return new CloudFederationFactory(); |
| 1150 | 1150 | }); |
| 1151 | 1151 | |
@@ -1154,27 +1154,27 @@ discard block |
||
| 1154 | 1154 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
| 1155 | 1155 | $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1156 | 1156 | |
| 1157 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1157 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1158 | 1158 | return new Defaults( |
| 1159 | 1159 | $c->get('ThemingDefaults') |
| 1160 | 1160 | ); |
| 1161 | 1161 | }); |
| 1162 | 1162 | |
| 1163 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1163 | + $this->registerService(\OCP\ISession::class, function(ContainerInterface $c) { |
|
| 1164 | 1164 | return $c->get(\OCP\IUserSession::class)->getSession(); |
| 1165 | 1165 | }, false); |
| 1166 | 1166 | |
| 1167 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1167 | + $this->registerService(IShareHelper::class, function(ContainerInterface $c) { |
|
| 1168 | 1168 | return new ShareHelper( |
| 1169 | 1169 | $c->get(\OCP\Share\IManager::class) |
| 1170 | 1170 | ); |
| 1171 | 1171 | }); |
| 1172 | 1172 | |
| 1173 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1173 | + $this->registerService(IApiFactory::class, function(ContainerInterface $c) { |
|
| 1174 | 1174 | return new ApiFactory($c->get(IClientService::class)); |
| 1175 | 1175 | }); |
| 1176 | 1176 | |
| 1177 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1177 | + $this->registerService(IInstanceFactory::class, function(ContainerInterface $c) { |
|
| 1178 | 1178 | $memcacheFactory = $c->get(ICacheFactory::class); |
| 1179 | 1179 | return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
| 1180 | 1180 | }); |