@@ -34,54 +34,54 @@ |
||
| 34 | 34 | |
| 35 | 35 | class UploadCleanup extends TimedJob { |
| 36 | 36 | |
| 37 | - /** @var IRootFolder */ |
|
| 38 | - private $rootFolder; |
|
| 39 | - |
|
| 40 | - /** @var IJobList */ |
|
| 41 | - private $jobList; |
|
| 42 | - |
|
| 43 | - public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList) { |
|
| 44 | - parent::__construct($time); |
|
| 45 | - $this->rootFolder = $rootFolder; |
|
| 46 | - $this->jobList = $jobList; |
|
| 47 | - |
|
| 48 | - // Run once a day |
|
| 49 | - $this->setInterval(60*60*24); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - protected function run($argument) { |
|
| 53 | - $uid = $argument['uid']; |
|
| 54 | - $folder = $argument['folder']; |
|
| 55 | - |
|
| 56 | - $userFolder = $this->rootFolder->getUserFolder($uid); |
|
| 57 | - $userRoot = $userFolder->getParent(); |
|
| 58 | - |
|
| 59 | - try { |
|
| 60 | - /** @var Folder $uploads */ |
|
| 61 | - $uploads = $userRoot->get('uploads'); |
|
| 62 | - /** @var Folder $uploadFolder */ |
|
| 63 | - $uploadFolder = $uploads->get($folder); |
|
| 64 | - } catch (NotFoundException $e) { |
|
| 65 | - $this->jobList->remove(self::class, $argument); |
|
| 66 | - return; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $files = $uploadFolder->getDirectoryListing(); |
|
| 70 | - |
|
| 71 | - // Remove if all files have an mtime of more than a day |
|
| 72 | - $time = $this->time->getTime() - 60 * 60 * 24; |
|
| 73 | - |
|
| 74 | - // The folder has to be more than a day old |
|
| 75 | - $initial = $uploadFolder->getMTime() < $time; |
|
| 76 | - |
|
| 77 | - $expire = array_reduce($files, function(bool $carry, File $file) use ($time) { |
|
| 78 | - return $carry && $file->getMTime() < $time; |
|
| 79 | - }, $initial); |
|
| 80 | - |
|
| 81 | - if ($expire) { |
|
| 82 | - $uploadFolder->delete(); |
|
| 83 | - $this->jobList->remove(self::class, $argument); |
|
| 84 | - } |
|
| 85 | - } |
|
| 37 | + /** @var IRootFolder */ |
|
| 38 | + private $rootFolder; |
|
| 39 | + |
|
| 40 | + /** @var IJobList */ |
|
| 41 | + private $jobList; |
|
| 42 | + |
|
| 43 | + public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList) { |
|
| 44 | + parent::__construct($time); |
|
| 45 | + $this->rootFolder = $rootFolder; |
|
| 46 | + $this->jobList = $jobList; |
|
| 47 | + |
|
| 48 | + // Run once a day |
|
| 49 | + $this->setInterval(60*60*24); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + protected function run($argument) { |
|
| 53 | + $uid = $argument['uid']; |
|
| 54 | + $folder = $argument['folder']; |
|
| 55 | + |
|
| 56 | + $userFolder = $this->rootFolder->getUserFolder($uid); |
|
| 57 | + $userRoot = $userFolder->getParent(); |
|
| 58 | + |
|
| 59 | + try { |
|
| 60 | + /** @var Folder $uploads */ |
|
| 61 | + $uploads = $userRoot->get('uploads'); |
|
| 62 | + /** @var Folder $uploadFolder */ |
|
| 63 | + $uploadFolder = $uploads->get($folder); |
|
| 64 | + } catch (NotFoundException $e) { |
|
| 65 | + $this->jobList->remove(self::class, $argument); |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $files = $uploadFolder->getDirectoryListing(); |
|
| 70 | + |
|
| 71 | + // Remove if all files have an mtime of more than a day |
|
| 72 | + $time = $this->time->getTime() - 60 * 60 * 24; |
|
| 73 | + |
|
| 74 | + // The folder has to be more than a day old |
|
| 75 | + $initial = $uploadFolder->getMTime() < $time; |
|
| 76 | + |
|
| 77 | + $expire = array_reduce($files, function(bool $carry, File $file) use ($time) { |
|
| 78 | + return $carry && $file->getMTime() < $time; |
|
| 79 | + }, $initial); |
|
| 80 | + |
|
| 81 | + if ($expire) { |
|
| 82 | + $uploadFolder->delete(); |
|
| 83 | + $this->jobList->remove(self::class, $argument); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | } |
@@ -37,59 +37,59 @@ |
||
| 37 | 37 | |
| 38 | 38 | class ChunkCleanup implements IRepairStep { |
| 39 | 39 | |
| 40 | - /** @var IConfig */ |
|
| 41 | - private $config; |
|
| 42 | - /** @var IUserManager */ |
|
| 43 | - private $userManager; |
|
| 44 | - /** @var IRootFolder */ |
|
| 45 | - private $rootFolder; |
|
| 46 | - /** @var IJobList */ |
|
| 47 | - private $jobList; |
|
| 40 | + /** @var IConfig */ |
|
| 41 | + private $config; |
|
| 42 | + /** @var IUserManager */ |
|
| 43 | + private $userManager; |
|
| 44 | + /** @var IRootFolder */ |
|
| 45 | + private $rootFolder; |
|
| 46 | + /** @var IJobList */ |
|
| 47 | + private $jobList; |
|
| 48 | 48 | |
| 49 | - public function __construct(IConfig $config, |
|
| 50 | - IUserManager $userManager, |
|
| 51 | - IRootFolder $rootFolder, |
|
| 52 | - IJobList $jobList) { |
|
| 53 | - $this->config = $config; |
|
| 54 | - $this->userManager = $userManager; |
|
| 55 | - $this->rootFolder = $rootFolder; |
|
| 56 | - $this->jobList = $jobList; |
|
| 57 | - } |
|
| 49 | + public function __construct(IConfig $config, |
|
| 50 | + IUserManager $userManager, |
|
| 51 | + IRootFolder $rootFolder, |
|
| 52 | + IJobList $jobList) { |
|
| 53 | + $this->config = $config; |
|
| 54 | + $this->userManager = $userManager; |
|
| 55 | + $this->rootFolder = $rootFolder; |
|
| 56 | + $this->jobList = $jobList; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function getName(): string { |
|
| 60 | - return 'Chunk cleanup scheduler'; |
|
| 61 | - } |
|
| 59 | + public function getName(): string { |
|
| 60 | + return 'Chunk cleanup scheduler'; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function run(IOutput $output) { |
|
| 64 | - // If we already ran this onec there is no need to run it again |
|
| 65 | - if ($this->config->getAppValue('dav', 'chunks_migrated', '0') === '1') { |
|
| 66 | - $output->info('Cleanup not required'); |
|
| 67 | - } |
|
| 63 | + public function run(IOutput $output) { |
|
| 64 | + // If we already ran this onec there is no need to run it again |
|
| 65 | + if ($this->config->getAppValue('dav', 'chunks_migrated', '0') === '1') { |
|
| 66 | + $output->info('Cleanup not required'); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $output->startProgress(); |
|
| 70 | - // Loop over all seen users |
|
| 71 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($output) { |
|
| 72 | - try { |
|
| 73 | - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
| 74 | - $userRoot = $userFolder->getParent(); |
|
| 75 | - /** @var Folder $uploadFolder */ |
|
| 76 | - $uploadFolder = $userRoot->get('uploads'); |
|
| 77 | - } catch (NotFoundException $e) { |
|
| 78 | - // No folder so skipping |
|
| 79 | - return; |
|
| 80 | - } |
|
| 69 | + $output->startProgress(); |
|
| 70 | + // Loop over all seen users |
|
| 71 | + $this->userManager->callForSeenUsers(function (IUser $user) use ($output) { |
|
| 72 | + try { |
|
| 73 | + $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
| 74 | + $userRoot = $userFolder->getParent(); |
|
| 75 | + /** @var Folder $uploadFolder */ |
|
| 76 | + $uploadFolder = $userRoot->get('uploads'); |
|
| 77 | + } catch (NotFoundException $e) { |
|
| 78 | + // No folder so skipping |
|
| 79 | + return; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // Insert a cleanup job for each folder we find |
|
| 83 | - $uploads = $uploadFolder->getDirectoryListing(); |
|
| 84 | - foreach ($uploads as $upload) { |
|
| 85 | - $this->jobList->add(UploadCleanup::class, ['uid' => $user->getUID(), 'folder' => $upload->getName()]); |
|
| 86 | - } |
|
| 87 | - $output->advance(); |
|
| 88 | - }); |
|
| 89 | - $output->finishProgress(); |
|
| 82 | + // Insert a cleanup job for each folder we find |
|
| 83 | + $uploads = $uploadFolder->getDirectoryListing(); |
|
| 84 | + foreach ($uploads as $upload) { |
|
| 85 | + $this->jobList->add(UploadCleanup::class, ['uid' => $user->getUID(), 'folder' => $upload->getName()]); |
|
| 86 | + } |
|
| 87 | + $output->advance(); |
|
| 88 | + }); |
|
| 89 | + $output->finishProgress(); |
|
| 90 | 90 | |
| 91 | 91 | |
| 92 | - $this->config->setAppValue('dav', 'chunks_migrated', '1'); |
|
| 93 | - } |
|
| 92 | + $this->config->setAppValue('dav', 'chunks_migrated', '1'); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | 95 | } |
@@ -40,121 +40,121 @@ |
||
| 40 | 40 | |
| 41 | 41 | class RootCollection extends SimpleCollection { |
| 42 | 42 | |
| 43 | - public function __construct() { |
|
| 44 | - $config = \OC::$server->getConfig(); |
|
| 45 | - $l10n = \OC::$server->getL10N('dav'); |
|
| 46 | - $random = \OC::$server->getSecureRandom(); |
|
| 47 | - $logger = \OC::$server->getLogger(); |
|
| 48 | - $userManager = \OC::$server->getUserManager(); |
|
| 49 | - $userSession = \OC::$server->getUserSession(); |
|
| 50 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 51 | - $shareManager = \OC::$server->getShareManager(); |
|
| 52 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 53 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 54 | - $userPrincipalBackend = new Principal( |
|
| 55 | - $userManager, |
|
| 56 | - $groupManager, |
|
| 57 | - $shareManager, |
|
| 58 | - \OC::$server->getUserSession(), |
|
| 59 | - $config |
|
| 60 | - ); |
|
| 61 | - $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $l10n); |
|
| 62 | - $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger); |
|
| 63 | - $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger); |
|
| 64 | - // as soon as debug mode is enabled we allow listing of principals |
|
| 65 | - $disableListing = !$config->getSystemValue('debug', false); |
|
| 66 | - |
|
| 67 | - // setup the first level of the dav tree |
|
| 68 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 69 | - $userPrincipals->disableListing = $disableListing; |
|
| 70 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 71 | - $groupPrincipals->disableListing = $disableListing; |
|
| 72 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 73 | - $systemPrincipals->disableListing = $disableListing; |
|
| 74 | - $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 75 | - $calendarResourcePrincipals->disableListing = $disableListing; |
|
| 76 | - $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 77 | - $calendarRoomPrincipals->disableListing = $disableListing; |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 81 | - $filesCollection->disableListing = $disableListing; |
|
| 82 | - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 83 | - $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 84 | - $userCalendarRoot->disableListing = $disableListing; |
|
| 85 | - |
|
| 86 | - $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 87 | - $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); |
|
| 88 | - $resourceCalendarRoot->disableListing = $disableListing; |
|
| 89 | - $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 90 | - $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); |
|
| 91 | - $roomCalendarRoot->disableListing = $disableListing; |
|
| 92 | - |
|
| 93 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); |
|
| 94 | - $publicCalendarRoot->disableListing = $disableListing; |
|
| 95 | - |
|
| 96 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 97 | - \OC::$server->getSystemTagManager(), |
|
| 98 | - \OC::$server->getUserSession(), |
|
| 99 | - $groupManager |
|
| 100 | - ); |
|
| 101 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 102 | - \OC::$server->getSystemTagManager(), |
|
| 103 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 104 | - \OC::$server->getUserSession(), |
|
| 105 | - $groupManager, |
|
| 106 | - \OC::$server->getEventDispatcher() |
|
| 107 | - ); |
|
| 108 | - $commentsCollection = new Comments\RootCollection( |
|
| 109 | - \OC::$server->getCommentsManager(), |
|
| 110 | - $userManager, |
|
| 111 | - \OC::$server->getUserSession(), |
|
| 112 | - \OC::$server->getEventDispatcher(), |
|
| 113 | - \OC::$server->getLogger() |
|
| 114 | - ); |
|
| 115 | - |
|
| 116 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 117 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 118 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
| 119 | - |
|
| 120 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 121 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 122 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
| 123 | - |
|
| 124 | - $uploadCollection = new Upload\RootCollection( |
|
| 125 | - $userPrincipalBackend, |
|
| 126 | - 'principals/users', |
|
| 127 | - \OC::$server->query(CleanupService::class)); |
|
| 128 | - $uploadCollection->disableListing = $disableListing; |
|
| 129 | - |
|
| 130 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 131 | - $avatarCollection->disableListing = $disableListing; |
|
| 132 | - |
|
| 133 | - $children = [ |
|
| 134 | - new SimpleCollection('principals', [ |
|
| 135 | - $userPrincipals, |
|
| 136 | - $groupPrincipals, |
|
| 137 | - $systemPrincipals, |
|
| 138 | - $calendarResourcePrincipals, |
|
| 139 | - $calendarRoomPrincipals]), |
|
| 140 | - $filesCollection, |
|
| 141 | - $userCalendarRoot, |
|
| 142 | - new SimpleCollection('system-calendars', [ |
|
| 143 | - $resourceCalendarRoot, |
|
| 144 | - $roomCalendarRoot, |
|
| 145 | - ]), |
|
| 146 | - $publicCalendarRoot, |
|
| 147 | - new SimpleCollection('addressbooks', [ |
|
| 148 | - $usersAddressBookRoot, |
|
| 149 | - $systemAddressBookRoot]), |
|
| 150 | - $systemTagCollection, |
|
| 151 | - $systemTagRelationsCollection, |
|
| 152 | - $commentsCollection, |
|
| 153 | - $uploadCollection, |
|
| 154 | - $avatarCollection |
|
| 155 | - ]; |
|
| 156 | - |
|
| 157 | - parent::__construct('root', $children); |
|
| 158 | - } |
|
| 43 | + public function __construct() { |
|
| 44 | + $config = \OC::$server->getConfig(); |
|
| 45 | + $l10n = \OC::$server->getL10N('dav'); |
|
| 46 | + $random = \OC::$server->getSecureRandom(); |
|
| 47 | + $logger = \OC::$server->getLogger(); |
|
| 48 | + $userManager = \OC::$server->getUserManager(); |
|
| 49 | + $userSession = \OC::$server->getUserSession(); |
|
| 50 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 51 | + $shareManager = \OC::$server->getShareManager(); |
|
| 52 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 53 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 54 | + $userPrincipalBackend = new Principal( |
|
| 55 | + $userManager, |
|
| 56 | + $groupManager, |
|
| 57 | + $shareManager, |
|
| 58 | + \OC::$server->getUserSession(), |
|
| 59 | + $config |
|
| 60 | + ); |
|
| 61 | + $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $l10n); |
|
| 62 | + $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger); |
|
| 63 | + $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger); |
|
| 64 | + // as soon as debug mode is enabled we allow listing of principals |
|
| 65 | + $disableListing = !$config->getSystemValue('debug', false); |
|
| 66 | + |
|
| 67 | + // setup the first level of the dav tree |
|
| 68 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 69 | + $userPrincipals->disableListing = $disableListing; |
|
| 70 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 71 | + $groupPrincipals->disableListing = $disableListing; |
|
| 72 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 73 | + $systemPrincipals->disableListing = $disableListing; |
|
| 74 | + $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
| 75 | + $calendarResourcePrincipals->disableListing = $disableListing; |
|
| 76 | + $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
| 77 | + $calendarRoomPrincipals->disableListing = $disableListing; |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 81 | + $filesCollection->disableListing = $disableListing; |
|
| 82 | + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 83 | + $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 84 | + $userCalendarRoot->disableListing = $disableListing; |
|
| 85 | + |
|
| 86 | + $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 87 | + $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); |
|
| 88 | + $resourceCalendarRoot->disableListing = $disableListing; |
|
| 89 | + $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher); |
|
| 90 | + $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); |
|
| 91 | + $roomCalendarRoot->disableListing = $disableListing; |
|
| 92 | + |
|
| 93 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); |
|
| 94 | + $publicCalendarRoot->disableListing = $disableListing; |
|
| 95 | + |
|
| 96 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 97 | + \OC::$server->getSystemTagManager(), |
|
| 98 | + \OC::$server->getUserSession(), |
|
| 99 | + $groupManager |
|
| 100 | + ); |
|
| 101 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 102 | + \OC::$server->getSystemTagManager(), |
|
| 103 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 104 | + \OC::$server->getUserSession(), |
|
| 105 | + $groupManager, |
|
| 106 | + \OC::$server->getEventDispatcher() |
|
| 107 | + ); |
|
| 108 | + $commentsCollection = new Comments\RootCollection( |
|
| 109 | + \OC::$server->getCommentsManager(), |
|
| 110 | + $userManager, |
|
| 111 | + \OC::$server->getUserSession(), |
|
| 112 | + \OC::$server->getEventDispatcher(), |
|
| 113 | + \OC::$server->getLogger() |
|
| 114 | + ); |
|
| 115 | + |
|
| 116 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 117 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 118 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
| 119 | + |
|
| 120 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher); |
|
| 121 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 122 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
| 123 | + |
|
| 124 | + $uploadCollection = new Upload\RootCollection( |
|
| 125 | + $userPrincipalBackend, |
|
| 126 | + 'principals/users', |
|
| 127 | + \OC::$server->query(CleanupService::class)); |
|
| 128 | + $uploadCollection->disableListing = $disableListing; |
|
| 129 | + |
|
| 130 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 131 | + $avatarCollection->disableListing = $disableListing; |
|
| 132 | + |
|
| 133 | + $children = [ |
|
| 134 | + new SimpleCollection('principals', [ |
|
| 135 | + $userPrincipals, |
|
| 136 | + $groupPrincipals, |
|
| 137 | + $systemPrincipals, |
|
| 138 | + $calendarResourcePrincipals, |
|
| 139 | + $calendarRoomPrincipals]), |
|
| 140 | + $filesCollection, |
|
| 141 | + $userCalendarRoot, |
|
| 142 | + new SimpleCollection('system-calendars', [ |
|
| 143 | + $resourceCalendarRoot, |
|
| 144 | + $roomCalendarRoot, |
|
| 145 | + ]), |
|
| 146 | + $publicCalendarRoot, |
|
| 147 | + new SimpleCollection('addressbooks', [ |
|
| 148 | + $usersAddressBookRoot, |
|
| 149 | + $systemAddressBookRoot]), |
|
| 150 | + $systemTagCollection, |
|
| 151 | + $systemTagRelationsCollection, |
|
| 152 | + $commentsCollection, |
|
| 153 | + $uploadCollection, |
|
| 154 | + $avatarCollection |
|
| 155 | + ]; |
|
| 156 | + |
|
| 157 | + parent::__construct('root', $children); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | 160 | } |
@@ -31,70 +31,70 @@ |
||
| 31 | 31 | |
| 32 | 32 | class UploadHome implements ICollection { |
| 33 | 33 | |
| 34 | - /** @var array */ |
|
| 35 | - private $principalInfo; |
|
| 36 | - /** @var CleanupService */ |
|
| 37 | - private $cleanupService; |
|
| 34 | + /** @var array */ |
|
| 35 | + private $principalInfo; |
|
| 36 | + /** @var CleanupService */ |
|
| 37 | + private $cleanupService; |
|
| 38 | 38 | |
| 39 | - public function __construct(array $principalInfo, CleanupService $cleanupService) { |
|
| 40 | - $this->principalInfo = $principalInfo; |
|
| 41 | - $this->cleanupService = $cleanupService; |
|
| 42 | - } |
|
| 39 | + public function __construct(array $principalInfo, CleanupService $cleanupService) { |
|
| 40 | + $this->principalInfo = $principalInfo; |
|
| 41 | + $this->cleanupService = $cleanupService; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function createFile($name, $data = null) { |
|
| 45 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 46 | - } |
|
| 44 | + public function createFile($name, $data = null) { |
|
| 45 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function createDirectory($name) { |
|
| 49 | - $this->impl()->createDirectory($name); |
|
| 48 | + public function createDirectory($name) { |
|
| 49 | + $this->impl()->createDirectory($name); |
|
| 50 | 50 | |
| 51 | - // Add a cleanup job |
|
| 52 | - $this->cleanupService->addJob($name); |
|
| 53 | - } |
|
| 51 | + // Add a cleanup job |
|
| 52 | + $this->cleanupService->addJob($name); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function getChild($name): UploadFolder { |
|
| 56 | - return new UploadFolder($this->impl()->getChild($name), $this->cleanupService); |
|
| 57 | - } |
|
| 55 | + public function getChild($name): UploadFolder { |
|
| 56 | + return new UploadFolder($this->impl()->getChild($name), $this->cleanupService); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function getChildren(): array { |
|
| 60 | - return array_map(function($node) { |
|
| 61 | - return new UploadFolder($node, $this->cleanupService); |
|
| 62 | - }, $this->impl()->getChildren()); |
|
| 63 | - } |
|
| 59 | + public function getChildren(): array { |
|
| 60 | + return array_map(function($node) { |
|
| 61 | + return new UploadFolder($node, $this->cleanupService); |
|
| 62 | + }, $this->impl()->getChildren()); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function childExists($name): bool { |
|
| 66 | - return !is_null($this->getChild($name)); |
|
| 67 | - } |
|
| 65 | + public function childExists($name): bool { |
|
| 66 | + return !is_null($this->getChild($name)); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public function delete() { |
|
| 70 | - $this->impl()->delete(); |
|
| 71 | - } |
|
| 69 | + public function delete() { |
|
| 70 | + $this->impl()->delete(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function getName() { |
|
| 74 | - list(,$name) = \Sabre\Uri\split($this->principalInfo['uri']); |
|
| 75 | - return $name; |
|
| 76 | - } |
|
| 73 | + public function getName() { |
|
| 74 | + list(,$name) = \Sabre\Uri\split($this->principalInfo['uri']); |
|
| 75 | + return $name; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function setName($name) { |
|
| 79 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 80 | - } |
|
| 78 | + public function setName($name) { |
|
| 79 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function getLastModified() { |
|
| 83 | - return $this->impl()->getLastModified(); |
|
| 84 | - } |
|
| 82 | + public function getLastModified() { |
|
| 83 | + return $this->impl()->getLastModified(); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @return Directory |
|
| 88 | - */ |
|
| 89 | - private function impl() { |
|
| 90 | - $rootView = new View(); |
|
| 91 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 92 | - Filesystem::initMountPoints($user->getUID()); |
|
| 93 | - if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { |
|
| 94 | - $rootView->mkdir('/' . $user->getUID() . '/uploads'); |
|
| 95 | - } |
|
| 96 | - $view = new View('/' . $user->getUID() . '/uploads'); |
|
| 97 | - $rootInfo = $view->getFileInfo(''); |
|
| 98 | - return new Directory($view, $rootInfo); |
|
| 99 | - } |
|
| 86 | + /** |
|
| 87 | + * @return Directory |
|
| 88 | + */ |
|
| 89 | + private function impl() { |
|
| 90 | + $rootView = new View(); |
|
| 91 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 92 | + Filesystem::initMountPoints($user->getUID()); |
|
| 93 | + if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { |
|
| 94 | + $rootView->mkdir('/' . $user->getUID() . '/uploads'); |
|
| 95 | + } |
|
| 96 | + $view = new View('/' . $user->getUID() . '/uploads'); |
|
| 97 | + $rootInfo = $view->getFileInfo(''); |
|
| 98 | + return new Directory($view, $rootInfo); |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -29,21 +29,21 @@ |
||
| 29 | 29 | use OCP\IUserSession; |
| 30 | 30 | |
| 31 | 31 | class CleanupService { |
| 32 | - /** @var IUserSession */ |
|
| 33 | - private $userSession; |
|
| 34 | - /** @var IJobList */ |
|
| 35 | - private $jobList; |
|
| 32 | + /** @var IUserSession */ |
|
| 33 | + private $userSession; |
|
| 34 | + /** @var IJobList */ |
|
| 35 | + private $jobList; |
|
| 36 | 36 | |
| 37 | - public function __construct(IUserSession $userSession, IJobList $jobList) { |
|
| 38 | - $this->userSession = $userSession; |
|
| 39 | - $this->jobList = $jobList; |
|
| 40 | - } |
|
| 37 | + public function __construct(IUserSession $userSession, IJobList $jobList) { |
|
| 38 | + $this->userSession = $userSession; |
|
| 39 | + $this->jobList = $jobList; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function addJob(string $folder) { |
|
| 43 | - $this->jobList->add(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]); |
|
| 44 | - } |
|
| 42 | + public function addJob(string $folder) { |
|
| 43 | + $this->jobList->add(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function removeJob(string $folder) { |
|
| 47 | - $this->jobList->remove(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]); |
|
| 48 | - } |
|
| 46 | + public function removeJob(string $folder) { |
|
| 47 | + $this->jobList->remove(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -28,28 +28,28 @@ |
||
| 28 | 28 | |
| 29 | 29 | class RootCollection extends AbstractPrincipalCollection { |
| 30 | 30 | |
| 31 | - /** @var CleanupService */ |
|
| 32 | - private $cleanupService; |
|
| 31 | + /** @var CleanupService */ |
|
| 32 | + private $cleanupService; |
|
| 33 | 33 | |
| 34 | - public function __construct(PrincipalBackend\BackendInterface $principalBackend, |
|
| 35 | - string $principalPrefix, |
|
| 36 | - CleanupService $cleanupService) { |
|
| 37 | - parent::__construct($principalBackend, $principalPrefix); |
|
| 38 | - $this->cleanupService = $cleanupService; |
|
| 39 | - } |
|
| 34 | + public function __construct(PrincipalBackend\BackendInterface $principalBackend, |
|
| 35 | + string $principalPrefix, |
|
| 36 | + CleanupService $cleanupService) { |
|
| 37 | + parent::__construct($principalBackend, $principalPrefix); |
|
| 38 | + $this->cleanupService = $cleanupService; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @inheritdoc |
|
| 43 | - */ |
|
| 44 | - public function getChildForPrincipal(array $principalInfo): UploadHome { |
|
| 45 | - return new UploadHome($principalInfo, $this->cleanupService); |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * @inheritdoc |
|
| 43 | + */ |
|
| 44 | + public function getChildForPrincipal(array $principalInfo): UploadHome { |
|
| 45 | + return new UploadHome($principalInfo, $this->cleanupService); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @inheritdoc |
|
| 50 | - */ |
|
| 51 | - public function getName(): string { |
|
| 52 | - return 'uploads'; |
|
| 53 | - } |
|
| 48 | + /** |
|
| 49 | + * @inheritdoc |
|
| 50 | + */ |
|
| 51 | + public function getName(): string { |
|
| 52 | + return 'uploads'; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | } |
@@ -30,61 +30,61 @@ |
||
| 30 | 30 | |
| 31 | 31 | class UploadFolder implements ICollection { |
| 32 | 32 | |
| 33 | - /** @var Directory */ |
|
| 34 | - private $node; |
|
| 35 | - /** @var CleanupService */ |
|
| 36 | - private $cleanupService; |
|
| 33 | + /** @var Directory */ |
|
| 34 | + private $node; |
|
| 35 | + /** @var CleanupService */ |
|
| 36 | + private $cleanupService; |
|
| 37 | 37 | |
| 38 | - function __construct(Directory $node, CleanupService $cleanupService) { |
|
| 39 | - $this->node = $node; |
|
| 40 | - $this->cleanupService = $cleanupService; |
|
| 41 | - } |
|
| 38 | + function __construct(Directory $node, CleanupService $cleanupService) { |
|
| 39 | + $this->node = $node; |
|
| 40 | + $this->cleanupService = $cleanupService; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - function createFile($name, $data = null) { |
|
| 44 | - // TODO: verify name - should be a simple number |
|
| 45 | - $this->node->createFile($name, $data); |
|
| 46 | - } |
|
| 43 | + function createFile($name, $data = null) { |
|
| 44 | + // TODO: verify name - should be a simple number |
|
| 45 | + $this->node->createFile($name, $data); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - function createDirectory($name) { |
|
| 49 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 50 | - } |
|
| 48 | + function createDirectory($name) { |
|
| 49 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - function getChild($name) { |
|
| 53 | - if ($name === '.file') { |
|
| 54 | - return new FutureFile($this->node, '.file'); |
|
| 55 | - } |
|
| 56 | - return $this->node->getChild($name); |
|
| 57 | - } |
|
| 52 | + function getChild($name) { |
|
| 53 | + if ($name === '.file') { |
|
| 54 | + return new FutureFile($this->node, '.file'); |
|
| 55 | + } |
|
| 56 | + return $this->node->getChild($name); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - function getChildren() { |
|
| 60 | - $children = $this->node->getChildren(); |
|
| 61 | - $children[] = new FutureFile($this->node, '.file'); |
|
| 62 | - return $children; |
|
| 63 | - } |
|
| 59 | + function getChildren() { |
|
| 60 | + $children = $this->node->getChildren(); |
|
| 61 | + $children[] = new FutureFile($this->node, '.file'); |
|
| 62 | + return $children; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - function childExists($name) { |
|
| 66 | - if ($name === '.file') { |
|
| 67 | - return true; |
|
| 68 | - } |
|
| 69 | - return $this->node->childExists($name); |
|
| 70 | - } |
|
| 65 | + function childExists($name) { |
|
| 66 | + if ($name === '.file') { |
|
| 67 | + return true; |
|
| 68 | + } |
|
| 69 | + return $this->node->childExists($name); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - function delete() { |
|
| 73 | - $this->node->delete(); |
|
| 72 | + function delete() { |
|
| 73 | + $this->node->delete(); |
|
| 74 | 74 | |
| 75 | - // Background cleanup job is not needed anymore |
|
| 76 | - $this->cleanupService->removeJob($this->getName()); |
|
| 77 | - } |
|
| 75 | + // Background cleanup job is not needed anymore |
|
| 76 | + $this->cleanupService->removeJob($this->getName()); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - function getName() { |
|
| 80 | - return $this->node->getName(); |
|
| 81 | - } |
|
| 79 | + function getName() { |
|
| 80 | + return $this->node->getName(); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - function setName($name) { |
|
| 84 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 85 | - } |
|
| 83 | + function setName($name) { |
|
| 84 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - function getLastModified() { |
|
| 88 | - return $this->node->getLastModified(); |
|
| 89 | - } |
|
| 87 | + function getLastModified() { |
|
| 88 | + return $this->node->getLastModified(); |
|
| 89 | + } |
|
| 90 | 90 | } |