@@ -35,41 +35,41 @@ discard block |
||
35 | 35 | |
36 | 36 | $application = new Application(); |
37 | 37 | $application->registerRoutes($this, [ |
38 | - 'routes' => [ |
|
39 | - ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
40 | - ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
41 | - ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
42 | - ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
43 | - ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
44 | - ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
45 | - ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
46 | - ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
47 | - ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
48 | - ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
49 | - ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
50 | - ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
51 | - ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
52 | - ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'], |
|
53 | - ['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'], |
|
54 | - ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'], |
|
55 | - ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
56 | - ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
57 | - ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
58 | - ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
59 | - ['name' => 'Preview#getPreview', 'url' => '/core/preview', 'verb' => 'GET'], |
|
60 | - ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
61 | - ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
62 | - ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
63 | - ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], |
|
64 | - ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], |
|
65 | - ['name' => 'AutoComplete#get', 'url' => 'autocomplete/get', 'verb' => 'GET'] |
|
66 | - ], |
|
67 | - 'ocs' => [ |
|
68 | - ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
69 | - ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
70 | - ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
71 | - ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
72 | - ], |
|
38 | + 'routes' => [ |
|
39 | + ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
40 | + ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
41 | + ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
42 | + ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
43 | + ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
44 | + ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
45 | + ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
46 | + ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
47 | + ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
48 | + ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
49 | + ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
50 | + ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
51 | + ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
52 | + ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'], |
|
53 | + ['name' => 'ClientFlowLogin#redirectPage', 'url' => '/login/flow/redirect', 'verb' => 'GET'], |
|
54 | + ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'], |
|
55 | + ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
56 | + ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
57 | + ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
58 | + ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
59 | + ['name' => 'Preview#getPreview', 'url' => '/core/preview', 'verb' => 'GET'], |
|
60 | + ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
61 | + ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
62 | + ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
63 | + ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], |
|
64 | + ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], |
|
65 | + ['name' => 'AutoComplete#get', 'url' => 'autocomplete/get', 'verb' => 'GET'] |
|
66 | + ], |
|
67 | + 'ocs' => [ |
|
68 | + ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
69 | + ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
70 | + ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
71 | + ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
72 | + ], |
|
73 | 73 | ]); |
74 | 74 | |
75 | 75 | // Post installation check |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | // Core ajax actions |
79 | 79 | // Search |
80 | 80 | $this->create('search_ajax_search', '/core/search') |
81 | - ->actionInclude('core/search/ajax/search.php'); |
|
81 | + ->actionInclude('core/search/ajax/search.php'); |
|
82 | 82 | // Routing |
83 | 83 | $this->create('core_ajax_update', '/core/ajax/update.php') |
84 | - ->actionInclude('core/ajax/update.php'); |
|
84 | + ->actionInclude('core/ajax/update.php'); |
|
85 | 85 | |
86 | 86 | // File routes |
87 | 87 | $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) { |
88 | - $app = new \OCA\Files\AppInfo\Application($urlParams); |
|
89 | - $app->dispatch('ViewController', 'index'); |
|
88 | + $app = new \OCA\Files\AppInfo\Application($urlParams); |
|
89 | + $app->dispatch('ViewController', 'index'); |
|
90 | 90 | }); |
91 | 91 | |
92 | 92 | // Call routes |
@@ -95,57 +95,57 @@ discard block |
||
95 | 95 | * @suppress PhanUndeclaredClassMethod |
96 | 96 | */ |
97 | 97 | $this->create('spreed.pagecontroller.showCall', '/call/{token}')->action(function($urlParams) { |
98 | - if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) { |
|
99 | - $app = new \OCA\Spreed\AppInfo\Application($urlParams); |
|
100 | - $app->dispatch('PageController', 'index'); |
|
101 | - } else { |
|
102 | - throw new \OC\HintException('App spreed is not enabled'); |
|
103 | - } |
|
98 | + if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) { |
|
99 | + $app = new \OCA\Spreed\AppInfo\Application($urlParams); |
|
100 | + $app->dispatch('PageController', 'index'); |
|
101 | + } else { |
|
102 | + throw new \OC\HintException('App spreed is not enabled'); |
|
103 | + } |
|
104 | 104 | }); |
105 | 105 | |
106 | 106 | // Sharing routes |
107 | 107 | $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) { |
108 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
109 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
110 | - $app->dispatch('ShareController', 'showShare'); |
|
111 | - } else { |
|
112 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
113 | - } |
|
108 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
109 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
110 | + $app->dispatch('ShareController', 'showShare'); |
|
111 | + } else { |
|
112 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
113 | + } |
|
114 | 114 | }); |
115 | 115 | $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate')->post()->action(function($urlParams) { |
116 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
117 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
118 | - $app->dispatch('ShareController', 'authenticate'); |
|
119 | - } else { |
|
120 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
121 | - } |
|
116 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
117 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
118 | + $app->dispatch('ShareController', 'authenticate'); |
|
119 | + } else { |
|
120 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
121 | + } |
|
122 | 122 | }); |
123 | 123 | $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate')->get()->action(function($urlParams) { |
124 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
125 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
126 | - $app->dispatch('ShareController', 'showAuthenticate'); |
|
127 | - } else { |
|
128 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
129 | - } |
|
124 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
125 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
126 | + $app->dispatch('ShareController', 'showAuthenticate'); |
|
127 | + } else { |
|
128 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
129 | + } |
|
130 | 130 | }); |
131 | 131 | $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) { |
132 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
133 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
134 | - $app->dispatch('ShareController', 'downloadShare'); |
|
135 | - } else { |
|
136 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
137 | - } |
|
132 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
133 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
134 | + $app->dispatch('ShareController', 'downloadShare'); |
|
135 | + } else { |
|
136 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
137 | + } |
|
138 | 138 | }); |
139 | 139 | $this->create('files_sharing.publicpreview.directLink', '/s/{token}/preview')->get()->action(function($urlParams) { |
140 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
141 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
142 | - $app->dispatch('PublicPreviewController', 'directLink'); |
|
143 | - } else { |
|
144 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
145 | - } |
|
140 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
141 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
142 | + $app->dispatch('PublicPreviewController', 'directLink'); |
|
143 | + } else { |
|
144 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
145 | + } |
|
146 | 146 | }); |
147 | 147 | |
148 | 148 | // used for heartbeat |
149 | 149 | $this->create('heartbeat', '/heartbeat')->action(function(){ |
150 | - // do nothing |
|
150 | + // do nothing |
|
151 | 151 | }); |
@@ -35,277 +35,277 @@ |
||
35 | 35 | */ |
36 | 36 | interface ICommentsManager { |
37 | 37 | |
38 | - /** |
|
39 | - * @const DELETED_USER type and id for a user that has been deleted |
|
40 | - * @see deleteReferencesOfActor |
|
41 | - * @since 9.0.0 |
|
42 | - * |
|
43 | - * To be used as replacement for user type actors in deleteReferencesOfActor(). |
|
44 | - * |
|
45 | - * User interfaces shall show "Deleted user" as display name, if needed. |
|
46 | - */ |
|
47 | - const DELETED_USER = 'deleted_users'; |
|
38 | + /** |
|
39 | + * @const DELETED_USER type and id for a user that has been deleted |
|
40 | + * @see deleteReferencesOfActor |
|
41 | + * @since 9.0.0 |
|
42 | + * |
|
43 | + * To be used as replacement for user type actors in deleteReferencesOfActor(). |
|
44 | + * |
|
45 | + * User interfaces shall show "Deleted user" as display name, if needed. |
|
46 | + */ |
|
47 | + const DELETED_USER = 'deleted_users'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * returns a comment instance |
|
51 | - * |
|
52 | - * @param string $id the ID of the comment |
|
53 | - * @return IComment |
|
54 | - * @throws NotFoundException |
|
55 | - * @since 9.0.0 |
|
56 | - */ |
|
57 | - public function get($id); |
|
49 | + /** |
|
50 | + * returns a comment instance |
|
51 | + * |
|
52 | + * @param string $id the ID of the comment |
|
53 | + * @return IComment |
|
54 | + * @throws NotFoundException |
|
55 | + * @since 9.0.0 |
|
56 | + */ |
|
57 | + public function get($id); |
|
58 | 58 | |
59 | - /** |
|
60 | - * returns the comment specified by the id and all it's child comments |
|
61 | - * |
|
62 | - * @param string $id |
|
63 | - * @param int $limit max number of entries to return, 0 returns all |
|
64 | - * @param int $offset the start entry |
|
65 | - * @return array |
|
66 | - * @since 9.0.0 |
|
67 | - * |
|
68 | - * The return array looks like this |
|
69 | - * [ |
|
70 | - * 'comment' => IComment, // root comment |
|
71 | - * 'replies' => |
|
72 | - * [ |
|
73 | - * 0 => |
|
74 | - * [ |
|
75 | - * 'comment' => IComment, |
|
76 | - * 'replies' => |
|
77 | - * [ |
|
78 | - * 0 => |
|
79 | - * [ |
|
80 | - * 'comment' => IComment, |
|
81 | - * 'replies' => [ … ] |
|
82 | - * ], |
|
83 | - * … |
|
84 | - * ] |
|
85 | - * ] |
|
86 | - * 1 => |
|
87 | - * [ |
|
88 | - * 'comment' => IComment, |
|
89 | - * 'replies'=> [ … ] |
|
90 | - * ], |
|
91 | - * … |
|
92 | - * ] |
|
93 | - * ] |
|
94 | - */ |
|
95 | - public function getTree($id, $limit = 0, $offset = 0); |
|
59 | + /** |
|
60 | + * returns the comment specified by the id and all it's child comments |
|
61 | + * |
|
62 | + * @param string $id |
|
63 | + * @param int $limit max number of entries to return, 0 returns all |
|
64 | + * @param int $offset the start entry |
|
65 | + * @return array |
|
66 | + * @since 9.0.0 |
|
67 | + * |
|
68 | + * The return array looks like this |
|
69 | + * [ |
|
70 | + * 'comment' => IComment, // root comment |
|
71 | + * 'replies' => |
|
72 | + * [ |
|
73 | + * 0 => |
|
74 | + * [ |
|
75 | + * 'comment' => IComment, |
|
76 | + * 'replies' => |
|
77 | + * [ |
|
78 | + * 0 => |
|
79 | + * [ |
|
80 | + * 'comment' => IComment, |
|
81 | + * 'replies' => [ … ] |
|
82 | + * ], |
|
83 | + * … |
|
84 | + * ] |
|
85 | + * ] |
|
86 | + * 1 => |
|
87 | + * [ |
|
88 | + * 'comment' => IComment, |
|
89 | + * 'replies'=> [ … ] |
|
90 | + * ], |
|
91 | + * … |
|
92 | + * ] |
|
93 | + * ] |
|
94 | + */ |
|
95 | + public function getTree($id, $limit = 0, $offset = 0); |
|
96 | 96 | |
97 | - /** |
|
98 | - * returns comments for a specific object (e.g. a file). |
|
99 | - * |
|
100 | - * The sort order is always newest to oldest. |
|
101 | - * |
|
102 | - * @param string $objectType the object type, e.g. 'files' |
|
103 | - * @param string $objectId the id of the object |
|
104 | - * @param int $limit optional, number of maximum comments to be returned. if |
|
105 | - * not specified, all comments are returned. |
|
106 | - * @param int $offset optional, starting point |
|
107 | - * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
108 | - * that may be returned |
|
109 | - * @return IComment[] |
|
110 | - * @since 9.0.0 |
|
111 | - */ |
|
112 | - public function getForObject( |
|
113 | - $objectType, |
|
114 | - $objectId, |
|
115 | - $limit = 0, |
|
116 | - $offset = 0, |
|
117 | - \DateTime $notOlderThan = null |
|
118 | - ); |
|
97 | + /** |
|
98 | + * returns comments for a specific object (e.g. a file). |
|
99 | + * |
|
100 | + * The sort order is always newest to oldest. |
|
101 | + * |
|
102 | + * @param string $objectType the object type, e.g. 'files' |
|
103 | + * @param string $objectId the id of the object |
|
104 | + * @param int $limit optional, number of maximum comments to be returned. if |
|
105 | + * not specified, all comments are returned. |
|
106 | + * @param int $offset optional, starting point |
|
107 | + * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
108 | + * that may be returned |
|
109 | + * @return IComment[] |
|
110 | + * @since 9.0.0 |
|
111 | + */ |
|
112 | + public function getForObject( |
|
113 | + $objectType, |
|
114 | + $objectId, |
|
115 | + $limit = 0, |
|
116 | + $offset = 0, |
|
117 | + \DateTime $notOlderThan = null |
|
118 | + ); |
|
119 | 119 | |
120 | - /** |
|
121 | - * @param $objectType string the object type, e.g. 'files' |
|
122 | - * @param $objectId string the id of the object |
|
123 | - * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
124 | - * that may be returned |
|
125 | - * @return Int |
|
126 | - * @since 9.0.0 |
|
127 | - */ |
|
128 | - public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null); |
|
120 | + /** |
|
121 | + * @param $objectType string the object type, e.g. 'files' |
|
122 | + * @param $objectId string the id of the object |
|
123 | + * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
124 | + * that may be returned |
|
125 | + * @return Int |
|
126 | + * @since 9.0.0 |
|
127 | + */ |
|
128 | + public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null); |
|
129 | 129 | |
130 | - /** |
|
131 | - * Get the number of unread comments for all files in a folder |
|
132 | - * |
|
133 | - * @param int $folderId |
|
134 | - * @param IUser $user |
|
135 | - * @return array [$fileId => $unreadCount] |
|
136 | - * @since 12.0.0 |
|
137 | - */ |
|
138 | - public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user); |
|
130 | + /** |
|
131 | + * Get the number of unread comments for all files in a folder |
|
132 | + * |
|
133 | + * @param int $folderId |
|
134 | + * @param IUser $user |
|
135 | + * @return array [$fileId => $unreadCount] |
|
136 | + * @since 12.0.0 |
|
137 | + */ |
|
138 | + public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user); |
|
139 | 139 | |
140 | - /** |
|
141 | - * Get the actor types and ID that commented in the tree specified by the ID |
|
142 | - * |
|
143 | - * @param string $id |
|
144 | - * @return array |
|
145 | - * @since 13.0.0 |
|
146 | - * |
|
147 | - * The return array looks like this: |
|
148 | - * |
|
149 | - * [ |
|
150 | - * 'users' => [ |
|
151 | - * 'alice', |
|
152 | - * 'bob', |
|
153 | - * ], |
|
154 | - * 'robots' => [ |
|
155 | - * 'r2-d2', |
|
156 | - * 'c-3po', |
|
157 | - * ] |
|
158 | - * ] |
|
159 | - */ |
|
160 | - public function getActorsInTree($id); |
|
140 | + /** |
|
141 | + * Get the actor types and ID that commented in the tree specified by the ID |
|
142 | + * |
|
143 | + * @param string $id |
|
144 | + * @return array |
|
145 | + * @since 13.0.0 |
|
146 | + * |
|
147 | + * The return array looks like this: |
|
148 | + * |
|
149 | + * [ |
|
150 | + * 'users' => [ |
|
151 | + * 'alice', |
|
152 | + * 'bob', |
|
153 | + * ], |
|
154 | + * 'robots' => [ |
|
155 | + * 'r2-d2', |
|
156 | + * 'c-3po', |
|
157 | + * ] |
|
158 | + * ] |
|
159 | + */ |
|
160 | + public function getActorsInTree($id); |
|
161 | 161 | |
162 | - /** |
|
163 | - * creates a new comment and returns it. At this point of time, it is not |
|
164 | - * saved in the used data storage. Use save() after setting other fields |
|
165 | - * of the comment (e.g. message or verb). |
|
166 | - * |
|
167 | - * @param string $actorType the actor type (e.g. 'users') |
|
168 | - * @param string $actorId a user id |
|
169 | - * @param string $objectType the object type the comment is attached to |
|
170 | - * @param string $objectId the object id the comment is attached to |
|
171 | - * @return IComment |
|
172 | - * @since 9.0.0 |
|
173 | - */ |
|
174 | - public function create($actorType, $actorId, $objectType, $objectId); |
|
162 | + /** |
|
163 | + * creates a new comment and returns it. At this point of time, it is not |
|
164 | + * saved in the used data storage. Use save() after setting other fields |
|
165 | + * of the comment (e.g. message or verb). |
|
166 | + * |
|
167 | + * @param string $actorType the actor type (e.g. 'users') |
|
168 | + * @param string $actorId a user id |
|
169 | + * @param string $objectType the object type the comment is attached to |
|
170 | + * @param string $objectId the object id the comment is attached to |
|
171 | + * @return IComment |
|
172 | + * @since 9.0.0 |
|
173 | + */ |
|
174 | + public function create($actorType, $actorId, $objectType, $objectId); |
|
175 | 175 | |
176 | - /** |
|
177 | - * permanently deletes the comment specified by the ID |
|
178 | - * |
|
179 | - * When the comment has child comments, their parent ID will be changed to |
|
180 | - * the parent ID of the item that is to be deleted. |
|
181 | - * |
|
182 | - * @param string $id |
|
183 | - * @return bool |
|
184 | - * @since 9.0.0 |
|
185 | - */ |
|
186 | - public function delete($id); |
|
176 | + /** |
|
177 | + * permanently deletes the comment specified by the ID |
|
178 | + * |
|
179 | + * When the comment has child comments, their parent ID will be changed to |
|
180 | + * the parent ID of the item that is to be deleted. |
|
181 | + * |
|
182 | + * @param string $id |
|
183 | + * @return bool |
|
184 | + * @since 9.0.0 |
|
185 | + */ |
|
186 | + public function delete($id); |
|
187 | 187 | |
188 | - /** |
|
189 | - * saves the comment permanently |
|
190 | - * |
|
191 | - * if the supplied comment has an empty ID, a new entry comment will be |
|
192 | - * saved and the instance updated with the new ID. |
|
193 | - * |
|
194 | - * Otherwise, an existing comment will be updated. |
|
195 | - * |
|
196 | - * Throws NotFoundException when a comment that is to be updated does not |
|
197 | - * exist anymore at this point of time. |
|
198 | - * |
|
199 | - * @param IComment $comment |
|
200 | - * @return bool |
|
201 | - * @throws NotFoundException |
|
202 | - * @since 9.0.0 |
|
203 | - */ |
|
204 | - public function save(IComment $comment); |
|
188 | + /** |
|
189 | + * saves the comment permanently |
|
190 | + * |
|
191 | + * if the supplied comment has an empty ID, a new entry comment will be |
|
192 | + * saved and the instance updated with the new ID. |
|
193 | + * |
|
194 | + * Otherwise, an existing comment will be updated. |
|
195 | + * |
|
196 | + * Throws NotFoundException when a comment that is to be updated does not |
|
197 | + * exist anymore at this point of time. |
|
198 | + * |
|
199 | + * @param IComment $comment |
|
200 | + * @return bool |
|
201 | + * @throws NotFoundException |
|
202 | + * @since 9.0.0 |
|
203 | + */ |
|
204 | + public function save(IComment $comment); |
|
205 | 205 | |
206 | - /** |
|
207 | - * removes references to specific actor (e.g. on user delete) of a comment. |
|
208 | - * The comment itself must not get lost/deleted. |
|
209 | - * |
|
210 | - * A 'users' type actor (type and id) should get replaced by the |
|
211 | - * value of the DELETED_USER constant of this interface. |
|
212 | - * |
|
213 | - * @param string $actorType the actor type (e.g. 'users') |
|
214 | - * @param string $actorId a user id |
|
215 | - * @return boolean |
|
216 | - * @since 9.0.0 |
|
217 | - */ |
|
218 | - public function deleteReferencesOfActor($actorType, $actorId); |
|
206 | + /** |
|
207 | + * removes references to specific actor (e.g. on user delete) of a comment. |
|
208 | + * The comment itself must not get lost/deleted. |
|
209 | + * |
|
210 | + * A 'users' type actor (type and id) should get replaced by the |
|
211 | + * value of the DELETED_USER constant of this interface. |
|
212 | + * |
|
213 | + * @param string $actorType the actor type (e.g. 'users') |
|
214 | + * @param string $actorId a user id |
|
215 | + * @return boolean |
|
216 | + * @since 9.0.0 |
|
217 | + */ |
|
218 | + public function deleteReferencesOfActor($actorType, $actorId); |
|
219 | 219 | |
220 | - /** |
|
221 | - * deletes all comments made of a specific object (e.g. on file delete) |
|
222 | - * |
|
223 | - * @param string $objectType the object type (e.g. 'files') |
|
224 | - * @param string $objectId e.g. the file id |
|
225 | - * @return boolean |
|
226 | - * @since 9.0.0 |
|
227 | - */ |
|
228 | - public function deleteCommentsAtObject($objectType, $objectId); |
|
220 | + /** |
|
221 | + * deletes all comments made of a specific object (e.g. on file delete) |
|
222 | + * |
|
223 | + * @param string $objectType the object type (e.g. 'files') |
|
224 | + * @param string $objectId e.g. the file id |
|
225 | + * @return boolean |
|
226 | + * @since 9.0.0 |
|
227 | + */ |
|
228 | + public function deleteCommentsAtObject($objectType, $objectId); |
|
229 | 229 | |
230 | - /** |
|
231 | - * sets the read marker for a given file to the specified date for the |
|
232 | - * provided user |
|
233 | - * |
|
234 | - * @param string $objectType |
|
235 | - * @param string $objectId |
|
236 | - * @param \DateTime $dateTime |
|
237 | - * @param \OCP\IUser $user |
|
238 | - * @since 9.0.0 |
|
239 | - */ |
|
240 | - public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user); |
|
230 | + /** |
|
231 | + * sets the read marker for a given file to the specified date for the |
|
232 | + * provided user |
|
233 | + * |
|
234 | + * @param string $objectType |
|
235 | + * @param string $objectId |
|
236 | + * @param \DateTime $dateTime |
|
237 | + * @param \OCP\IUser $user |
|
238 | + * @since 9.0.0 |
|
239 | + */ |
|
240 | + public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user); |
|
241 | 241 | |
242 | - /** |
|
243 | - * returns the read marker for a given file to the specified date for the |
|
244 | - * provided user. It returns null, when the marker is not present, i.e. |
|
245 | - * no comments were marked as read. |
|
246 | - * |
|
247 | - * @param string $objectType |
|
248 | - * @param string $objectId |
|
249 | - * @param \OCP\IUser $user |
|
250 | - * @return \DateTime|null |
|
251 | - * @since 9.0.0 |
|
252 | - */ |
|
253 | - public function getReadMark($objectType, $objectId, \OCP\IUser $user); |
|
242 | + /** |
|
243 | + * returns the read marker for a given file to the specified date for the |
|
244 | + * provided user. It returns null, when the marker is not present, i.e. |
|
245 | + * no comments were marked as read. |
|
246 | + * |
|
247 | + * @param string $objectType |
|
248 | + * @param string $objectId |
|
249 | + * @param \OCP\IUser $user |
|
250 | + * @return \DateTime|null |
|
251 | + * @since 9.0.0 |
|
252 | + */ |
|
253 | + public function getReadMark($objectType, $objectId, \OCP\IUser $user); |
|
254 | 254 | |
255 | - /** |
|
256 | - * deletes the read markers for the specified user |
|
257 | - * |
|
258 | - * @param \OCP\IUser $user |
|
259 | - * @return bool |
|
260 | - * @since 9.0.0 |
|
261 | - */ |
|
262 | - public function deleteReadMarksFromUser(\OCP\IUser $user); |
|
255 | + /** |
|
256 | + * deletes the read markers for the specified user |
|
257 | + * |
|
258 | + * @param \OCP\IUser $user |
|
259 | + * @return bool |
|
260 | + * @since 9.0.0 |
|
261 | + */ |
|
262 | + public function deleteReadMarksFromUser(\OCP\IUser $user); |
|
263 | 263 | |
264 | - /** |
|
265 | - * deletes the read markers on the specified object |
|
266 | - * |
|
267 | - * @param string $objectType |
|
268 | - * @param string $objectId |
|
269 | - * @return bool |
|
270 | - * @since 9.0.0 |
|
271 | - */ |
|
272 | - public function deleteReadMarksOnObject($objectType, $objectId); |
|
264 | + /** |
|
265 | + * deletes the read markers on the specified object |
|
266 | + * |
|
267 | + * @param string $objectType |
|
268 | + * @param string $objectId |
|
269 | + * @return bool |
|
270 | + * @since 9.0.0 |
|
271 | + */ |
|
272 | + public function deleteReadMarksOnObject($objectType, $objectId); |
|
273 | 273 | |
274 | - /** |
|
275 | - * registers an Entity to the manager, so event notifications can be send |
|
276 | - * to consumers of the comments infrastructure |
|
277 | - * |
|
278 | - * @param \Closure $closure |
|
279 | - * @since 11.0.0 |
|
280 | - */ |
|
281 | - public function registerEventHandler(\Closure $closure); |
|
274 | + /** |
|
275 | + * registers an Entity to the manager, so event notifications can be send |
|
276 | + * to consumers of the comments infrastructure |
|
277 | + * |
|
278 | + * @param \Closure $closure |
|
279 | + * @since 11.0.0 |
|
280 | + */ |
|
281 | + public function registerEventHandler(\Closure $closure); |
|
282 | 282 | |
283 | - /** |
|
284 | - * registers a method that resolves an ID to a display name for a given type |
|
285 | - * |
|
286 | - * @param string $type |
|
287 | - * @param \Closure $closure |
|
288 | - * @throws \OutOfBoundsException |
|
289 | - * @since 11.0.0 |
|
290 | - * |
|
291 | - * Only one resolver shall be registered per type. Otherwise a |
|
292 | - * \OutOfBoundsException has to thrown. |
|
293 | - */ |
|
294 | - public function registerDisplayNameResolver($type, \Closure $closure); |
|
283 | + /** |
|
284 | + * registers a method that resolves an ID to a display name for a given type |
|
285 | + * |
|
286 | + * @param string $type |
|
287 | + * @param \Closure $closure |
|
288 | + * @throws \OutOfBoundsException |
|
289 | + * @since 11.0.0 |
|
290 | + * |
|
291 | + * Only one resolver shall be registered per type. Otherwise a |
|
292 | + * \OutOfBoundsException has to thrown. |
|
293 | + */ |
|
294 | + public function registerDisplayNameResolver($type, \Closure $closure); |
|
295 | 295 | |
296 | - /** |
|
297 | - * resolves a given ID of a given Type to a display name. |
|
298 | - * |
|
299 | - * @param string $type |
|
300 | - * @param string $id |
|
301 | - * @return string |
|
302 | - * @throws \OutOfBoundsException |
|
303 | - * @since 11.0.0 |
|
304 | - * |
|
305 | - * If a provided type was not registered, an \OutOfBoundsException shall |
|
306 | - * be thrown. It is upon the resolver discretion what to return of the |
|
307 | - * provided ID is unknown. It must be ensured that a string is returned. |
|
308 | - */ |
|
309 | - public function resolveDisplayName($type, $id); |
|
296 | + /** |
|
297 | + * resolves a given ID of a given Type to a display name. |
|
298 | + * |
|
299 | + * @param string $type |
|
300 | + * @param string $id |
|
301 | + * @return string |
|
302 | + * @throws \OutOfBoundsException |
|
303 | + * @since 11.0.0 |
|
304 | + * |
|
305 | + * If a provided type was not registered, an \OutOfBoundsException shall |
|
306 | + * be thrown. It is upon the resolver discretion what to return of the |
|
307 | + * provided ID is unknown. It must be ensured that a string is returned. |
|
308 | + */ |
|
309 | + public function resolveDisplayName($type, $id); |
|
310 | 310 | |
311 | 311 | } |
@@ -30,17 +30,17 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface IManager { |
33 | - /** |
|
34 | - * @param string $className – class name of the ISorter implementation |
|
35 | - * @since 13.0.0 |
|
36 | - */ |
|
37 | - public function registerSorter($className); |
|
33 | + /** |
|
34 | + * @param string $className – class name of the ISorter implementation |
|
35 | + * @since 13.0.0 |
|
36 | + */ |
|
37 | + public function registerSorter($className); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param array $sorters list of sorter IDs, seperated by "|" |
|
41 | - * @param array $sortArray array representation of OCP\Collaboration\Collaborators\ISearchResult |
|
42 | - * @param array $context context info of the search, keys: itemType, itemId |
|
43 | - * @since 13.0.0 |
|
44 | - */ |
|
45 | - public function runSorters(array $sorters, array &$sortArray, array $context); |
|
39 | + /** |
|
40 | + * @param array $sorters list of sorter IDs, seperated by "|" |
|
41 | + * @param array $sortArray array representation of OCP\Collaboration\Collaborators\ISearchResult |
|
42 | + * @param array $context context info of the search, keys: itemType, itemId |
|
43 | + * @since 13.0.0 |
|
44 | + */ |
|
45 | + public function runSorters(array $sorters, array &$sortArray, array $context); |
|
46 | 46 | } |
@@ -28,54 +28,54 @@ |
||
28 | 28 | use OCP\IServerContainer; |
29 | 29 | |
30 | 30 | class Manager implements IManager { |
31 | - /** @var string[] */ |
|
32 | - protected $sorters =[]; |
|
31 | + /** @var string[] */ |
|
32 | + protected $sorters =[]; |
|
33 | 33 | |
34 | - /** @var ISorter[] */ |
|
35 | - protected $sorterInstances = []; |
|
36 | - /** @var IServerContainer */ |
|
37 | - private $c; |
|
34 | + /** @var ISorter[] */ |
|
35 | + protected $sorterInstances = []; |
|
36 | + /** @var IServerContainer */ |
|
37 | + private $c; |
|
38 | 38 | |
39 | - public function __construct(IServerContainer $container) { |
|
40 | - $this->c = $container; |
|
41 | - } |
|
39 | + public function __construct(IServerContainer $container) { |
|
40 | + $this->c = $container; |
|
41 | + } |
|
42 | 42 | |
43 | - public function runSorters(array $sorters, array &$sortArray, array $context) { |
|
44 | - $sorterInstances = $this->getSorters(); |
|
45 | - while($sorter = array_shift($sorters)) { |
|
46 | - if(isset($sorterInstances[$sorter])) { |
|
47 | - $sorterInstances[$sorter]->sort($sortArray, $context); |
|
48 | - } else { |
|
49 | - $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ |
|
50 | - 'app' => 'core', 'id' => $sorter |
|
51 | - ]); |
|
52 | - } |
|
53 | - } |
|
54 | - } |
|
43 | + public function runSorters(array $sorters, array &$sortArray, array $context) { |
|
44 | + $sorterInstances = $this->getSorters(); |
|
45 | + while($sorter = array_shift($sorters)) { |
|
46 | + if(isset($sorterInstances[$sorter])) { |
|
47 | + $sorterInstances[$sorter]->sort($sortArray, $context); |
|
48 | + } else { |
|
49 | + $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ |
|
50 | + 'app' => 'core', 'id' => $sorter |
|
51 | + ]); |
|
52 | + } |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - public function registerSorter($className) { |
|
57 | - $sorters[] = $className; |
|
58 | - } |
|
56 | + public function registerSorter($className) { |
|
57 | + $sorters[] = $className; |
|
58 | + } |
|
59 | 59 | |
60 | - protected function getSorters() { |
|
61 | - if(count($this->sorterInstances) === 0) { |
|
62 | - foreach ($this->sorters as $sorter) { |
|
63 | - /** @var ISorter $instance */ |
|
64 | - $instance = $this->c->resolve($sorter); |
|
65 | - if(!$instance instanceof ISorter) { |
|
66 | - $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', |
|
67 | - ['app' => 'core', 'class' => $sorter]); |
|
68 | - continue; |
|
69 | - } |
|
70 | - $sorterId = trim($instance->getId()); |
|
71 | - if(trim($sorterId) === '') { |
|
72 | - $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', |
|
73 | - ['app' => 'core', 'class' => $sorter]); |
|
74 | - continue; |
|
75 | - } |
|
76 | - $this->sorterInstances[$sorterId] = $instance; |
|
77 | - } |
|
78 | - } |
|
79 | - return $this->sorterInstances; |
|
80 | - } |
|
60 | + protected function getSorters() { |
|
61 | + if(count($this->sorterInstances) === 0) { |
|
62 | + foreach ($this->sorters as $sorter) { |
|
63 | + /** @var ISorter $instance */ |
|
64 | + $instance = $this->c->resolve($sorter); |
|
65 | + if(!$instance instanceof ISorter) { |
|
66 | + $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', |
|
67 | + ['app' => 'core', 'class' => $sorter]); |
|
68 | + continue; |
|
69 | + } |
|
70 | + $sorterId = trim($instance->getId()); |
|
71 | + if(trim($sorterId) === '') { |
|
72 | + $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', |
|
73 | + ['app' => 'core', 'class' => $sorter]); |
|
74 | + continue; |
|
75 | + } |
|
76 | + $this->sorterInstances[$sorterId] = $instance; |
|
77 | + } |
|
78 | + } |
|
79 | + return $this->sorterInstances; |
|
80 | + } |
|
81 | 81 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | class Manager implements IManager { |
31 | 31 | /** @var string[] */ |
32 | - protected $sorters =[]; |
|
32 | + protected $sorters = []; |
|
33 | 33 | |
34 | 34 | /** @var ISorter[] */ |
35 | 35 | protected $sorterInstances = []; |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | |
43 | 43 | public function runSorters(array $sorters, array &$sortArray, array $context) { |
44 | 44 | $sorterInstances = $this->getSorters(); |
45 | - while($sorter = array_shift($sorters)) { |
|
46 | - if(isset($sorterInstances[$sorter])) { |
|
45 | + while ($sorter = array_shift($sorters)) { |
|
46 | + if (isset($sorterInstances[$sorter])) { |
|
47 | 47 | $sorterInstances[$sorter]->sort($sortArray, $context); |
48 | 48 | } else { |
49 | 49 | $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ |
@@ -58,17 +58,17 @@ discard block |
||
58 | 58 | } |
59 | 59 | |
60 | 60 | protected function getSorters() { |
61 | - if(count($this->sorterInstances) === 0) { |
|
61 | + if (count($this->sorterInstances) === 0) { |
|
62 | 62 | foreach ($this->sorters as $sorter) { |
63 | 63 | /** @var ISorter $instance */ |
64 | 64 | $instance = $this->c->resolve($sorter); |
65 | - if(!$instance instanceof ISorter) { |
|
65 | + if (!$instance instanceof ISorter) { |
|
66 | 66 | $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', |
67 | 67 | ['app' => 'core', 'class' => $sorter]); |
68 | 68 | continue; |
69 | 69 | } |
70 | 70 | $sorterId = trim($instance->getId()); |
71 | - if(trim($sorterId) === '') { |
|
71 | + if (trim($sorterId) === '') { |
|
72 | 72 | $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', |
73 | 73 | ['app' => 'core', 'class' => $sorter]); |
74 | 74 | continue; |
@@ -132,1723 +132,1723 @@ |
||
132 | 132 | * TODO: hookup all manager classes |
133 | 133 | */ |
134 | 134 | class Server extends ServerContainer implements IServerContainer { |
135 | - /** @var string */ |
|
136 | - private $webRoot; |
|
137 | - |
|
138 | - /** |
|
139 | - * @param string $webRoot |
|
140 | - * @param \OC\Config $config |
|
141 | - */ |
|
142 | - public function __construct($webRoot, \OC\Config $config) { |
|
143 | - parent::__construct(); |
|
144 | - $this->webRoot = $webRoot; |
|
145 | - |
|
146 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
147 | - return $c; |
|
148 | - }); |
|
149 | - |
|
150 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
151 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
152 | - |
|
153 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
154 | - |
|
155 | - |
|
156 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
157 | - return new PreviewManager( |
|
158 | - $c->getConfig(), |
|
159 | - $c->getRootFolder(), |
|
160 | - $c->getAppDataDir('preview'), |
|
161 | - $c->getEventDispatcher(), |
|
162 | - $c->getSession()->get('user_id') |
|
163 | - ); |
|
164 | - }); |
|
165 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
166 | - |
|
167 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
168 | - return new \OC\Preview\Watcher( |
|
169 | - $c->getAppDataDir('preview') |
|
170 | - ); |
|
171 | - }); |
|
172 | - |
|
173 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
174 | - $view = new View(); |
|
175 | - $util = new Encryption\Util( |
|
176 | - $view, |
|
177 | - $c->getUserManager(), |
|
178 | - $c->getGroupManager(), |
|
179 | - $c->getConfig() |
|
180 | - ); |
|
181 | - return new Encryption\Manager( |
|
182 | - $c->getConfig(), |
|
183 | - $c->getLogger(), |
|
184 | - $c->getL10N('core'), |
|
185 | - new View(), |
|
186 | - $util, |
|
187 | - new ArrayCache() |
|
188 | - ); |
|
189 | - }); |
|
190 | - |
|
191 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
192 | - $util = new Encryption\Util( |
|
193 | - new View(), |
|
194 | - $c->getUserManager(), |
|
195 | - $c->getGroupManager(), |
|
196 | - $c->getConfig() |
|
197 | - ); |
|
198 | - return new Encryption\File( |
|
199 | - $util, |
|
200 | - $c->getRootFolder(), |
|
201 | - $c->getShareManager() |
|
202 | - ); |
|
203 | - }); |
|
204 | - |
|
205 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
206 | - $view = new View(); |
|
207 | - $util = new Encryption\Util( |
|
208 | - $view, |
|
209 | - $c->getUserManager(), |
|
210 | - $c->getGroupManager(), |
|
211 | - $c->getConfig() |
|
212 | - ); |
|
213 | - |
|
214 | - return new Encryption\Keys\Storage($view, $util); |
|
215 | - }); |
|
216 | - $this->registerService('TagMapper', function (Server $c) { |
|
217 | - return new TagMapper($c->getDatabaseConnection()); |
|
218 | - }); |
|
219 | - |
|
220 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
221 | - $tagMapper = $c->query('TagMapper'); |
|
222 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
223 | - }); |
|
224 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
225 | - |
|
226 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
227 | - $config = $c->getConfig(); |
|
228 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
229 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
230 | - $factory = new $factoryClass($this); |
|
231 | - return $factory; |
|
232 | - }); |
|
233 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
234 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
235 | - }); |
|
236 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
237 | - |
|
238 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
239 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
240 | - }); |
|
241 | - $this->registerService('RootFolder', function (Server $c) { |
|
242 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
243 | - $view = new View(); |
|
244 | - $root = new Root( |
|
245 | - $manager, |
|
246 | - $view, |
|
247 | - null, |
|
248 | - $c->getUserMountCache(), |
|
249 | - $this->getLogger(), |
|
250 | - $this->getUserManager() |
|
251 | - ); |
|
252 | - $connector = new HookConnector($root, $view); |
|
253 | - $connector->viewToNode(); |
|
254 | - |
|
255 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
256 | - $previewConnector->connectWatcher(); |
|
257 | - |
|
258 | - return $root; |
|
259 | - }); |
|
260 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
261 | - |
|
262 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
263 | - return new LazyRoot(function () use ($c) { |
|
264 | - return $c->query('RootFolder'); |
|
265 | - }); |
|
266 | - }); |
|
267 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
268 | - |
|
269 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
270 | - $config = $c->getConfig(); |
|
271 | - return new \OC\User\Manager($config); |
|
272 | - }); |
|
273 | - $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
274 | - |
|
275 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
276 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
277 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
278 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
279 | - }); |
|
280 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
281 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
282 | - }); |
|
283 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
284 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
285 | - }); |
|
286 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
287 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
288 | - }); |
|
289 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
290 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
291 | - }); |
|
292 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
293 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
294 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
295 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
296 | - }); |
|
297 | - return $groupManager; |
|
298 | - }); |
|
299 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
300 | - |
|
301 | - $this->registerService(Store::class, function (Server $c) { |
|
302 | - $session = $c->getSession(); |
|
303 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
304 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
305 | - } else { |
|
306 | - $tokenProvider = null; |
|
307 | - } |
|
308 | - $logger = $c->getLogger(); |
|
309 | - return new Store($session, $logger, $tokenProvider); |
|
310 | - }); |
|
311 | - $this->registerAlias(IStore::class, Store::class); |
|
312 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
313 | - $dbConnection = $c->getDatabaseConnection(); |
|
314 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
315 | - }); |
|
316 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
317 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
318 | - $crypto = $c->getCrypto(); |
|
319 | - $config = $c->getConfig(); |
|
320 | - $logger = $c->getLogger(); |
|
321 | - $timeFactory = new TimeFactory(); |
|
322 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
323 | - }); |
|
324 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
325 | - |
|
326 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
327 | - $manager = $c->getUserManager(); |
|
328 | - $session = new \OC\Session\Memory(''); |
|
329 | - $timeFactory = new TimeFactory(); |
|
330 | - // Token providers might require a working database. This code |
|
331 | - // might however be called when ownCloud is not yet setup. |
|
332 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
333 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
334 | - } else { |
|
335 | - $defaultTokenProvider = null; |
|
336 | - } |
|
337 | - |
|
338 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
339 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
340 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
341 | - }); |
|
342 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
343 | - /** @var $user \OC\User\User */ |
|
344 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
345 | - }); |
|
346 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
347 | - /** @var $user \OC\User\User */ |
|
348 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
349 | - }); |
|
350 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
351 | - /** @var $user \OC\User\User */ |
|
352 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
353 | - }); |
|
354 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
355 | - /** @var $user \OC\User\User */ |
|
356 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
357 | - }); |
|
358 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
359 | - /** @var $user \OC\User\User */ |
|
360 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
361 | - }); |
|
362 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
363 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
364 | - }); |
|
365 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
366 | - /** @var $user \OC\User\User */ |
|
367 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
368 | - }); |
|
369 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
370 | - /** @var $user \OC\User\User */ |
|
371 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
372 | - }); |
|
373 | - $userSession->listen('\OC\User', 'logout', function () { |
|
374 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
375 | - }); |
|
376 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
377 | - /** @var $user \OC\User\User */ |
|
378 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
379 | - }); |
|
380 | - return $userSession; |
|
381 | - }); |
|
382 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
383 | - |
|
384 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
385 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
386 | - $c->getAppManager(), |
|
387 | - $c->getSession(), |
|
388 | - $c->getConfig(), |
|
389 | - $c->getActivityManager(), |
|
390 | - $c->getLogger(), |
|
391 | - $c->query(\OC\Authentication\Token\IProvider::class), |
|
392 | - $c->query(ITimeFactory::class) |
|
393 | - ); |
|
394 | - }); |
|
395 | - |
|
396 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
397 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
398 | - |
|
399 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
400 | - return new \OC\AllConfig( |
|
401 | - $c->getSystemConfig() |
|
402 | - ); |
|
403 | - }); |
|
404 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
405 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
406 | - |
|
407 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
408 | - return new \OC\SystemConfig($config); |
|
409 | - }); |
|
410 | - |
|
411 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
412 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
413 | - }); |
|
414 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
415 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
416 | - |
|
417 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
418 | - return new \OC\L10N\Factory( |
|
419 | - $c->getConfig(), |
|
420 | - $c->getRequest(), |
|
421 | - $c->getUserSession(), |
|
422 | - \OC::$SERVERROOT |
|
423 | - ); |
|
424 | - }); |
|
425 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
426 | - |
|
427 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
428 | - $config = $c->getConfig(); |
|
429 | - $cacheFactory = $c->getMemCacheFactory(); |
|
430 | - $request = $c->getRequest(); |
|
431 | - return new \OC\URLGenerator( |
|
432 | - $config, |
|
433 | - $cacheFactory, |
|
434 | - $request |
|
435 | - ); |
|
436 | - }); |
|
437 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
438 | - |
|
439 | - $this->registerService('AppHelper', function ($c) { |
|
440 | - return new \OC\AppHelper(); |
|
441 | - }); |
|
442 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
443 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
444 | - |
|
445 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
446 | - return new Cache\File(); |
|
447 | - }); |
|
448 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
449 | - |
|
450 | - $this->registerService(Factory::class, function (Server $c) { |
|
451 | - |
|
452 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
453 | - '\\OC\\Memcache\\ArrayCache', |
|
454 | - '\\OC\\Memcache\\ArrayCache', |
|
455 | - '\\OC\\Memcache\\ArrayCache' |
|
456 | - ); |
|
457 | - $config = $c->getConfig(); |
|
458 | - $request = $c->getRequest(); |
|
459 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
460 | - |
|
461 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
462 | - $v = \OC_App::getAppVersions(); |
|
463 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
464 | - $version = implode(',', $v); |
|
465 | - $instanceId = \OC_Util::getInstanceId(); |
|
466 | - $path = \OC::$SERVERROOT; |
|
467 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
468 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
469 | - $config->getSystemValue('memcache.local', null), |
|
470 | - $config->getSystemValue('memcache.distributed', null), |
|
471 | - $config->getSystemValue('memcache.locking', null) |
|
472 | - ); |
|
473 | - } |
|
474 | - return $arrayCacheFactory; |
|
475 | - |
|
476 | - }); |
|
477 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
478 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
479 | - |
|
480 | - $this->registerService('RedisFactory', function (Server $c) { |
|
481 | - $systemConfig = $c->getSystemConfig(); |
|
482 | - return new RedisFactory($systemConfig); |
|
483 | - }); |
|
484 | - |
|
485 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
486 | - return new \OC\Activity\Manager( |
|
487 | - $c->getRequest(), |
|
488 | - $c->getUserSession(), |
|
489 | - $c->getConfig(), |
|
490 | - $c->query(IValidator::class) |
|
491 | - ); |
|
492 | - }); |
|
493 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
494 | - |
|
495 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
496 | - return new \OC\Activity\EventMerger( |
|
497 | - $c->getL10N('lib') |
|
498 | - ); |
|
499 | - }); |
|
500 | - $this->registerAlias(IValidator::class, Validator::class); |
|
501 | - |
|
502 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
503 | - return new AvatarManager( |
|
504 | - $c->getUserManager(), |
|
505 | - $c->getAppDataDir('avatar'), |
|
506 | - $c->getL10N('lib'), |
|
507 | - $c->getLogger(), |
|
508 | - $c->getConfig() |
|
509 | - ); |
|
510 | - }); |
|
511 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
512 | - |
|
513 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
514 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
515 | - $logger = Log::getLogClass($logType); |
|
516 | - call_user_func(array($logger, 'init')); |
|
517 | - |
|
518 | - return new Log($logger); |
|
519 | - }); |
|
520 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
521 | - |
|
522 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
523 | - $config = $c->getConfig(); |
|
524 | - return new \OC\BackgroundJob\JobList( |
|
525 | - $c->getDatabaseConnection(), |
|
526 | - $config, |
|
527 | - new TimeFactory() |
|
528 | - ); |
|
529 | - }); |
|
530 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
531 | - |
|
532 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
533 | - $cacheFactory = $c->getMemCacheFactory(); |
|
534 | - $logger = $c->getLogger(); |
|
535 | - if ($cacheFactory->isAvailable()) { |
|
536 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
537 | - } else { |
|
538 | - $router = new \OC\Route\Router($logger); |
|
539 | - } |
|
540 | - return $router; |
|
541 | - }); |
|
542 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
543 | - |
|
544 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
545 | - return new Search(); |
|
546 | - }); |
|
547 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
548 | - |
|
549 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
550 | - return new \OC\Security\RateLimiting\Limiter( |
|
551 | - $this->getUserSession(), |
|
552 | - $this->getRequest(), |
|
553 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
554 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
555 | - ); |
|
556 | - }); |
|
557 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
558 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
559 | - $this->getMemCacheFactory(), |
|
560 | - new \OC\AppFramework\Utility\TimeFactory() |
|
561 | - ); |
|
562 | - }); |
|
563 | - |
|
564 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
565 | - return new SecureRandom(); |
|
566 | - }); |
|
567 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
568 | - |
|
569 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
570 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
571 | - }); |
|
572 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
573 | - |
|
574 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
575 | - return new Hasher($c->getConfig()); |
|
576 | - }); |
|
577 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
578 | - |
|
579 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
580 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
581 | - }); |
|
582 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
583 | - |
|
584 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
585 | - $systemConfig = $c->getSystemConfig(); |
|
586 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
587 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
588 | - if (!$factory->isValidType($type)) { |
|
589 | - throw new \OC\DatabaseException('Invalid database type'); |
|
590 | - } |
|
591 | - $connectionParams = $factory->createConnectionParams(); |
|
592 | - $connection = $factory->getConnection($type, $connectionParams); |
|
593 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
594 | - return $connection; |
|
595 | - }); |
|
596 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
597 | - |
|
598 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
599 | - $config = $c->getConfig(); |
|
600 | - return new HTTPHelper( |
|
601 | - $config, |
|
602 | - $c->getHTTPClientService() |
|
603 | - ); |
|
604 | - }); |
|
605 | - |
|
606 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
607 | - $user = \OC_User::getUser(); |
|
608 | - $uid = $user ? $user : null; |
|
609 | - return new ClientService( |
|
610 | - $c->getConfig(), |
|
611 | - new \OC\Security\CertificateManager( |
|
612 | - $uid, |
|
613 | - new View(), |
|
614 | - $c->getConfig(), |
|
615 | - $c->getLogger(), |
|
616 | - $c->getSecureRandom() |
|
617 | - ) |
|
618 | - ); |
|
619 | - }); |
|
620 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
621 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
622 | - $eventLogger = new EventLogger(); |
|
623 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
624 | - // In debug mode, module is being activated by default |
|
625 | - $eventLogger->activate(); |
|
626 | - } |
|
627 | - return $eventLogger; |
|
628 | - }); |
|
629 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
630 | - |
|
631 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
632 | - $queryLogger = new QueryLogger(); |
|
633 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
634 | - // In debug mode, module is being activated by default |
|
635 | - $queryLogger->activate(); |
|
636 | - } |
|
637 | - return $queryLogger; |
|
638 | - }); |
|
639 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
640 | - |
|
641 | - $this->registerService(TempManager::class, function (Server $c) { |
|
642 | - return new TempManager( |
|
643 | - $c->getLogger(), |
|
644 | - $c->getConfig() |
|
645 | - ); |
|
646 | - }); |
|
647 | - $this->registerAlias('TempManager', TempManager::class); |
|
648 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
649 | - |
|
650 | - $this->registerService(AppManager::class, function (Server $c) { |
|
651 | - return new \OC\App\AppManager( |
|
652 | - $c->getUserSession(), |
|
653 | - $c->getAppConfig(), |
|
654 | - $c->getGroupManager(), |
|
655 | - $c->getMemCacheFactory(), |
|
656 | - $c->getEventDispatcher() |
|
657 | - ); |
|
658 | - }); |
|
659 | - $this->registerAlias('AppManager', AppManager::class); |
|
660 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
661 | - |
|
662 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
663 | - return new DateTimeZone( |
|
664 | - $c->getConfig(), |
|
665 | - $c->getSession() |
|
666 | - ); |
|
667 | - }); |
|
668 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
669 | - |
|
670 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
671 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
672 | - |
|
673 | - return new DateTimeFormatter( |
|
674 | - $c->getDateTimeZone()->getTimeZone(), |
|
675 | - $c->getL10N('lib', $language) |
|
676 | - ); |
|
677 | - }); |
|
678 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
679 | - |
|
680 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
681 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
682 | - $listener = new UserMountCacheListener($mountCache); |
|
683 | - $listener->listen($c->getUserManager()); |
|
684 | - return $mountCache; |
|
685 | - }); |
|
686 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
687 | - |
|
688 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
689 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
690 | - $mountCache = $c->query('UserMountCache'); |
|
691 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
692 | - |
|
693 | - // builtin providers |
|
694 | - |
|
695 | - $config = $c->getConfig(); |
|
696 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
697 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
698 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
699 | - |
|
700 | - return $manager; |
|
701 | - }); |
|
702 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
703 | - |
|
704 | - $this->registerService('IniWrapper', function ($c) { |
|
705 | - return new IniGetWrapper(); |
|
706 | - }); |
|
707 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
708 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
709 | - if ($busClass) { |
|
710 | - list($app, $class) = explode('::', $busClass, 2); |
|
711 | - if ($c->getAppManager()->isInstalled($app)) { |
|
712 | - \OC_App::loadApp($app); |
|
713 | - return $c->query($class); |
|
714 | - } else { |
|
715 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
716 | - } |
|
717 | - } else { |
|
718 | - $jobList = $c->getJobList(); |
|
719 | - return new CronBus($jobList); |
|
720 | - } |
|
721 | - }); |
|
722 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
723 | - return new TrustedDomainHelper($this->getConfig()); |
|
724 | - }); |
|
725 | - $this->registerService('Throttler', function (Server $c) { |
|
726 | - return new Throttler( |
|
727 | - $c->getDatabaseConnection(), |
|
728 | - new TimeFactory(), |
|
729 | - $c->getLogger(), |
|
730 | - $c->getConfig() |
|
731 | - ); |
|
732 | - }); |
|
733 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
734 | - // IConfig and IAppManager requires a working database. This code |
|
735 | - // might however be called when ownCloud is not yet setup. |
|
736 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
737 | - $config = $c->getConfig(); |
|
738 | - $appManager = $c->getAppManager(); |
|
739 | - } else { |
|
740 | - $config = null; |
|
741 | - $appManager = null; |
|
742 | - } |
|
743 | - |
|
744 | - return new Checker( |
|
745 | - new EnvironmentHelper(), |
|
746 | - new FileAccessHelper(), |
|
747 | - new AppLocator(), |
|
748 | - $config, |
|
749 | - $c->getMemCacheFactory(), |
|
750 | - $appManager, |
|
751 | - $c->getTempManager() |
|
752 | - ); |
|
753 | - }); |
|
754 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
755 | - if (isset($this['urlParams'])) { |
|
756 | - $urlParams = $this['urlParams']; |
|
757 | - } else { |
|
758 | - $urlParams = []; |
|
759 | - } |
|
760 | - |
|
761 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
762 | - && in_array('fakeinput', stream_get_wrappers()) |
|
763 | - ) { |
|
764 | - $stream = 'fakeinput://data'; |
|
765 | - } else { |
|
766 | - $stream = 'php://input'; |
|
767 | - } |
|
768 | - |
|
769 | - return new Request( |
|
770 | - [ |
|
771 | - 'get' => $_GET, |
|
772 | - 'post' => $_POST, |
|
773 | - 'files' => $_FILES, |
|
774 | - 'server' => $_SERVER, |
|
775 | - 'env' => $_ENV, |
|
776 | - 'cookies' => $_COOKIE, |
|
777 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
778 | - ? $_SERVER['REQUEST_METHOD'] |
|
779 | - : null, |
|
780 | - 'urlParams' => $urlParams, |
|
781 | - ], |
|
782 | - $this->getSecureRandom(), |
|
783 | - $this->getConfig(), |
|
784 | - $this->getCsrfTokenManager(), |
|
785 | - $stream |
|
786 | - ); |
|
787 | - }); |
|
788 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
789 | - |
|
790 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
791 | - return new Mailer( |
|
792 | - $c->getConfig(), |
|
793 | - $c->getLogger(), |
|
794 | - $c->query(Defaults::class), |
|
795 | - $c->getURLGenerator(), |
|
796 | - $c->getL10N('lib') |
|
797 | - ); |
|
798 | - }); |
|
799 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
800 | - |
|
801 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
802 | - $config = $c->getConfig(); |
|
803 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
804 | - if (is_null($factoryClass)) { |
|
805 | - throw new \Exception('ldapProviderFactory not set'); |
|
806 | - } |
|
807 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
808 | - $factory = new $factoryClass($this); |
|
809 | - return $factory->getLDAPProvider(); |
|
810 | - }); |
|
811 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
812 | - $ini = $c->getIniWrapper(); |
|
813 | - $config = $c->getConfig(); |
|
814 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
815 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
816 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
817 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
818 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
819 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
820 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
821 | - } |
|
822 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
823 | - } |
|
824 | - return new NoopLockingProvider(); |
|
825 | - }); |
|
826 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
827 | - |
|
828 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
829 | - return new \OC\Files\Mount\Manager(); |
|
830 | - }); |
|
831 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
832 | - |
|
833 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
834 | - return new \OC\Files\Type\Detection( |
|
835 | - $c->getURLGenerator(), |
|
836 | - \OC::$configDir, |
|
837 | - \OC::$SERVERROOT . '/resources/config/' |
|
838 | - ); |
|
839 | - }); |
|
840 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
841 | - |
|
842 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
843 | - return new \OC\Files\Type\Loader( |
|
844 | - $c->getDatabaseConnection() |
|
845 | - ); |
|
846 | - }); |
|
847 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
848 | - $this->registerService(BundleFetcher::class, function () { |
|
849 | - return new BundleFetcher($this->getL10N('lib')); |
|
850 | - }); |
|
851 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
852 | - return new Manager( |
|
853 | - $c->query(IValidator::class) |
|
854 | - ); |
|
855 | - }); |
|
856 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
857 | - |
|
858 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
859 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
860 | - $manager->registerCapability(function () use ($c) { |
|
861 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
862 | - }); |
|
863 | - $manager->registerCapability(function () use ($c) { |
|
864 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
865 | - }); |
|
866 | - return $manager; |
|
867 | - }); |
|
868 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
869 | - |
|
870 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
871 | - $config = $c->getConfig(); |
|
872 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
873 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
874 | - $factory = new $factoryClass($this); |
|
875 | - return $factory->getManager(); |
|
876 | - }); |
|
877 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
878 | - |
|
879 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
880 | - /* |
|
135 | + /** @var string */ |
|
136 | + private $webRoot; |
|
137 | + |
|
138 | + /** |
|
139 | + * @param string $webRoot |
|
140 | + * @param \OC\Config $config |
|
141 | + */ |
|
142 | + public function __construct($webRoot, \OC\Config $config) { |
|
143 | + parent::__construct(); |
|
144 | + $this->webRoot = $webRoot; |
|
145 | + |
|
146 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
147 | + return $c; |
|
148 | + }); |
|
149 | + |
|
150 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
151 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
152 | + |
|
153 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
154 | + |
|
155 | + |
|
156 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
157 | + return new PreviewManager( |
|
158 | + $c->getConfig(), |
|
159 | + $c->getRootFolder(), |
|
160 | + $c->getAppDataDir('preview'), |
|
161 | + $c->getEventDispatcher(), |
|
162 | + $c->getSession()->get('user_id') |
|
163 | + ); |
|
164 | + }); |
|
165 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
166 | + |
|
167 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
168 | + return new \OC\Preview\Watcher( |
|
169 | + $c->getAppDataDir('preview') |
|
170 | + ); |
|
171 | + }); |
|
172 | + |
|
173 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
174 | + $view = new View(); |
|
175 | + $util = new Encryption\Util( |
|
176 | + $view, |
|
177 | + $c->getUserManager(), |
|
178 | + $c->getGroupManager(), |
|
179 | + $c->getConfig() |
|
180 | + ); |
|
181 | + return new Encryption\Manager( |
|
182 | + $c->getConfig(), |
|
183 | + $c->getLogger(), |
|
184 | + $c->getL10N('core'), |
|
185 | + new View(), |
|
186 | + $util, |
|
187 | + new ArrayCache() |
|
188 | + ); |
|
189 | + }); |
|
190 | + |
|
191 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
192 | + $util = new Encryption\Util( |
|
193 | + new View(), |
|
194 | + $c->getUserManager(), |
|
195 | + $c->getGroupManager(), |
|
196 | + $c->getConfig() |
|
197 | + ); |
|
198 | + return new Encryption\File( |
|
199 | + $util, |
|
200 | + $c->getRootFolder(), |
|
201 | + $c->getShareManager() |
|
202 | + ); |
|
203 | + }); |
|
204 | + |
|
205 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
206 | + $view = new View(); |
|
207 | + $util = new Encryption\Util( |
|
208 | + $view, |
|
209 | + $c->getUserManager(), |
|
210 | + $c->getGroupManager(), |
|
211 | + $c->getConfig() |
|
212 | + ); |
|
213 | + |
|
214 | + return new Encryption\Keys\Storage($view, $util); |
|
215 | + }); |
|
216 | + $this->registerService('TagMapper', function (Server $c) { |
|
217 | + return new TagMapper($c->getDatabaseConnection()); |
|
218 | + }); |
|
219 | + |
|
220 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
221 | + $tagMapper = $c->query('TagMapper'); |
|
222 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
223 | + }); |
|
224 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
225 | + |
|
226 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
227 | + $config = $c->getConfig(); |
|
228 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
229 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
230 | + $factory = new $factoryClass($this); |
|
231 | + return $factory; |
|
232 | + }); |
|
233 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
234 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
235 | + }); |
|
236 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
237 | + |
|
238 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
239 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
240 | + }); |
|
241 | + $this->registerService('RootFolder', function (Server $c) { |
|
242 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
243 | + $view = new View(); |
|
244 | + $root = new Root( |
|
245 | + $manager, |
|
246 | + $view, |
|
247 | + null, |
|
248 | + $c->getUserMountCache(), |
|
249 | + $this->getLogger(), |
|
250 | + $this->getUserManager() |
|
251 | + ); |
|
252 | + $connector = new HookConnector($root, $view); |
|
253 | + $connector->viewToNode(); |
|
254 | + |
|
255 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
256 | + $previewConnector->connectWatcher(); |
|
257 | + |
|
258 | + return $root; |
|
259 | + }); |
|
260 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
261 | + |
|
262 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
263 | + return new LazyRoot(function () use ($c) { |
|
264 | + return $c->query('RootFolder'); |
|
265 | + }); |
|
266 | + }); |
|
267 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
268 | + |
|
269 | + $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
270 | + $config = $c->getConfig(); |
|
271 | + return new \OC\User\Manager($config); |
|
272 | + }); |
|
273 | + $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
274 | + |
|
275 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
276 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
277 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
278 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
279 | + }); |
|
280 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
281 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
282 | + }); |
|
283 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
284 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
285 | + }); |
|
286 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
287 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
288 | + }); |
|
289 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
290 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
291 | + }); |
|
292 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
293 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
294 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
295 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
296 | + }); |
|
297 | + return $groupManager; |
|
298 | + }); |
|
299 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
300 | + |
|
301 | + $this->registerService(Store::class, function (Server $c) { |
|
302 | + $session = $c->getSession(); |
|
303 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
304 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
305 | + } else { |
|
306 | + $tokenProvider = null; |
|
307 | + } |
|
308 | + $logger = $c->getLogger(); |
|
309 | + return new Store($session, $logger, $tokenProvider); |
|
310 | + }); |
|
311 | + $this->registerAlias(IStore::class, Store::class); |
|
312 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
313 | + $dbConnection = $c->getDatabaseConnection(); |
|
314 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
315 | + }); |
|
316 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
317 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
318 | + $crypto = $c->getCrypto(); |
|
319 | + $config = $c->getConfig(); |
|
320 | + $logger = $c->getLogger(); |
|
321 | + $timeFactory = new TimeFactory(); |
|
322 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
323 | + }); |
|
324 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
325 | + |
|
326 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
327 | + $manager = $c->getUserManager(); |
|
328 | + $session = new \OC\Session\Memory(''); |
|
329 | + $timeFactory = new TimeFactory(); |
|
330 | + // Token providers might require a working database. This code |
|
331 | + // might however be called when ownCloud is not yet setup. |
|
332 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
333 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
334 | + } else { |
|
335 | + $defaultTokenProvider = null; |
|
336 | + } |
|
337 | + |
|
338 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
339 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
340 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
341 | + }); |
|
342 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
343 | + /** @var $user \OC\User\User */ |
|
344 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
345 | + }); |
|
346 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
347 | + /** @var $user \OC\User\User */ |
|
348 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
349 | + }); |
|
350 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
351 | + /** @var $user \OC\User\User */ |
|
352 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
353 | + }); |
|
354 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
355 | + /** @var $user \OC\User\User */ |
|
356 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
357 | + }); |
|
358 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
359 | + /** @var $user \OC\User\User */ |
|
360 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
361 | + }); |
|
362 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
363 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
364 | + }); |
|
365 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
366 | + /** @var $user \OC\User\User */ |
|
367 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
368 | + }); |
|
369 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
370 | + /** @var $user \OC\User\User */ |
|
371 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
372 | + }); |
|
373 | + $userSession->listen('\OC\User', 'logout', function () { |
|
374 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
375 | + }); |
|
376 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
377 | + /** @var $user \OC\User\User */ |
|
378 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
379 | + }); |
|
380 | + return $userSession; |
|
381 | + }); |
|
382 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
383 | + |
|
384 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
385 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
386 | + $c->getAppManager(), |
|
387 | + $c->getSession(), |
|
388 | + $c->getConfig(), |
|
389 | + $c->getActivityManager(), |
|
390 | + $c->getLogger(), |
|
391 | + $c->query(\OC\Authentication\Token\IProvider::class), |
|
392 | + $c->query(ITimeFactory::class) |
|
393 | + ); |
|
394 | + }); |
|
395 | + |
|
396 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
397 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
398 | + |
|
399 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
400 | + return new \OC\AllConfig( |
|
401 | + $c->getSystemConfig() |
|
402 | + ); |
|
403 | + }); |
|
404 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
405 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
406 | + |
|
407 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
408 | + return new \OC\SystemConfig($config); |
|
409 | + }); |
|
410 | + |
|
411 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
412 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
413 | + }); |
|
414 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
415 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
416 | + |
|
417 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
418 | + return new \OC\L10N\Factory( |
|
419 | + $c->getConfig(), |
|
420 | + $c->getRequest(), |
|
421 | + $c->getUserSession(), |
|
422 | + \OC::$SERVERROOT |
|
423 | + ); |
|
424 | + }); |
|
425 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
426 | + |
|
427 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
428 | + $config = $c->getConfig(); |
|
429 | + $cacheFactory = $c->getMemCacheFactory(); |
|
430 | + $request = $c->getRequest(); |
|
431 | + return new \OC\URLGenerator( |
|
432 | + $config, |
|
433 | + $cacheFactory, |
|
434 | + $request |
|
435 | + ); |
|
436 | + }); |
|
437 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
438 | + |
|
439 | + $this->registerService('AppHelper', function ($c) { |
|
440 | + return new \OC\AppHelper(); |
|
441 | + }); |
|
442 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
443 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
444 | + |
|
445 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
446 | + return new Cache\File(); |
|
447 | + }); |
|
448 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
449 | + |
|
450 | + $this->registerService(Factory::class, function (Server $c) { |
|
451 | + |
|
452 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
453 | + '\\OC\\Memcache\\ArrayCache', |
|
454 | + '\\OC\\Memcache\\ArrayCache', |
|
455 | + '\\OC\\Memcache\\ArrayCache' |
|
456 | + ); |
|
457 | + $config = $c->getConfig(); |
|
458 | + $request = $c->getRequest(); |
|
459 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
460 | + |
|
461 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
462 | + $v = \OC_App::getAppVersions(); |
|
463 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
464 | + $version = implode(',', $v); |
|
465 | + $instanceId = \OC_Util::getInstanceId(); |
|
466 | + $path = \OC::$SERVERROOT; |
|
467 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
468 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
469 | + $config->getSystemValue('memcache.local', null), |
|
470 | + $config->getSystemValue('memcache.distributed', null), |
|
471 | + $config->getSystemValue('memcache.locking', null) |
|
472 | + ); |
|
473 | + } |
|
474 | + return $arrayCacheFactory; |
|
475 | + |
|
476 | + }); |
|
477 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
478 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
479 | + |
|
480 | + $this->registerService('RedisFactory', function (Server $c) { |
|
481 | + $systemConfig = $c->getSystemConfig(); |
|
482 | + return new RedisFactory($systemConfig); |
|
483 | + }); |
|
484 | + |
|
485 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
486 | + return new \OC\Activity\Manager( |
|
487 | + $c->getRequest(), |
|
488 | + $c->getUserSession(), |
|
489 | + $c->getConfig(), |
|
490 | + $c->query(IValidator::class) |
|
491 | + ); |
|
492 | + }); |
|
493 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
494 | + |
|
495 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
496 | + return new \OC\Activity\EventMerger( |
|
497 | + $c->getL10N('lib') |
|
498 | + ); |
|
499 | + }); |
|
500 | + $this->registerAlias(IValidator::class, Validator::class); |
|
501 | + |
|
502 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
503 | + return new AvatarManager( |
|
504 | + $c->getUserManager(), |
|
505 | + $c->getAppDataDir('avatar'), |
|
506 | + $c->getL10N('lib'), |
|
507 | + $c->getLogger(), |
|
508 | + $c->getConfig() |
|
509 | + ); |
|
510 | + }); |
|
511 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
512 | + |
|
513 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
514 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
515 | + $logger = Log::getLogClass($logType); |
|
516 | + call_user_func(array($logger, 'init')); |
|
517 | + |
|
518 | + return new Log($logger); |
|
519 | + }); |
|
520 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
521 | + |
|
522 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
523 | + $config = $c->getConfig(); |
|
524 | + return new \OC\BackgroundJob\JobList( |
|
525 | + $c->getDatabaseConnection(), |
|
526 | + $config, |
|
527 | + new TimeFactory() |
|
528 | + ); |
|
529 | + }); |
|
530 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
531 | + |
|
532 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
533 | + $cacheFactory = $c->getMemCacheFactory(); |
|
534 | + $logger = $c->getLogger(); |
|
535 | + if ($cacheFactory->isAvailable()) { |
|
536 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
537 | + } else { |
|
538 | + $router = new \OC\Route\Router($logger); |
|
539 | + } |
|
540 | + return $router; |
|
541 | + }); |
|
542 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
543 | + |
|
544 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
545 | + return new Search(); |
|
546 | + }); |
|
547 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
548 | + |
|
549 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
550 | + return new \OC\Security\RateLimiting\Limiter( |
|
551 | + $this->getUserSession(), |
|
552 | + $this->getRequest(), |
|
553 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
554 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
555 | + ); |
|
556 | + }); |
|
557 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
558 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
559 | + $this->getMemCacheFactory(), |
|
560 | + new \OC\AppFramework\Utility\TimeFactory() |
|
561 | + ); |
|
562 | + }); |
|
563 | + |
|
564 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
565 | + return new SecureRandom(); |
|
566 | + }); |
|
567 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
568 | + |
|
569 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
570 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
571 | + }); |
|
572 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
573 | + |
|
574 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
575 | + return new Hasher($c->getConfig()); |
|
576 | + }); |
|
577 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
578 | + |
|
579 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
580 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
581 | + }); |
|
582 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
583 | + |
|
584 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
585 | + $systemConfig = $c->getSystemConfig(); |
|
586 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
587 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
588 | + if (!$factory->isValidType($type)) { |
|
589 | + throw new \OC\DatabaseException('Invalid database type'); |
|
590 | + } |
|
591 | + $connectionParams = $factory->createConnectionParams(); |
|
592 | + $connection = $factory->getConnection($type, $connectionParams); |
|
593 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
594 | + return $connection; |
|
595 | + }); |
|
596 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
597 | + |
|
598 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
599 | + $config = $c->getConfig(); |
|
600 | + return new HTTPHelper( |
|
601 | + $config, |
|
602 | + $c->getHTTPClientService() |
|
603 | + ); |
|
604 | + }); |
|
605 | + |
|
606 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
607 | + $user = \OC_User::getUser(); |
|
608 | + $uid = $user ? $user : null; |
|
609 | + return new ClientService( |
|
610 | + $c->getConfig(), |
|
611 | + new \OC\Security\CertificateManager( |
|
612 | + $uid, |
|
613 | + new View(), |
|
614 | + $c->getConfig(), |
|
615 | + $c->getLogger(), |
|
616 | + $c->getSecureRandom() |
|
617 | + ) |
|
618 | + ); |
|
619 | + }); |
|
620 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
621 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
622 | + $eventLogger = new EventLogger(); |
|
623 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
624 | + // In debug mode, module is being activated by default |
|
625 | + $eventLogger->activate(); |
|
626 | + } |
|
627 | + return $eventLogger; |
|
628 | + }); |
|
629 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
630 | + |
|
631 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
632 | + $queryLogger = new QueryLogger(); |
|
633 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
634 | + // In debug mode, module is being activated by default |
|
635 | + $queryLogger->activate(); |
|
636 | + } |
|
637 | + return $queryLogger; |
|
638 | + }); |
|
639 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
640 | + |
|
641 | + $this->registerService(TempManager::class, function (Server $c) { |
|
642 | + return new TempManager( |
|
643 | + $c->getLogger(), |
|
644 | + $c->getConfig() |
|
645 | + ); |
|
646 | + }); |
|
647 | + $this->registerAlias('TempManager', TempManager::class); |
|
648 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
649 | + |
|
650 | + $this->registerService(AppManager::class, function (Server $c) { |
|
651 | + return new \OC\App\AppManager( |
|
652 | + $c->getUserSession(), |
|
653 | + $c->getAppConfig(), |
|
654 | + $c->getGroupManager(), |
|
655 | + $c->getMemCacheFactory(), |
|
656 | + $c->getEventDispatcher() |
|
657 | + ); |
|
658 | + }); |
|
659 | + $this->registerAlias('AppManager', AppManager::class); |
|
660 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
661 | + |
|
662 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
663 | + return new DateTimeZone( |
|
664 | + $c->getConfig(), |
|
665 | + $c->getSession() |
|
666 | + ); |
|
667 | + }); |
|
668 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
669 | + |
|
670 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
671 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
672 | + |
|
673 | + return new DateTimeFormatter( |
|
674 | + $c->getDateTimeZone()->getTimeZone(), |
|
675 | + $c->getL10N('lib', $language) |
|
676 | + ); |
|
677 | + }); |
|
678 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
679 | + |
|
680 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
681 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
682 | + $listener = new UserMountCacheListener($mountCache); |
|
683 | + $listener->listen($c->getUserManager()); |
|
684 | + return $mountCache; |
|
685 | + }); |
|
686 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
687 | + |
|
688 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
689 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
690 | + $mountCache = $c->query('UserMountCache'); |
|
691 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
692 | + |
|
693 | + // builtin providers |
|
694 | + |
|
695 | + $config = $c->getConfig(); |
|
696 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
697 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
698 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
699 | + |
|
700 | + return $manager; |
|
701 | + }); |
|
702 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
703 | + |
|
704 | + $this->registerService('IniWrapper', function ($c) { |
|
705 | + return new IniGetWrapper(); |
|
706 | + }); |
|
707 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
708 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
709 | + if ($busClass) { |
|
710 | + list($app, $class) = explode('::', $busClass, 2); |
|
711 | + if ($c->getAppManager()->isInstalled($app)) { |
|
712 | + \OC_App::loadApp($app); |
|
713 | + return $c->query($class); |
|
714 | + } else { |
|
715 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
716 | + } |
|
717 | + } else { |
|
718 | + $jobList = $c->getJobList(); |
|
719 | + return new CronBus($jobList); |
|
720 | + } |
|
721 | + }); |
|
722 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
723 | + return new TrustedDomainHelper($this->getConfig()); |
|
724 | + }); |
|
725 | + $this->registerService('Throttler', function (Server $c) { |
|
726 | + return new Throttler( |
|
727 | + $c->getDatabaseConnection(), |
|
728 | + new TimeFactory(), |
|
729 | + $c->getLogger(), |
|
730 | + $c->getConfig() |
|
731 | + ); |
|
732 | + }); |
|
733 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
734 | + // IConfig and IAppManager requires a working database. This code |
|
735 | + // might however be called when ownCloud is not yet setup. |
|
736 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
737 | + $config = $c->getConfig(); |
|
738 | + $appManager = $c->getAppManager(); |
|
739 | + } else { |
|
740 | + $config = null; |
|
741 | + $appManager = null; |
|
742 | + } |
|
743 | + |
|
744 | + return new Checker( |
|
745 | + new EnvironmentHelper(), |
|
746 | + new FileAccessHelper(), |
|
747 | + new AppLocator(), |
|
748 | + $config, |
|
749 | + $c->getMemCacheFactory(), |
|
750 | + $appManager, |
|
751 | + $c->getTempManager() |
|
752 | + ); |
|
753 | + }); |
|
754 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
755 | + if (isset($this['urlParams'])) { |
|
756 | + $urlParams = $this['urlParams']; |
|
757 | + } else { |
|
758 | + $urlParams = []; |
|
759 | + } |
|
760 | + |
|
761 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
762 | + && in_array('fakeinput', stream_get_wrappers()) |
|
763 | + ) { |
|
764 | + $stream = 'fakeinput://data'; |
|
765 | + } else { |
|
766 | + $stream = 'php://input'; |
|
767 | + } |
|
768 | + |
|
769 | + return new Request( |
|
770 | + [ |
|
771 | + 'get' => $_GET, |
|
772 | + 'post' => $_POST, |
|
773 | + 'files' => $_FILES, |
|
774 | + 'server' => $_SERVER, |
|
775 | + 'env' => $_ENV, |
|
776 | + 'cookies' => $_COOKIE, |
|
777 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
778 | + ? $_SERVER['REQUEST_METHOD'] |
|
779 | + : null, |
|
780 | + 'urlParams' => $urlParams, |
|
781 | + ], |
|
782 | + $this->getSecureRandom(), |
|
783 | + $this->getConfig(), |
|
784 | + $this->getCsrfTokenManager(), |
|
785 | + $stream |
|
786 | + ); |
|
787 | + }); |
|
788 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
789 | + |
|
790 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
791 | + return new Mailer( |
|
792 | + $c->getConfig(), |
|
793 | + $c->getLogger(), |
|
794 | + $c->query(Defaults::class), |
|
795 | + $c->getURLGenerator(), |
|
796 | + $c->getL10N('lib') |
|
797 | + ); |
|
798 | + }); |
|
799 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
800 | + |
|
801 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
802 | + $config = $c->getConfig(); |
|
803 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
804 | + if (is_null($factoryClass)) { |
|
805 | + throw new \Exception('ldapProviderFactory not set'); |
|
806 | + } |
|
807 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
808 | + $factory = new $factoryClass($this); |
|
809 | + return $factory->getLDAPProvider(); |
|
810 | + }); |
|
811 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
812 | + $ini = $c->getIniWrapper(); |
|
813 | + $config = $c->getConfig(); |
|
814 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
815 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
816 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
817 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
818 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
819 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
820 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
821 | + } |
|
822 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
823 | + } |
|
824 | + return new NoopLockingProvider(); |
|
825 | + }); |
|
826 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
827 | + |
|
828 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
829 | + return new \OC\Files\Mount\Manager(); |
|
830 | + }); |
|
831 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
832 | + |
|
833 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
834 | + return new \OC\Files\Type\Detection( |
|
835 | + $c->getURLGenerator(), |
|
836 | + \OC::$configDir, |
|
837 | + \OC::$SERVERROOT . '/resources/config/' |
|
838 | + ); |
|
839 | + }); |
|
840 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
841 | + |
|
842 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
843 | + return new \OC\Files\Type\Loader( |
|
844 | + $c->getDatabaseConnection() |
|
845 | + ); |
|
846 | + }); |
|
847 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
848 | + $this->registerService(BundleFetcher::class, function () { |
|
849 | + return new BundleFetcher($this->getL10N('lib')); |
|
850 | + }); |
|
851 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
852 | + return new Manager( |
|
853 | + $c->query(IValidator::class) |
|
854 | + ); |
|
855 | + }); |
|
856 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
857 | + |
|
858 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
859 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
860 | + $manager->registerCapability(function () use ($c) { |
|
861 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
862 | + }); |
|
863 | + $manager->registerCapability(function () use ($c) { |
|
864 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
865 | + }); |
|
866 | + return $manager; |
|
867 | + }); |
|
868 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
869 | + |
|
870 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
871 | + $config = $c->getConfig(); |
|
872 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
873 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
874 | + $factory = new $factoryClass($this); |
|
875 | + return $factory->getManager(); |
|
876 | + }); |
|
877 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
878 | + |
|
879 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
880 | + /* |
|
881 | 881 | * Dark magic for autoloader. |
882 | 882 | * If we do a class_exists it will try to load the class which will |
883 | 883 | * make composer cache the result. Resulting in errors when enabling |
884 | 884 | * the theming app. |
885 | 885 | */ |
886 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
887 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
888 | - $classExists = true; |
|
889 | - } else { |
|
890 | - $classExists = false; |
|
891 | - } |
|
892 | - |
|
893 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
894 | - return new ThemingDefaults( |
|
895 | - $c->getConfig(), |
|
896 | - $c->getL10N('theming'), |
|
897 | - $c->getURLGenerator(), |
|
898 | - $c->getAppDataDir('theming'), |
|
899 | - $c->getMemCacheFactory(), |
|
900 | - new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
901 | - $this->getAppManager() |
|
902 | - ); |
|
903 | - } |
|
904 | - return new \OC_Defaults(); |
|
905 | - }); |
|
906 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
907 | - /** @var Factory $cacheFactory */ |
|
908 | - $cacheFactory = $c->query(Factory::class); |
|
909 | - return new SCSSCacher( |
|
910 | - $c->getLogger(), |
|
911 | - $c->query(\OC\Files\AppData\Factory::class), |
|
912 | - $c->getURLGenerator(), |
|
913 | - $c->getConfig(), |
|
914 | - $c->getThemingDefaults(), |
|
915 | - \OC::$SERVERROOT, |
|
916 | - $cacheFactory->create('SCSS') |
|
917 | - ); |
|
918 | - }); |
|
919 | - $this->registerService(EventDispatcher::class, function () { |
|
920 | - return new EventDispatcher(); |
|
921 | - }); |
|
922 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
923 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
924 | - |
|
925 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
926 | - // FIXME: Instantiiated here due to cyclic dependency |
|
927 | - $request = new Request( |
|
928 | - [ |
|
929 | - 'get' => $_GET, |
|
930 | - 'post' => $_POST, |
|
931 | - 'files' => $_FILES, |
|
932 | - 'server' => $_SERVER, |
|
933 | - 'env' => $_ENV, |
|
934 | - 'cookies' => $_COOKIE, |
|
935 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
936 | - ? $_SERVER['REQUEST_METHOD'] |
|
937 | - : null, |
|
938 | - ], |
|
939 | - $c->getSecureRandom(), |
|
940 | - $c->getConfig() |
|
941 | - ); |
|
942 | - |
|
943 | - return new CryptoWrapper( |
|
944 | - $c->getConfig(), |
|
945 | - $c->getCrypto(), |
|
946 | - $c->getSecureRandom(), |
|
947 | - $request |
|
948 | - ); |
|
949 | - }); |
|
950 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
951 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
952 | - |
|
953 | - return new CsrfTokenManager( |
|
954 | - $tokenGenerator, |
|
955 | - $c->query(SessionStorage::class) |
|
956 | - ); |
|
957 | - }); |
|
958 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
959 | - return new SessionStorage($c->getSession()); |
|
960 | - }); |
|
961 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
962 | - return new ContentSecurityPolicyManager(); |
|
963 | - }); |
|
964 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
965 | - |
|
966 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
967 | - return new ContentSecurityPolicyNonceManager( |
|
968 | - $c->getCsrfTokenManager(), |
|
969 | - $c->getRequest() |
|
970 | - ); |
|
971 | - }); |
|
972 | - |
|
973 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
974 | - $config = $c->getConfig(); |
|
975 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
976 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
977 | - $factory = new $factoryClass($this); |
|
978 | - |
|
979 | - $manager = new \OC\Share20\Manager( |
|
980 | - $c->getLogger(), |
|
981 | - $c->getConfig(), |
|
982 | - $c->getSecureRandom(), |
|
983 | - $c->getHasher(), |
|
984 | - $c->getMountManager(), |
|
985 | - $c->getGroupManager(), |
|
986 | - $c->getL10N('lib'), |
|
987 | - $c->getL10NFactory(), |
|
988 | - $factory, |
|
989 | - $c->getUserManager(), |
|
990 | - $c->getLazyRootFolder(), |
|
991 | - $c->getEventDispatcher(), |
|
992 | - $c->getMailer(), |
|
993 | - $c->getURLGenerator(), |
|
994 | - $c->getThemingDefaults() |
|
995 | - ); |
|
996 | - |
|
997 | - return $manager; |
|
998 | - }); |
|
999 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1000 | - |
|
1001 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1002 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1003 | - |
|
1004 | - // register default plugins |
|
1005 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1006 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1007 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1008 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1009 | - |
|
1010 | - return $instance; |
|
1011 | - }); |
|
1012 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1013 | - |
|
1014 | - $this->registerService(\OCP\Collaboration\AutoComplete\IManager::class, function (Server $c) { |
|
1015 | - return new Collaboration\AutoComplete\Manager($c); |
|
1016 | - }); |
|
1017 | - $this->registerAlias('AutoCompleteManager', \OCP\Collaboration\AutoComplete\IManager::class); |
|
1018 | - |
|
1019 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1020 | - $manager = new \OC\Settings\Manager( |
|
1021 | - $c->getLogger(), |
|
1022 | - $c->getDatabaseConnection(), |
|
1023 | - $c->getL10N('lib'), |
|
1024 | - $c->getConfig(), |
|
1025 | - $c->getEncryptionManager(), |
|
1026 | - $c->getUserManager(), |
|
1027 | - $c->getLockingProvider(), |
|
1028 | - $c->getRequest(), |
|
1029 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
1030 | - $c->getURLGenerator(), |
|
1031 | - $c->query(AccountManager::class), |
|
1032 | - $c->getGroupManager(), |
|
1033 | - $c->getL10NFactory(), |
|
1034 | - $c->getThemingDefaults(), |
|
1035 | - $c->getAppManager() |
|
1036 | - ); |
|
1037 | - return $manager; |
|
1038 | - }); |
|
1039 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1040 | - return new \OC\Files\AppData\Factory( |
|
1041 | - $c->getRootFolder(), |
|
1042 | - $c->getSystemConfig() |
|
1043 | - ); |
|
1044 | - }); |
|
1045 | - |
|
1046 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1047 | - return new LockdownManager(function () use ($c) { |
|
1048 | - return $c->getSession(); |
|
1049 | - }); |
|
1050 | - }); |
|
1051 | - |
|
1052 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1053 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1054 | - }); |
|
1055 | - |
|
1056 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1057 | - return new CloudIdManager(); |
|
1058 | - }); |
|
1059 | - |
|
1060 | - /* To trick DI since we don't extend the DIContainer here */ |
|
1061 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1062 | - return new CleanPreviewsBackgroundJob( |
|
1063 | - $c->getRootFolder(), |
|
1064 | - $c->getLogger(), |
|
1065 | - $c->getJobList(), |
|
1066 | - new TimeFactory() |
|
1067 | - ); |
|
1068 | - }); |
|
1069 | - |
|
1070 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1071 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1072 | - |
|
1073 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1074 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1075 | - |
|
1076 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1077 | - return new Defaults( |
|
1078 | - $c->getThemingDefaults() |
|
1079 | - ); |
|
1080 | - }); |
|
1081 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1082 | - |
|
1083 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1084 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1085 | - }); |
|
1086 | - |
|
1087 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1088 | - return new ShareHelper( |
|
1089 | - $c->query(\OCP\Share\IManager::class) |
|
1090 | - ); |
|
1091 | - }); |
|
1092 | - } |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * @return \OCP\Contacts\IManager |
|
1096 | - */ |
|
1097 | - public function getContactsManager() { |
|
1098 | - return $this->query('ContactsManager'); |
|
1099 | - } |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * @return \OC\Encryption\Manager |
|
1103 | - */ |
|
1104 | - public function getEncryptionManager() { |
|
1105 | - return $this->query('EncryptionManager'); |
|
1106 | - } |
|
1107 | - |
|
1108 | - /** |
|
1109 | - * @return \OC\Encryption\File |
|
1110 | - */ |
|
1111 | - public function getEncryptionFilesHelper() { |
|
1112 | - return $this->query('EncryptionFileHelper'); |
|
1113 | - } |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * @return \OCP\Encryption\Keys\IStorage |
|
1117 | - */ |
|
1118 | - public function getEncryptionKeyStorage() { |
|
1119 | - return $this->query('EncryptionKeyStorage'); |
|
1120 | - } |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * The current request object holding all information about the request |
|
1124 | - * currently being processed is returned from this method. |
|
1125 | - * In case the current execution was not initiated by a web request null is returned |
|
1126 | - * |
|
1127 | - * @return \OCP\IRequest |
|
1128 | - */ |
|
1129 | - public function getRequest() { |
|
1130 | - return $this->query('Request'); |
|
1131 | - } |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * Returns the preview manager which can create preview images for a given file |
|
1135 | - * |
|
1136 | - * @return \OCP\IPreview |
|
1137 | - */ |
|
1138 | - public function getPreviewManager() { |
|
1139 | - return $this->query('PreviewManager'); |
|
1140 | - } |
|
1141 | - |
|
1142 | - /** |
|
1143 | - * Returns the tag manager which can get and set tags for different object types |
|
1144 | - * |
|
1145 | - * @see \OCP\ITagManager::load() |
|
1146 | - * @return \OCP\ITagManager |
|
1147 | - */ |
|
1148 | - public function getTagManager() { |
|
1149 | - return $this->query('TagManager'); |
|
1150 | - } |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * Returns the system-tag manager |
|
1154 | - * |
|
1155 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1156 | - * |
|
1157 | - * @since 9.0.0 |
|
1158 | - */ |
|
1159 | - public function getSystemTagManager() { |
|
1160 | - return $this->query('SystemTagManager'); |
|
1161 | - } |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * Returns the system-tag object mapper |
|
1165 | - * |
|
1166 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1167 | - * |
|
1168 | - * @since 9.0.0 |
|
1169 | - */ |
|
1170 | - public function getSystemTagObjectMapper() { |
|
1171 | - return $this->query('SystemTagObjectMapper'); |
|
1172 | - } |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * Returns the avatar manager, used for avatar functionality |
|
1176 | - * |
|
1177 | - * @return \OCP\IAvatarManager |
|
1178 | - */ |
|
1179 | - public function getAvatarManager() { |
|
1180 | - return $this->query('AvatarManager'); |
|
1181 | - } |
|
1182 | - |
|
1183 | - /** |
|
1184 | - * Returns the root folder of ownCloud's data directory |
|
1185 | - * |
|
1186 | - * @return \OCP\Files\IRootFolder |
|
1187 | - */ |
|
1188 | - public function getRootFolder() { |
|
1189 | - return $this->query('LazyRootFolder'); |
|
1190 | - } |
|
1191 | - |
|
1192 | - /** |
|
1193 | - * Returns the root folder of ownCloud's data directory |
|
1194 | - * This is the lazy variant so this gets only initialized once it |
|
1195 | - * is actually used. |
|
1196 | - * |
|
1197 | - * @return \OCP\Files\IRootFolder |
|
1198 | - */ |
|
1199 | - public function getLazyRootFolder() { |
|
1200 | - return $this->query('LazyRootFolder'); |
|
1201 | - } |
|
1202 | - |
|
1203 | - /** |
|
1204 | - * Returns a view to ownCloud's files folder |
|
1205 | - * |
|
1206 | - * @param string $userId user ID |
|
1207 | - * @return \OCP\Files\Folder|null |
|
1208 | - */ |
|
1209 | - public function getUserFolder($userId = null) { |
|
1210 | - if ($userId === null) { |
|
1211 | - $user = $this->getUserSession()->getUser(); |
|
1212 | - if (!$user) { |
|
1213 | - return null; |
|
1214 | - } |
|
1215 | - $userId = $user->getUID(); |
|
1216 | - } |
|
1217 | - $root = $this->getRootFolder(); |
|
1218 | - return $root->getUserFolder($userId); |
|
1219 | - } |
|
1220 | - |
|
1221 | - /** |
|
1222 | - * Returns an app-specific view in ownClouds data directory |
|
1223 | - * |
|
1224 | - * @return \OCP\Files\Folder |
|
1225 | - * @deprecated since 9.2.0 use IAppData |
|
1226 | - */ |
|
1227 | - public function getAppFolder() { |
|
1228 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1229 | - $root = $this->getRootFolder(); |
|
1230 | - if (!$root->nodeExists($dir)) { |
|
1231 | - $folder = $root->newFolder($dir); |
|
1232 | - } else { |
|
1233 | - $folder = $root->get($dir); |
|
1234 | - } |
|
1235 | - return $folder; |
|
1236 | - } |
|
1237 | - |
|
1238 | - /** |
|
1239 | - * @return \OC\User\Manager |
|
1240 | - */ |
|
1241 | - public function getUserManager() { |
|
1242 | - return $this->query('UserManager'); |
|
1243 | - } |
|
1244 | - |
|
1245 | - /** |
|
1246 | - * @return \OC\Group\Manager |
|
1247 | - */ |
|
1248 | - public function getGroupManager() { |
|
1249 | - return $this->query('GroupManager'); |
|
1250 | - } |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * @return \OC\User\Session |
|
1254 | - */ |
|
1255 | - public function getUserSession() { |
|
1256 | - return $this->query('UserSession'); |
|
1257 | - } |
|
1258 | - |
|
1259 | - /** |
|
1260 | - * @return \OCP\ISession |
|
1261 | - */ |
|
1262 | - public function getSession() { |
|
1263 | - return $this->query('UserSession')->getSession(); |
|
1264 | - } |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * @param \OCP\ISession $session |
|
1268 | - */ |
|
1269 | - public function setSession(\OCP\ISession $session) { |
|
1270 | - $this->query(SessionStorage::class)->setSession($session); |
|
1271 | - $this->query('UserSession')->setSession($session); |
|
1272 | - $this->query(Store::class)->setSession($session); |
|
1273 | - } |
|
1274 | - |
|
1275 | - /** |
|
1276 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1277 | - */ |
|
1278 | - public function getTwoFactorAuthManager() { |
|
1279 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1280 | - } |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * @return \OC\NavigationManager |
|
1284 | - */ |
|
1285 | - public function getNavigationManager() { |
|
1286 | - return $this->query('NavigationManager'); |
|
1287 | - } |
|
1288 | - |
|
1289 | - /** |
|
1290 | - * @return \OCP\IConfig |
|
1291 | - */ |
|
1292 | - public function getConfig() { |
|
1293 | - return $this->query('AllConfig'); |
|
1294 | - } |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * @return \OC\SystemConfig |
|
1298 | - */ |
|
1299 | - public function getSystemConfig() { |
|
1300 | - return $this->query('SystemConfig'); |
|
1301 | - } |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * Returns the app config manager |
|
1305 | - * |
|
1306 | - * @return \OCP\IAppConfig |
|
1307 | - */ |
|
1308 | - public function getAppConfig() { |
|
1309 | - return $this->query('AppConfig'); |
|
1310 | - } |
|
1311 | - |
|
1312 | - /** |
|
1313 | - * @return \OCP\L10N\IFactory |
|
1314 | - */ |
|
1315 | - public function getL10NFactory() { |
|
1316 | - return $this->query('L10NFactory'); |
|
1317 | - } |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * get an L10N instance |
|
1321 | - * |
|
1322 | - * @param string $app appid |
|
1323 | - * @param string $lang |
|
1324 | - * @return IL10N |
|
1325 | - */ |
|
1326 | - public function getL10N($app, $lang = null) { |
|
1327 | - return $this->getL10NFactory()->get($app, $lang); |
|
1328 | - } |
|
1329 | - |
|
1330 | - /** |
|
1331 | - * @return \OCP\IURLGenerator |
|
1332 | - */ |
|
1333 | - public function getURLGenerator() { |
|
1334 | - return $this->query('URLGenerator'); |
|
1335 | - } |
|
1336 | - |
|
1337 | - /** |
|
1338 | - * @return \OCP\IHelper |
|
1339 | - */ |
|
1340 | - public function getHelper() { |
|
1341 | - return $this->query('AppHelper'); |
|
1342 | - } |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * @return AppFetcher |
|
1346 | - */ |
|
1347 | - public function getAppFetcher() { |
|
1348 | - return $this->query(AppFetcher::class); |
|
1349 | - } |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1353 | - * getMemCacheFactory() instead. |
|
1354 | - * |
|
1355 | - * @return \OCP\ICache |
|
1356 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1357 | - */ |
|
1358 | - public function getCache() { |
|
1359 | - return $this->query('UserCache'); |
|
1360 | - } |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * Returns an \OCP\CacheFactory instance |
|
1364 | - * |
|
1365 | - * @return \OCP\ICacheFactory |
|
1366 | - */ |
|
1367 | - public function getMemCacheFactory() { |
|
1368 | - return $this->query('MemCacheFactory'); |
|
1369 | - } |
|
1370 | - |
|
1371 | - /** |
|
1372 | - * Returns an \OC\RedisFactory instance |
|
1373 | - * |
|
1374 | - * @return \OC\RedisFactory |
|
1375 | - */ |
|
1376 | - public function getGetRedisFactory() { |
|
1377 | - return $this->query('RedisFactory'); |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * Returns the current session |
|
1383 | - * |
|
1384 | - * @return \OCP\IDBConnection |
|
1385 | - */ |
|
1386 | - public function getDatabaseConnection() { |
|
1387 | - return $this->query('DatabaseConnection'); |
|
1388 | - } |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * Returns the activity manager |
|
1392 | - * |
|
1393 | - * @return \OCP\Activity\IManager |
|
1394 | - */ |
|
1395 | - public function getActivityManager() { |
|
1396 | - return $this->query('ActivityManager'); |
|
1397 | - } |
|
1398 | - |
|
1399 | - /** |
|
1400 | - * Returns an job list for controlling background jobs |
|
1401 | - * |
|
1402 | - * @return \OCP\BackgroundJob\IJobList |
|
1403 | - */ |
|
1404 | - public function getJobList() { |
|
1405 | - return $this->query('JobList'); |
|
1406 | - } |
|
1407 | - |
|
1408 | - /** |
|
1409 | - * Returns a logger instance |
|
1410 | - * |
|
1411 | - * @return \OCP\ILogger |
|
1412 | - */ |
|
1413 | - public function getLogger() { |
|
1414 | - return $this->query('Logger'); |
|
1415 | - } |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * Returns a router for generating and matching urls |
|
1419 | - * |
|
1420 | - * @return \OCP\Route\IRouter |
|
1421 | - */ |
|
1422 | - public function getRouter() { |
|
1423 | - return $this->query('Router'); |
|
1424 | - } |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * Returns a search instance |
|
1428 | - * |
|
1429 | - * @return \OCP\ISearch |
|
1430 | - */ |
|
1431 | - public function getSearch() { |
|
1432 | - return $this->query('Search'); |
|
1433 | - } |
|
1434 | - |
|
1435 | - /** |
|
1436 | - * Returns a SecureRandom instance |
|
1437 | - * |
|
1438 | - * @return \OCP\Security\ISecureRandom |
|
1439 | - */ |
|
1440 | - public function getSecureRandom() { |
|
1441 | - return $this->query('SecureRandom'); |
|
1442 | - } |
|
1443 | - |
|
1444 | - /** |
|
1445 | - * Returns a Crypto instance |
|
1446 | - * |
|
1447 | - * @return \OCP\Security\ICrypto |
|
1448 | - */ |
|
1449 | - public function getCrypto() { |
|
1450 | - return $this->query('Crypto'); |
|
1451 | - } |
|
1452 | - |
|
1453 | - /** |
|
1454 | - * Returns a Hasher instance |
|
1455 | - * |
|
1456 | - * @return \OCP\Security\IHasher |
|
1457 | - */ |
|
1458 | - public function getHasher() { |
|
1459 | - return $this->query('Hasher'); |
|
1460 | - } |
|
1461 | - |
|
1462 | - /** |
|
1463 | - * Returns a CredentialsManager instance |
|
1464 | - * |
|
1465 | - * @return \OCP\Security\ICredentialsManager |
|
1466 | - */ |
|
1467 | - public function getCredentialsManager() { |
|
1468 | - return $this->query('CredentialsManager'); |
|
1469 | - } |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Returns an instance of the HTTP helper class |
|
1473 | - * |
|
1474 | - * @deprecated Use getHTTPClientService() |
|
1475 | - * @return \OC\HTTPHelper |
|
1476 | - */ |
|
1477 | - public function getHTTPHelper() { |
|
1478 | - return $this->query('HTTPHelper'); |
|
1479 | - } |
|
1480 | - |
|
1481 | - /** |
|
1482 | - * Get the certificate manager for the user |
|
1483 | - * |
|
1484 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1485 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1486 | - */ |
|
1487 | - public function getCertificateManager($userId = '') { |
|
1488 | - if ($userId === '') { |
|
1489 | - $userSession = $this->getUserSession(); |
|
1490 | - $user = $userSession->getUser(); |
|
1491 | - if (is_null($user)) { |
|
1492 | - return null; |
|
1493 | - } |
|
1494 | - $userId = $user->getUID(); |
|
1495 | - } |
|
1496 | - return new CertificateManager( |
|
1497 | - $userId, |
|
1498 | - new View(), |
|
1499 | - $this->getConfig(), |
|
1500 | - $this->getLogger(), |
|
1501 | - $this->getSecureRandom() |
|
1502 | - ); |
|
1503 | - } |
|
1504 | - |
|
1505 | - /** |
|
1506 | - * Returns an instance of the HTTP client service |
|
1507 | - * |
|
1508 | - * @return \OCP\Http\Client\IClientService |
|
1509 | - */ |
|
1510 | - public function getHTTPClientService() { |
|
1511 | - return $this->query('HttpClientService'); |
|
1512 | - } |
|
1513 | - |
|
1514 | - /** |
|
1515 | - * Create a new event source |
|
1516 | - * |
|
1517 | - * @return \OCP\IEventSource |
|
1518 | - */ |
|
1519 | - public function createEventSource() { |
|
1520 | - return new \OC_EventSource(); |
|
1521 | - } |
|
1522 | - |
|
1523 | - /** |
|
1524 | - * Get the active event logger |
|
1525 | - * |
|
1526 | - * The returned logger only logs data when debug mode is enabled |
|
1527 | - * |
|
1528 | - * @return \OCP\Diagnostics\IEventLogger |
|
1529 | - */ |
|
1530 | - public function getEventLogger() { |
|
1531 | - return $this->query('EventLogger'); |
|
1532 | - } |
|
1533 | - |
|
1534 | - /** |
|
1535 | - * Get the active query logger |
|
1536 | - * |
|
1537 | - * The returned logger only logs data when debug mode is enabled |
|
1538 | - * |
|
1539 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1540 | - */ |
|
1541 | - public function getQueryLogger() { |
|
1542 | - return $this->query('QueryLogger'); |
|
1543 | - } |
|
1544 | - |
|
1545 | - /** |
|
1546 | - * Get the manager for temporary files and folders |
|
1547 | - * |
|
1548 | - * @return \OCP\ITempManager |
|
1549 | - */ |
|
1550 | - public function getTempManager() { |
|
1551 | - return $this->query('TempManager'); |
|
1552 | - } |
|
1553 | - |
|
1554 | - /** |
|
1555 | - * Get the app manager |
|
1556 | - * |
|
1557 | - * @return \OCP\App\IAppManager |
|
1558 | - */ |
|
1559 | - public function getAppManager() { |
|
1560 | - return $this->query('AppManager'); |
|
1561 | - } |
|
1562 | - |
|
1563 | - /** |
|
1564 | - * Creates a new mailer |
|
1565 | - * |
|
1566 | - * @return \OCP\Mail\IMailer |
|
1567 | - */ |
|
1568 | - public function getMailer() { |
|
1569 | - return $this->query('Mailer'); |
|
1570 | - } |
|
1571 | - |
|
1572 | - /** |
|
1573 | - * Get the webroot |
|
1574 | - * |
|
1575 | - * @return string |
|
1576 | - */ |
|
1577 | - public function getWebRoot() { |
|
1578 | - return $this->webRoot; |
|
1579 | - } |
|
1580 | - |
|
1581 | - /** |
|
1582 | - * @return \OC\OCSClient |
|
1583 | - */ |
|
1584 | - public function getOcsClient() { |
|
1585 | - return $this->query('OcsClient'); |
|
1586 | - } |
|
1587 | - |
|
1588 | - /** |
|
1589 | - * @return \OCP\IDateTimeZone |
|
1590 | - */ |
|
1591 | - public function getDateTimeZone() { |
|
1592 | - return $this->query('DateTimeZone'); |
|
1593 | - } |
|
1594 | - |
|
1595 | - /** |
|
1596 | - * @return \OCP\IDateTimeFormatter |
|
1597 | - */ |
|
1598 | - public function getDateTimeFormatter() { |
|
1599 | - return $this->query('DateTimeFormatter'); |
|
1600 | - } |
|
1601 | - |
|
1602 | - /** |
|
1603 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1604 | - */ |
|
1605 | - public function getMountProviderCollection() { |
|
1606 | - return $this->query('MountConfigManager'); |
|
1607 | - } |
|
1608 | - |
|
1609 | - /** |
|
1610 | - * Get the IniWrapper |
|
1611 | - * |
|
1612 | - * @return IniGetWrapper |
|
1613 | - */ |
|
1614 | - public function getIniWrapper() { |
|
1615 | - return $this->query('IniWrapper'); |
|
1616 | - } |
|
1617 | - |
|
1618 | - /** |
|
1619 | - * @return \OCP\Command\IBus |
|
1620 | - */ |
|
1621 | - public function getCommandBus() { |
|
1622 | - return $this->query('AsyncCommandBus'); |
|
1623 | - } |
|
1624 | - |
|
1625 | - /** |
|
1626 | - * Get the trusted domain helper |
|
1627 | - * |
|
1628 | - * @return TrustedDomainHelper |
|
1629 | - */ |
|
1630 | - public function getTrustedDomainHelper() { |
|
1631 | - return $this->query('TrustedDomainHelper'); |
|
1632 | - } |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Get the locking provider |
|
1636 | - * |
|
1637 | - * @return \OCP\Lock\ILockingProvider |
|
1638 | - * @since 8.1.0 |
|
1639 | - */ |
|
1640 | - public function getLockingProvider() { |
|
1641 | - return $this->query('LockingProvider'); |
|
1642 | - } |
|
1643 | - |
|
1644 | - /** |
|
1645 | - * @return \OCP\Files\Mount\IMountManager |
|
1646 | - **/ |
|
1647 | - function getMountManager() { |
|
1648 | - return $this->query('MountManager'); |
|
1649 | - } |
|
1650 | - |
|
1651 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1652 | - function getUserMountCache() { |
|
1653 | - return $this->query('UserMountCache'); |
|
1654 | - } |
|
1655 | - |
|
1656 | - /** |
|
1657 | - * Get the MimeTypeDetector |
|
1658 | - * |
|
1659 | - * @return \OCP\Files\IMimeTypeDetector |
|
1660 | - */ |
|
1661 | - public function getMimeTypeDetector() { |
|
1662 | - return $this->query('MimeTypeDetector'); |
|
1663 | - } |
|
1664 | - |
|
1665 | - /** |
|
1666 | - * Get the MimeTypeLoader |
|
1667 | - * |
|
1668 | - * @return \OCP\Files\IMimeTypeLoader |
|
1669 | - */ |
|
1670 | - public function getMimeTypeLoader() { |
|
1671 | - return $this->query('MimeTypeLoader'); |
|
1672 | - } |
|
1673 | - |
|
1674 | - /** |
|
1675 | - * Get the manager of all the capabilities |
|
1676 | - * |
|
1677 | - * @return \OC\CapabilitiesManager |
|
1678 | - */ |
|
1679 | - public function getCapabilitiesManager() { |
|
1680 | - return $this->query('CapabilitiesManager'); |
|
1681 | - } |
|
1682 | - |
|
1683 | - /** |
|
1684 | - * Get the EventDispatcher |
|
1685 | - * |
|
1686 | - * @return EventDispatcherInterface |
|
1687 | - * @since 8.2.0 |
|
1688 | - */ |
|
1689 | - public function getEventDispatcher() { |
|
1690 | - return $this->query('EventDispatcher'); |
|
1691 | - } |
|
1692 | - |
|
1693 | - /** |
|
1694 | - * Get the Notification Manager |
|
1695 | - * |
|
1696 | - * @return \OCP\Notification\IManager |
|
1697 | - * @since 8.2.0 |
|
1698 | - */ |
|
1699 | - public function getNotificationManager() { |
|
1700 | - return $this->query('NotificationManager'); |
|
1701 | - } |
|
1702 | - |
|
1703 | - /** |
|
1704 | - * @return \OCP\Comments\ICommentsManager |
|
1705 | - */ |
|
1706 | - public function getCommentsManager() { |
|
1707 | - return $this->query('CommentsManager'); |
|
1708 | - } |
|
1709 | - |
|
1710 | - /** |
|
1711 | - * @return \OCA\Theming\ThemingDefaults |
|
1712 | - */ |
|
1713 | - public function getThemingDefaults() { |
|
1714 | - return $this->query('ThemingDefaults'); |
|
1715 | - } |
|
1716 | - |
|
1717 | - /** |
|
1718 | - * @return \OC\IntegrityCheck\Checker |
|
1719 | - */ |
|
1720 | - public function getIntegrityCodeChecker() { |
|
1721 | - return $this->query('IntegrityCodeChecker'); |
|
1722 | - } |
|
1723 | - |
|
1724 | - /** |
|
1725 | - * @return \OC\Session\CryptoWrapper |
|
1726 | - */ |
|
1727 | - public function getSessionCryptoWrapper() { |
|
1728 | - return $this->query('CryptoWrapper'); |
|
1729 | - } |
|
1730 | - |
|
1731 | - /** |
|
1732 | - * @return CsrfTokenManager |
|
1733 | - */ |
|
1734 | - public function getCsrfTokenManager() { |
|
1735 | - return $this->query('CsrfTokenManager'); |
|
1736 | - } |
|
1737 | - |
|
1738 | - /** |
|
1739 | - * @return Throttler |
|
1740 | - */ |
|
1741 | - public function getBruteForceThrottler() { |
|
1742 | - return $this->query('Throttler'); |
|
1743 | - } |
|
1744 | - |
|
1745 | - /** |
|
1746 | - * @return IContentSecurityPolicyManager |
|
1747 | - */ |
|
1748 | - public function getContentSecurityPolicyManager() { |
|
1749 | - return $this->query('ContentSecurityPolicyManager'); |
|
1750 | - } |
|
1751 | - |
|
1752 | - /** |
|
1753 | - * @return ContentSecurityPolicyNonceManager |
|
1754 | - */ |
|
1755 | - public function getContentSecurityPolicyNonceManager() { |
|
1756 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1757 | - } |
|
1758 | - |
|
1759 | - /** |
|
1760 | - * Not a public API as of 8.2, wait for 9.0 |
|
1761 | - * |
|
1762 | - * @return \OCA\Files_External\Service\BackendService |
|
1763 | - */ |
|
1764 | - public function getStoragesBackendService() { |
|
1765 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1766 | - } |
|
1767 | - |
|
1768 | - /** |
|
1769 | - * Not a public API as of 8.2, wait for 9.0 |
|
1770 | - * |
|
1771 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1772 | - */ |
|
1773 | - public function getGlobalStoragesService() { |
|
1774 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1775 | - } |
|
1776 | - |
|
1777 | - /** |
|
1778 | - * Not a public API as of 8.2, wait for 9.0 |
|
1779 | - * |
|
1780 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1781 | - */ |
|
1782 | - public function getUserGlobalStoragesService() { |
|
1783 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1784 | - } |
|
1785 | - |
|
1786 | - /** |
|
1787 | - * Not a public API as of 8.2, wait for 9.0 |
|
1788 | - * |
|
1789 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1790 | - */ |
|
1791 | - public function getUserStoragesService() { |
|
1792 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1793 | - } |
|
1794 | - |
|
1795 | - /** |
|
1796 | - * @return \OCP\Share\IManager |
|
1797 | - */ |
|
1798 | - public function getShareManager() { |
|
1799 | - return $this->query('ShareManager'); |
|
1800 | - } |
|
1801 | - |
|
1802 | - /** |
|
1803 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1804 | - */ |
|
1805 | - public function getCollaboratorSearch() { |
|
1806 | - return $this->query('CollaboratorSearch'); |
|
1807 | - } |
|
1808 | - |
|
1809 | - /** |
|
1810 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1811 | - */ |
|
1812 | - public function getAutoCompleteManager(){ |
|
1813 | - return $this->query('AutoCompleteManager'); |
|
1814 | - } |
|
1815 | - |
|
1816 | - /** |
|
1817 | - * Returns the LDAP Provider |
|
1818 | - * |
|
1819 | - * @return \OCP\LDAP\ILDAPProvider |
|
1820 | - */ |
|
1821 | - public function getLDAPProvider() { |
|
1822 | - return $this->query('LDAPProvider'); |
|
1823 | - } |
|
1824 | - |
|
1825 | - /** |
|
1826 | - * @return \OCP\Settings\IManager |
|
1827 | - */ |
|
1828 | - public function getSettingsManager() { |
|
1829 | - return $this->query('SettingsManager'); |
|
1830 | - } |
|
1831 | - |
|
1832 | - /** |
|
1833 | - * @return \OCP\Files\IAppData |
|
1834 | - */ |
|
1835 | - public function getAppDataDir($app) { |
|
1836 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1837 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1838 | - return $factory->get($app); |
|
1839 | - } |
|
1840 | - |
|
1841 | - /** |
|
1842 | - * @return \OCP\Lockdown\ILockdownManager |
|
1843 | - */ |
|
1844 | - public function getLockdownManager() { |
|
1845 | - return $this->query('LockdownManager'); |
|
1846 | - } |
|
1847 | - |
|
1848 | - /** |
|
1849 | - * @return \OCP\Federation\ICloudIdManager |
|
1850 | - */ |
|
1851 | - public function getCloudIdManager() { |
|
1852 | - return $this->query(ICloudIdManager::class); |
|
1853 | - } |
|
886 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
887 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
888 | + $classExists = true; |
|
889 | + } else { |
|
890 | + $classExists = false; |
|
891 | + } |
|
892 | + |
|
893 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
894 | + return new ThemingDefaults( |
|
895 | + $c->getConfig(), |
|
896 | + $c->getL10N('theming'), |
|
897 | + $c->getURLGenerator(), |
|
898 | + $c->getAppDataDir('theming'), |
|
899 | + $c->getMemCacheFactory(), |
|
900 | + new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
901 | + $this->getAppManager() |
|
902 | + ); |
|
903 | + } |
|
904 | + return new \OC_Defaults(); |
|
905 | + }); |
|
906 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
907 | + /** @var Factory $cacheFactory */ |
|
908 | + $cacheFactory = $c->query(Factory::class); |
|
909 | + return new SCSSCacher( |
|
910 | + $c->getLogger(), |
|
911 | + $c->query(\OC\Files\AppData\Factory::class), |
|
912 | + $c->getURLGenerator(), |
|
913 | + $c->getConfig(), |
|
914 | + $c->getThemingDefaults(), |
|
915 | + \OC::$SERVERROOT, |
|
916 | + $cacheFactory->create('SCSS') |
|
917 | + ); |
|
918 | + }); |
|
919 | + $this->registerService(EventDispatcher::class, function () { |
|
920 | + return new EventDispatcher(); |
|
921 | + }); |
|
922 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
923 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
924 | + |
|
925 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
926 | + // FIXME: Instantiiated here due to cyclic dependency |
|
927 | + $request = new Request( |
|
928 | + [ |
|
929 | + 'get' => $_GET, |
|
930 | + 'post' => $_POST, |
|
931 | + 'files' => $_FILES, |
|
932 | + 'server' => $_SERVER, |
|
933 | + 'env' => $_ENV, |
|
934 | + 'cookies' => $_COOKIE, |
|
935 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
936 | + ? $_SERVER['REQUEST_METHOD'] |
|
937 | + : null, |
|
938 | + ], |
|
939 | + $c->getSecureRandom(), |
|
940 | + $c->getConfig() |
|
941 | + ); |
|
942 | + |
|
943 | + return new CryptoWrapper( |
|
944 | + $c->getConfig(), |
|
945 | + $c->getCrypto(), |
|
946 | + $c->getSecureRandom(), |
|
947 | + $request |
|
948 | + ); |
|
949 | + }); |
|
950 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
951 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
952 | + |
|
953 | + return new CsrfTokenManager( |
|
954 | + $tokenGenerator, |
|
955 | + $c->query(SessionStorage::class) |
|
956 | + ); |
|
957 | + }); |
|
958 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
959 | + return new SessionStorage($c->getSession()); |
|
960 | + }); |
|
961 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
962 | + return new ContentSecurityPolicyManager(); |
|
963 | + }); |
|
964 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
965 | + |
|
966 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
967 | + return new ContentSecurityPolicyNonceManager( |
|
968 | + $c->getCsrfTokenManager(), |
|
969 | + $c->getRequest() |
|
970 | + ); |
|
971 | + }); |
|
972 | + |
|
973 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
974 | + $config = $c->getConfig(); |
|
975 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
976 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
977 | + $factory = new $factoryClass($this); |
|
978 | + |
|
979 | + $manager = new \OC\Share20\Manager( |
|
980 | + $c->getLogger(), |
|
981 | + $c->getConfig(), |
|
982 | + $c->getSecureRandom(), |
|
983 | + $c->getHasher(), |
|
984 | + $c->getMountManager(), |
|
985 | + $c->getGroupManager(), |
|
986 | + $c->getL10N('lib'), |
|
987 | + $c->getL10NFactory(), |
|
988 | + $factory, |
|
989 | + $c->getUserManager(), |
|
990 | + $c->getLazyRootFolder(), |
|
991 | + $c->getEventDispatcher(), |
|
992 | + $c->getMailer(), |
|
993 | + $c->getURLGenerator(), |
|
994 | + $c->getThemingDefaults() |
|
995 | + ); |
|
996 | + |
|
997 | + return $manager; |
|
998 | + }); |
|
999 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1000 | + |
|
1001 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1002 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1003 | + |
|
1004 | + // register default plugins |
|
1005 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1006 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1007 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1008 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1009 | + |
|
1010 | + return $instance; |
|
1011 | + }); |
|
1012 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1013 | + |
|
1014 | + $this->registerService(\OCP\Collaboration\AutoComplete\IManager::class, function (Server $c) { |
|
1015 | + return new Collaboration\AutoComplete\Manager($c); |
|
1016 | + }); |
|
1017 | + $this->registerAlias('AutoCompleteManager', \OCP\Collaboration\AutoComplete\IManager::class); |
|
1018 | + |
|
1019 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1020 | + $manager = new \OC\Settings\Manager( |
|
1021 | + $c->getLogger(), |
|
1022 | + $c->getDatabaseConnection(), |
|
1023 | + $c->getL10N('lib'), |
|
1024 | + $c->getConfig(), |
|
1025 | + $c->getEncryptionManager(), |
|
1026 | + $c->getUserManager(), |
|
1027 | + $c->getLockingProvider(), |
|
1028 | + $c->getRequest(), |
|
1029 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
1030 | + $c->getURLGenerator(), |
|
1031 | + $c->query(AccountManager::class), |
|
1032 | + $c->getGroupManager(), |
|
1033 | + $c->getL10NFactory(), |
|
1034 | + $c->getThemingDefaults(), |
|
1035 | + $c->getAppManager() |
|
1036 | + ); |
|
1037 | + return $manager; |
|
1038 | + }); |
|
1039 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1040 | + return new \OC\Files\AppData\Factory( |
|
1041 | + $c->getRootFolder(), |
|
1042 | + $c->getSystemConfig() |
|
1043 | + ); |
|
1044 | + }); |
|
1045 | + |
|
1046 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1047 | + return new LockdownManager(function () use ($c) { |
|
1048 | + return $c->getSession(); |
|
1049 | + }); |
|
1050 | + }); |
|
1051 | + |
|
1052 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1053 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1054 | + }); |
|
1055 | + |
|
1056 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1057 | + return new CloudIdManager(); |
|
1058 | + }); |
|
1059 | + |
|
1060 | + /* To trick DI since we don't extend the DIContainer here */ |
|
1061 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1062 | + return new CleanPreviewsBackgroundJob( |
|
1063 | + $c->getRootFolder(), |
|
1064 | + $c->getLogger(), |
|
1065 | + $c->getJobList(), |
|
1066 | + new TimeFactory() |
|
1067 | + ); |
|
1068 | + }); |
|
1069 | + |
|
1070 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1071 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1072 | + |
|
1073 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1074 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1075 | + |
|
1076 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1077 | + return new Defaults( |
|
1078 | + $c->getThemingDefaults() |
|
1079 | + ); |
|
1080 | + }); |
|
1081 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1082 | + |
|
1083 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1084 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1085 | + }); |
|
1086 | + |
|
1087 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1088 | + return new ShareHelper( |
|
1089 | + $c->query(\OCP\Share\IManager::class) |
|
1090 | + ); |
|
1091 | + }); |
|
1092 | + } |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * @return \OCP\Contacts\IManager |
|
1096 | + */ |
|
1097 | + public function getContactsManager() { |
|
1098 | + return $this->query('ContactsManager'); |
|
1099 | + } |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * @return \OC\Encryption\Manager |
|
1103 | + */ |
|
1104 | + public function getEncryptionManager() { |
|
1105 | + return $this->query('EncryptionManager'); |
|
1106 | + } |
|
1107 | + |
|
1108 | + /** |
|
1109 | + * @return \OC\Encryption\File |
|
1110 | + */ |
|
1111 | + public function getEncryptionFilesHelper() { |
|
1112 | + return $this->query('EncryptionFileHelper'); |
|
1113 | + } |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * @return \OCP\Encryption\Keys\IStorage |
|
1117 | + */ |
|
1118 | + public function getEncryptionKeyStorage() { |
|
1119 | + return $this->query('EncryptionKeyStorage'); |
|
1120 | + } |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * The current request object holding all information about the request |
|
1124 | + * currently being processed is returned from this method. |
|
1125 | + * In case the current execution was not initiated by a web request null is returned |
|
1126 | + * |
|
1127 | + * @return \OCP\IRequest |
|
1128 | + */ |
|
1129 | + public function getRequest() { |
|
1130 | + return $this->query('Request'); |
|
1131 | + } |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * Returns the preview manager which can create preview images for a given file |
|
1135 | + * |
|
1136 | + * @return \OCP\IPreview |
|
1137 | + */ |
|
1138 | + public function getPreviewManager() { |
|
1139 | + return $this->query('PreviewManager'); |
|
1140 | + } |
|
1141 | + |
|
1142 | + /** |
|
1143 | + * Returns the tag manager which can get and set tags for different object types |
|
1144 | + * |
|
1145 | + * @see \OCP\ITagManager::load() |
|
1146 | + * @return \OCP\ITagManager |
|
1147 | + */ |
|
1148 | + public function getTagManager() { |
|
1149 | + return $this->query('TagManager'); |
|
1150 | + } |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * Returns the system-tag manager |
|
1154 | + * |
|
1155 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1156 | + * |
|
1157 | + * @since 9.0.0 |
|
1158 | + */ |
|
1159 | + public function getSystemTagManager() { |
|
1160 | + return $this->query('SystemTagManager'); |
|
1161 | + } |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * Returns the system-tag object mapper |
|
1165 | + * |
|
1166 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1167 | + * |
|
1168 | + * @since 9.0.0 |
|
1169 | + */ |
|
1170 | + public function getSystemTagObjectMapper() { |
|
1171 | + return $this->query('SystemTagObjectMapper'); |
|
1172 | + } |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * Returns the avatar manager, used for avatar functionality |
|
1176 | + * |
|
1177 | + * @return \OCP\IAvatarManager |
|
1178 | + */ |
|
1179 | + public function getAvatarManager() { |
|
1180 | + return $this->query('AvatarManager'); |
|
1181 | + } |
|
1182 | + |
|
1183 | + /** |
|
1184 | + * Returns the root folder of ownCloud's data directory |
|
1185 | + * |
|
1186 | + * @return \OCP\Files\IRootFolder |
|
1187 | + */ |
|
1188 | + public function getRootFolder() { |
|
1189 | + return $this->query('LazyRootFolder'); |
|
1190 | + } |
|
1191 | + |
|
1192 | + /** |
|
1193 | + * Returns the root folder of ownCloud's data directory |
|
1194 | + * This is the lazy variant so this gets only initialized once it |
|
1195 | + * is actually used. |
|
1196 | + * |
|
1197 | + * @return \OCP\Files\IRootFolder |
|
1198 | + */ |
|
1199 | + public function getLazyRootFolder() { |
|
1200 | + return $this->query('LazyRootFolder'); |
|
1201 | + } |
|
1202 | + |
|
1203 | + /** |
|
1204 | + * Returns a view to ownCloud's files folder |
|
1205 | + * |
|
1206 | + * @param string $userId user ID |
|
1207 | + * @return \OCP\Files\Folder|null |
|
1208 | + */ |
|
1209 | + public function getUserFolder($userId = null) { |
|
1210 | + if ($userId === null) { |
|
1211 | + $user = $this->getUserSession()->getUser(); |
|
1212 | + if (!$user) { |
|
1213 | + return null; |
|
1214 | + } |
|
1215 | + $userId = $user->getUID(); |
|
1216 | + } |
|
1217 | + $root = $this->getRootFolder(); |
|
1218 | + return $root->getUserFolder($userId); |
|
1219 | + } |
|
1220 | + |
|
1221 | + /** |
|
1222 | + * Returns an app-specific view in ownClouds data directory |
|
1223 | + * |
|
1224 | + * @return \OCP\Files\Folder |
|
1225 | + * @deprecated since 9.2.0 use IAppData |
|
1226 | + */ |
|
1227 | + public function getAppFolder() { |
|
1228 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1229 | + $root = $this->getRootFolder(); |
|
1230 | + if (!$root->nodeExists($dir)) { |
|
1231 | + $folder = $root->newFolder($dir); |
|
1232 | + } else { |
|
1233 | + $folder = $root->get($dir); |
|
1234 | + } |
|
1235 | + return $folder; |
|
1236 | + } |
|
1237 | + |
|
1238 | + /** |
|
1239 | + * @return \OC\User\Manager |
|
1240 | + */ |
|
1241 | + public function getUserManager() { |
|
1242 | + return $this->query('UserManager'); |
|
1243 | + } |
|
1244 | + |
|
1245 | + /** |
|
1246 | + * @return \OC\Group\Manager |
|
1247 | + */ |
|
1248 | + public function getGroupManager() { |
|
1249 | + return $this->query('GroupManager'); |
|
1250 | + } |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * @return \OC\User\Session |
|
1254 | + */ |
|
1255 | + public function getUserSession() { |
|
1256 | + return $this->query('UserSession'); |
|
1257 | + } |
|
1258 | + |
|
1259 | + /** |
|
1260 | + * @return \OCP\ISession |
|
1261 | + */ |
|
1262 | + public function getSession() { |
|
1263 | + return $this->query('UserSession')->getSession(); |
|
1264 | + } |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * @param \OCP\ISession $session |
|
1268 | + */ |
|
1269 | + public function setSession(\OCP\ISession $session) { |
|
1270 | + $this->query(SessionStorage::class)->setSession($session); |
|
1271 | + $this->query('UserSession')->setSession($session); |
|
1272 | + $this->query(Store::class)->setSession($session); |
|
1273 | + } |
|
1274 | + |
|
1275 | + /** |
|
1276 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1277 | + */ |
|
1278 | + public function getTwoFactorAuthManager() { |
|
1279 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1280 | + } |
|
1281 | + |
|
1282 | + /** |
|
1283 | + * @return \OC\NavigationManager |
|
1284 | + */ |
|
1285 | + public function getNavigationManager() { |
|
1286 | + return $this->query('NavigationManager'); |
|
1287 | + } |
|
1288 | + |
|
1289 | + /** |
|
1290 | + * @return \OCP\IConfig |
|
1291 | + */ |
|
1292 | + public function getConfig() { |
|
1293 | + return $this->query('AllConfig'); |
|
1294 | + } |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * @return \OC\SystemConfig |
|
1298 | + */ |
|
1299 | + public function getSystemConfig() { |
|
1300 | + return $this->query('SystemConfig'); |
|
1301 | + } |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * Returns the app config manager |
|
1305 | + * |
|
1306 | + * @return \OCP\IAppConfig |
|
1307 | + */ |
|
1308 | + public function getAppConfig() { |
|
1309 | + return $this->query('AppConfig'); |
|
1310 | + } |
|
1311 | + |
|
1312 | + /** |
|
1313 | + * @return \OCP\L10N\IFactory |
|
1314 | + */ |
|
1315 | + public function getL10NFactory() { |
|
1316 | + return $this->query('L10NFactory'); |
|
1317 | + } |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * get an L10N instance |
|
1321 | + * |
|
1322 | + * @param string $app appid |
|
1323 | + * @param string $lang |
|
1324 | + * @return IL10N |
|
1325 | + */ |
|
1326 | + public function getL10N($app, $lang = null) { |
|
1327 | + return $this->getL10NFactory()->get($app, $lang); |
|
1328 | + } |
|
1329 | + |
|
1330 | + /** |
|
1331 | + * @return \OCP\IURLGenerator |
|
1332 | + */ |
|
1333 | + public function getURLGenerator() { |
|
1334 | + return $this->query('URLGenerator'); |
|
1335 | + } |
|
1336 | + |
|
1337 | + /** |
|
1338 | + * @return \OCP\IHelper |
|
1339 | + */ |
|
1340 | + public function getHelper() { |
|
1341 | + return $this->query('AppHelper'); |
|
1342 | + } |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * @return AppFetcher |
|
1346 | + */ |
|
1347 | + public function getAppFetcher() { |
|
1348 | + return $this->query(AppFetcher::class); |
|
1349 | + } |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1353 | + * getMemCacheFactory() instead. |
|
1354 | + * |
|
1355 | + * @return \OCP\ICache |
|
1356 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1357 | + */ |
|
1358 | + public function getCache() { |
|
1359 | + return $this->query('UserCache'); |
|
1360 | + } |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * Returns an \OCP\CacheFactory instance |
|
1364 | + * |
|
1365 | + * @return \OCP\ICacheFactory |
|
1366 | + */ |
|
1367 | + public function getMemCacheFactory() { |
|
1368 | + return $this->query('MemCacheFactory'); |
|
1369 | + } |
|
1370 | + |
|
1371 | + /** |
|
1372 | + * Returns an \OC\RedisFactory instance |
|
1373 | + * |
|
1374 | + * @return \OC\RedisFactory |
|
1375 | + */ |
|
1376 | + public function getGetRedisFactory() { |
|
1377 | + return $this->query('RedisFactory'); |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * Returns the current session |
|
1383 | + * |
|
1384 | + * @return \OCP\IDBConnection |
|
1385 | + */ |
|
1386 | + public function getDatabaseConnection() { |
|
1387 | + return $this->query('DatabaseConnection'); |
|
1388 | + } |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * Returns the activity manager |
|
1392 | + * |
|
1393 | + * @return \OCP\Activity\IManager |
|
1394 | + */ |
|
1395 | + public function getActivityManager() { |
|
1396 | + return $this->query('ActivityManager'); |
|
1397 | + } |
|
1398 | + |
|
1399 | + /** |
|
1400 | + * Returns an job list for controlling background jobs |
|
1401 | + * |
|
1402 | + * @return \OCP\BackgroundJob\IJobList |
|
1403 | + */ |
|
1404 | + public function getJobList() { |
|
1405 | + return $this->query('JobList'); |
|
1406 | + } |
|
1407 | + |
|
1408 | + /** |
|
1409 | + * Returns a logger instance |
|
1410 | + * |
|
1411 | + * @return \OCP\ILogger |
|
1412 | + */ |
|
1413 | + public function getLogger() { |
|
1414 | + return $this->query('Logger'); |
|
1415 | + } |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * Returns a router for generating and matching urls |
|
1419 | + * |
|
1420 | + * @return \OCP\Route\IRouter |
|
1421 | + */ |
|
1422 | + public function getRouter() { |
|
1423 | + return $this->query('Router'); |
|
1424 | + } |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * Returns a search instance |
|
1428 | + * |
|
1429 | + * @return \OCP\ISearch |
|
1430 | + */ |
|
1431 | + public function getSearch() { |
|
1432 | + return $this->query('Search'); |
|
1433 | + } |
|
1434 | + |
|
1435 | + /** |
|
1436 | + * Returns a SecureRandom instance |
|
1437 | + * |
|
1438 | + * @return \OCP\Security\ISecureRandom |
|
1439 | + */ |
|
1440 | + public function getSecureRandom() { |
|
1441 | + return $this->query('SecureRandom'); |
|
1442 | + } |
|
1443 | + |
|
1444 | + /** |
|
1445 | + * Returns a Crypto instance |
|
1446 | + * |
|
1447 | + * @return \OCP\Security\ICrypto |
|
1448 | + */ |
|
1449 | + public function getCrypto() { |
|
1450 | + return $this->query('Crypto'); |
|
1451 | + } |
|
1452 | + |
|
1453 | + /** |
|
1454 | + * Returns a Hasher instance |
|
1455 | + * |
|
1456 | + * @return \OCP\Security\IHasher |
|
1457 | + */ |
|
1458 | + public function getHasher() { |
|
1459 | + return $this->query('Hasher'); |
|
1460 | + } |
|
1461 | + |
|
1462 | + /** |
|
1463 | + * Returns a CredentialsManager instance |
|
1464 | + * |
|
1465 | + * @return \OCP\Security\ICredentialsManager |
|
1466 | + */ |
|
1467 | + public function getCredentialsManager() { |
|
1468 | + return $this->query('CredentialsManager'); |
|
1469 | + } |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Returns an instance of the HTTP helper class |
|
1473 | + * |
|
1474 | + * @deprecated Use getHTTPClientService() |
|
1475 | + * @return \OC\HTTPHelper |
|
1476 | + */ |
|
1477 | + public function getHTTPHelper() { |
|
1478 | + return $this->query('HTTPHelper'); |
|
1479 | + } |
|
1480 | + |
|
1481 | + /** |
|
1482 | + * Get the certificate manager for the user |
|
1483 | + * |
|
1484 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1485 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1486 | + */ |
|
1487 | + public function getCertificateManager($userId = '') { |
|
1488 | + if ($userId === '') { |
|
1489 | + $userSession = $this->getUserSession(); |
|
1490 | + $user = $userSession->getUser(); |
|
1491 | + if (is_null($user)) { |
|
1492 | + return null; |
|
1493 | + } |
|
1494 | + $userId = $user->getUID(); |
|
1495 | + } |
|
1496 | + return new CertificateManager( |
|
1497 | + $userId, |
|
1498 | + new View(), |
|
1499 | + $this->getConfig(), |
|
1500 | + $this->getLogger(), |
|
1501 | + $this->getSecureRandom() |
|
1502 | + ); |
|
1503 | + } |
|
1504 | + |
|
1505 | + /** |
|
1506 | + * Returns an instance of the HTTP client service |
|
1507 | + * |
|
1508 | + * @return \OCP\Http\Client\IClientService |
|
1509 | + */ |
|
1510 | + public function getHTTPClientService() { |
|
1511 | + return $this->query('HttpClientService'); |
|
1512 | + } |
|
1513 | + |
|
1514 | + /** |
|
1515 | + * Create a new event source |
|
1516 | + * |
|
1517 | + * @return \OCP\IEventSource |
|
1518 | + */ |
|
1519 | + public function createEventSource() { |
|
1520 | + return new \OC_EventSource(); |
|
1521 | + } |
|
1522 | + |
|
1523 | + /** |
|
1524 | + * Get the active event logger |
|
1525 | + * |
|
1526 | + * The returned logger only logs data when debug mode is enabled |
|
1527 | + * |
|
1528 | + * @return \OCP\Diagnostics\IEventLogger |
|
1529 | + */ |
|
1530 | + public function getEventLogger() { |
|
1531 | + return $this->query('EventLogger'); |
|
1532 | + } |
|
1533 | + |
|
1534 | + /** |
|
1535 | + * Get the active query logger |
|
1536 | + * |
|
1537 | + * The returned logger only logs data when debug mode is enabled |
|
1538 | + * |
|
1539 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1540 | + */ |
|
1541 | + public function getQueryLogger() { |
|
1542 | + return $this->query('QueryLogger'); |
|
1543 | + } |
|
1544 | + |
|
1545 | + /** |
|
1546 | + * Get the manager for temporary files and folders |
|
1547 | + * |
|
1548 | + * @return \OCP\ITempManager |
|
1549 | + */ |
|
1550 | + public function getTempManager() { |
|
1551 | + return $this->query('TempManager'); |
|
1552 | + } |
|
1553 | + |
|
1554 | + /** |
|
1555 | + * Get the app manager |
|
1556 | + * |
|
1557 | + * @return \OCP\App\IAppManager |
|
1558 | + */ |
|
1559 | + public function getAppManager() { |
|
1560 | + return $this->query('AppManager'); |
|
1561 | + } |
|
1562 | + |
|
1563 | + /** |
|
1564 | + * Creates a new mailer |
|
1565 | + * |
|
1566 | + * @return \OCP\Mail\IMailer |
|
1567 | + */ |
|
1568 | + public function getMailer() { |
|
1569 | + return $this->query('Mailer'); |
|
1570 | + } |
|
1571 | + |
|
1572 | + /** |
|
1573 | + * Get the webroot |
|
1574 | + * |
|
1575 | + * @return string |
|
1576 | + */ |
|
1577 | + public function getWebRoot() { |
|
1578 | + return $this->webRoot; |
|
1579 | + } |
|
1580 | + |
|
1581 | + /** |
|
1582 | + * @return \OC\OCSClient |
|
1583 | + */ |
|
1584 | + public function getOcsClient() { |
|
1585 | + return $this->query('OcsClient'); |
|
1586 | + } |
|
1587 | + |
|
1588 | + /** |
|
1589 | + * @return \OCP\IDateTimeZone |
|
1590 | + */ |
|
1591 | + public function getDateTimeZone() { |
|
1592 | + return $this->query('DateTimeZone'); |
|
1593 | + } |
|
1594 | + |
|
1595 | + /** |
|
1596 | + * @return \OCP\IDateTimeFormatter |
|
1597 | + */ |
|
1598 | + public function getDateTimeFormatter() { |
|
1599 | + return $this->query('DateTimeFormatter'); |
|
1600 | + } |
|
1601 | + |
|
1602 | + /** |
|
1603 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1604 | + */ |
|
1605 | + public function getMountProviderCollection() { |
|
1606 | + return $this->query('MountConfigManager'); |
|
1607 | + } |
|
1608 | + |
|
1609 | + /** |
|
1610 | + * Get the IniWrapper |
|
1611 | + * |
|
1612 | + * @return IniGetWrapper |
|
1613 | + */ |
|
1614 | + public function getIniWrapper() { |
|
1615 | + return $this->query('IniWrapper'); |
|
1616 | + } |
|
1617 | + |
|
1618 | + /** |
|
1619 | + * @return \OCP\Command\IBus |
|
1620 | + */ |
|
1621 | + public function getCommandBus() { |
|
1622 | + return $this->query('AsyncCommandBus'); |
|
1623 | + } |
|
1624 | + |
|
1625 | + /** |
|
1626 | + * Get the trusted domain helper |
|
1627 | + * |
|
1628 | + * @return TrustedDomainHelper |
|
1629 | + */ |
|
1630 | + public function getTrustedDomainHelper() { |
|
1631 | + return $this->query('TrustedDomainHelper'); |
|
1632 | + } |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Get the locking provider |
|
1636 | + * |
|
1637 | + * @return \OCP\Lock\ILockingProvider |
|
1638 | + * @since 8.1.0 |
|
1639 | + */ |
|
1640 | + public function getLockingProvider() { |
|
1641 | + return $this->query('LockingProvider'); |
|
1642 | + } |
|
1643 | + |
|
1644 | + /** |
|
1645 | + * @return \OCP\Files\Mount\IMountManager |
|
1646 | + **/ |
|
1647 | + function getMountManager() { |
|
1648 | + return $this->query('MountManager'); |
|
1649 | + } |
|
1650 | + |
|
1651 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1652 | + function getUserMountCache() { |
|
1653 | + return $this->query('UserMountCache'); |
|
1654 | + } |
|
1655 | + |
|
1656 | + /** |
|
1657 | + * Get the MimeTypeDetector |
|
1658 | + * |
|
1659 | + * @return \OCP\Files\IMimeTypeDetector |
|
1660 | + */ |
|
1661 | + public function getMimeTypeDetector() { |
|
1662 | + return $this->query('MimeTypeDetector'); |
|
1663 | + } |
|
1664 | + |
|
1665 | + /** |
|
1666 | + * Get the MimeTypeLoader |
|
1667 | + * |
|
1668 | + * @return \OCP\Files\IMimeTypeLoader |
|
1669 | + */ |
|
1670 | + public function getMimeTypeLoader() { |
|
1671 | + return $this->query('MimeTypeLoader'); |
|
1672 | + } |
|
1673 | + |
|
1674 | + /** |
|
1675 | + * Get the manager of all the capabilities |
|
1676 | + * |
|
1677 | + * @return \OC\CapabilitiesManager |
|
1678 | + */ |
|
1679 | + public function getCapabilitiesManager() { |
|
1680 | + return $this->query('CapabilitiesManager'); |
|
1681 | + } |
|
1682 | + |
|
1683 | + /** |
|
1684 | + * Get the EventDispatcher |
|
1685 | + * |
|
1686 | + * @return EventDispatcherInterface |
|
1687 | + * @since 8.2.0 |
|
1688 | + */ |
|
1689 | + public function getEventDispatcher() { |
|
1690 | + return $this->query('EventDispatcher'); |
|
1691 | + } |
|
1692 | + |
|
1693 | + /** |
|
1694 | + * Get the Notification Manager |
|
1695 | + * |
|
1696 | + * @return \OCP\Notification\IManager |
|
1697 | + * @since 8.2.0 |
|
1698 | + */ |
|
1699 | + public function getNotificationManager() { |
|
1700 | + return $this->query('NotificationManager'); |
|
1701 | + } |
|
1702 | + |
|
1703 | + /** |
|
1704 | + * @return \OCP\Comments\ICommentsManager |
|
1705 | + */ |
|
1706 | + public function getCommentsManager() { |
|
1707 | + return $this->query('CommentsManager'); |
|
1708 | + } |
|
1709 | + |
|
1710 | + /** |
|
1711 | + * @return \OCA\Theming\ThemingDefaults |
|
1712 | + */ |
|
1713 | + public function getThemingDefaults() { |
|
1714 | + return $this->query('ThemingDefaults'); |
|
1715 | + } |
|
1716 | + |
|
1717 | + /** |
|
1718 | + * @return \OC\IntegrityCheck\Checker |
|
1719 | + */ |
|
1720 | + public function getIntegrityCodeChecker() { |
|
1721 | + return $this->query('IntegrityCodeChecker'); |
|
1722 | + } |
|
1723 | + |
|
1724 | + /** |
|
1725 | + * @return \OC\Session\CryptoWrapper |
|
1726 | + */ |
|
1727 | + public function getSessionCryptoWrapper() { |
|
1728 | + return $this->query('CryptoWrapper'); |
|
1729 | + } |
|
1730 | + |
|
1731 | + /** |
|
1732 | + * @return CsrfTokenManager |
|
1733 | + */ |
|
1734 | + public function getCsrfTokenManager() { |
|
1735 | + return $this->query('CsrfTokenManager'); |
|
1736 | + } |
|
1737 | + |
|
1738 | + /** |
|
1739 | + * @return Throttler |
|
1740 | + */ |
|
1741 | + public function getBruteForceThrottler() { |
|
1742 | + return $this->query('Throttler'); |
|
1743 | + } |
|
1744 | + |
|
1745 | + /** |
|
1746 | + * @return IContentSecurityPolicyManager |
|
1747 | + */ |
|
1748 | + public function getContentSecurityPolicyManager() { |
|
1749 | + return $this->query('ContentSecurityPolicyManager'); |
|
1750 | + } |
|
1751 | + |
|
1752 | + /** |
|
1753 | + * @return ContentSecurityPolicyNonceManager |
|
1754 | + */ |
|
1755 | + public function getContentSecurityPolicyNonceManager() { |
|
1756 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1757 | + } |
|
1758 | + |
|
1759 | + /** |
|
1760 | + * Not a public API as of 8.2, wait for 9.0 |
|
1761 | + * |
|
1762 | + * @return \OCA\Files_External\Service\BackendService |
|
1763 | + */ |
|
1764 | + public function getStoragesBackendService() { |
|
1765 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1766 | + } |
|
1767 | + |
|
1768 | + /** |
|
1769 | + * Not a public API as of 8.2, wait for 9.0 |
|
1770 | + * |
|
1771 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1772 | + */ |
|
1773 | + public function getGlobalStoragesService() { |
|
1774 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1775 | + } |
|
1776 | + |
|
1777 | + /** |
|
1778 | + * Not a public API as of 8.2, wait for 9.0 |
|
1779 | + * |
|
1780 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1781 | + */ |
|
1782 | + public function getUserGlobalStoragesService() { |
|
1783 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1784 | + } |
|
1785 | + |
|
1786 | + /** |
|
1787 | + * Not a public API as of 8.2, wait for 9.0 |
|
1788 | + * |
|
1789 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1790 | + */ |
|
1791 | + public function getUserStoragesService() { |
|
1792 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1793 | + } |
|
1794 | + |
|
1795 | + /** |
|
1796 | + * @return \OCP\Share\IManager |
|
1797 | + */ |
|
1798 | + public function getShareManager() { |
|
1799 | + return $this->query('ShareManager'); |
|
1800 | + } |
|
1801 | + |
|
1802 | + /** |
|
1803 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1804 | + */ |
|
1805 | + public function getCollaboratorSearch() { |
|
1806 | + return $this->query('CollaboratorSearch'); |
|
1807 | + } |
|
1808 | + |
|
1809 | + /** |
|
1810 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1811 | + */ |
|
1812 | + public function getAutoCompleteManager(){ |
|
1813 | + return $this->query('AutoCompleteManager'); |
|
1814 | + } |
|
1815 | + |
|
1816 | + /** |
|
1817 | + * Returns the LDAP Provider |
|
1818 | + * |
|
1819 | + * @return \OCP\LDAP\ILDAPProvider |
|
1820 | + */ |
|
1821 | + public function getLDAPProvider() { |
|
1822 | + return $this->query('LDAPProvider'); |
|
1823 | + } |
|
1824 | + |
|
1825 | + /** |
|
1826 | + * @return \OCP\Settings\IManager |
|
1827 | + */ |
|
1828 | + public function getSettingsManager() { |
|
1829 | + return $this->query('SettingsManager'); |
|
1830 | + } |
|
1831 | + |
|
1832 | + /** |
|
1833 | + * @return \OCP\Files\IAppData |
|
1834 | + */ |
|
1835 | + public function getAppDataDir($app) { |
|
1836 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1837 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1838 | + return $factory->get($app); |
|
1839 | + } |
|
1840 | + |
|
1841 | + /** |
|
1842 | + * @return \OCP\Lockdown\ILockdownManager |
|
1843 | + */ |
|
1844 | + public function getLockdownManager() { |
|
1845 | + return $this->query('LockdownManager'); |
|
1846 | + } |
|
1847 | + |
|
1848 | + /** |
|
1849 | + * @return \OCP\Federation\ICloudIdManager |
|
1850 | + */ |
|
1851 | + public function getCloudIdManager() { |
|
1852 | + return $this->query(ICloudIdManager::class); |
|
1853 | + } |
|
1854 | 1854 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | parent::__construct(); |
144 | 144 | $this->webRoot = $webRoot; |
145 | 145 | |
146 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
146 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
147 | 147 | return $c; |
148 | 148 | }); |
149 | 149 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
154 | 154 | |
155 | 155 | |
156 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
156 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
157 | 157 | return new PreviewManager( |
158 | 158 | $c->getConfig(), |
159 | 159 | $c->getRootFolder(), |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | }); |
165 | 165 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
166 | 166 | |
167 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
167 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
168 | 168 | return new \OC\Preview\Watcher( |
169 | 169 | $c->getAppDataDir('preview') |
170 | 170 | ); |
171 | 171 | }); |
172 | 172 | |
173 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
173 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
174 | 174 | $view = new View(); |
175 | 175 | $util = new Encryption\Util( |
176 | 176 | $view, |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | ); |
189 | 189 | }); |
190 | 190 | |
191 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
191 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
192 | 192 | $util = new Encryption\Util( |
193 | 193 | new View(), |
194 | 194 | $c->getUserManager(), |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | ); |
203 | 203 | }); |
204 | 204 | |
205 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
205 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
206 | 206 | $view = new View(); |
207 | 207 | $util = new Encryption\Util( |
208 | 208 | $view, |
@@ -213,32 +213,32 @@ discard block |
||
213 | 213 | |
214 | 214 | return new Encryption\Keys\Storage($view, $util); |
215 | 215 | }); |
216 | - $this->registerService('TagMapper', function (Server $c) { |
|
216 | + $this->registerService('TagMapper', function(Server $c) { |
|
217 | 217 | return new TagMapper($c->getDatabaseConnection()); |
218 | 218 | }); |
219 | 219 | |
220 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
220 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
221 | 221 | $tagMapper = $c->query('TagMapper'); |
222 | 222 | return new TagManager($tagMapper, $c->getUserSession()); |
223 | 223 | }); |
224 | 224 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
225 | 225 | |
226 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
226 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
227 | 227 | $config = $c->getConfig(); |
228 | 228 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
229 | 229 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
230 | 230 | $factory = new $factoryClass($this); |
231 | 231 | return $factory; |
232 | 232 | }); |
233 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
233 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
234 | 234 | return $c->query('SystemTagManagerFactory')->getManager(); |
235 | 235 | }); |
236 | 236 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
237 | 237 | |
238 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
238 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
239 | 239 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
240 | 240 | }); |
241 | - $this->registerService('RootFolder', function (Server $c) { |
|
241 | + $this->registerService('RootFolder', function(Server $c) { |
|
242 | 242 | $manager = \OC\Files\Filesystem::getMountManager(null); |
243 | 243 | $view = new View(); |
244 | 244 | $root = new Root( |
@@ -259,37 +259,37 @@ discard block |
||
259 | 259 | }); |
260 | 260 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
261 | 261 | |
262 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
263 | - return new LazyRoot(function () use ($c) { |
|
262 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
263 | + return new LazyRoot(function() use ($c) { |
|
264 | 264 | return $c->query('RootFolder'); |
265 | 265 | }); |
266 | 266 | }); |
267 | 267 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
268 | 268 | |
269 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
269 | + $this->registerService(\OCP\IUserManager::class, function(Server $c) { |
|
270 | 270 | $config = $c->getConfig(); |
271 | 271 | return new \OC\User\Manager($config); |
272 | 272 | }); |
273 | 273 | $this->registerAlias('UserManager', \OCP\IUserManager::class); |
274 | 274 | |
275 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
275 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
276 | 276 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
277 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
277 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
278 | 278 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
279 | 279 | }); |
280 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
280 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
281 | 281 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
282 | 282 | }); |
283 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
283 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
284 | 284 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
285 | 285 | }); |
286 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
286 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
287 | 287 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
288 | 288 | }); |
289 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
289 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
290 | 290 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
291 | 291 | }); |
292 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
292 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
293 | 293 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
294 | 294 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
295 | 295 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | }); |
299 | 299 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
300 | 300 | |
301 | - $this->registerService(Store::class, function (Server $c) { |
|
301 | + $this->registerService(Store::class, function(Server $c) { |
|
302 | 302 | $session = $c->getSession(); |
303 | 303 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
304 | 304 | $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | return new Store($session, $logger, $tokenProvider); |
310 | 310 | }); |
311 | 311 | $this->registerAlias(IStore::class, Store::class); |
312 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
312 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) { |
|
313 | 313 | $dbConnection = $c->getDatabaseConnection(); |
314 | 314 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
315 | 315 | }); |
316 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
316 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) { |
|
317 | 317 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
318 | 318 | $crypto = $c->getCrypto(); |
319 | 319 | $config = $c->getConfig(); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | }); |
324 | 324 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
325 | 325 | |
326 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
326 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
327 | 327 | $manager = $c->getUserManager(); |
328 | 328 | $session = new \OC\Session\Memory(''); |
329 | 329 | $timeFactory = new TimeFactory(); |
@@ -336,44 +336,44 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
339 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
339 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
340 | 340 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
341 | 341 | }); |
342 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
342 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
343 | 343 | /** @var $user \OC\User\User */ |
344 | 344 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
345 | 345 | }); |
346 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
346 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
347 | 347 | /** @var $user \OC\User\User */ |
348 | 348 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
349 | 349 | }); |
350 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
350 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
351 | 351 | /** @var $user \OC\User\User */ |
352 | 352 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
353 | 353 | }); |
354 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
354 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
355 | 355 | /** @var $user \OC\User\User */ |
356 | 356 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
357 | 357 | }); |
358 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
358 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
359 | 359 | /** @var $user \OC\User\User */ |
360 | 360 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
361 | 361 | }); |
362 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
362 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
363 | 363 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
364 | 364 | }); |
365 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
365 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
366 | 366 | /** @var $user \OC\User\User */ |
367 | 367 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
368 | 368 | }); |
369 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
369 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
370 | 370 | /** @var $user \OC\User\User */ |
371 | 371 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
372 | 372 | }); |
373 | - $userSession->listen('\OC\User', 'logout', function () { |
|
373 | + $userSession->listen('\OC\User', 'logout', function() { |
|
374 | 374 | \OC_Hook::emit('OC_User', 'logout', array()); |
375 | 375 | }); |
376 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
376 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
377 | 377 | /** @var $user \OC\User\User */ |
378 | 378 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
379 | 379 | }); |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | }); |
382 | 382 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
383 | 383 | |
384 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
384 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
385 | 385 | return new \OC\Authentication\TwoFactorAuth\Manager( |
386 | 386 | $c->getAppManager(), |
387 | 387 | $c->getSession(), |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
397 | 397 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
398 | 398 | |
399 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
399 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
400 | 400 | return new \OC\AllConfig( |
401 | 401 | $c->getSystemConfig() |
402 | 402 | ); |
@@ -404,17 +404,17 @@ discard block |
||
404 | 404 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
405 | 405 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
406 | 406 | |
407 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
407 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
408 | 408 | return new \OC\SystemConfig($config); |
409 | 409 | }); |
410 | 410 | |
411 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
411 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
412 | 412 | return new \OC\AppConfig($c->getDatabaseConnection()); |
413 | 413 | }); |
414 | 414 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
415 | 415 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
416 | 416 | |
417 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
417 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
418 | 418 | return new \OC\L10N\Factory( |
419 | 419 | $c->getConfig(), |
420 | 420 | $c->getRequest(), |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | }); |
425 | 425 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
426 | 426 | |
427 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
427 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
428 | 428 | $config = $c->getConfig(); |
429 | 429 | $cacheFactory = $c->getMemCacheFactory(); |
430 | 430 | $request = $c->getRequest(); |
@@ -436,18 +436,18 @@ discard block |
||
436 | 436 | }); |
437 | 437 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
438 | 438 | |
439 | - $this->registerService('AppHelper', function ($c) { |
|
439 | + $this->registerService('AppHelper', function($c) { |
|
440 | 440 | return new \OC\AppHelper(); |
441 | 441 | }); |
442 | 442 | $this->registerAlias('AppFetcher', AppFetcher::class); |
443 | 443 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
444 | 444 | |
445 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
445 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
446 | 446 | return new Cache\File(); |
447 | 447 | }); |
448 | 448 | $this->registerAlias('UserCache', \OCP\ICache::class); |
449 | 449 | |
450 | - $this->registerService(Factory::class, function (Server $c) { |
|
450 | + $this->registerService(Factory::class, function(Server $c) { |
|
451 | 451 | |
452 | 452 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
453 | 453 | '\\OC\\Memcache\\ArrayCache', |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | $version = implode(',', $v); |
465 | 465 | $instanceId = \OC_Util::getInstanceId(); |
466 | 466 | $path = \OC::$SERVERROOT; |
467 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
467 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.$urlGenerator->getBaseUrl()); |
|
468 | 468 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
469 | 469 | $config->getSystemValue('memcache.local', null), |
470 | 470 | $config->getSystemValue('memcache.distributed', null), |
@@ -477,12 +477,12 @@ discard block |
||
477 | 477 | $this->registerAlias('MemCacheFactory', Factory::class); |
478 | 478 | $this->registerAlias(ICacheFactory::class, Factory::class); |
479 | 479 | |
480 | - $this->registerService('RedisFactory', function (Server $c) { |
|
480 | + $this->registerService('RedisFactory', function(Server $c) { |
|
481 | 481 | $systemConfig = $c->getSystemConfig(); |
482 | 482 | return new RedisFactory($systemConfig); |
483 | 483 | }); |
484 | 484 | |
485 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
485 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
486 | 486 | return new \OC\Activity\Manager( |
487 | 487 | $c->getRequest(), |
488 | 488 | $c->getUserSession(), |
@@ -492,14 +492,14 @@ discard block |
||
492 | 492 | }); |
493 | 493 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
494 | 494 | |
495 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
495 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
496 | 496 | return new \OC\Activity\EventMerger( |
497 | 497 | $c->getL10N('lib') |
498 | 498 | ); |
499 | 499 | }); |
500 | 500 | $this->registerAlias(IValidator::class, Validator::class); |
501 | 501 | |
502 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
502 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
503 | 503 | return new AvatarManager( |
504 | 504 | $c->getUserManager(), |
505 | 505 | $c->getAppDataDir('avatar'), |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | }); |
511 | 511 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
512 | 512 | |
513 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
513 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
514 | 514 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
515 | 515 | $logger = Log::getLogClass($logType); |
516 | 516 | call_user_func(array($logger, 'init')); |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | }); |
520 | 520 | $this->registerAlias('Logger', \OCP\ILogger::class); |
521 | 521 | |
522 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
522 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
523 | 523 | $config = $c->getConfig(); |
524 | 524 | return new \OC\BackgroundJob\JobList( |
525 | 525 | $c->getDatabaseConnection(), |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | }); |
530 | 530 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
531 | 531 | |
532 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
532 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
533 | 533 | $cacheFactory = $c->getMemCacheFactory(); |
534 | 534 | $logger = $c->getLogger(); |
535 | 535 | if ($cacheFactory->isAvailable()) { |
@@ -541,12 +541,12 @@ discard block |
||
541 | 541 | }); |
542 | 542 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
543 | 543 | |
544 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
544 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
545 | 545 | return new Search(); |
546 | 546 | }); |
547 | 547 | $this->registerAlias('Search', \OCP\ISearch::class); |
548 | 548 | |
549 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
549 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
550 | 550 | return new \OC\Security\RateLimiting\Limiter( |
551 | 551 | $this->getUserSession(), |
552 | 552 | $this->getRequest(), |
@@ -554,34 +554,34 @@ discard block |
||
554 | 554 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
555 | 555 | ); |
556 | 556 | }); |
557 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
557 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
558 | 558 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
559 | 559 | $this->getMemCacheFactory(), |
560 | 560 | new \OC\AppFramework\Utility\TimeFactory() |
561 | 561 | ); |
562 | 562 | }); |
563 | 563 | |
564 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
564 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
565 | 565 | return new SecureRandom(); |
566 | 566 | }); |
567 | 567 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
568 | 568 | |
569 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
569 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
570 | 570 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
571 | 571 | }); |
572 | 572 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
573 | 573 | |
574 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
574 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
575 | 575 | return new Hasher($c->getConfig()); |
576 | 576 | }); |
577 | 577 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
578 | 578 | |
579 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
579 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
580 | 580 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
581 | 581 | }); |
582 | 582 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
583 | 583 | |
584 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
584 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
585 | 585 | $systemConfig = $c->getSystemConfig(); |
586 | 586 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
587 | 587 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | }); |
596 | 596 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
597 | 597 | |
598 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
598 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
599 | 599 | $config = $c->getConfig(); |
600 | 600 | return new HTTPHelper( |
601 | 601 | $config, |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | ); |
604 | 604 | }); |
605 | 605 | |
606 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
606 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
607 | 607 | $user = \OC_User::getUser(); |
608 | 608 | $uid = $user ? $user : null; |
609 | 609 | return new ClientService( |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | ); |
619 | 619 | }); |
620 | 620 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
621 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
621 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
622 | 622 | $eventLogger = new EventLogger(); |
623 | 623 | if ($c->getSystemConfig()->getValue('debug', false)) { |
624 | 624 | // In debug mode, module is being activated by default |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | }); |
629 | 629 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
630 | 630 | |
631 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
631 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
632 | 632 | $queryLogger = new QueryLogger(); |
633 | 633 | if ($c->getSystemConfig()->getValue('debug', false)) { |
634 | 634 | // In debug mode, module is being activated by default |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | }); |
639 | 639 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
640 | 640 | |
641 | - $this->registerService(TempManager::class, function (Server $c) { |
|
641 | + $this->registerService(TempManager::class, function(Server $c) { |
|
642 | 642 | return new TempManager( |
643 | 643 | $c->getLogger(), |
644 | 644 | $c->getConfig() |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | $this->registerAlias('TempManager', TempManager::class); |
648 | 648 | $this->registerAlias(ITempManager::class, TempManager::class); |
649 | 649 | |
650 | - $this->registerService(AppManager::class, function (Server $c) { |
|
650 | + $this->registerService(AppManager::class, function(Server $c) { |
|
651 | 651 | return new \OC\App\AppManager( |
652 | 652 | $c->getUserSession(), |
653 | 653 | $c->getAppConfig(), |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | $this->registerAlias('AppManager', AppManager::class); |
660 | 660 | $this->registerAlias(IAppManager::class, AppManager::class); |
661 | 661 | |
662 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
662 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
663 | 663 | return new DateTimeZone( |
664 | 664 | $c->getConfig(), |
665 | 665 | $c->getSession() |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | }); |
668 | 668 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
669 | 669 | |
670 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
670 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
671 | 671 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
672 | 672 | |
673 | 673 | return new DateTimeFormatter( |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | }); |
678 | 678 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
679 | 679 | |
680 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
680 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
681 | 681 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
682 | 682 | $listener = new UserMountCacheListener($mountCache); |
683 | 683 | $listener->listen($c->getUserManager()); |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | }); |
686 | 686 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
687 | 687 | |
688 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
688 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
689 | 689 | $loader = \OC\Files\Filesystem::getLoader(); |
690 | 690 | $mountCache = $c->query('UserMountCache'); |
691 | 691 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -701,10 +701,10 @@ discard block |
||
701 | 701 | }); |
702 | 702 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
703 | 703 | |
704 | - $this->registerService('IniWrapper', function ($c) { |
|
704 | + $this->registerService('IniWrapper', function($c) { |
|
705 | 705 | return new IniGetWrapper(); |
706 | 706 | }); |
707 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
707 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
708 | 708 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
709 | 709 | if ($busClass) { |
710 | 710 | list($app, $class) = explode('::', $busClass, 2); |
@@ -719,10 +719,10 @@ discard block |
||
719 | 719 | return new CronBus($jobList); |
720 | 720 | } |
721 | 721 | }); |
722 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
722 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
723 | 723 | return new TrustedDomainHelper($this->getConfig()); |
724 | 724 | }); |
725 | - $this->registerService('Throttler', function (Server $c) { |
|
725 | + $this->registerService('Throttler', function(Server $c) { |
|
726 | 726 | return new Throttler( |
727 | 727 | $c->getDatabaseConnection(), |
728 | 728 | new TimeFactory(), |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | $c->getConfig() |
731 | 731 | ); |
732 | 732 | }); |
733 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
733 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
734 | 734 | // IConfig and IAppManager requires a working database. This code |
735 | 735 | // might however be called when ownCloud is not yet setup. |
736 | 736 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | $c->getTempManager() |
752 | 752 | ); |
753 | 753 | }); |
754 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
754 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
755 | 755 | if (isset($this['urlParams'])) { |
756 | 756 | $urlParams = $this['urlParams']; |
757 | 757 | } else { |
@@ -787,7 +787,7 @@ discard block |
||
787 | 787 | }); |
788 | 788 | $this->registerAlias('Request', \OCP\IRequest::class); |
789 | 789 | |
790 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
790 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
791 | 791 | return new Mailer( |
792 | 792 | $c->getConfig(), |
793 | 793 | $c->getLogger(), |
@@ -798,7 +798,7 @@ discard block |
||
798 | 798 | }); |
799 | 799 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
800 | 800 | |
801 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
801 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
802 | 802 | $config = $c->getConfig(); |
803 | 803 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
804 | 804 | if (is_null($factoryClass)) { |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | $factory = new $factoryClass($this); |
809 | 809 | return $factory->getLDAPProvider(); |
810 | 810 | }); |
811 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
811 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
812 | 812 | $ini = $c->getIniWrapper(); |
813 | 813 | $config = $c->getConfig(); |
814 | 814 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -825,49 +825,49 @@ discard block |
||
825 | 825 | }); |
826 | 826 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
827 | 827 | |
828 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
828 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
829 | 829 | return new \OC\Files\Mount\Manager(); |
830 | 830 | }); |
831 | 831 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
832 | 832 | |
833 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
833 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
834 | 834 | return new \OC\Files\Type\Detection( |
835 | 835 | $c->getURLGenerator(), |
836 | 836 | \OC::$configDir, |
837 | - \OC::$SERVERROOT . '/resources/config/' |
|
837 | + \OC::$SERVERROOT.'/resources/config/' |
|
838 | 838 | ); |
839 | 839 | }); |
840 | 840 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
841 | 841 | |
842 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
842 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
843 | 843 | return new \OC\Files\Type\Loader( |
844 | 844 | $c->getDatabaseConnection() |
845 | 845 | ); |
846 | 846 | }); |
847 | 847 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
848 | - $this->registerService(BundleFetcher::class, function () { |
|
848 | + $this->registerService(BundleFetcher::class, function() { |
|
849 | 849 | return new BundleFetcher($this->getL10N('lib')); |
850 | 850 | }); |
851 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
851 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
852 | 852 | return new Manager( |
853 | 853 | $c->query(IValidator::class) |
854 | 854 | ); |
855 | 855 | }); |
856 | 856 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
857 | 857 | |
858 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
858 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
859 | 859 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
860 | - $manager->registerCapability(function () use ($c) { |
|
860 | + $manager->registerCapability(function() use ($c) { |
|
861 | 861 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
862 | 862 | }); |
863 | - $manager->registerCapability(function () use ($c) { |
|
863 | + $manager->registerCapability(function() use ($c) { |
|
864 | 864 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
865 | 865 | }); |
866 | 866 | return $manager; |
867 | 867 | }); |
868 | 868 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
869 | 869 | |
870 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
870 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
871 | 871 | $config = $c->getConfig(); |
872 | 872 | $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
873 | 873 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | }); |
877 | 877 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
878 | 878 | |
879 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
879 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
880 | 880 | /* |
881 | 881 | * Dark magic for autoloader. |
882 | 882 | * If we do a class_exists it will try to load the class which will |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | } |
904 | 904 | return new \OC_Defaults(); |
905 | 905 | }); |
906 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
906 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
907 | 907 | /** @var Factory $cacheFactory */ |
908 | 908 | $cacheFactory = $c->query(Factory::class); |
909 | 909 | return new SCSSCacher( |
@@ -916,13 +916,13 @@ discard block |
||
916 | 916 | $cacheFactory->create('SCSS') |
917 | 917 | ); |
918 | 918 | }); |
919 | - $this->registerService(EventDispatcher::class, function () { |
|
919 | + $this->registerService(EventDispatcher::class, function() { |
|
920 | 920 | return new EventDispatcher(); |
921 | 921 | }); |
922 | 922 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
923 | 923 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
924 | 924 | |
925 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
925 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
926 | 926 | // FIXME: Instantiiated here due to cyclic dependency |
927 | 927 | $request = new Request( |
928 | 928 | [ |
@@ -947,7 +947,7 @@ discard block |
||
947 | 947 | $request |
948 | 948 | ); |
949 | 949 | }); |
950 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
950 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
951 | 951 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
952 | 952 | |
953 | 953 | return new CsrfTokenManager( |
@@ -955,22 +955,22 @@ discard block |
||
955 | 955 | $c->query(SessionStorage::class) |
956 | 956 | ); |
957 | 957 | }); |
958 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
958 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
959 | 959 | return new SessionStorage($c->getSession()); |
960 | 960 | }); |
961 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
961 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
962 | 962 | return new ContentSecurityPolicyManager(); |
963 | 963 | }); |
964 | 964 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
965 | 965 | |
966 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
966 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
967 | 967 | return new ContentSecurityPolicyNonceManager( |
968 | 968 | $c->getCsrfTokenManager(), |
969 | 969 | $c->getRequest() |
970 | 970 | ); |
971 | 971 | }); |
972 | 972 | |
973 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
973 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
974 | 974 | $config = $c->getConfig(); |
975 | 975 | $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
976 | 976 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1011,12 +1011,12 @@ discard block |
||
1011 | 1011 | }); |
1012 | 1012 | $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
1013 | 1013 | |
1014 | - $this->registerService(\OCP\Collaboration\AutoComplete\IManager::class, function (Server $c) { |
|
1014 | + $this->registerService(\OCP\Collaboration\AutoComplete\IManager::class, function(Server $c) { |
|
1015 | 1015 | return new Collaboration\AutoComplete\Manager($c); |
1016 | 1016 | }); |
1017 | 1017 | $this->registerAlias('AutoCompleteManager', \OCP\Collaboration\AutoComplete\IManager::class); |
1018 | 1018 | |
1019 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1019 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1020 | 1020 | $manager = new \OC\Settings\Manager( |
1021 | 1021 | $c->getLogger(), |
1022 | 1022 | $c->getDatabaseConnection(), |
@@ -1036,29 +1036,29 @@ discard block |
||
1036 | 1036 | ); |
1037 | 1037 | return $manager; |
1038 | 1038 | }); |
1039 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1039 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1040 | 1040 | return new \OC\Files\AppData\Factory( |
1041 | 1041 | $c->getRootFolder(), |
1042 | 1042 | $c->getSystemConfig() |
1043 | 1043 | ); |
1044 | 1044 | }); |
1045 | 1045 | |
1046 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1047 | - return new LockdownManager(function () use ($c) { |
|
1046 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1047 | + return new LockdownManager(function() use ($c) { |
|
1048 | 1048 | return $c->getSession(); |
1049 | 1049 | }); |
1050 | 1050 | }); |
1051 | 1051 | |
1052 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1052 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1053 | 1053 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1054 | 1054 | }); |
1055 | 1055 | |
1056 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1056 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1057 | 1057 | return new CloudIdManager(); |
1058 | 1058 | }); |
1059 | 1059 | |
1060 | 1060 | /* To trick DI since we don't extend the DIContainer here */ |
1061 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1061 | + $this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) { |
|
1062 | 1062 | return new CleanPreviewsBackgroundJob( |
1063 | 1063 | $c->getRootFolder(), |
1064 | 1064 | $c->getLogger(), |
@@ -1073,18 +1073,18 @@ discard block |
||
1073 | 1073 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1074 | 1074 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1075 | 1075 | |
1076 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1076 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1077 | 1077 | return new Defaults( |
1078 | 1078 | $c->getThemingDefaults() |
1079 | 1079 | ); |
1080 | 1080 | }); |
1081 | 1081 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1082 | 1082 | |
1083 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1083 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1084 | 1084 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1085 | 1085 | }); |
1086 | 1086 | |
1087 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1087 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1088 | 1088 | return new ShareHelper( |
1089 | 1089 | $c->query(\OCP\Share\IManager::class) |
1090 | 1090 | ); |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | * @deprecated since 9.2.0 use IAppData |
1226 | 1226 | */ |
1227 | 1227 | public function getAppFolder() { |
1228 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1228 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1229 | 1229 | $root = $this->getRootFolder(); |
1230 | 1230 | if (!$root->nodeExists($dir)) { |
1231 | 1231 | $folder = $root->newFolder($dir); |
@@ -1809,7 +1809,7 @@ discard block |
||
1809 | 1809 | /** |
1810 | 1810 | * @return \OCP\Collaboration\AutoComplete\IManager |
1811 | 1811 | */ |
1812 | - public function getAutoCompleteManager(){ |
|
1812 | + public function getAutoCompleteManager() { |
|
1813 | 1813 | return $this->query('AutoCompleteManager'); |
1814 | 1814 | } |
1815 | 1815 |
@@ -31,59 +31,59 @@ |
||
31 | 31 | use OCP\Share; |
32 | 32 | |
33 | 33 | class AutoCompleteController extends Controller { |
34 | - /** @var ISearch */ |
|
35 | - private $collaboratorSearch; |
|
36 | - /** @var IManager */ |
|
37 | - private $autoCompleteManager; |
|
34 | + /** @var ISearch */ |
|
35 | + private $collaboratorSearch; |
|
36 | + /** @var IManager */ |
|
37 | + private $autoCompleteManager; |
|
38 | 38 | |
39 | - public function __construct($appName, IRequest $request, ISearch $collaboratorSearch, IManager $autoCompleteManager) { |
|
40 | - parent::__construct($appName, $request); |
|
39 | + public function __construct($appName, IRequest $request, ISearch $collaboratorSearch, IManager $autoCompleteManager) { |
|
40 | + parent::__construct($appName, $request); |
|
41 | 41 | |
42 | - $this->collaboratorSearch = $collaboratorSearch; |
|
43 | - $this->autoCompleteManager = $autoCompleteManager; |
|
44 | - } |
|
42 | + $this->collaboratorSearch = $collaboratorSearch; |
|
43 | + $this->autoCompleteManager = $autoCompleteManager; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @NoAdminRequired |
|
48 | - * |
|
49 | - * @param string $itemType |
|
50 | - * @param string $itemId |
|
51 | - * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
52 | - * @param array $shareTypes |
|
53 | - * @return DataResponse |
|
54 | - */ |
|
55 | - public function get($itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER]) { |
|
56 | - // if enumeration/user listings are disabled, we'll receive an empty |
|
57 | - // result from search() – thus nothing else to do here. |
|
58 | - list($results,) = $this->collaboratorSearch->search('', $shareTypes, false, 20, 0); |
|
46 | + /** |
|
47 | + * @NoAdminRequired |
|
48 | + * |
|
49 | + * @param string $itemType |
|
50 | + * @param string $itemId |
|
51 | + * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
52 | + * @param array $shareTypes |
|
53 | + * @return DataResponse |
|
54 | + */ |
|
55 | + public function get($itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER]) { |
|
56 | + // if enumeration/user listings are disabled, we'll receive an empty |
|
57 | + // result from search() – thus nothing else to do here. |
|
58 | + list($results,) = $this->collaboratorSearch->search('', $shareTypes, false, 20, 0); |
|
59 | 59 | |
60 | - // there won't be exact matches without a search string |
|
61 | - unset($results['exact']); |
|
60 | + // there won't be exact matches without a search string |
|
61 | + unset($results['exact']); |
|
62 | 62 | |
63 | - $sorters = array_reverse(explode('|', $sorter)); |
|
64 | - $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
65 | - 'itemType' => $itemType, |
|
66 | - 'itemId' => $itemId, |
|
67 | - ]); |
|
63 | + $sorters = array_reverse(explode('|', $sorter)); |
|
64 | + $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
65 | + 'itemType' => $itemType, |
|
66 | + 'itemId' => $itemId, |
|
67 | + ]); |
|
68 | 68 | |
69 | - // transform to expected format |
|
70 | - $results = $this->prepareResultArray($results); |
|
69 | + // transform to expected format |
|
70 | + $results = $this->prepareResultArray($results); |
|
71 | 71 | |
72 | - return new DataResponse($results); |
|
73 | - } |
|
72 | + return new DataResponse($results); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - protected function prepareResultArray(array $results) { |
|
77 | - $output = []; |
|
78 | - foreach ($results as $type => $subResult) { |
|
79 | - foreach ($subResult as $result) { |
|
80 | - $output[] = [ |
|
81 | - 'id' => $result['value']['shareWith'], |
|
82 | - 'label' => $result['label'], |
|
83 | - 'source' => $type, |
|
84 | - ]; |
|
85 | - } |
|
86 | - } |
|
87 | - return $output; |
|
88 | - } |
|
76 | + protected function prepareResultArray(array $results) { |
|
77 | + $output = []; |
|
78 | + foreach ($results as $type => $subResult) { |
|
79 | + foreach ($subResult as $result) { |
|
80 | + $output[] = [ |
|
81 | + 'id' => $result['value']['shareWith'], |
|
82 | + 'label' => $result['label'], |
|
83 | + 'source' => $type, |
|
84 | + ]; |
|
85 | + } |
|
86 | + } |
|
87 | + return $output; |
|
88 | + } |
|
89 | 89 | } |
@@ -33,18 +33,18 @@ |
||
33 | 33 | */ |
34 | 34 | interface ISorter { |
35 | 35 | |
36 | - /** |
|
37 | - * @return string The ID of the sorter, e.g. commenters |
|
38 | - * @since 13.0.0 |
|
39 | - */ |
|
40 | - public function getId(); |
|
36 | + /** |
|
37 | + * @return string The ID of the sorter, e.g. commenters |
|
38 | + * @since 13.0.0 |
|
39 | + */ |
|
40 | + public function getId(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * executes the sort action |
|
44 | - * |
|
45 | - * @param array $sortArray the array to be sorted, provided as reference |
|
46 | - * @param array $context carries key 'itemType' and 'itemId' of the source object (e.g. a file) |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function sort(array &$sortArray, array $context); |
|
42 | + /** |
|
43 | + * executes the sort action |
|
44 | + * |
|
45 | + * @param array $sortArray the array to be sorted, provided as reference |
|
46 | + * @param array $context carries key 'itemType' and 'itemId' of the source object (e.g. a file) |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function sort(array &$sortArray, array $context); |
|
50 | 50 | } |
@@ -38,926 +38,926 @@ |
||
38 | 38 | |
39 | 39 | class Manager implements ICommentsManager { |
40 | 40 | |
41 | - /** @var IDBConnection */ |
|
42 | - protected $dbConn; |
|
43 | - |
|
44 | - /** @var ILogger */ |
|
45 | - protected $logger; |
|
46 | - |
|
47 | - /** @var IConfig */ |
|
48 | - protected $config; |
|
49 | - |
|
50 | - /** @var IComment[] */ |
|
51 | - protected $commentsCache = []; |
|
52 | - |
|
53 | - /** @var \Closure[] */ |
|
54 | - protected $eventHandlerClosures = []; |
|
55 | - |
|
56 | - /** @var ICommentsEventHandler[] */ |
|
57 | - protected $eventHandlers = []; |
|
58 | - |
|
59 | - /** @var \Closure[] */ |
|
60 | - protected $displayNameResolvers = []; |
|
61 | - |
|
62 | - /** |
|
63 | - * Manager constructor. |
|
64 | - * |
|
65 | - * @param IDBConnection $dbConn |
|
66 | - * @param ILogger $logger |
|
67 | - * @param IConfig $config |
|
68 | - */ |
|
69 | - public function __construct( |
|
70 | - IDBConnection $dbConn, |
|
71 | - ILogger $logger, |
|
72 | - IConfig $config |
|
73 | - ) { |
|
74 | - $this->dbConn = $dbConn; |
|
75 | - $this->logger = $logger; |
|
76 | - $this->config = $config; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * converts data base data into PHP native, proper types as defined by |
|
81 | - * IComment interface. |
|
82 | - * |
|
83 | - * @param array $data |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function normalizeDatabaseData(array $data) { |
|
87 | - $data['id'] = strval($data['id']); |
|
88 | - $data['parent_id'] = strval($data['parent_id']); |
|
89 | - $data['topmost_parent_id'] = strval($data['topmost_parent_id']); |
|
90 | - $data['creation_timestamp'] = new \DateTime($data['creation_timestamp']); |
|
91 | - if (!is_null($data['latest_child_timestamp'])) { |
|
92 | - $data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']); |
|
93 | - } |
|
94 | - $data['children_count'] = intval($data['children_count']); |
|
95 | - return $data; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * prepares a comment for an insert or update operation after making sure |
|
100 | - * all necessary fields have a value assigned. |
|
101 | - * |
|
102 | - * @param IComment $comment |
|
103 | - * @return IComment returns the same updated IComment instance as provided |
|
104 | - * by parameter for convenience |
|
105 | - * @throws \UnexpectedValueException |
|
106 | - */ |
|
107 | - protected function prepareCommentForDatabaseWrite(IComment $comment) { |
|
108 | - if (!$comment->getActorType() |
|
109 | - || !$comment->getActorId() |
|
110 | - || !$comment->getObjectType() |
|
111 | - || !$comment->getObjectId() |
|
112 | - || !$comment->getVerb() |
|
113 | - ) { |
|
114 | - throw new \UnexpectedValueException('Actor, Object and Verb information must be provided for saving'); |
|
115 | - } |
|
116 | - |
|
117 | - if ($comment->getId() === '') { |
|
118 | - $comment->setChildrenCount(0); |
|
119 | - $comment->setLatestChildDateTime(new \DateTime('0000-00-00 00:00:00', new \DateTimeZone('UTC'))); |
|
120 | - $comment->setLatestChildDateTime(null); |
|
121 | - } |
|
122 | - |
|
123 | - if (is_null($comment->getCreationDateTime())) { |
|
124 | - $comment->setCreationDateTime(new \DateTime()); |
|
125 | - } |
|
126 | - |
|
127 | - if ($comment->getParentId() !== '0') { |
|
128 | - $comment->setTopmostParentId($this->determineTopmostParentId($comment->getParentId())); |
|
129 | - } else { |
|
130 | - $comment->setTopmostParentId('0'); |
|
131 | - } |
|
132 | - |
|
133 | - $this->cache($comment); |
|
134 | - |
|
135 | - return $comment; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * returns the topmost parent id of a given comment identified by ID |
|
140 | - * |
|
141 | - * @param string $id |
|
142 | - * @return string |
|
143 | - * @throws NotFoundException |
|
144 | - */ |
|
145 | - protected function determineTopmostParentId($id) { |
|
146 | - $comment = $this->get($id); |
|
147 | - if ($comment->getParentId() === '0') { |
|
148 | - return $comment->getId(); |
|
149 | - } else { |
|
150 | - return $this->determineTopmostParentId($comment->getId()); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * updates child information of a comment |
|
156 | - * |
|
157 | - * @param string $id |
|
158 | - * @param \DateTime $cDateTime the date time of the most recent child |
|
159 | - * @throws NotFoundException |
|
160 | - */ |
|
161 | - protected function updateChildrenInformation($id, \DateTime $cDateTime) { |
|
162 | - $qb = $this->dbConn->getQueryBuilder(); |
|
163 | - $query = $qb->select($qb->createFunction('COUNT(`id`)')) |
|
164 | - ->from('comments') |
|
165 | - ->where($qb->expr()->eq('parent_id', $qb->createParameter('id'))) |
|
166 | - ->setParameter('id', $id); |
|
167 | - |
|
168 | - $resultStatement = $query->execute(); |
|
169 | - $data = $resultStatement->fetch(\PDO::FETCH_NUM); |
|
170 | - $resultStatement->closeCursor(); |
|
171 | - $children = intval($data[0]); |
|
172 | - |
|
173 | - $comment = $this->get($id); |
|
174 | - $comment->setChildrenCount($children); |
|
175 | - $comment->setLatestChildDateTime($cDateTime); |
|
176 | - $this->save($comment); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Tests whether actor or object type and id parameters are acceptable. |
|
181 | - * Throws exception if not. |
|
182 | - * |
|
183 | - * @param string $role |
|
184 | - * @param string $type |
|
185 | - * @param string $id |
|
186 | - * @throws \InvalidArgumentException |
|
187 | - */ |
|
188 | - protected function checkRoleParameters($role, $type, $id) { |
|
189 | - if ( |
|
190 | - !is_string($type) || empty($type) |
|
191 | - || !is_string($id) || empty($id) |
|
192 | - ) { |
|
193 | - throw new \InvalidArgumentException($role . ' parameters must be string and not empty'); |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * run-time caches a comment |
|
199 | - * |
|
200 | - * @param IComment $comment |
|
201 | - */ |
|
202 | - protected function cache(IComment $comment) { |
|
203 | - $id = $comment->getId(); |
|
204 | - if (empty($id)) { |
|
205 | - return; |
|
206 | - } |
|
207 | - $this->commentsCache[strval($id)] = $comment; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * removes an entry from the comments run time cache |
|
212 | - * |
|
213 | - * @param mixed $id the comment's id |
|
214 | - */ |
|
215 | - protected function uncache($id) { |
|
216 | - $id = strval($id); |
|
217 | - if (isset($this->commentsCache[$id])) { |
|
218 | - unset($this->commentsCache[$id]); |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * returns a comment instance |
|
224 | - * |
|
225 | - * @param string $id the ID of the comment |
|
226 | - * @return IComment |
|
227 | - * @throws NotFoundException |
|
228 | - * @throws \InvalidArgumentException |
|
229 | - * @since 9.0.0 |
|
230 | - */ |
|
231 | - public function get($id) { |
|
232 | - if (intval($id) === 0) { |
|
233 | - throw new \InvalidArgumentException('IDs must be translatable to a number in this implementation.'); |
|
234 | - } |
|
235 | - |
|
236 | - if (isset($this->commentsCache[$id])) { |
|
237 | - return $this->commentsCache[$id]; |
|
238 | - } |
|
239 | - |
|
240 | - $qb = $this->dbConn->getQueryBuilder(); |
|
241 | - $resultStatement = $qb->select('*') |
|
242 | - ->from('comments') |
|
243 | - ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
244 | - ->setParameter('id', $id, IQueryBuilder::PARAM_INT) |
|
245 | - ->execute(); |
|
246 | - |
|
247 | - $data = $resultStatement->fetch(); |
|
248 | - $resultStatement->closeCursor(); |
|
249 | - if (!$data) { |
|
250 | - throw new NotFoundException(); |
|
251 | - } |
|
252 | - |
|
253 | - $comment = new Comment($this->normalizeDatabaseData($data)); |
|
254 | - $this->cache($comment); |
|
255 | - return $comment; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * returns the comment specified by the id and all it's child comments. |
|
260 | - * At this point of time, we do only support one level depth. |
|
261 | - * |
|
262 | - * @param string $id |
|
263 | - * @param int $limit max number of entries to return, 0 returns all |
|
264 | - * @param int $offset the start entry |
|
265 | - * @return array |
|
266 | - * @since 9.0.0 |
|
267 | - * |
|
268 | - * The return array looks like this |
|
269 | - * [ |
|
270 | - * 'comment' => IComment, // root comment |
|
271 | - * 'replies' => |
|
272 | - * [ |
|
273 | - * 0 => |
|
274 | - * [ |
|
275 | - * 'comment' => IComment, |
|
276 | - * 'replies' => [] |
|
277 | - * ] |
|
278 | - * 1 => |
|
279 | - * [ |
|
280 | - * 'comment' => IComment, |
|
281 | - * 'replies'=> [] |
|
282 | - * ], |
|
283 | - * … |
|
284 | - * ] |
|
285 | - * ] |
|
286 | - */ |
|
287 | - public function getTree($id, $limit = 0, $offset = 0) { |
|
288 | - $tree = []; |
|
289 | - $tree['comment'] = $this->get($id); |
|
290 | - $tree['replies'] = []; |
|
291 | - |
|
292 | - $qb = $this->dbConn->getQueryBuilder(); |
|
293 | - $query = $qb->select('*') |
|
294 | - ->from('comments') |
|
295 | - ->where($qb->expr()->eq('topmost_parent_id', $qb->createParameter('id'))) |
|
296 | - ->orderBy('creation_timestamp', 'DESC') |
|
297 | - ->setParameter('id', $id); |
|
298 | - |
|
299 | - if ($limit > 0) { |
|
300 | - $query->setMaxResults($limit); |
|
301 | - } |
|
302 | - if ($offset > 0) { |
|
303 | - $query->setFirstResult($offset); |
|
304 | - } |
|
305 | - |
|
306 | - $resultStatement = $query->execute(); |
|
307 | - while ($data = $resultStatement->fetch()) { |
|
308 | - $comment = new Comment($this->normalizeDatabaseData($data)); |
|
309 | - $this->cache($comment); |
|
310 | - $tree['replies'][] = [ |
|
311 | - 'comment' => $comment, |
|
312 | - 'replies' => [] |
|
313 | - ]; |
|
314 | - } |
|
315 | - $resultStatement->closeCursor(); |
|
316 | - |
|
317 | - return $tree; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Get the actor types and ID that commented in the tree specified by the ID |
|
322 | - * |
|
323 | - * @param string $id |
|
324 | - * @return array |
|
325 | - * @since 13.0.0 |
|
326 | - * |
|
327 | - * The return array looks like this: |
|
328 | - * |
|
329 | - * [ |
|
330 | - * 'user' => [ |
|
331 | - * 'alice' => 2, |
|
332 | - * 'bob' => 3 |
|
333 | - * ], |
|
334 | - * 'robot' => [ |
|
335 | - * 'r2-d2' => 5, |
|
336 | - * 'c-3po' => 17, |
|
337 | - * ] |
|
338 | - * ] |
|
339 | - */ |
|
340 | - public function getActorsInTree($id) { |
|
341 | - $tree = $this->getTree($id); |
|
342 | - $actors = []; |
|
343 | - $this->walkTree($tree, $actors, [$this, 'extractActor']); |
|
344 | - return $actors; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * @param IComment $comment |
|
349 | - * @param array &$actors |
|
350 | - * |
|
351 | - * build an array that looks like: |
|
352 | - * |
|
353 | - * [ |
|
354 | - * 'user' => [ |
|
355 | - * 'alice' => 2, |
|
356 | - * 'bob' => 3 |
|
357 | - * ], |
|
358 | - * 'robot' => [ |
|
359 | - * 'r2-d2' => 5, |
|
360 | - * 'c-3po' => 17, |
|
361 | - * ] |
|
362 | - * ] |
|
363 | - * |
|
364 | - */ |
|
365 | - protected function extractActor(IComment $comment, &$actors) { |
|
366 | - if(!isset($actors[$comment->getActorType()])) { |
|
367 | - $actors[$comment->getActorType()] = []; |
|
368 | - } |
|
369 | - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
370 | - $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
371 | - } else { |
|
372 | - $actors[$comment->getActorType()][$comment->getActorId()] += 1; |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * walks through a comment tree (as returned by getTree() and invokes a callback |
|
378 | - * with the current IComment instance (and optionally custom parameters) |
|
379 | - * |
|
380 | - * @param array $node |
|
381 | - * @param array &$results |
|
382 | - * @param callable $callback |
|
383 | - * @param array|null $parameters |
|
384 | - */ |
|
385 | - protected function walkTree($node, array &$results, callable $callback, array $parameters = null) { |
|
386 | - if(isset($node['replies'])) { |
|
387 | - foreach ($node['replies'] as $subNode) { |
|
388 | - $this->walkTree($subNode, $results, $callback, $parameters); |
|
389 | - } |
|
390 | - } |
|
391 | - if(isset($node['comment']) && $node['comment'] instanceof IComment) { |
|
392 | - $callback($node['comment'], $results, $parameters); |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * returns comments for a specific object (e.g. a file). |
|
398 | - * |
|
399 | - * The sort order is always newest to oldest. |
|
400 | - * |
|
401 | - * @param string $objectType the object type, e.g. 'files' |
|
402 | - * @param string $objectId the id of the object |
|
403 | - * @param int $limit optional, number of maximum comments to be returned. if |
|
404 | - * not specified, all comments are returned. |
|
405 | - * @param int $offset optional, starting point |
|
406 | - * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |
|
407 | - * that may be returned |
|
408 | - * @return IComment[] |
|
409 | - * @since 9.0.0 |
|
410 | - */ |
|
411 | - public function getForObject( |
|
412 | - $objectType, |
|
413 | - $objectId, |
|
414 | - $limit = 0, |
|
415 | - $offset = 0, |
|
416 | - \DateTime $notOlderThan = null |
|
417 | - ) { |
|
418 | - $comments = []; |
|
419 | - |
|
420 | - $qb = $this->dbConn->getQueryBuilder(); |
|
421 | - $query = $qb->select('*') |
|
422 | - ->from('comments') |
|
423 | - ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
424 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
425 | - ->orderBy('creation_timestamp', 'DESC') |
|
426 | - ->setParameter('type', $objectType) |
|
427 | - ->setParameter('id', $objectId); |
|
428 | - |
|
429 | - if ($limit > 0) { |
|
430 | - $query->setMaxResults($limit); |
|
431 | - } |
|
432 | - if ($offset > 0) { |
|
433 | - $query->setFirstResult($offset); |
|
434 | - } |
|
435 | - if (!is_null($notOlderThan)) { |
|
436 | - $query |
|
437 | - ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
|
438 | - ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
|
439 | - } |
|
440 | - |
|
441 | - $resultStatement = $query->execute(); |
|
442 | - while ($data = $resultStatement->fetch()) { |
|
443 | - $comment = new Comment($this->normalizeDatabaseData($data)); |
|
444 | - $this->cache($comment); |
|
445 | - $comments[] = $comment; |
|
446 | - } |
|
447 | - $resultStatement->closeCursor(); |
|
448 | - |
|
449 | - return $comments; |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * @param $objectType string the object type, e.g. 'files' |
|
454 | - * @param $objectId string the id of the object |
|
455 | - * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |
|
456 | - * that may be returned |
|
457 | - * @return Int |
|
458 | - * @since 9.0.0 |
|
459 | - */ |
|
460 | - public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) { |
|
461 | - $qb = $this->dbConn->getQueryBuilder(); |
|
462 | - $query = $qb->select($qb->createFunction('COUNT(`id`)')) |
|
463 | - ->from('comments') |
|
464 | - ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
465 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
466 | - ->setParameter('type', $objectType) |
|
467 | - ->setParameter('id', $objectId); |
|
468 | - |
|
469 | - if (!is_null($notOlderThan)) { |
|
470 | - $query |
|
471 | - ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
|
472 | - ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
|
473 | - } |
|
474 | - |
|
475 | - $resultStatement = $query->execute(); |
|
476 | - $data = $resultStatement->fetch(\PDO::FETCH_NUM); |
|
477 | - $resultStatement->closeCursor(); |
|
478 | - return intval($data[0]); |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * Get the number of unread comments for all files in a folder |
|
483 | - * |
|
484 | - * @param int $folderId |
|
485 | - * @param IUser $user |
|
486 | - * @return array [$fileId => $unreadCount] |
|
487 | - */ |
|
488 | - public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) { |
|
489 | - $qb = $this->dbConn->getQueryBuilder(); |
|
490 | - $query = $qb->select('f.fileid') |
|
491 | - ->selectAlias( |
|
492 | - $qb->createFunction('COUNT(' . $qb->getColumnName('c.id') . ')'), |
|
493 | - 'num_ids' |
|
494 | - ) |
|
495 | - ->from('comments', 'c') |
|
496 | - ->innerJoin('c', 'filecache', 'f', $qb->expr()->andX( |
|
497 | - $qb->expr()->eq('c.object_type', $qb->createNamedParameter('files')), |
|
498 | - $qb->expr()->eq('f.fileid', $qb->expr()->castColumn('c.object_id', IQueryBuilder::PARAM_INT)) |
|
499 | - )) |
|
500 | - ->leftJoin('c', 'comments_read_markers', 'm', $qb->expr()->andX( |
|
501 | - $qb->expr()->eq('m.object_type', $qb->createNamedParameter('files')), |
|
502 | - $qb->expr()->eq('m.object_id', 'c.object_id'), |
|
503 | - $qb->expr()->eq('m.user_id', $qb->createNamedParameter($user->getUID())) |
|
504 | - )) |
|
505 | - ->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($folderId))) |
|
506 | - ->andWhere($qb->expr()->orX( |
|
507 | - $qb->expr()->gt('c.creation_timestamp', 'marker_datetime'), |
|
508 | - $qb->expr()->isNull('marker_datetime') |
|
509 | - )) |
|
510 | - ->groupBy('f.fileid'); |
|
511 | - |
|
512 | - $resultStatement = $query->execute(); |
|
513 | - |
|
514 | - $results = []; |
|
515 | - while ($row = $resultStatement->fetch()) { |
|
516 | - $results[$row['fileid']] = (int) $row['num_ids']; |
|
517 | - } |
|
518 | - $resultStatement->closeCursor(); |
|
519 | - return $results; |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * creates a new comment and returns it. At this point of time, it is not |
|
524 | - * saved in the used data storage. Use save() after setting other fields |
|
525 | - * of the comment (e.g. message or verb). |
|
526 | - * |
|
527 | - * @param string $actorType the actor type (e.g. 'users') |
|
528 | - * @param string $actorId a user id |
|
529 | - * @param string $objectType the object type the comment is attached to |
|
530 | - * @param string $objectId the object id the comment is attached to |
|
531 | - * @return IComment |
|
532 | - * @since 9.0.0 |
|
533 | - */ |
|
534 | - public function create($actorType, $actorId, $objectType, $objectId) { |
|
535 | - $comment = new Comment(); |
|
536 | - $comment |
|
537 | - ->setActor($actorType, $actorId) |
|
538 | - ->setObject($objectType, $objectId); |
|
539 | - return $comment; |
|
540 | - } |
|
541 | - |
|
542 | - /** |
|
543 | - * permanently deletes the comment specified by the ID |
|
544 | - * |
|
545 | - * When the comment has child comments, their parent ID will be changed to |
|
546 | - * the parent ID of the item that is to be deleted. |
|
547 | - * |
|
548 | - * @param string $id |
|
549 | - * @return bool |
|
550 | - * @throws \InvalidArgumentException |
|
551 | - * @since 9.0.0 |
|
552 | - */ |
|
553 | - public function delete($id) { |
|
554 | - if (!is_string($id)) { |
|
555 | - throw new \InvalidArgumentException('Parameter must be string'); |
|
556 | - } |
|
557 | - |
|
558 | - try { |
|
559 | - $comment = $this->get($id); |
|
560 | - } catch (\Exception $e) { |
|
561 | - // Ignore exceptions, we just don't fire a hook then |
|
562 | - $comment = null; |
|
563 | - } |
|
564 | - |
|
565 | - $qb = $this->dbConn->getQueryBuilder(); |
|
566 | - $query = $qb->delete('comments') |
|
567 | - ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
568 | - ->setParameter('id', $id); |
|
569 | - |
|
570 | - try { |
|
571 | - $affectedRows = $query->execute(); |
|
572 | - $this->uncache($id); |
|
573 | - } catch (DriverException $e) { |
|
574 | - $this->logger->logException($e, ['app' => 'core_comments']); |
|
575 | - return false; |
|
576 | - } |
|
577 | - |
|
578 | - if ($affectedRows > 0 && $comment instanceof IComment) { |
|
579 | - $this->sendEvent(CommentsEvent::EVENT_DELETE, $comment); |
|
580 | - } |
|
581 | - |
|
582 | - return ($affectedRows > 0); |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * saves the comment permanently |
|
587 | - * |
|
588 | - * if the supplied comment has an empty ID, a new entry comment will be |
|
589 | - * saved and the instance updated with the new ID. |
|
590 | - * |
|
591 | - * Otherwise, an existing comment will be updated. |
|
592 | - * |
|
593 | - * Throws NotFoundException when a comment that is to be updated does not |
|
594 | - * exist anymore at this point of time. |
|
595 | - * |
|
596 | - * @param IComment $comment |
|
597 | - * @return bool |
|
598 | - * @throws NotFoundException |
|
599 | - * @since 9.0.0 |
|
600 | - */ |
|
601 | - public function save(IComment $comment) { |
|
602 | - if ($this->prepareCommentForDatabaseWrite($comment)->getId() === '') { |
|
603 | - $result = $this->insert($comment); |
|
604 | - } else { |
|
605 | - $result = $this->update($comment); |
|
606 | - } |
|
607 | - |
|
608 | - if ($result && !!$comment->getParentId()) { |
|
609 | - $this->updateChildrenInformation( |
|
610 | - $comment->getParentId(), |
|
611 | - $comment->getCreationDateTime() |
|
612 | - ); |
|
613 | - $this->cache($comment); |
|
614 | - } |
|
615 | - |
|
616 | - return $result; |
|
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * inserts the provided comment in the database |
|
621 | - * |
|
622 | - * @param IComment $comment |
|
623 | - * @return bool |
|
624 | - */ |
|
625 | - protected function insert(IComment &$comment) { |
|
626 | - $qb = $this->dbConn->getQueryBuilder(); |
|
627 | - $affectedRows = $qb |
|
628 | - ->insert('comments') |
|
629 | - ->values([ |
|
630 | - 'parent_id' => $qb->createNamedParameter($comment->getParentId()), |
|
631 | - 'topmost_parent_id' => $qb->createNamedParameter($comment->getTopmostParentId()), |
|
632 | - 'children_count' => $qb->createNamedParameter($comment->getChildrenCount()), |
|
633 | - 'actor_type' => $qb->createNamedParameter($comment->getActorType()), |
|
634 | - 'actor_id' => $qb->createNamedParameter($comment->getActorId()), |
|
635 | - 'message' => $qb->createNamedParameter($comment->getMessage()), |
|
636 | - 'verb' => $qb->createNamedParameter($comment->getVerb()), |
|
637 | - 'creation_timestamp' => $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime'), |
|
638 | - 'latest_child_timestamp' => $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'), |
|
639 | - 'object_type' => $qb->createNamedParameter($comment->getObjectType()), |
|
640 | - 'object_id' => $qb->createNamedParameter($comment->getObjectId()), |
|
641 | - ]) |
|
642 | - ->execute(); |
|
643 | - |
|
644 | - if ($affectedRows > 0) { |
|
645 | - $comment->setId(strval($qb->getLastInsertId())); |
|
646 | - $this->sendEvent(CommentsEvent::EVENT_ADD, $comment); |
|
647 | - } |
|
648 | - |
|
649 | - return $affectedRows > 0; |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * updates a Comment data row |
|
654 | - * |
|
655 | - * @param IComment $comment |
|
656 | - * @return bool |
|
657 | - * @throws NotFoundException |
|
658 | - */ |
|
659 | - protected function update(IComment $comment) { |
|
660 | - // for properly working preUpdate Events we need the old comments as is |
|
661 | - // in the DB and overcome caching. Also avoid that outdated information stays. |
|
662 | - $this->uncache($comment->getId()); |
|
663 | - $this->sendEvent(CommentsEvent::EVENT_PRE_UPDATE, $this->get($comment->getId())); |
|
664 | - $this->uncache($comment->getId()); |
|
665 | - |
|
666 | - $qb = $this->dbConn->getQueryBuilder(); |
|
667 | - $affectedRows = $qb |
|
668 | - ->update('comments') |
|
669 | - ->set('parent_id', $qb->createNamedParameter($comment->getParentId())) |
|
670 | - ->set('topmost_parent_id', $qb->createNamedParameter($comment->getTopmostParentId())) |
|
671 | - ->set('children_count', $qb->createNamedParameter($comment->getChildrenCount())) |
|
672 | - ->set('actor_type', $qb->createNamedParameter($comment->getActorType())) |
|
673 | - ->set('actor_id', $qb->createNamedParameter($comment->getActorId())) |
|
674 | - ->set('message', $qb->createNamedParameter($comment->getMessage())) |
|
675 | - ->set('verb', $qb->createNamedParameter($comment->getVerb())) |
|
676 | - ->set('creation_timestamp', $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime')) |
|
677 | - ->set('latest_child_timestamp', $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime')) |
|
678 | - ->set('object_type', $qb->createNamedParameter($comment->getObjectType())) |
|
679 | - ->set('object_id', $qb->createNamedParameter($comment->getObjectId())) |
|
680 | - ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
681 | - ->setParameter('id', $comment->getId()) |
|
682 | - ->execute(); |
|
683 | - |
|
684 | - if ($affectedRows === 0) { |
|
685 | - throw new NotFoundException('Comment to update does ceased to exist'); |
|
686 | - } |
|
687 | - |
|
688 | - $this->sendEvent(CommentsEvent::EVENT_UPDATE, $comment); |
|
689 | - |
|
690 | - return $affectedRows > 0; |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * removes references to specific actor (e.g. on user delete) of a comment. |
|
695 | - * The comment itself must not get lost/deleted. |
|
696 | - * |
|
697 | - * @param string $actorType the actor type (e.g. 'users') |
|
698 | - * @param string $actorId a user id |
|
699 | - * @return boolean |
|
700 | - * @since 9.0.0 |
|
701 | - */ |
|
702 | - public function deleteReferencesOfActor($actorType, $actorId) { |
|
703 | - $this->checkRoleParameters('Actor', $actorType, $actorId); |
|
704 | - |
|
705 | - $qb = $this->dbConn->getQueryBuilder(); |
|
706 | - $affectedRows = $qb |
|
707 | - ->update('comments') |
|
708 | - ->set('actor_type', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
709 | - ->set('actor_id', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
710 | - ->where($qb->expr()->eq('actor_type', $qb->createParameter('type'))) |
|
711 | - ->andWhere($qb->expr()->eq('actor_id', $qb->createParameter('id'))) |
|
712 | - ->setParameter('type', $actorType) |
|
713 | - ->setParameter('id', $actorId) |
|
714 | - ->execute(); |
|
715 | - |
|
716 | - $this->commentsCache = []; |
|
717 | - |
|
718 | - return is_int($affectedRows); |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * deletes all comments made of a specific object (e.g. on file delete) |
|
723 | - * |
|
724 | - * @param string $objectType the object type (e.g. 'files') |
|
725 | - * @param string $objectId e.g. the file id |
|
726 | - * @return boolean |
|
727 | - * @since 9.0.0 |
|
728 | - */ |
|
729 | - public function deleteCommentsAtObject($objectType, $objectId) { |
|
730 | - $this->checkRoleParameters('Object', $objectType, $objectId); |
|
731 | - |
|
732 | - $qb = $this->dbConn->getQueryBuilder(); |
|
733 | - $affectedRows = $qb |
|
734 | - ->delete('comments') |
|
735 | - ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
736 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
737 | - ->setParameter('type', $objectType) |
|
738 | - ->setParameter('id', $objectId) |
|
739 | - ->execute(); |
|
740 | - |
|
741 | - $this->commentsCache = []; |
|
742 | - |
|
743 | - return is_int($affectedRows); |
|
744 | - } |
|
745 | - |
|
746 | - /** |
|
747 | - * deletes the read markers for the specified user |
|
748 | - * |
|
749 | - * @param \OCP\IUser $user |
|
750 | - * @return bool |
|
751 | - * @since 9.0.0 |
|
752 | - */ |
|
753 | - public function deleteReadMarksFromUser(IUser $user) { |
|
754 | - $qb = $this->dbConn->getQueryBuilder(); |
|
755 | - $query = $qb->delete('comments_read_markers') |
|
756 | - ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
757 | - ->setParameter('user_id', $user->getUID()); |
|
758 | - |
|
759 | - try { |
|
760 | - $affectedRows = $query->execute(); |
|
761 | - } catch (DriverException $e) { |
|
762 | - $this->logger->logException($e, ['app' => 'core_comments']); |
|
763 | - return false; |
|
764 | - } |
|
765 | - return ($affectedRows > 0); |
|
766 | - } |
|
767 | - |
|
768 | - /** |
|
769 | - * sets the read marker for a given file to the specified date for the |
|
770 | - * provided user |
|
771 | - * |
|
772 | - * @param string $objectType |
|
773 | - * @param string $objectId |
|
774 | - * @param \DateTime $dateTime |
|
775 | - * @param IUser $user |
|
776 | - * @since 9.0.0 |
|
777 | - * @suppress SqlInjectionChecker |
|
778 | - */ |
|
779 | - public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) { |
|
780 | - $this->checkRoleParameters('Object', $objectType, $objectId); |
|
781 | - |
|
782 | - $qb = $this->dbConn->getQueryBuilder(); |
|
783 | - $values = [ |
|
784 | - 'user_id' => $qb->createNamedParameter($user->getUID()), |
|
785 | - 'marker_datetime' => $qb->createNamedParameter($dateTime, 'datetime'), |
|
786 | - 'object_type' => $qb->createNamedParameter($objectType), |
|
787 | - 'object_id' => $qb->createNamedParameter($objectId), |
|
788 | - ]; |
|
789 | - |
|
790 | - // Strategy: try to update, if this does not return affected rows, do an insert. |
|
791 | - $affectedRows = $qb |
|
792 | - ->update('comments_read_markers') |
|
793 | - ->set('user_id', $values['user_id']) |
|
794 | - ->set('marker_datetime', $values['marker_datetime']) |
|
795 | - ->set('object_type', $values['object_type']) |
|
796 | - ->set('object_id', $values['object_id']) |
|
797 | - ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
798 | - ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
799 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
800 | - ->setParameter('user_id', $user->getUID(), IQueryBuilder::PARAM_STR) |
|
801 | - ->setParameter('object_type', $objectType, IQueryBuilder::PARAM_STR) |
|
802 | - ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) |
|
803 | - ->execute(); |
|
804 | - |
|
805 | - if ($affectedRows > 0) { |
|
806 | - return; |
|
807 | - } |
|
808 | - |
|
809 | - $qb->insert('comments_read_markers') |
|
810 | - ->values($values) |
|
811 | - ->execute(); |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * returns the read marker for a given file to the specified date for the |
|
816 | - * provided user. It returns null, when the marker is not present, i.e. |
|
817 | - * no comments were marked as read. |
|
818 | - * |
|
819 | - * @param string $objectType |
|
820 | - * @param string $objectId |
|
821 | - * @param IUser $user |
|
822 | - * @return \DateTime|null |
|
823 | - * @since 9.0.0 |
|
824 | - */ |
|
825 | - public function getReadMark($objectType, $objectId, IUser $user) { |
|
826 | - $qb = $this->dbConn->getQueryBuilder(); |
|
827 | - $resultStatement = $qb->select('marker_datetime') |
|
828 | - ->from('comments_read_markers') |
|
829 | - ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
830 | - ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
831 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
832 | - ->setParameter('user_id', $user->getUID(), IQueryBuilder::PARAM_STR) |
|
833 | - ->setParameter('object_type', $objectType, IQueryBuilder::PARAM_STR) |
|
834 | - ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) |
|
835 | - ->execute(); |
|
836 | - |
|
837 | - $data = $resultStatement->fetch(); |
|
838 | - $resultStatement->closeCursor(); |
|
839 | - if (!$data || is_null($data['marker_datetime'])) { |
|
840 | - return null; |
|
841 | - } |
|
842 | - |
|
843 | - return new \DateTime($data['marker_datetime']); |
|
844 | - } |
|
845 | - |
|
846 | - /** |
|
847 | - * deletes the read markers on the specified object |
|
848 | - * |
|
849 | - * @param string $objectType |
|
850 | - * @param string $objectId |
|
851 | - * @return bool |
|
852 | - * @since 9.0.0 |
|
853 | - */ |
|
854 | - public function deleteReadMarksOnObject($objectType, $objectId) { |
|
855 | - $this->checkRoleParameters('Object', $objectType, $objectId); |
|
856 | - |
|
857 | - $qb = $this->dbConn->getQueryBuilder(); |
|
858 | - $query = $qb->delete('comments_read_markers') |
|
859 | - ->where($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
860 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
861 | - ->setParameter('object_type', $objectType) |
|
862 | - ->setParameter('object_id', $objectId); |
|
863 | - |
|
864 | - try { |
|
865 | - $affectedRows = $query->execute(); |
|
866 | - } catch (DriverException $e) { |
|
867 | - $this->logger->logException($e, ['app' => 'core_comments']); |
|
868 | - return false; |
|
869 | - } |
|
870 | - return ($affectedRows > 0); |
|
871 | - } |
|
872 | - |
|
873 | - /** |
|
874 | - * registers an Entity to the manager, so event notifications can be send |
|
875 | - * to consumers of the comments infrastructure |
|
876 | - * |
|
877 | - * @param \Closure $closure |
|
878 | - */ |
|
879 | - public function registerEventHandler(\Closure $closure) { |
|
880 | - $this->eventHandlerClosures[] = $closure; |
|
881 | - $this->eventHandlers = []; |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * registers a method that resolves an ID to a display name for a given type |
|
886 | - * |
|
887 | - * @param string $type |
|
888 | - * @param \Closure $closure |
|
889 | - * @throws \OutOfBoundsException |
|
890 | - * @since 11.0.0 |
|
891 | - * |
|
892 | - * Only one resolver shall be registered per type. Otherwise a |
|
893 | - * \OutOfBoundsException has to thrown. |
|
894 | - */ |
|
895 | - public function registerDisplayNameResolver($type, \Closure $closure) { |
|
896 | - if (!is_string($type)) { |
|
897 | - throw new \InvalidArgumentException('String expected.'); |
|
898 | - } |
|
899 | - if (isset($this->displayNameResolvers[$type])) { |
|
900 | - throw new \OutOfBoundsException('Displayname resolver for this type already registered'); |
|
901 | - } |
|
902 | - $this->displayNameResolvers[$type] = $closure; |
|
903 | - } |
|
904 | - |
|
905 | - /** |
|
906 | - * resolves a given ID of a given Type to a display name. |
|
907 | - * |
|
908 | - * @param string $type |
|
909 | - * @param string $id |
|
910 | - * @return string |
|
911 | - * @throws \OutOfBoundsException |
|
912 | - * @since 11.0.0 |
|
913 | - * |
|
914 | - * If a provided type was not registered, an \OutOfBoundsException shall |
|
915 | - * be thrown. It is upon the resolver discretion what to return of the |
|
916 | - * provided ID is unknown. It must be ensured that a string is returned. |
|
917 | - */ |
|
918 | - public function resolveDisplayName($type, $id) { |
|
919 | - if (!is_string($type)) { |
|
920 | - throw new \InvalidArgumentException('String expected.'); |
|
921 | - } |
|
922 | - if (!isset($this->displayNameResolvers[$type])) { |
|
923 | - throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
|
924 | - } |
|
925 | - return (string)$this->displayNameResolvers[$type]($id); |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * returns valid, registered entities |
|
930 | - * |
|
931 | - * @return \OCP\Comments\ICommentsEventHandler[] |
|
932 | - */ |
|
933 | - private function getEventHandlers() { |
|
934 | - if (!empty($this->eventHandlers)) { |
|
935 | - return $this->eventHandlers; |
|
936 | - } |
|
937 | - |
|
938 | - $this->eventHandlers = []; |
|
939 | - foreach ($this->eventHandlerClosures as $name => $closure) { |
|
940 | - $entity = $closure(); |
|
941 | - if (!($entity instanceof ICommentsEventHandler)) { |
|
942 | - throw new \InvalidArgumentException('The given entity does not implement the ICommentsEntity interface'); |
|
943 | - } |
|
944 | - $this->eventHandlers[$name] = $entity; |
|
945 | - } |
|
946 | - |
|
947 | - return $this->eventHandlers; |
|
948 | - } |
|
949 | - |
|
950 | - /** |
|
951 | - * sends notifications to the registered entities |
|
952 | - * |
|
953 | - * @param $eventType |
|
954 | - * @param IComment $comment |
|
955 | - */ |
|
956 | - private function sendEvent($eventType, IComment $comment) { |
|
957 | - $entities = $this->getEventHandlers(); |
|
958 | - $event = new CommentsEvent($eventType, $comment); |
|
959 | - foreach ($entities as $entity) { |
|
960 | - $entity->handle($event); |
|
961 | - } |
|
962 | - } |
|
41 | + /** @var IDBConnection */ |
|
42 | + protected $dbConn; |
|
43 | + |
|
44 | + /** @var ILogger */ |
|
45 | + protected $logger; |
|
46 | + |
|
47 | + /** @var IConfig */ |
|
48 | + protected $config; |
|
49 | + |
|
50 | + /** @var IComment[] */ |
|
51 | + protected $commentsCache = []; |
|
52 | + |
|
53 | + /** @var \Closure[] */ |
|
54 | + protected $eventHandlerClosures = []; |
|
55 | + |
|
56 | + /** @var ICommentsEventHandler[] */ |
|
57 | + protected $eventHandlers = []; |
|
58 | + |
|
59 | + /** @var \Closure[] */ |
|
60 | + protected $displayNameResolvers = []; |
|
61 | + |
|
62 | + /** |
|
63 | + * Manager constructor. |
|
64 | + * |
|
65 | + * @param IDBConnection $dbConn |
|
66 | + * @param ILogger $logger |
|
67 | + * @param IConfig $config |
|
68 | + */ |
|
69 | + public function __construct( |
|
70 | + IDBConnection $dbConn, |
|
71 | + ILogger $logger, |
|
72 | + IConfig $config |
|
73 | + ) { |
|
74 | + $this->dbConn = $dbConn; |
|
75 | + $this->logger = $logger; |
|
76 | + $this->config = $config; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * converts data base data into PHP native, proper types as defined by |
|
81 | + * IComment interface. |
|
82 | + * |
|
83 | + * @param array $data |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function normalizeDatabaseData(array $data) { |
|
87 | + $data['id'] = strval($data['id']); |
|
88 | + $data['parent_id'] = strval($data['parent_id']); |
|
89 | + $data['topmost_parent_id'] = strval($data['topmost_parent_id']); |
|
90 | + $data['creation_timestamp'] = new \DateTime($data['creation_timestamp']); |
|
91 | + if (!is_null($data['latest_child_timestamp'])) { |
|
92 | + $data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']); |
|
93 | + } |
|
94 | + $data['children_count'] = intval($data['children_count']); |
|
95 | + return $data; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * prepares a comment for an insert or update operation after making sure |
|
100 | + * all necessary fields have a value assigned. |
|
101 | + * |
|
102 | + * @param IComment $comment |
|
103 | + * @return IComment returns the same updated IComment instance as provided |
|
104 | + * by parameter for convenience |
|
105 | + * @throws \UnexpectedValueException |
|
106 | + */ |
|
107 | + protected function prepareCommentForDatabaseWrite(IComment $comment) { |
|
108 | + if (!$comment->getActorType() |
|
109 | + || !$comment->getActorId() |
|
110 | + || !$comment->getObjectType() |
|
111 | + || !$comment->getObjectId() |
|
112 | + || !$comment->getVerb() |
|
113 | + ) { |
|
114 | + throw new \UnexpectedValueException('Actor, Object and Verb information must be provided for saving'); |
|
115 | + } |
|
116 | + |
|
117 | + if ($comment->getId() === '') { |
|
118 | + $comment->setChildrenCount(0); |
|
119 | + $comment->setLatestChildDateTime(new \DateTime('0000-00-00 00:00:00', new \DateTimeZone('UTC'))); |
|
120 | + $comment->setLatestChildDateTime(null); |
|
121 | + } |
|
122 | + |
|
123 | + if (is_null($comment->getCreationDateTime())) { |
|
124 | + $comment->setCreationDateTime(new \DateTime()); |
|
125 | + } |
|
126 | + |
|
127 | + if ($comment->getParentId() !== '0') { |
|
128 | + $comment->setTopmostParentId($this->determineTopmostParentId($comment->getParentId())); |
|
129 | + } else { |
|
130 | + $comment->setTopmostParentId('0'); |
|
131 | + } |
|
132 | + |
|
133 | + $this->cache($comment); |
|
134 | + |
|
135 | + return $comment; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * returns the topmost parent id of a given comment identified by ID |
|
140 | + * |
|
141 | + * @param string $id |
|
142 | + * @return string |
|
143 | + * @throws NotFoundException |
|
144 | + */ |
|
145 | + protected function determineTopmostParentId($id) { |
|
146 | + $comment = $this->get($id); |
|
147 | + if ($comment->getParentId() === '0') { |
|
148 | + return $comment->getId(); |
|
149 | + } else { |
|
150 | + return $this->determineTopmostParentId($comment->getId()); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * updates child information of a comment |
|
156 | + * |
|
157 | + * @param string $id |
|
158 | + * @param \DateTime $cDateTime the date time of the most recent child |
|
159 | + * @throws NotFoundException |
|
160 | + */ |
|
161 | + protected function updateChildrenInformation($id, \DateTime $cDateTime) { |
|
162 | + $qb = $this->dbConn->getQueryBuilder(); |
|
163 | + $query = $qb->select($qb->createFunction('COUNT(`id`)')) |
|
164 | + ->from('comments') |
|
165 | + ->where($qb->expr()->eq('parent_id', $qb->createParameter('id'))) |
|
166 | + ->setParameter('id', $id); |
|
167 | + |
|
168 | + $resultStatement = $query->execute(); |
|
169 | + $data = $resultStatement->fetch(\PDO::FETCH_NUM); |
|
170 | + $resultStatement->closeCursor(); |
|
171 | + $children = intval($data[0]); |
|
172 | + |
|
173 | + $comment = $this->get($id); |
|
174 | + $comment->setChildrenCount($children); |
|
175 | + $comment->setLatestChildDateTime($cDateTime); |
|
176 | + $this->save($comment); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Tests whether actor or object type and id parameters are acceptable. |
|
181 | + * Throws exception if not. |
|
182 | + * |
|
183 | + * @param string $role |
|
184 | + * @param string $type |
|
185 | + * @param string $id |
|
186 | + * @throws \InvalidArgumentException |
|
187 | + */ |
|
188 | + protected function checkRoleParameters($role, $type, $id) { |
|
189 | + if ( |
|
190 | + !is_string($type) || empty($type) |
|
191 | + || !is_string($id) || empty($id) |
|
192 | + ) { |
|
193 | + throw new \InvalidArgumentException($role . ' parameters must be string and not empty'); |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * run-time caches a comment |
|
199 | + * |
|
200 | + * @param IComment $comment |
|
201 | + */ |
|
202 | + protected function cache(IComment $comment) { |
|
203 | + $id = $comment->getId(); |
|
204 | + if (empty($id)) { |
|
205 | + return; |
|
206 | + } |
|
207 | + $this->commentsCache[strval($id)] = $comment; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * removes an entry from the comments run time cache |
|
212 | + * |
|
213 | + * @param mixed $id the comment's id |
|
214 | + */ |
|
215 | + protected function uncache($id) { |
|
216 | + $id = strval($id); |
|
217 | + if (isset($this->commentsCache[$id])) { |
|
218 | + unset($this->commentsCache[$id]); |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * returns a comment instance |
|
224 | + * |
|
225 | + * @param string $id the ID of the comment |
|
226 | + * @return IComment |
|
227 | + * @throws NotFoundException |
|
228 | + * @throws \InvalidArgumentException |
|
229 | + * @since 9.0.0 |
|
230 | + */ |
|
231 | + public function get($id) { |
|
232 | + if (intval($id) === 0) { |
|
233 | + throw new \InvalidArgumentException('IDs must be translatable to a number in this implementation.'); |
|
234 | + } |
|
235 | + |
|
236 | + if (isset($this->commentsCache[$id])) { |
|
237 | + return $this->commentsCache[$id]; |
|
238 | + } |
|
239 | + |
|
240 | + $qb = $this->dbConn->getQueryBuilder(); |
|
241 | + $resultStatement = $qb->select('*') |
|
242 | + ->from('comments') |
|
243 | + ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
244 | + ->setParameter('id', $id, IQueryBuilder::PARAM_INT) |
|
245 | + ->execute(); |
|
246 | + |
|
247 | + $data = $resultStatement->fetch(); |
|
248 | + $resultStatement->closeCursor(); |
|
249 | + if (!$data) { |
|
250 | + throw new NotFoundException(); |
|
251 | + } |
|
252 | + |
|
253 | + $comment = new Comment($this->normalizeDatabaseData($data)); |
|
254 | + $this->cache($comment); |
|
255 | + return $comment; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * returns the comment specified by the id and all it's child comments. |
|
260 | + * At this point of time, we do only support one level depth. |
|
261 | + * |
|
262 | + * @param string $id |
|
263 | + * @param int $limit max number of entries to return, 0 returns all |
|
264 | + * @param int $offset the start entry |
|
265 | + * @return array |
|
266 | + * @since 9.0.0 |
|
267 | + * |
|
268 | + * The return array looks like this |
|
269 | + * [ |
|
270 | + * 'comment' => IComment, // root comment |
|
271 | + * 'replies' => |
|
272 | + * [ |
|
273 | + * 0 => |
|
274 | + * [ |
|
275 | + * 'comment' => IComment, |
|
276 | + * 'replies' => [] |
|
277 | + * ] |
|
278 | + * 1 => |
|
279 | + * [ |
|
280 | + * 'comment' => IComment, |
|
281 | + * 'replies'=> [] |
|
282 | + * ], |
|
283 | + * … |
|
284 | + * ] |
|
285 | + * ] |
|
286 | + */ |
|
287 | + public function getTree($id, $limit = 0, $offset = 0) { |
|
288 | + $tree = []; |
|
289 | + $tree['comment'] = $this->get($id); |
|
290 | + $tree['replies'] = []; |
|
291 | + |
|
292 | + $qb = $this->dbConn->getQueryBuilder(); |
|
293 | + $query = $qb->select('*') |
|
294 | + ->from('comments') |
|
295 | + ->where($qb->expr()->eq('topmost_parent_id', $qb->createParameter('id'))) |
|
296 | + ->orderBy('creation_timestamp', 'DESC') |
|
297 | + ->setParameter('id', $id); |
|
298 | + |
|
299 | + if ($limit > 0) { |
|
300 | + $query->setMaxResults($limit); |
|
301 | + } |
|
302 | + if ($offset > 0) { |
|
303 | + $query->setFirstResult($offset); |
|
304 | + } |
|
305 | + |
|
306 | + $resultStatement = $query->execute(); |
|
307 | + while ($data = $resultStatement->fetch()) { |
|
308 | + $comment = new Comment($this->normalizeDatabaseData($data)); |
|
309 | + $this->cache($comment); |
|
310 | + $tree['replies'][] = [ |
|
311 | + 'comment' => $comment, |
|
312 | + 'replies' => [] |
|
313 | + ]; |
|
314 | + } |
|
315 | + $resultStatement->closeCursor(); |
|
316 | + |
|
317 | + return $tree; |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Get the actor types and ID that commented in the tree specified by the ID |
|
322 | + * |
|
323 | + * @param string $id |
|
324 | + * @return array |
|
325 | + * @since 13.0.0 |
|
326 | + * |
|
327 | + * The return array looks like this: |
|
328 | + * |
|
329 | + * [ |
|
330 | + * 'user' => [ |
|
331 | + * 'alice' => 2, |
|
332 | + * 'bob' => 3 |
|
333 | + * ], |
|
334 | + * 'robot' => [ |
|
335 | + * 'r2-d2' => 5, |
|
336 | + * 'c-3po' => 17, |
|
337 | + * ] |
|
338 | + * ] |
|
339 | + */ |
|
340 | + public function getActorsInTree($id) { |
|
341 | + $tree = $this->getTree($id); |
|
342 | + $actors = []; |
|
343 | + $this->walkTree($tree, $actors, [$this, 'extractActor']); |
|
344 | + return $actors; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * @param IComment $comment |
|
349 | + * @param array &$actors |
|
350 | + * |
|
351 | + * build an array that looks like: |
|
352 | + * |
|
353 | + * [ |
|
354 | + * 'user' => [ |
|
355 | + * 'alice' => 2, |
|
356 | + * 'bob' => 3 |
|
357 | + * ], |
|
358 | + * 'robot' => [ |
|
359 | + * 'r2-d2' => 5, |
|
360 | + * 'c-3po' => 17, |
|
361 | + * ] |
|
362 | + * ] |
|
363 | + * |
|
364 | + */ |
|
365 | + protected function extractActor(IComment $comment, &$actors) { |
|
366 | + if(!isset($actors[$comment->getActorType()])) { |
|
367 | + $actors[$comment->getActorType()] = []; |
|
368 | + } |
|
369 | + if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
370 | + $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
371 | + } else { |
|
372 | + $actors[$comment->getActorType()][$comment->getActorId()] += 1; |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * walks through a comment tree (as returned by getTree() and invokes a callback |
|
378 | + * with the current IComment instance (and optionally custom parameters) |
|
379 | + * |
|
380 | + * @param array $node |
|
381 | + * @param array &$results |
|
382 | + * @param callable $callback |
|
383 | + * @param array|null $parameters |
|
384 | + */ |
|
385 | + protected function walkTree($node, array &$results, callable $callback, array $parameters = null) { |
|
386 | + if(isset($node['replies'])) { |
|
387 | + foreach ($node['replies'] as $subNode) { |
|
388 | + $this->walkTree($subNode, $results, $callback, $parameters); |
|
389 | + } |
|
390 | + } |
|
391 | + if(isset($node['comment']) && $node['comment'] instanceof IComment) { |
|
392 | + $callback($node['comment'], $results, $parameters); |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * returns comments for a specific object (e.g. a file). |
|
398 | + * |
|
399 | + * The sort order is always newest to oldest. |
|
400 | + * |
|
401 | + * @param string $objectType the object type, e.g. 'files' |
|
402 | + * @param string $objectId the id of the object |
|
403 | + * @param int $limit optional, number of maximum comments to be returned. if |
|
404 | + * not specified, all comments are returned. |
|
405 | + * @param int $offset optional, starting point |
|
406 | + * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |
|
407 | + * that may be returned |
|
408 | + * @return IComment[] |
|
409 | + * @since 9.0.0 |
|
410 | + */ |
|
411 | + public function getForObject( |
|
412 | + $objectType, |
|
413 | + $objectId, |
|
414 | + $limit = 0, |
|
415 | + $offset = 0, |
|
416 | + \DateTime $notOlderThan = null |
|
417 | + ) { |
|
418 | + $comments = []; |
|
419 | + |
|
420 | + $qb = $this->dbConn->getQueryBuilder(); |
|
421 | + $query = $qb->select('*') |
|
422 | + ->from('comments') |
|
423 | + ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
424 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
425 | + ->orderBy('creation_timestamp', 'DESC') |
|
426 | + ->setParameter('type', $objectType) |
|
427 | + ->setParameter('id', $objectId); |
|
428 | + |
|
429 | + if ($limit > 0) { |
|
430 | + $query->setMaxResults($limit); |
|
431 | + } |
|
432 | + if ($offset > 0) { |
|
433 | + $query->setFirstResult($offset); |
|
434 | + } |
|
435 | + if (!is_null($notOlderThan)) { |
|
436 | + $query |
|
437 | + ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
|
438 | + ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
|
439 | + } |
|
440 | + |
|
441 | + $resultStatement = $query->execute(); |
|
442 | + while ($data = $resultStatement->fetch()) { |
|
443 | + $comment = new Comment($this->normalizeDatabaseData($data)); |
|
444 | + $this->cache($comment); |
|
445 | + $comments[] = $comment; |
|
446 | + } |
|
447 | + $resultStatement->closeCursor(); |
|
448 | + |
|
449 | + return $comments; |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * @param $objectType string the object type, e.g. 'files' |
|
454 | + * @param $objectId string the id of the object |
|
455 | + * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |
|
456 | + * that may be returned |
|
457 | + * @return Int |
|
458 | + * @since 9.0.0 |
|
459 | + */ |
|
460 | + public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) { |
|
461 | + $qb = $this->dbConn->getQueryBuilder(); |
|
462 | + $query = $qb->select($qb->createFunction('COUNT(`id`)')) |
|
463 | + ->from('comments') |
|
464 | + ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
465 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
466 | + ->setParameter('type', $objectType) |
|
467 | + ->setParameter('id', $objectId); |
|
468 | + |
|
469 | + if (!is_null($notOlderThan)) { |
|
470 | + $query |
|
471 | + ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
|
472 | + ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
|
473 | + } |
|
474 | + |
|
475 | + $resultStatement = $query->execute(); |
|
476 | + $data = $resultStatement->fetch(\PDO::FETCH_NUM); |
|
477 | + $resultStatement->closeCursor(); |
|
478 | + return intval($data[0]); |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Get the number of unread comments for all files in a folder |
|
483 | + * |
|
484 | + * @param int $folderId |
|
485 | + * @param IUser $user |
|
486 | + * @return array [$fileId => $unreadCount] |
|
487 | + */ |
|
488 | + public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) { |
|
489 | + $qb = $this->dbConn->getQueryBuilder(); |
|
490 | + $query = $qb->select('f.fileid') |
|
491 | + ->selectAlias( |
|
492 | + $qb->createFunction('COUNT(' . $qb->getColumnName('c.id') . ')'), |
|
493 | + 'num_ids' |
|
494 | + ) |
|
495 | + ->from('comments', 'c') |
|
496 | + ->innerJoin('c', 'filecache', 'f', $qb->expr()->andX( |
|
497 | + $qb->expr()->eq('c.object_type', $qb->createNamedParameter('files')), |
|
498 | + $qb->expr()->eq('f.fileid', $qb->expr()->castColumn('c.object_id', IQueryBuilder::PARAM_INT)) |
|
499 | + )) |
|
500 | + ->leftJoin('c', 'comments_read_markers', 'm', $qb->expr()->andX( |
|
501 | + $qb->expr()->eq('m.object_type', $qb->createNamedParameter('files')), |
|
502 | + $qb->expr()->eq('m.object_id', 'c.object_id'), |
|
503 | + $qb->expr()->eq('m.user_id', $qb->createNamedParameter($user->getUID())) |
|
504 | + )) |
|
505 | + ->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($folderId))) |
|
506 | + ->andWhere($qb->expr()->orX( |
|
507 | + $qb->expr()->gt('c.creation_timestamp', 'marker_datetime'), |
|
508 | + $qb->expr()->isNull('marker_datetime') |
|
509 | + )) |
|
510 | + ->groupBy('f.fileid'); |
|
511 | + |
|
512 | + $resultStatement = $query->execute(); |
|
513 | + |
|
514 | + $results = []; |
|
515 | + while ($row = $resultStatement->fetch()) { |
|
516 | + $results[$row['fileid']] = (int) $row['num_ids']; |
|
517 | + } |
|
518 | + $resultStatement->closeCursor(); |
|
519 | + return $results; |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * creates a new comment and returns it. At this point of time, it is not |
|
524 | + * saved in the used data storage. Use save() after setting other fields |
|
525 | + * of the comment (e.g. message or verb). |
|
526 | + * |
|
527 | + * @param string $actorType the actor type (e.g. 'users') |
|
528 | + * @param string $actorId a user id |
|
529 | + * @param string $objectType the object type the comment is attached to |
|
530 | + * @param string $objectId the object id the comment is attached to |
|
531 | + * @return IComment |
|
532 | + * @since 9.0.0 |
|
533 | + */ |
|
534 | + public function create($actorType, $actorId, $objectType, $objectId) { |
|
535 | + $comment = new Comment(); |
|
536 | + $comment |
|
537 | + ->setActor($actorType, $actorId) |
|
538 | + ->setObject($objectType, $objectId); |
|
539 | + return $comment; |
|
540 | + } |
|
541 | + |
|
542 | + /** |
|
543 | + * permanently deletes the comment specified by the ID |
|
544 | + * |
|
545 | + * When the comment has child comments, their parent ID will be changed to |
|
546 | + * the parent ID of the item that is to be deleted. |
|
547 | + * |
|
548 | + * @param string $id |
|
549 | + * @return bool |
|
550 | + * @throws \InvalidArgumentException |
|
551 | + * @since 9.0.0 |
|
552 | + */ |
|
553 | + public function delete($id) { |
|
554 | + if (!is_string($id)) { |
|
555 | + throw new \InvalidArgumentException('Parameter must be string'); |
|
556 | + } |
|
557 | + |
|
558 | + try { |
|
559 | + $comment = $this->get($id); |
|
560 | + } catch (\Exception $e) { |
|
561 | + // Ignore exceptions, we just don't fire a hook then |
|
562 | + $comment = null; |
|
563 | + } |
|
564 | + |
|
565 | + $qb = $this->dbConn->getQueryBuilder(); |
|
566 | + $query = $qb->delete('comments') |
|
567 | + ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
568 | + ->setParameter('id', $id); |
|
569 | + |
|
570 | + try { |
|
571 | + $affectedRows = $query->execute(); |
|
572 | + $this->uncache($id); |
|
573 | + } catch (DriverException $e) { |
|
574 | + $this->logger->logException($e, ['app' => 'core_comments']); |
|
575 | + return false; |
|
576 | + } |
|
577 | + |
|
578 | + if ($affectedRows > 0 && $comment instanceof IComment) { |
|
579 | + $this->sendEvent(CommentsEvent::EVENT_DELETE, $comment); |
|
580 | + } |
|
581 | + |
|
582 | + return ($affectedRows > 0); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * saves the comment permanently |
|
587 | + * |
|
588 | + * if the supplied comment has an empty ID, a new entry comment will be |
|
589 | + * saved and the instance updated with the new ID. |
|
590 | + * |
|
591 | + * Otherwise, an existing comment will be updated. |
|
592 | + * |
|
593 | + * Throws NotFoundException when a comment that is to be updated does not |
|
594 | + * exist anymore at this point of time. |
|
595 | + * |
|
596 | + * @param IComment $comment |
|
597 | + * @return bool |
|
598 | + * @throws NotFoundException |
|
599 | + * @since 9.0.0 |
|
600 | + */ |
|
601 | + public function save(IComment $comment) { |
|
602 | + if ($this->prepareCommentForDatabaseWrite($comment)->getId() === '') { |
|
603 | + $result = $this->insert($comment); |
|
604 | + } else { |
|
605 | + $result = $this->update($comment); |
|
606 | + } |
|
607 | + |
|
608 | + if ($result && !!$comment->getParentId()) { |
|
609 | + $this->updateChildrenInformation( |
|
610 | + $comment->getParentId(), |
|
611 | + $comment->getCreationDateTime() |
|
612 | + ); |
|
613 | + $this->cache($comment); |
|
614 | + } |
|
615 | + |
|
616 | + return $result; |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * inserts the provided comment in the database |
|
621 | + * |
|
622 | + * @param IComment $comment |
|
623 | + * @return bool |
|
624 | + */ |
|
625 | + protected function insert(IComment &$comment) { |
|
626 | + $qb = $this->dbConn->getQueryBuilder(); |
|
627 | + $affectedRows = $qb |
|
628 | + ->insert('comments') |
|
629 | + ->values([ |
|
630 | + 'parent_id' => $qb->createNamedParameter($comment->getParentId()), |
|
631 | + 'topmost_parent_id' => $qb->createNamedParameter($comment->getTopmostParentId()), |
|
632 | + 'children_count' => $qb->createNamedParameter($comment->getChildrenCount()), |
|
633 | + 'actor_type' => $qb->createNamedParameter($comment->getActorType()), |
|
634 | + 'actor_id' => $qb->createNamedParameter($comment->getActorId()), |
|
635 | + 'message' => $qb->createNamedParameter($comment->getMessage()), |
|
636 | + 'verb' => $qb->createNamedParameter($comment->getVerb()), |
|
637 | + 'creation_timestamp' => $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime'), |
|
638 | + 'latest_child_timestamp' => $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'), |
|
639 | + 'object_type' => $qb->createNamedParameter($comment->getObjectType()), |
|
640 | + 'object_id' => $qb->createNamedParameter($comment->getObjectId()), |
|
641 | + ]) |
|
642 | + ->execute(); |
|
643 | + |
|
644 | + if ($affectedRows > 0) { |
|
645 | + $comment->setId(strval($qb->getLastInsertId())); |
|
646 | + $this->sendEvent(CommentsEvent::EVENT_ADD, $comment); |
|
647 | + } |
|
648 | + |
|
649 | + return $affectedRows > 0; |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * updates a Comment data row |
|
654 | + * |
|
655 | + * @param IComment $comment |
|
656 | + * @return bool |
|
657 | + * @throws NotFoundException |
|
658 | + */ |
|
659 | + protected function update(IComment $comment) { |
|
660 | + // for properly working preUpdate Events we need the old comments as is |
|
661 | + // in the DB and overcome caching. Also avoid that outdated information stays. |
|
662 | + $this->uncache($comment->getId()); |
|
663 | + $this->sendEvent(CommentsEvent::EVENT_PRE_UPDATE, $this->get($comment->getId())); |
|
664 | + $this->uncache($comment->getId()); |
|
665 | + |
|
666 | + $qb = $this->dbConn->getQueryBuilder(); |
|
667 | + $affectedRows = $qb |
|
668 | + ->update('comments') |
|
669 | + ->set('parent_id', $qb->createNamedParameter($comment->getParentId())) |
|
670 | + ->set('topmost_parent_id', $qb->createNamedParameter($comment->getTopmostParentId())) |
|
671 | + ->set('children_count', $qb->createNamedParameter($comment->getChildrenCount())) |
|
672 | + ->set('actor_type', $qb->createNamedParameter($comment->getActorType())) |
|
673 | + ->set('actor_id', $qb->createNamedParameter($comment->getActorId())) |
|
674 | + ->set('message', $qb->createNamedParameter($comment->getMessage())) |
|
675 | + ->set('verb', $qb->createNamedParameter($comment->getVerb())) |
|
676 | + ->set('creation_timestamp', $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime')) |
|
677 | + ->set('latest_child_timestamp', $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime')) |
|
678 | + ->set('object_type', $qb->createNamedParameter($comment->getObjectType())) |
|
679 | + ->set('object_id', $qb->createNamedParameter($comment->getObjectId())) |
|
680 | + ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
681 | + ->setParameter('id', $comment->getId()) |
|
682 | + ->execute(); |
|
683 | + |
|
684 | + if ($affectedRows === 0) { |
|
685 | + throw new NotFoundException('Comment to update does ceased to exist'); |
|
686 | + } |
|
687 | + |
|
688 | + $this->sendEvent(CommentsEvent::EVENT_UPDATE, $comment); |
|
689 | + |
|
690 | + return $affectedRows > 0; |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * removes references to specific actor (e.g. on user delete) of a comment. |
|
695 | + * The comment itself must not get lost/deleted. |
|
696 | + * |
|
697 | + * @param string $actorType the actor type (e.g. 'users') |
|
698 | + * @param string $actorId a user id |
|
699 | + * @return boolean |
|
700 | + * @since 9.0.0 |
|
701 | + */ |
|
702 | + public function deleteReferencesOfActor($actorType, $actorId) { |
|
703 | + $this->checkRoleParameters('Actor', $actorType, $actorId); |
|
704 | + |
|
705 | + $qb = $this->dbConn->getQueryBuilder(); |
|
706 | + $affectedRows = $qb |
|
707 | + ->update('comments') |
|
708 | + ->set('actor_type', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
709 | + ->set('actor_id', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
710 | + ->where($qb->expr()->eq('actor_type', $qb->createParameter('type'))) |
|
711 | + ->andWhere($qb->expr()->eq('actor_id', $qb->createParameter('id'))) |
|
712 | + ->setParameter('type', $actorType) |
|
713 | + ->setParameter('id', $actorId) |
|
714 | + ->execute(); |
|
715 | + |
|
716 | + $this->commentsCache = []; |
|
717 | + |
|
718 | + return is_int($affectedRows); |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * deletes all comments made of a specific object (e.g. on file delete) |
|
723 | + * |
|
724 | + * @param string $objectType the object type (e.g. 'files') |
|
725 | + * @param string $objectId e.g. the file id |
|
726 | + * @return boolean |
|
727 | + * @since 9.0.0 |
|
728 | + */ |
|
729 | + public function deleteCommentsAtObject($objectType, $objectId) { |
|
730 | + $this->checkRoleParameters('Object', $objectType, $objectId); |
|
731 | + |
|
732 | + $qb = $this->dbConn->getQueryBuilder(); |
|
733 | + $affectedRows = $qb |
|
734 | + ->delete('comments') |
|
735 | + ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
736 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
737 | + ->setParameter('type', $objectType) |
|
738 | + ->setParameter('id', $objectId) |
|
739 | + ->execute(); |
|
740 | + |
|
741 | + $this->commentsCache = []; |
|
742 | + |
|
743 | + return is_int($affectedRows); |
|
744 | + } |
|
745 | + |
|
746 | + /** |
|
747 | + * deletes the read markers for the specified user |
|
748 | + * |
|
749 | + * @param \OCP\IUser $user |
|
750 | + * @return bool |
|
751 | + * @since 9.0.0 |
|
752 | + */ |
|
753 | + public function deleteReadMarksFromUser(IUser $user) { |
|
754 | + $qb = $this->dbConn->getQueryBuilder(); |
|
755 | + $query = $qb->delete('comments_read_markers') |
|
756 | + ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
757 | + ->setParameter('user_id', $user->getUID()); |
|
758 | + |
|
759 | + try { |
|
760 | + $affectedRows = $query->execute(); |
|
761 | + } catch (DriverException $e) { |
|
762 | + $this->logger->logException($e, ['app' => 'core_comments']); |
|
763 | + return false; |
|
764 | + } |
|
765 | + return ($affectedRows > 0); |
|
766 | + } |
|
767 | + |
|
768 | + /** |
|
769 | + * sets the read marker for a given file to the specified date for the |
|
770 | + * provided user |
|
771 | + * |
|
772 | + * @param string $objectType |
|
773 | + * @param string $objectId |
|
774 | + * @param \DateTime $dateTime |
|
775 | + * @param IUser $user |
|
776 | + * @since 9.0.0 |
|
777 | + * @suppress SqlInjectionChecker |
|
778 | + */ |
|
779 | + public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) { |
|
780 | + $this->checkRoleParameters('Object', $objectType, $objectId); |
|
781 | + |
|
782 | + $qb = $this->dbConn->getQueryBuilder(); |
|
783 | + $values = [ |
|
784 | + 'user_id' => $qb->createNamedParameter($user->getUID()), |
|
785 | + 'marker_datetime' => $qb->createNamedParameter($dateTime, 'datetime'), |
|
786 | + 'object_type' => $qb->createNamedParameter($objectType), |
|
787 | + 'object_id' => $qb->createNamedParameter($objectId), |
|
788 | + ]; |
|
789 | + |
|
790 | + // Strategy: try to update, if this does not return affected rows, do an insert. |
|
791 | + $affectedRows = $qb |
|
792 | + ->update('comments_read_markers') |
|
793 | + ->set('user_id', $values['user_id']) |
|
794 | + ->set('marker_datetime', $values['marker_datetime']) |
|
795 | + ->set('object_type', $values['object_type']) |
|
796 | + ->set('object_id', $values['object_id']) |
|
797 | + ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
798 | + ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
799 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
800 | + ->setParameter('user_id', $user->getUID(), IQueryBuilder::PARAM_STR) |
|
801 | + ->setParameter('object_type', $objectType, IQueryBuilder::PARAM_STR) |
|
802 | + ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) |
|
803 | + ->execute(); |
|
804 | + |
|
805 | + if ($affectedRows > 0) { |
|
806 | + return; |
|
807 | + } |
|
808 | + |
|
809 | + $qb->insert('comments_read_markers') |
|
810 | + ->values($values) |
|
811 | + ->execute(); |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * returns the read marker for a given file to the specified date for the |
|
816 | + * provided user. It returns null, when the marker is not present, i.e. |
|
817 | + * no comments were marked as read. |
|
818 | + * |
|
819 | + * @param string $objectType |
|
820 | + * @param string $objectId |
|
821 | + * @param IUser $user |
|
822 | + * @return \DateTime|null |
|
823 | + * @since 9.0.0 |
|
824 | + */ |
|
825 | + public function getReadMark($objectType, $objectId, IUser $user) { |
|
826 | + $qb = $this->dbConn->getQueryBuilder(); |
|
827 | + $resultStatement = $qb->select('marker_datetime') |
|
828 | + ->from('comments_read_markers') |
|
829 | + ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
830 | + ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
831 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
832 | + ->setParameter('user_id', $user->getUID(), IQueryBuilder::PARAM_STR) |
|
833 | + ->setParameter('object_type', $objectType, IQueryBuilder::PARAM_STR) |
|
834 | + ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) |
|
835 | + ->execute(); |
|
836 | + |
|
837 | + $data = $resultStatement->fetch(); |
|
838 | + $resultStatement->closeCursor(); |
|
839 | + if (!$data || is_null($data['marker_datetime'])) { |
|
840 | + return null; |
|
841 | + } |
|
842 | + |
|
843 | + return new \DateTime($data['marker_datetime']); |
|
844 | + } |
|
845 | + |
|
846 | + /** |
|
847 | + * deletes the read markers on the specified object |
|
848 | + * |
|
849 | + * @param string $objectType |
|
850 | + * @param string $objectId |
|
851 | + * @return bool |
|
852 | + * @since 9.0.0 |
|
853 | + */ |
|
854 | + public function deleteReadMarksOnObject($objectType, $objectId) { |
|
855 | + $this->checkRoleParameters('Object', $objectType, $objectId); |
|
856 | + |
|
857 | + $qb = $this->dbConn->getQueryBuilder(); |
|
858 | + $query = $qb->delete('comments_read_markers') |
|
859 | + ->where($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
860 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
861 | + ->setParameter('object_type', $objectType) |
|
862 | + ->setParameter('object_id', $objectId); |
|
863 | + |
|
864 | + try { |
|
865 | + $affectedRows = $query->execute(); |
|
866 | + } catch (DriverException $e) { |
|
867 | + $this->logger->logException($e, ['app' => 'core_comments']); |
|
868 | + return false; |
|
869 | + } |
|
870 | + return ($affectedRows > 0); |
|
871 | + } |
|
872 | + |
|
873 | + /** |
|
874 | + * registers an Entity to the manager, so event notifications can be send |
|
875 | + * to consumers of the comments infrastructure |
|
876 | + * |
|
877 | + * @param \Closure $closure |
|
878 | + */ |
|
879 | + public function registerEventHandler(\Closure $closure) { |
|
880 | + $this->eventHandlerClosures[] = $closure; |
|
881 | + $this->eventHandlers = []; |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * registers a method that resolves an ID to a display name for a given type |
|
886 | + * |
|
887 | + * @param string $type |
|
888 | + * @param \Closure $closure |
|
889 | + * @throws \OutOfBoundsException |
|
890 | + * @since 11.0.0 |
|
891 | + * |
|
892 | + * Only one resolver shall be registered per type. Otherwise a |
|
893 | + * \OutOfBoundsException has to thrown. |
|
894 | + */ |
|
895 | + public function registerDisplayNameResolver($type, \Closure $closure) { |
|
896 | + if (!is_string($type)) { |
|
897 | + throw new \InvalidArgumentException('String expected.'); |
|
898 | + } |
|
899 | + if (isset($this->displayNameResolvers[$type])) { |
|
900 | + throw new \OutOfBoundsException('Displayname resolver for this type already registered'); |
|
901 | + } |
|
902 | + $this->displayNameResolvers[$type] = $closure; |
|
903 | + } |
|
904 | + |
|
905 | + /** |
|
906 | + * resolves a given ID of a given Type to a display name. |
|
907 | + * |
|
908 | + * @param string $type |
|
909 | + * @param string $id |
|
910 | + * @return string |
|
911 | + * @throws \OutOfBoundsException |
|
912 | + * @since 11.0.0 |
|
913 | + * |
|
914 | + * If a provided type was not registered, an \OutOfBoundsException shall |
|
915 | + * be thrown. It is upon the resolver discretion what to return of the |
|
916 | + * provided ID is unknown. It must be ensured that a string is returned. |
|
917 | + */ |
|
918 | + public function resolveDisplayName($type, $id) { |
|
919 | + if (!is_string($type)) { |
|
920 | + throw new \InvalidArgumentException('String expected.'); |
|
921 | + } |
|
922 | + if (!isset($this->displayNameResolvers[$type])) { |
|
923 | + throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
|
924 | + } |
|
925 | + return (string)$this->displayNameResolvers[$type]($id); |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * returns valid, registered entities |
|
930 | + * |
|
931 | + * @return \OCP\Comments\ICommentsEventHandler[] |
|
932 | + */ |
|
933 | + private function getEventHandlers() { |
|
934 | + if (!empty($this->eventHandlers)) { |
|
935 | + return $this->eventHandlers; |
|
936 | + } |
|
937 | + |
|
938 | + $this->eventHandlers = []; |
|
939 | + foreach ($this->eventHandlerClosures as $name => $closure) { |
|
940 | + $entity = $closure(); |
|
941 | + if (!($entity instanceof ICommentsEventHandler)) { |
|
942 | + throw new \InvalidArgumentException('The given entity does not implement the ICommentsEntity interface'); |
|
943 | + } |
|
944 | + $this->eventHandlers[$name] = $entity; |
|
945 | + } |
|
946 | + |
|
947 | + return $this->eventHandlers; |
|
948 | + } |
|
949 | + |
|
950 | + /** |
|
951 | + * sends notifications to the registered entities |
|
952 | + * |
|
953 | + * @param $eventType |
|
954 | + * @param IComment $comment |
|
955 | + */ |
|
956 | + private function sendEvent($eventType, IComment $comment) { |
|
957 | + $entities = $this->getEventHandlers(); |
|
958 | + $event = new CommentsEvent($eventType, $comment); |
|
959 | + foreach ($entities as $entity) { |
|
960 | + $entity->handle($event); |
|
961 | + } |
|
962 | + } |
|
963 | 963 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | !is_string($type) || empty($type) |
191 | 191 | || !is_string($id) || empty($id) |
192 | 192 | ) { |
193 | - throw new \InvalidArgumentException($role . ' parameters must be string and not empty'); |
|
193 | + throw new \InvalidArgumentException($role.' parameters must be string and not empty'); |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
@@ -363,10 +363,10 @@ discard block |
||
363 | 363 | * |
364 | 364 | */ |
365 | 365 | protected function extractActor(IComment $comment, &$actors) { |
366 | - if(!isset($actors[$comment->getActorType()])) { |
|
366 | + if (!isset($actors[$comment->getActorType()])) { |
|
367 | 367 | $actors[$comment->getActorType()] = []; |
368 | 368 | } |
369 | - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
369 | + if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
370 | 370 | $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
371 | 371 | } else { |
372 | 372 | $actors[$comment->getActorType()][$comment->getActorId()] += 1; |
@@ -383,12 +383,12 @@ discard block |
||
383 | 383 | * @param array|null $parameters |
384 | 384 | */ |
385 | 385 | protected function walkTree($node, array &$results, callable $callback, array $parameters = null) { |
386 | - if(isset($node['replies'])) { |
|
386 | + if (isset($node['replies'])) { |
|
387 | 387 | foreach ($node['replies'] as $subNode) { |
388 | 388 | $this->walkTree($subNode, $results, $callback, $parameters); |
389 | 389 | } |
390 | 390 | } |
391 | - if(isset($node['comment']) && $node['comment'] instanceof IComment) { |
|
391 | + if (isset($node['comment']) && $node['comment'] instanceof IComment) { |
|
392 | 392 | $callback($node['comment'], $results, $parameters); |
393 | 393 | } |
394 | 394 | } |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | $qb = $this->dbConn->getQueryBuilder(); |
490 | 490 | $query = $qb->select('f.fileid') |
491 | 491 | ->selectAlias( |
492 | - $qb->createFunction('COUNT(' . $qb->getColumnName('c.id') . ')'), |
|
492 | + $qb->createFunction('COUNT('.$qb->getColumnName('c.id').')'), |
|
493 | 493 | 'num_ids' |
494 | 494 | ) |
495 | 495 | ->from('comments', 'c') |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | * @param IComment $comment |
623 | 623 | * @return bool |
624 | 624 | */ |
625 | - protected function insert(IComment &$comment) { |
|
625 | + protected function insert(IComment & $comment) { |
|
626 | 626 | $qb = $this->dbConn->getQueryBuilder(); |
627 | 627 | $affectedRows = $qb |
628 | 628 | ->insert('comments') |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | if (!isset($this->displayNameResolvers[$type])) { |
923 | 923 | throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
924 | 924 | } |
925 | - return (string)$this->displayNameResolvers[$type]($id); |
|
925 | + return (string) $this->displayNameResolvers[$type]($id); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | /** |
@@ -29,76 +29,76 @@ |
||
29 | 29 | |
30 | 30 | class CommentersSorter implements ISorter { |
31 | 31 | |
32 | - /** @var ICommentsManager */ |
|
33 | - private $commentsManager; |
|
34 | - |
|
35 | - public function __construct(ICommentsManager $commentsManager) { |
|
36 | - $this->commentsManager = $commentsManager; |
|
37 | - } |
|
38 | - |
|
39 | - public function getId() { |
|
40 | - return 'commenters'; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Sorts people who commented on the given item atop (descelating) of the |
|
45 | - * others |
|
46 | - * |
|
47 | - * @param array $sortArray |
|
48 | - * @param array $context |
|
49 | - */ |
|
50 | - public function sort(array &$sortArray, array $context) { |
|
51 | - $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
52 | - if(count($commenters) === 0) { |
|
53 | - return; |
|
54 | - } |
|
55 | - |
|
56 | - foreach ($sortArray as $type => &$byType) { |
|
57 | - if(!isset($commenters[$type])) { |
|
58 | - continue; |
|
59 | - } |
|
60 | - |
|
61 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
62 | - // the current index to the value and compare it on a draw |
|
63 | - $i = 0; |
|
64 | - $workArray = array_map(function($element) use (&$i) { |
|
65 | - return [$i++, $element]; |
|
66 | - }, $byType); |
|
67 | - |
|
68 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
69 | - $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
70 | - if($r === 0) { |
|
71 | - $r = $a[0] - $b[0]; |
|
72 | - } |
|
73 | - return $r; |
|
74 | - }); |
|
75 | - |
|
76 | - // and remove the index values again |
|
77 | - $byType = array_column($workArray, 1); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param $type |
|
83 | - * @param $id |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function retrieveCommentsInformation($type, $id) { |
|
87 | - $comments = $this->commentsManager->getForObject($type, $id, 1); |
|
88 | - if(count($comments) === 0) { |
|
89 | - return []; |
|
90 | - } |
|
91 | - |
|
92 | - return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId()); |
|
93 | - } |
|
94 | - |
|
95 | - protected function compare(array $a, array $b, array $commenters) { |
|
96 | - $a = $a['value']['shareWith']; |
|
97 | - $b = $b['value']['shareWith']; |
|
98 | - |
|
99 | - $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
100 | - $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
101 | - |
|
102 | - return $valueB - $valueA; |
|
103 | - } |
|
32 | + /** @var ICommentsManager */ |
|
33 | + private $commentsManager; |
|
34 | + |
|
35 | + public function __construct(ICommentsManager $commentsManager) { |
|
36 | + $this->commentsManager = $commentsManager; |
|
37 | + } |
|
38 | + |
|
39 | + public function getId() { |
|
40 | + return 'commenters'; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Sorts people who commented on the given item atop (descelating) of the |
|
45 | + * others |
|
46 | + * |
|
47 | + * @param array $sortArray |
|
48 | + * @param array $context |
|
49 | + */ |
|
50 | + public function sort(array &$sortArray, array $context) { |
|
51 | + $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
52 | + if(count($commenters) === 0) { |
|
53 | + return; |
|
54 | + } |
|
55 | + |
|
56 | + foreach ($sortArray as $type => &$byType) { |
|
57 | + if(!isset($commenters[$type])) { |
|
58 | + continue; |
|
59 | + } |
|
60 | + |
|
61 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
62 | + // the current index to the value and compare it on a draw |
|
63 | + $i = 0; |
|
64 | + $workArray = array_map(function($element) use (&$i) { |
|
65 | + return [$i++, $element]; |
|
66 | + }, $byType); |
|
67 | + |
|
68 | + usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
69 | + $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
70 | + if($r === 0) { |
|
71 | + $r = $a[0] - $b[0]; |
|
72 | + } |
|
73 | + return $r; |
|
74 | + }); |
|
75 | + |
|
76 | + // and remove the index values again |
|
77 | + $byType = array_column($workArray, 1); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param $type |
|
83 | + * @param $id |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function retrieveCommentsInformation($type, $id) { |
|
87 | + $comments = $this->commentsManager->getForObject($type, $id, 1); |
|
88 | + if(count($comments) === 0) { |
|
89 | + return []; |
|
90 | + } |
|
91 | + |
|
92 | + return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId()); |
|
93 | + } |
|
94 | + |
|
95 | + protected function compare(array $a, array $b, array $commenters) { |
|
96 | + $a = $a['value']['shareWith']; |
|
97 | + $b = $b['value']['shareWith']; |
|
98 | + |
|
99 | + $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
100 | + $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
101 | + |
|
102 | + return $valueB - $valueA; |
|
103 | + } |
|
104 | 104 | } |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function sort(array &$sortArray, array $context) { |
51 | 51 | $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
52 | - if(count($commenters) === 0) { |
|
52 | + if (count($commenters) === 0) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | 56 | foreach ($sortArray as $type => &$byType) { |
57 | - if(!isset($commenters[$type])) { |
|
57 | + if (!isset($commenters[$type])) { |
|
58 | 58 | continue; |
59 | 59 | } |
60 | 60 | |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | return [$i++, $element]; |
66 | 66 | }, $byType); |
67 | 67 | |
68 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
68 | + usort($workArray, function($a, $b) use ($commenters, $type) { |
|
69 | 69 | $r = $this->compare($a[1], $b[1], $commenters[$type]); |
70 | - if($r === 0) { |
|
70 | + if ($r === 0) { |
|
71 | 71 | $r = $a[0] - $b[0]; |
72 | 72 | } |
73 | 73 | return $r; |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | protected function retrieveCommentsInformation($type, $id) { |
87 | 87 | $comments = $this->commentsManager->getForObject($type, $id, 1); |
88 | - if(count($comments) === 0) { |
|
88 | + if (count($comments) === 0) { |
|
89 | 89 | return []; |
90 | 90 | } |
91 | 91 |