@@ -29,58 +29,58 @@ |
||
| 29 | 29 | |
| 30 | 30 | class CommentersSorter implements ISorter { |
| 31 | 31 | |
| 32 | - /** @var ICommentsManager */ |
|
| 33 | - private $commentsManager; |
|
| 32 | + /** @var ICommentsManager */ |
|
| 33 | + private $commentsManager; |
|
| 34 | 34 | |
| 35 | - public function __construct(ICommentsManager $commentsManager) { |
|
| 36 | - $this->commentsManager = $commentsManager; |
|
| 37 | - } |
|
| 35 | + public function __construct(ICommentsManager $commentsManager) { |
|
| 36 | + $this->commentsManager = $commentsManager; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function getId() { |
|
| 40 | - return 'commenters'; |
|
| 41 | - } |
|
| 39 | + public function getId() { |
|
| 40 | + return 'commenters'; |
|
| 41 | + } |
|
| 42 | 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 | - } |
|
| 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 | 55 | |
| 56 | - foreach ($sortArray as &$byType) { |
|
| 57 | - usort($byType, function ($a, $b) use ($commenters) { |
|
| 58 | - $this->compare($a, $b, $commenters); |
|
| 59 | - }); |
|
| 60 | - } |
|
| 61 | - } |
|
| 56 | + foreach ($sortArray as &$byType) { |
|
| 57 | + usort($byType, function ($a, $b) use ($commenters) { |
|
| 58 | + $this->compare($a, $b, $commenters); |
|
| 59 | + }); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param $type |
|
| 65 | - * @param $id |
|
| 66 | - * @return array |
|
| 67 | - */ |
|
| 68 | - protected function retrieveCommentsInformation($type, $id) { |
|
| 69 | - $comments = $this->commentsManager->getForObject($type, $id, 1); |
|
| 70 | - if(count($comments) === 0) { |
|
| 71 | - return []; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * @param $type |
|
| 65 | + * @param $id |
|
| 66 | + * @return array |
|
| 67 | + */ |
|
| 68 | + protected function retrieveCommentsInformation($type, $id) { |
|
| 69 | + $comments = $this->commentsManager->getForObject($type, $id, 1); |
|
| 70 | + if(count($comments) === 0) { |
|
| 71 | + return []; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId()); |
|
| 75 | - } |
|
| 74 | + return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId()); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function compare(array $a, array $b, array $commenters) { |
|
| 78 | - $a = $a['value']['shareWith']; |
|
| 79 | - $b = $b['value']['shareWith']; |
|
| 77 | + public function compare(array $a, array $b, array $commenters) { |
|
| 78 | + $a = $a['value']['shareWith']; |
|
| 79 | + $b = $b['value']['shareWith']; |
|
| 80 | 80 | |
| 81 | - $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
| 82 | - $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
| 81 | + $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
| 82 | + $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
| 83 | 83 | |
| 84 | - return $valueA < $valueB ? -1 : $valueA > $valueB ? 1 : 0; |
|
| 85 | - } |
|
| 84 | + return $valueA < $valueB ? -1 : $valueA > $valueB ? 1 : 0; |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -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 &$byType) { |
| 57 | - usort($byType, function ($a, $b) use ($commenters) { |
|
| 57 | + usort($byType, function($a, $b) use ($commenters) { |
|
| 58 | 58 | $this->compare($a, $b, $commenters); |
| 59 | 59 | }); |
| 60 | 60 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | protected function retrieveCommentsInformation($type, $id) { |
| 69 | 69 | $comments = $this->commentsManager->getForObject($type, $id, 1); |
| 70 | - if(count($comments) === 0) { |
|
| 70 | + if (count($comments) === 0) { |
|
| 71 | 71 | return []; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -31,41 +31,41 @@ |
||
| 31 | 31 | use OCP\Share; |
| 32 | 32 | |
| 33 | 33 | class AutoCompleteController extends Controller { |
| 34 | - /** @var Search */ |
|
| 35 | - private $collaboratorSearch; |
|
| 36 | - /** @var IManager */ |
|
| 37 | - private $autoCompleteManager; |
|
| 34 | + /** @var Search */ |
|
| 35 | + private $collaboratorSearch; |
|
| 36 | + /** @var IManager */ |
|
| 37 | + private $autoCompleteManager; |
|
| 38 | 38 | |
| 39 | - public function __construct($appName, IRequest $request, Search $collaboratorSearch, IManager $autoCompleteManager) { |
|
| 40 | - parent::__construct($appName, $request); |
|
| 39 | + public function __construct($appName, IRequest $request, Search $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 |
|
| 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 |
|
| 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 | - return new DataResponse($results); |
|
| 70 | - } |
|
| 69 | + return new DataResponse($results); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -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 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | |
| 27 | 27 | interface ISorter { |
| 28 | 28 | |
| 29 | - public function getId(); |
|
| 29 | + public function getId(); |
|
| 30 | 30 | |
| 31 | - public function sort(array &$sortArray, array $context); |
|
| 31 | + public function sort(array &$sortArray, array $context); |
|
| 32 | 32 | } |
@@ -38,915 +38,915 @@ |
||
| 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->extractActor($tree, $actors); |
|
| 344 | - return $actors; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @param array $node |
|
| 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(array $node, array &$actors) { |
|
| 366 | - if(isset($node['replies'])) { |
|
| 367 | - foreach ($node['replies'] as $subNode) { |
|
| 368 | - $this->extractActor($subNode, $actors); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - if(isset($node['comment']) && $node['comment'] instanceof IComment) { |
|
| 372 | - /** @var IComment $comment */ |
|
| 373 | - $comment = $node['comment']; |
|
| 374 | - if(!isset($actors[$comment->getActorType()])) { |
|
| 375 | - $actors[$comment->getActorType()] = []; |
|
| 376 | - } |
|
| 377 | - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
| 378 | - $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
| 379 | - } else { |
|
| 380 | - $actors[$comment->getActorType()][$comment->getActorId()] += 1; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * returns comments for a specific object (e.g. a file). |
|
| 387 | - * |
|
| 388 | - * The sort order is always newest to oldest. |
|
| 389 | - * |
|
| 390 | - * @param string $objectType the object type, e.g. 'files' |
|
| 391 | - * @param string $objectId the id of the object |
|
| 392 | - * @param int $limit optional, number of maximum comments to be returned. if |
|
| 393 | - * not specified, all comments are returned. |
|
| 394 | - * @param int $offset optional, starting point |
|
| 395 | - * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |
|
| 396 | - * that may be returned |
|
| 397 | - * @return IComment[] |
|
| 398 | - * @since 9.0.0 |
|
| 399 | - */ |
|
| 400 | - public function getForObject( |
|
| 401 | - $objectType, |
|
| 402 | - $objectId, |
|
| 403 | - $limit = 0, |
|
| 404 | - $offset = 0, |
|
| 405 | - \DateTime $notOlderThan = null |
|
| 406 | - ) { |
|
| 407 | - $comments = []; |
|
| 408 | - |
|
| 409 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 410 | - $query = $qb->select('*') |
|
| 411 | - ->from('comments') |
|
| 412 | - ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
| 413 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
| 414 | - ->orderBy('creation_timestamp', 'DESC') |
|
| 415 | - ->setParameter('type', $objectType) |
|
| 416 | - ->setParameter('id', $objectId); |
|
| 417 | - |
|
| 418 | - if ($limit > 0) { |
|
| 419 | - $query->setMaxResults($limit); |
|
| 420 | - } |
|
| 421 | - if ($offset > 0) { |
|
| 422 | - $query->setFirstResult($offset); |
|
| 423 | - } |
|
| 424 | - if (!is_null($notOlderThan)) { |
|
| 425 | - $query |
|
| 426 | - ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
|
| 427 | - ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - $resultStatement = $query->execute(); |
|
| 431 | - while ($data = $resultStatement->fetch()) { |
|
| 432 | - $comment = new Comment($this->normalizeDatabaseData($data)); |
|
| 433 | - $this->cache($comment); |
|
| 434 | - $comments[] = $comment; |
|
| 435 | - } |
|
| 436 | - $resultStatement->closeCursor(); |
|
| 437 | - |
|
| 438 | - return $comments; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @param $objectType string the object type, e.g. 'files' |
|
| 443 | - * @param $objectId string the id of the object |
|
| 444 | - * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |
|
| 445 | - * that may be returned |
|
| 446 | - * @return Int |
|
| 447 | - * @since 9.0.0 |
|
| 448 | - */ |
|
| 449 | - public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) { |
|
| 450 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 451 | - $query = $qb->select($qb->createFunction('COUNT(`id`)')) |
|
| 452 | - ->from('comments') |
|
| 453 | - ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
| 454 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
| 455 | - ->setParameter('type', $objectType) |
|
| 456 | - ->setParameter('id', $objectId); |
|
| 457 | - |
|
| 458 | - if (!is_null($notOlderThan)) { |
|
| 459 | - $query |
|
| 460 | - ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
|
| 461 | - ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - $resultStatement = $query->execute(); |
|
| 465 | - $data = $resultStatement->fetch(\PDO::FETCH_NUM); |
|
| 466 | - $resultStatement->closeCursor(); |
|
| 467 | - return intval($data[0]); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Get the number of unread comments for all files in a folder |
|
| 472 | - * |
|
| 473 | - * @param int $folderId |
|
| 474 | - * @param IUser $user |
|
| 475 | - * @return array [$fileId => $unreadCount] |
|
| 476 | - */ |
|
| 477 | - public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) { |
|
| 478 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 479 | - $query = $qb->select('f.fileid') |
|
| 480 | - ->selectAlias( |
|
| 481 | - $qb->createFunction('COUNT(' . $qb->getColumnName('c.id') . ')'), |
|
| 482 | - 'num_ids' |
|
| 483 | - ) |
|
| 484 | - ->from('comments', 'c') |
|
| 485 | - ->innerJoin('c', 'filecache', 'f', $qb->expr()->andX( |
|
| 486 | - $qb->expr()->eq('c.object_type', $qb->createNamedParameter('files')), |
|
| 487 | - $qb->expr()->eq('f.fileid', $qb->expr()->castColumn('c.object_id', IQueryBuilder::PARAM_INT)) |
|
| 488 | - )) |
|
| 489 | - ->leftJoin('c', 'comments_read_markers', 'm', $qb->expr()->andX( |
|
| 490 | - $qb->expr()->eq('m.object_type', $qb->createNamedParameter('files')), |
|
| 491 | - $qb->expr()->eq('m.object_id', 'c.object_id'), |
|
| 492 | - $qb->expr()->eq('m.user_id', $qb->createNamedParameter($user->getUID())) |
|
| 493 | - )) |
|
| 494 | - ->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($folderId))) |
|
| 495 | - ->andWhere($qb->expr()->orX( |
|
| 496 | - $qb->expr()->gt('c.creation_timestamp', 'marker_datetime'), |
|
| 497 | - $qb->expr()->isNull('marker_datetime') |
|
| 498 | - )) |
|
| 499 | - ->groupBy('f.fileid'); |
|
| 500 | - |
|
| 501 | - $resultStatement = $query->execute(); |
|
| 502 | - |
|
| 503 | - $results = []; |
|
| 504 | - while ($row = $resultStatement->fetch()) { |
|
| 505 | - $results[$row['fileid']] = (int) $row['num_ids']; |
|
| 506 | - } |
|
| 507 | - $resultStatement->closeCursor(); |
|
| 508 | - return $results; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * creates a new comment and returns it. At this point of time, it is not |
|
| 513 | - * saved in the used data storage. Use save() after setting other fields |
|
| 514 | - * of the comment (e.g. message or verb). |
|
| 515 | - * |
|
| 516 | - * @param string $actorType the actor type (e.g. 'users') |
|
| 517 | - * @param string $actorId a user id |
|
| 518 | - * @param string $objectType the object type the comment is attached to |
|
| 519 | - * @param string $objectId the object id the comment is attached to |
|
| 520 | - * @return IComment |
|
| 521 | - * @since 9.0.0 |
|
| 522 | - */ |
|
| 523 | - public function create($actorType, $actorId, $objectType, $objectId) { |
|
| 524 | - $comment = new Comment(); |
|
| 525 | - $comment |
|
| 526 | - ->setActor($actorType, $actorId) |
|
| 527 | - ->setObject($objectType, $objectId); |
|
| 528 | - return $comment; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * permanently deletes the comment specified by the ID |
|
| 533 | - * |
|
| 534 | - * When the comment has child comments, their parent ID will be changed to |
|
| 535 | - * the parent ID of the item that is to be deleted. |
|
| 536 | - * |
|
| 537 | - * @param string $id |
|
| 538 | - * @return bool |
|
| 539 | - * @throws \InvalidArgumentException |
|
| 540 | - * @since 9.0.0 |
|
| 541 | - */ |
|
| 542 | - public function delete($id) { |
|
| 543 | - if (!is_string($id)) { |
|
| 544 | - throw new \InvalidArgumentException('Parameter must be string'); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - try { |
|
| 548 | - $comment = $this->get($id); |
|
| 549 | - } catch (\Exception $e) { |
|
| 550 | - // Ignore exceptions, we just don't fire a hook then |
|
| 551 | - $comment = null; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 555 | - $query = $qb->delete('comments') |
|
| 556 | - ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
| 557 | - ->setParameter('id', $id); |
|
| 558 | - |
|
| 559 | - try { |
|
| 560 | - $affectedRows = $query->execute(); |
|
| 561 | - $this->uncache($id); |
|
| 562 | - } catch (DriverException $e) { |
|
| 563 | - $this->logger->logException($e, ['app' => 'core_comments']); |
|
| 564 | - return false; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - if ($affectedRows > 0 && $comment instanceof IComment) { |
|
| 568 | - $this->sendEvent(CommentsEvent::EVENT_DELETE, $comment); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - return ($affectedRows > 0); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * saves the comment permanently |
|
| 576 | - * |
|
| 577 | - * if the supplied comment has an empty ID, a new entry comment will be |
|
| 578 | - * saved and the instance updated with the new ID. |
|
| 579 | - * |
|
| 580 | - * Otherwise, an existing comment will be updated. |
|
| 581 | - * |
|
| 582 | - * Throws NotFoundException when a comment that is to be updated does not |
|
| 583 | - * exist anymore at this point of time. |
|
| 584 | - * |
|
| 585 | - * @param IComment $comment |
|
| 586 | - * @return bool |
|
| 587 | - * @throws NotFoundException |
|
| 588 | - * @since 9.0.0 |
|
| 589 | - */ |
|
| 590 | - public function save(IComment $comment) { |
|
| 591 | - if ($this->prepareCommentForDatabaseWrite($comment)->getId() === '') { |
|
| 592 | - $result = $this->insert($comment); |
|
| 593 | - } else { |
|
| 594 | - $result = $this->update($comment); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - if ($result && !!$comment->getParentId()) { |
|
| 598 | - $this->updateChildrenInformation( |
|
| 599 | - $comment->getParentId(), |
|
| 600 | - $comment->getCreationDateTime() |
|
| 601 | - ); |
|
| 602 | - $this->cache($comment); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - return $result; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * inserts the provided comment in the database |
|
| 610 | - * |
|
| 611 | - * @param IComment $comment |
|
| 612 | - * @return bool |
|
| 613 | - */ |
|
| 614 | - protected function insert(IComment &$comment) { |
|
| 615 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 616 | - $affectedRows = $qb |
|
| 617 | - ->insert('comments') |
|
| 618 | - ->values([ |
|
| 619 | - 'parent_id' => $qb->createNamedParameter($comment->getParentId()), |
|
| 620 | - 'topmost_parent_id' => $qb->createNamedParameter($comment->getTopmostParentId()), |
|
| 621 | - 'children_count' => $qb->createNamedParameter($comment->getChildrenCount()), |
|
| 622 | - 'actor_type' => $qb->createNamedParameter($comment->getActorType()), |
|
| 623 | - 'actor_id' => $qb->createNamedParameter($comment->getActorId()), |
|
| 624 | - 'message' => $qb->createNamedParameter($comment->getMessage()), |
|
| 625 | - 'verb' => $qb->createNamedParameter($comment->getVerb()), |
|
| 626 | - 'creation_timestamp' => $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime'), |
|
| 627 | - 'latest_child_timestamp' => $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'), |
|
| 628 | - 'object_type' => $qb->createNamedParameter($comment->getObjectType()), |
|
| 629 | - 'object_id' => $qb->createNamedParameter($comment->getObjectId()), |
|
| 630 | - ]) |
|
| 631 | - ->execute(); |
|
| 632 | - |
|
| 633 | - if ($affectedRows > 0) { |
|
| 634 | - $comment->setId(strval($qb->getLastInsertId())); |
|
| 635 | - $this->sendEvent(CommentsEvent::EVENT_ADD, $comment); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - return $affectedRows > 0; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * updates a Comment data row |
|
| 643 | - * |
|
| 644 | - * @param IComment $comment |
|
| 645 | - * @return bool |
|
| 646 | - * @throws NotFoundException |
|
| 647 | - */ |
|
| 648 | - protected function update(IComment $comment) { |
|
| 649 | - // for properly working preUpdate Events we need the old comments as is |
|
| 650 | - // in the DB and overcome caching. Also avoid that outdated information stays. |
|
| 651 | - $this->uncache($comment->getId()); |
|
| 652 | - $this->sendEvent(CommentsEvent::EVENT_PRE_UPDATE, $this->get($comment->getId())); |
|
| 653 | - $this->uncache($comment->getId()); |
|
| 654 | - |
|
| 655 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 656 | - $affectedRows = $qb |
|
| 657 | - ->update('comments') |
|
| 658 | - ->set('parent_id', $qb->createNamedParameter($comment->getParentId())) |
|
| 659 | - ->set('topmost_parent_id', $qb->createNamedParameter($comment->getTopmostParentId())) |
|
| 660 | - ->set('children_count', $qb->createNamedParameter($comment->getChildrenCount())) |
|
| 661 | - ->set('actor_type', $qb->createNamedParameter($comment->getActorType())) |
|
| 662 | - ->set('actor_id', $qb->createNamedParameter($comment->getActorId())) |
|
| 663 | - ->set('message', $qb->createNamedParameter($comment->getMessage())) |
|
| 664 | - ->set('verb', $qb->createNamedParameter($comment->getVerb())) |
|
| 665 | - ->set('creation_timestamp', $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime')) |
|
| 666 | - ->set('latest_child_timestamp', $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime')) |
|
| 667 | - ->set('object_type', $qb->createNamedParameter($comment->getObjectType())) |
|
| 668 | - ->set('object_id', $qb->createNamedParameter($comment->getObjectId())) |
|
| 669 | - ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
| 670 | - ->setParameter('id', $comment->getId()) |
|
| 671 | - ->execute(); |
|
| 672 | - |
|
| 673 | - if ($affectedRows === 0) { |
|
| 674 | - throw new NotFoundException('Comment to update does ceased to exist'); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - $this->sendEvent(CommentsEvent::EVENT_UPDATE, $comment); |
|
| 678 | - |
|
| 679 | - return $affectedRows > 0; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * removes references to specific actor (e.g. on user delete) of a comment. |
|
| 684 | - * The comment itself must not get lost/deleted. |
|
| 685 | - * |
|
| 686 | - * @param string $actorType the actor type (e.g. 'users') |
|
| 687 | - * @param string $actorId a user id |
|
| 688 | - * @return boolean |
|
| 689 | - * @since 9.0.0 |
|
| 690 | - */ |
|
| 691 | - public function deleteReferencesOfActor($actorType, $actorId) { |
|
| 692 | - $this->checkRoleParameters('Actor', $actorType, $actorId); |
|
| 693 | - |
|
| 694 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 695 | - $affectedRows = $qb |
|
| 696 | - ->update('comments') |
|
| 697 | - ->set('actor_type', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
| 698 | - ->set('actor_id', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
| 699 | - ->where($qb->expr()->eq('actor_type', $qb->createParameter('type'))) |
|
| 700 | - ->andWhere($qb->expr()->eq('actor_id', $qb->createParameter('id'))) |
|
| 701 | - ->setParameter('type', $actorType) |
|
| 702 | - ->setParameter('id', $actorId) |
|
| 703 | - ->execute(); |
|
| 704 | - |
|
| 705 | - $this->commentsCache = []; |
|
| 706 | - |
|
| 707 | - return is_int($affectedRows); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * deletes all comments made of a specific object (e.g. on file delete) |
|
| 712 | - * |
|
| 713 | - * @param string $objectType the object type (e.g. 'files') |
|
| 714 | - * @param string $objectId e.g. the file id |
|
| 715 | - * @return boolean |
|
| 716 | - * @since 9.0.0 |
|
| 717 | - */ |
|
| 718 | - public function deleteCommentsAtObject($objectType, $objectId) { |
|
| 719 | - $this->checkRoleParameters('Object', $objectType, $objectId); |
|
| 720 | - |
|
| 721 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 722 | - $affectedRows = $qb |
|
| 723 | - ->delete('comments') |
|
| 724 | - ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
| 725 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
| 726 | - ->setParameter('type', $objectType) |
|
| 727 | - ->setParameter('id', $objectId) |
|
| 728 | - ->execute(); |
|
| 729 | - |
|
| 730 | - $this->commentsCache = []; |
|
| 731 | - |
|
| 732 | - return is_int($affectedRows); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * deletes the read markers for the specified user |
|
| 737 | - * |
|
| 738 | - * @param \OCP\IUser $user |
|
| 739 | - * @return bool |
|
| 740 | - * @since 9.0.0 |
|
| 741 | - */ |
|
| 742 | - public function deleteReadMarksFromUser(IUser $user) { |
|
| 743 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 744 | - $query = $qb->delete('comments_read_markers') |
|
| 745 | - ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
| 746 | - ->setParameter('user_id', $user->getUID()); |
|
| 747 | - |
|
| 748 | - try { |
|
| 749 | - $affectedRows = $query->execute(); |
|
| 750 | - } catch (DriverException $e) { |
|
| 751 | - $this->logger->logException($e, ['app' => 'core_comments']); |
|
| 752 | - return false; |
|
| 753 | - } |
|
| 754 | - return ($affectedRows > 0); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * sets the read marker for a given file to the specified date for the |
|
| 759 | - * provided user |
|
| 760 | - * |
|
| 761 | - * @param string $objectType |
|
| 762 | - * @param string $objectId |
|
| 763 | - * @param \DateTime $dateTime |
|
| 764 | - * @param IUser $user |
|
| 765 | - * @since 9.0.0 |
|
| 766 | - * @suppress SqlInjectionChecker |
|
| 767 | - */ |
|
| 768 | - public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) { |
|
| 769 | - $this->checkRoleParameters('Object', $objectType, $objectId); |
|
| 770 | - |
|
| 771 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 772 | - $values = [ |
|
| 773 | - 'user_id' => $qb->createNamedParameter($user->getUID()), |
|
| 774 | - 'marker_datetime' => $qb->createNamedParameter($dateTime, 'datetime'), |
|
| 775 | - 'object_type' => $qb->createNamedParameter($objectType), |
|
| 776 | - 'object_id' => $qb->createNamedParameter($objectId), |
|
| 777 | - ]; |
|
| 778 | - |
|
| 779 | - // Strategy: try to update, if this does not return affected rows, do an insert. |
|
| 780 | - $affectedRows = $qb |
|
| 781 | - ->update('comments_read_markers') |
|
| 782 | - ->set('user_id', $values['user_id']) |
|
| 783 | - ->set('marker_datetime', $values['marker_datetime']) |
|
| 784 | - ->set('object_type', $values['object_type']) |
|
| 785 | - ->set('object_id', $values['object_id']) |
|
| 786 | - ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
| 787 | - ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
| 788 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
| 789 | - ->setParameter('user_id', $user->getUID(), IQueryBuilder::PARAM_STR) |
|
| 790 | - ->setParameter('object_type', $objectType, IQueryBuilder::PARAM_STR) |
|
| 791 | - ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) |
|
| 792 | - ->execute(); |
|
| 793 | - |
|
| 794 | - if ($affectedRows > 0) { |
|
| 795 | - return; |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - $qb->insert('comments_read_markers') |
|
| 799 | - ->values($values) |
|
| 800 | - ->execute(); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * returns the read marker for a given file to the specified date for the |
|
| 805 | - * provided user. It returns null, when the marker is not present, i.e. |
|
| 806 | - * no comments were marked as read. |
|
| 807 | - * |
|
| 808 | - * @param string $objectType |
|
| 809 | - * @param string $objectId |
|
| 810 | - * @param IUser $user |
|
| 811 | - * @return \DateTime|null |
|
| 812 | - * @since 9.0.0 |
|
| 813 | - */ |
|
| 814 | - public function getReadMark($objectType, $objectId, IUser $user) { |
|
| 815 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 816 | - $resultStatement = $qb->select('marker_datetime') |
|
| 817 | - ->from('comments_read_markers') |
|
| 818 | - ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
| 819 | - ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
| 820 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
| 821 | - ->setParameter('user_id', $user->getUID(), IQueryBuilder::PARAM_STR) |
|
| 822 | - ->setParameter('object_type', $objectType, IQueryBuilder::PARAM_STR) |
|
| 823 | - ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) |
|
| 824 | - ->execute(); |
|
| 825 | - |
|
| 826 | - $data = $resultStatement->fetch(); |
|
| 827 | - $resultStatement->closeCursor(); |
|
| 828 | - if (!$data || is_null($data['marker_datetime'])) { |
|
| 829 | - return null; |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - return new \DateTime($data['marker_datetime']); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * deletes the read markers on the specified object |
|
| 837 | - * |
|
| 838 | - * @param string $objectType |
|
| 839 | - * @param string $objectId |
|
| 840 | - * @return bool |
|
| 841 | - * @since 9.0.0 |
|
| 842 | - */ |
|
| 843 | - public function deleteReadMarksOnObject($objectType, $objectId) { |
|
| 844 | - $this->checkRoleParameters('Object', $objectType, $objectId); |
|
| 845 | - |
|
| 846 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 847 | - $query = $qb->delete('comments_read_markers') |
|
| 848 | - ->where($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
| 849 | - ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
| 850 | - ->setParameter('object_type', $objectType) |
|
| 851 | - ->setParameter('object_id', $objectId); |
|
| 852 | - |
|
| 853 | - try { |
|
| 854 | - $affectedRows = $query->execute(); |
|
| 855 | - } catch (DriverException $e) { |
|
| 856 | - $this->logger->logException($e, ['app' => 'core_comments']); |
|
| 857 | - return false; |
|
| 858 | - } |
|
| 859 | - return ($affectedRows > 0); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * registers an Entity to the manager, so event notifications can be send |
|
| 864 | - * to consumers of the comments infrastructure |
|
| 865 | - * |
|
| 866 | - * @param \Closure $closure |
|
| 867 | - */ |
|
| 868 | - public function registerEventHandler(\Closure $closure) { |
|
| 869 | - $this->eventHandlerClosures[] = $closure; |
|
| 870 | - $this->eventHandlers = []; |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * registers a method that resolves an ID to a display name for a given type |
|
| 875 | - * |
|
| 876 | - * @param string $type |
|
| 877 | - * @param \Closure $closure |
|
| 878 | - * @throws \OutOfBoundsException |
|
| 879 | - * @since 11.0.0 |
|
| 880 | - * |
|
| 881 | - * Only one resolver shall be registered per type. Otherwise a |
|
| 882 | - * \OutOfBoundsException has to thrown. |
|
| 883 | - */ |
|
| 884 | - public function registerDisplayNameResolver($type, \Closure $closure) { |
|
| 885 | - if (!is_string($type)) { |
|
| 886 | - throw new \InvalidArgumentException('String expected.'); |
|
| 887 | - } |
|
| 888 | - if (isset($this->displayNameResolvers[$type])) { |
|
| 889 | - throw new \OutOfBoundsException('Displayname resolver for this type already registered'); |
|
| 890 | - } |
|
| 891 | - $this->displayNameResolvers[$type] = $closure; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /** |
|
| 895 | - * resolves a given ID of a given Type to a display name. |
|
| 896 | - * |
|
| 897 | - * @param string $type |
|
| 898 | - * @param string $id |
|
| 899 | - * @return string |
|
| 900 | - * @throws \OutOfBoundsException |
|
| 901 | - * @since 11.0.0 |
|
| 902 | - * |
|
| 903 | - * If a provided type was not registered, an \OutOfBoundsException shall |
|
| 904 | - * be thrown. It is upon the resolver discretion what to return of the |
|
| 905 | - * provided ID is unknown. It must be ensured that a string is returned. |
|
| 906 | - */ |
|
| 907 | - public function resolveDisplayName($type, $id) { |
|
| 908 | - if (!is_string($type)) { |
|
| 909 | - throw new \InvalidArgumentException('String expected.'); |
|
| 910 | - } |
|
| 911 | - if (!isset($this->displayNameResolvers[$type])) { |
|
| 912 | - throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
|
| 913 | - } |
|
| 914 | - return (string)$this->displayNameResolvers[$type]($id); |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * returns valid, registered entities |
|
| 919 | - * |
|
| 920 | - * @return \OCP\Comments\ICommentsEventHandler[] |
|
| 921 | - */ |
|
| 922 | - private function getEventHandlers() { |
|
| 923 | - if (!empty($this->eventHandlers)) { |
|
| 924 | - return $this->eventHandlers; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - $this->eventHandlers = []; |
|
| 928 | - foreach ($this->eventHandlerClosures as $name => $closure) { |
|
| 929 | - $entity = $closure(); |
|
| 930 | - if (!($entity instanceof ICommentsEventHandler)) { |
|
| 931 | - throw new \InvalidArgumentException('The given entity does not implement the ICommentsEntity interface'); |
|
| 932 | - } |
|
| 933 | - $this->eventHandlers[$name] = $entity; |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - return $this->eventHandlers; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * sends notifications to the registered entities |
|
| 941 | - * |
|
| 942 | - * @param $eventType |
|
| 943 | - * @param IComment $comment |
|
| 944 | - */ |
|
| 945 | - private function sendEvent($eventType, IComment $comment) { |
|
| 946 | - $entities = $this->getEventHandlers(); |
|
| 947 | - $event = new CommentsEvent($eventType, $comment); |
|
| 948 | - foreach ($entities as $entity) { |
|
| 949 | - $entity->handle($event); |
|
| 950 | - } |
|
| 951 | - } |
|
| 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->extractActor($tree, $actors); |
|
| 344 | + return $actors; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @param array $node |
|
| 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(array $node, array &$actors) { |
|
| 366 | + if(isset($node['replies'])) { |
|
| 367 | + foreach ($node['replies'] as $subNode) { |
|
| 368 | + $this->extractActor($subNode, $actors); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + if(isset($node['comment']) && $node['comment'] instanceof IComment) { |
|
| 372 | + /** @var IComment $comment */ |
|
| 373 | + $comment = $node['comment']; |
|
| 374 | + if(!isset($actors[$comment->getActorType()])) { |
|
| 375 | + $actors[$comment->getActorType()] = []; |
|
| 376 | + } |
|
| 377 | + if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
| 378 | + $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
| 379 | + } else { |
|
| 380 | + $actors[$comment->getActorType()][$comment->getActorId()] += 1; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * returns comments for a specific object (e.g. a file). |
|
| 387 | + * |
|
| 388 | + * The sort order is always newest to oldest. |
|
| 389 | + * |
|
| 390 | + * @param string $objectType the object type, e.g. 'files' |
|
| 391 | + * @param string $objectId the id of the object |
|
| 392 | + * @param int $limit optional, number of maximum comments to be returned. if |
|
| 393 | + * not specified, all comments are returned. |
|
| 394 | + * @param int $offset optional, starting point |
|
| 395 | + * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |
|
| 396 | + * that may be returned |
|
| 397 | + * @return IComment[] |
|
| 398 | + * @since 9.0.0 |
|
| 399 | + */ |
|
| 400 | + public function getForObject( |
|
| 401 | + $objectType, |
|
| 402 | + $objectId, |
|
| 403 | + $limit = 0, |
|
| 404 | + $offset = 0, |
|
| 405 | + \DateTime $notOlderThan = null |
|
| 406 | + ) { |
|
| 407 | + $comments = []; |
|
| 408 | + |
|
| 409 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 410 | + $query = $qb->select('*') |
|
| 411 | + ->from('comments') |
|
| 412 | + ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
| 413 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
| 414 | + ->orderBy('creation_timestamp', 'DESC') |
|
| 415 | + ->setParameter('type', $objectType) |
|
| 416 | + ->setParameter('id', $objectId); |
|
| 417 | + |
|
| 418 | + if ($limit > 0) { |
|
| 419 | + $query->setMaxResults($limit); |
|
| 420 | + } |
|
| 421 | + if ($offset > 0) { |
|
| 422 | + $query->setFirstResult($offset); |
|
| 423 | + } |
|
| 424 | + if (!is_null($notOlderThan)) { |
|
| 425 | + $query |
|
| 426 | + ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
|
| 427 | + ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + $resultStatement = $query->execute(); |
|
| 431 | + while ($data = $resultStatement->fetch()) { |
|
| 432 | + $comment = new Comment($this->normalizeDatabaseData($data)); |
|
| 433 | + $this->cache($comment); |
|
| 434 | + $comments[] = $comment; |
|
| 435 | + } |
|
| 436 | + $resultStatement->closeCursor(); |
|
| 437 | + |
|
| 438 | + return $comments; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @param $objectType string the object type, e.g. 'files' |
|
| 443 | + * @param $objectId string the id of the object |
|
| 444 | + * @param \DateTime $notOlderThan optional, timestamp of the oldest comments |
|
| 445 | + * that may be returned |
|
| 446 | + * @return Int |
|
| 447 | + * @since 9.0.0 |
|
| 448 | + */ |
|
| 449 | + public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) { |
|
| 450 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 451 | + $query = $qb->select($qb->createFunction('COUNT(`id`)')) |
|
| 452 | + ->from('comments') |
|
| 453 | + ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
| 454 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
| 455 | + ->setParameter('type', $objectType) |
|
| 456 | + ->setParameter('id', $objectId); |
|
| 457 | + |
|
| 458 | + if (!is_null($notOlderThan)) { |
|
| 459 | + $query |
|
| 460 | + ->andWhere($qb->expr()->gt('creation_timestamp', $qb->createParameter('notOlderThan'))) |
|
| 461 | + ->setParameter('notOlderThan', $notOlderThan, 'datetime'); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + $resultStatement = $query->execute(); |
|
| 465 | + $data = $resultStatement->fetch(\PDO::FETCH_NUM); |
|
| 466 | + $resultStatement->closeCursor(); |
|
| 467 | + return intval($data[0]); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Get the number of unread comments for all files in a folder |
|
| 472 | + * |
|
| 473 | + * @param int $folderId |
|
| 474 | + * @param IUser $user |
|
| 475 | + * @return array [$fileId => $unreadCount] |
|
| 476 | + */ |
|
| 477 | + public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) { |
|
| 478 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 479 | + $query = $qb->select('f.fileid') |
|
| 480 | + ->selectAlias( |
|
| 481 | + $qb->createFunction('COUNT(' . $qb->getColumnName('c.id') . ')'), |
|
| 482 | + 'num_ids' |
|
| 483 | + ) |
|
| 484 | + ->from('comments', 'c') |
|
| 485 | + ->innerJoin('c', 'filecache', 'f', $qb->expr()->andX( |
|
| 486 | + $qb->expr()->eq('c.object_type', $qb->createNamedParameter('files')), |
|
| 487 | + $qb->expr()->eq('f.fileid', $qb->expr()->castColumn('c.object_id', IQueryBuilder::PARAM_INT)) |
|
| 488 | + )) |
|
| 489 | + ->leftJoin('c', 'comments_read_markers', 'm', $qb->expr()->andX( |
|
| 490 | + $qb->expr()->eq('m.object_type', $qb->createNamedParameter('files')), |
|
| 491 | + $qb->expr()->eq('m.object_id', 'c.object_id'), |
|
| 492 | + $qb->expr()->eq('m.user_id', $qb->createNamedParameter($user->getUID())) |
|
| 493 | + )) |
|
| 494 | + ->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($folderId))) |
|
| 495 | + ->andWhere($qb->expr()->orX( |
|
| 496 | + $qb->expr()->gt('c.creation_timestamp', 'marker_datetime'), |
|
| 497 | + $qb->expr()->isNull('marker_datetime') |
|
| 498 | + )) |
|
| 499 | + ->groupBy('f.fileid'); |
|
| 500 | + |
|
| 501 | + $resultStatement = $query->execute(); |
|
| 502 | + |
|
| 503 | + $results = []; |
|
| 504 | + while ($row = $resultStatement->fetch()) { |
|
| 505 | + $results[$row['fileid']] = (int) $row['num_ids']; |
|
| 506 | + } |
|
| 507 | + $resultStatement->closeCursor(); |
|
| 508 | + return $results; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * creates a new comment and returns it. At this point of time, it is not |
|
| 513 | + * saved in the used data storage. Use save() after setting other fields |
|
| 514 | + * of the comment (e.g. message or verb). |
|
| 515 | + * |
|
| 516 | + * @param string $actorType the actor type (e.g. 'users') |
|
| 517 | + * @param string $actorId a user id |
|
| 518 | + * @param string $objectType the object type the comment is attached to |
|
| 519 | + * @param string $objectId the object id the comment is attached to |
|
| 520 | + * @return IComment |
|
| 521 | + * @since 9.0.0 |
|
| 522 | + */ |
|
| 523 | + public function create($actorType, $actorId, $objectType, $objectId) { |
|
| 524 | + $comment = new Comment(); |
|
| 525 | + $comment |
|
| 526 | + ->setActor($actorType, $actorId) |
|
| 527 | + ->setObject($objectType, $objectId); |
|
| 528 | + return $comment; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * permanently deletes the comment specified by the ID |
|
| 533 | + * |
|
| 534 | + * When the comment has child comments, their parent ID will be changed to |
|
| 535 | + * the parent ID of the item that is to be deleted. |
|
| 536 | + * |
|
| 537 | + * @param string $id |
|
| 538 | + * @return bool |
|
| 539 | + * @throws \InvalidArgumentException |
|
| 540 | + * @since 9.0.0 |
|
| 541 | + */ |
|
| 542 | + public function delete($id) { |
|
| 543 | + if (!is_string($id)) { |
|
| 544 | + throw new \InvalidArgumentException('Parameter must be string'); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + try { |
|
| 548 | + $comment = $this->get($id); |
|
| 549 | + } catch (\Exception $e) { |
|
| 550 | + // Ignore exceptions, we just don't fire a hook then |
|
| 551 | + $comment = null; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 555 | + $query = $qb->delete('comments') |
|
| 556 | + ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
| 557 | + ->setParameter('id', $id); |
|
| 558 | + |
|
| 559 | + try { |
|
| 560 | + $affectedRows = $query->execute(); |
|
| 561 | + $this->uncache($id); |
|
| 562 | + } catch (DriverException $e) { |
|
| 563 | + $this->logger->logException($e, ['app' => 'core_comments']); |
|
| 564 | + return false; |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + if ($affectedRows > 0 && $comment instanceof IComment) { |
|
| 568 | + $this->sendEvent(CommentsEvent::EVENT_DELETE, $comment); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + return ($affectedRows > 0); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * saves the comment permanently |
|
| 576 | + * |
|
| 577 | + * if the supplied comment has an empty ID, a new entry comment will be |
|
| 578 | + * saved and the instance updated with the new ID. |
|
| 579 | + * |
|
| 580 | + * Otherwise, an existing comment will be updated. |
|
| 581 | + * |
|
| 582 | + * Throws NotFoundException when a comment that is to be updated does not |
|
| 583 | + * exist anymore at this point of time. |
|
| 584 | + * |
|
| 585 | + * @param IComment $comment |
|
| 586 | + * @return bool |
|
| 587 | + * @throws NotFoundException |
|
| 588 | + * @since 9.0.0 |
|
| 589 | + */ |
|
| 590 | + public function save(IComment $comment) { |
|
| 591 | + if ($this->prepareCommentForDatabaseWrite($comment)->getId() === '') { |
|
| 592 | + $result = $this->insert($comment); |
|
| 593 | + } else { |
|
| 594 | + $result = $this->update($comment); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + if ($result && !!$comment->getParentId()) { |
|
| 598 | + $this->updateChildrenInformation( |
|
| 599 | + $comment->getParentId(), |
|
| 600 | + $comment->getCreationDateTime() |
|
| 601 | + ); |
|
| 602 | + $this->cache($comment); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + return $result; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * inserts the provided comment in the database |
|
| 610 | + * |
|
| 611 | + * @param IComment $comment |
|
| 612 | + * @return bool |
|
| 613 | + */ |
|
| 614 | + protected function insert(IComment &$comment) { |
|
| 615 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 616 | + $affectedRows = $qb |
|
| 617 | + ->insert('comments') |
|
| 618 | + ->values([ |
|
| 619 | + 'parent_id' => $qb->createNamedParameter($comment->getParentId()), |
|
| 620 | + 'topmost_parent_id' => $qb->createNamedParameter($comment->getTopmostParentId()), |
|
| 621 | + 'children_count' => $qb->createNamedParameter($comment->getChildrenCount()), |
|
| 622 | + 'actor_type' => $qb->createNamedParameter($comment->getActorType()), |
|
| 623 | + 'actor_id' => $qb->createNamedParameter($comment->getActorId()), |
|
| 624 | + 'message' => $qb->createNamedParameter($comment->getMessage()), |
|
| 625 | + 'verb' => $qb->createNamedParameter($comment->getVerb()), |
|
| 626 | + 'creation_timestamp' => $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime'), |
|
| 627 | + 'latest_child_timestamp' => $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'), |
|
| 628 | + 'object_type' => $qb->createNamedParameter($comment->getObjectType()), |
|
| 629 | + 'object_id' => $qb->createNamedParameter($comment->getObjectId()), |
|
| 630 | + ]) |
|
| 631 | + ->execute(); |
|
| 632 | + |
|
| 633 | + if ($affectedRows > 0) { |
|
| 634 | + $comment->setId(strval($qb->getLastInsertId())); |
|
| 635 | + $this->sendEvent(CommentsEvent::EVENT_ADD, $comment); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + return $affectedRows > 0; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * updates a Comment data row |
|
| 643 | + * |
|
| 644 | + * @param IComment $comment |
|
| 645 | + * @return bool |
|
| 646 | + * @throws NotFoundException |
|
| 647 | + */ |
|
| 648 | + protected function update(IComment $comment) { |
|
| 649 | + // for properly working preUpdate Events we need the old comments as is |
|
| 650 | + // in the DB and overcome caching. Also avoid that outdated information stays. |
|
| 651 | + $this->uncache($comment->getId()); |
|
| 652 | + $this->sendEvent(CommentsEvent::EVENT_PRE_UPDATE, $this->get($comment->getId())); |
|
| 653 | + $this->uncache($comment->getId()); |
|
| 654 | + |
|
| 655 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 656 | + $affectedRows = $qb |
|
| 657 | + ->update('comments') |
|
| 658 | + ->set('parent_id', $qb->createNamedParameter($comment->getParentId())) |
|
| 659 | + ->set('topmost_parent_id', $qb->createNamedParameter($comment->getTopmostParentId())) |
|
| 660 | + ->set('children_count', $qb->createNamedParameter($comment->getChildrenCount())) |
|
| 661 | + ->set('actor_type', $qb->createNamedParameter($comment->getActorType())) |
|
| 662 | + ->set('actor_id', $qb->createNamedParameter($comment->getActorId())) |
|
| 663 | + ->set('message', $qb->createNamedParameter($comment->getMessage())) |
|
| 664 | + ->set('verb', $qb->createNamedParameter($comment->getVerb())) |
|
| 665 | + ->set('creation_timestamp', $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime')) |
|
| 666 | + ->set('latest_child_timestamp', $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime')) |
|
| 667 | + ->set('object_type', $qb->createNamedParameter($comment->getObjectType())) |
|
| 668 | + ->set('object_id', $qb->createNamedParameter($comment->getObjectId())) |
|
| 669 | + ->where($qb->expr()->eq('id', $qb->createParameter('id'))) |
|
| 670 | + ->setParameter('id', $comment->getId()) |
|
| 671 | + ->execute(); |
|
| 672 | + |
|
| 673 | + if ($affectedRows === 0) { |
|
| 674 | + throw new NotFoundException('Comment to update does ceased to exist'); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + $this->sendEvent(CommentsEvent::EVENT_UPDATE, $comment); |
|
| 678 | + |
|
| 679 | + return $affectedRows > 0; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * removes references to specific actor (e.g. on user delete) of a comment. |
|
| 684 | + * The comment itself must not get lost/deleted. |
|
| 685 | + * |
|
| 686 | + * @param string $actorType the actor type (e.g. 'users') |
|
| 687 | + * @param string $actorId a user id |
|
| 688 | + * @return boolean |
|
| 689 | + * @since 9.0.0 |
|
| 690 | + */ |
|
| 691 | + public function deleteReferencesOfActor($actorType, $actorId) { |
|
| 692 | + $this->checkRoleParameters('Actor', $actorType, $actorId); |
|
| 693 | + |
|
| 694 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 695 | + $affectedRows = $qb |
|
| 696 | + ->update('comments') |
|
| 697 | + ->set('actor_type', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
| 698 | + ->set('actor_id', $qb->createNamedParameter(ICommentsManager::DELETED_USER)) |
|
| 699 | + ->where($qb->expr()->eq('actor_type', $qb->createParameter('type'))) |
|
| 700 | + ->andWhere($qb->expr()->eq('actor_id', $qb->createParameter('id'))) |
|
| 701 | + ->setParameter('type', $actorType) |
|
| 702 | + ->setParameter('id', $actorId) |
|
| 703 | + ->execute(); |
|
| 704 | + |
|
| 705 | + $this->commentsCache = []; |
|
| 706 | + |
|
| 707 | + return is_int($affectedRows); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * deletes all comments made of a specific object (e.g. on file delete) |
|
| 712 | + * |
|
| 713 | + * @param string $objectType the object type (e.g. 'files') |
|
| 714 | + * @param string $objectId e.g. the file id |
|
| 715 | + * @return boolean |
|
| 716 | + * @since 9.0.0 |
|
| 717 | + */ |
|
| 718 | + public function deleteCommentsAtObject($objectType, $objectId) { |
|
| 719 | + $this->checkRoleParameters('Object', $objectType, $objectId); |
|
| 720 | + |
|
| 721 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 722 | + $affectedRows = $qb |
|
| 723 | + ->delete('comments') |
|
| 724 | + ->where($qb->expr()->eq('object_type', $qb->createParameter('type'))) |
|
| 725 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('id'))) |
|
| 726 | + ->setParameter('type', $objectType) |
|
| 727 | + ->setParameter('id', $objectId) |
|
| 728 | + ->execute(); |
|
| 729 | + |
|
| 730 | + $this->commentsCache = []; |
|
| 731 | + |
|
| 732 | + return is_int($affectedRows); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * deletes the read markers for the specified user |
|
| 737 | + * |
|
| 738 | + * @param \OCP\IUser $user |
|
| 739 | + * @return bool |
|
| 740 | + * @since 9.0.0 |
|
| 741 | + */ |
|
| 742 | + public function deleteReadMarksFromUser(IUser $user) { |
|
| 743 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 744 | + $query = $qb->delete('comments_read_markers') |
|
| 745 | + ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
| 746 | + ->setParameter('user_id', $user->getUID()); |
|
| 747 | + |
|
| 748 | + try { |
|
| 749 | + $affectedRows = $query->execute(); |
|
| 750 | + } catch (DriverException $e) { |
|
| 751 | + $this->logger->logException($e, ['app' => 'core_comments']); |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | + return ($affectedRows > 0); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * sets the read marker for a given file to the specified date for the |
|
| 759 | + * provided user |
|
| 760 | + * |
|
| 761 | + * @param string $objectType |
|
| 762 | + * @param string $objectId |
|
| 763 | + * @param \DateTime $dateTime |
|
| 764 | + * @param IUser $user |
|
| 765 | + * @since 9.0.0 |
|
| 766 | + * @suppress SqlInjectionChecker |
|
| 767 | + */ |
|
| 768 | + public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) { |
|
| 769 | + $this->checkRoleParameters('Object', $objectType, $objectId); |
|
| 770 | + |
|
| 771 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 772 | + $values = [ |
|
| 773 | + 'user_id' => $qb->createNamedParameter($user->getUID()), |
|
| 774 | + 'marker_datetime' => $qb->createNamedParameter($dateTime, 'datetime'), |
|
| 775 | + 'object_type' => $qb->createNamedParameter($objectType), |
|
| 776 | + 'object_id' => $qb->createNamedParameter($objectId), |
|
| 777 | + ]; |
|
| 778 | + |
|
| 779 | + // Strategy: try to update, if this does not return affected rows, do an insert. |
|
| 780 | + $affectedRows = $qb |
|
| 781 | + ->update('comments_read_markers') |
|
| 782 | + ->set('user_id', $values['user_id']) |
|
| 783 | + ->set('marker_datetime', $values['marker_datetime']) |
|
| 784 | + ->set('object_type', $values['object_type']) |
|
| 785 | + ->set('object_id', $values['object_id']) |
|
| 786 | + ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
| 787 | + ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
| 788 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
| 789 | + ->setParameter('user_id', $user->getUID(), IQueryBuilder::PARAM_STR) |
|
| 790 | + ->setParameter('object_type', $objectType, IQueryBuilder::PARAM_STR) |
|
| 791 | + ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) |
|
| 792 | + ->execute(); |
|
| 793 | + |
|
| 794 | + if ($affectedRows > 0) { |
|
| 795 | + return; |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + $qb->insert('comments_read_markers') |
|
| 799 | + ->values($values) |
|
| 800 | + ->execute(); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * returns the read marker for a given file to the specified date for the |
|
| 805 | + * provided user. It returns null, when the marker is not present, i.e. |
|
| 806 | + * no comments were marked as read. |
|
| 807 | + * |
|
| 808 | + * @param string $objectType |
|
| 809 | + * @param string $objectId |
|
| 810 | + * @param IUser $user |
|
| 811 | + * @return \DateTime|null |
|
| 812 | + * @since 9.0.0 |
|
| 813 | + */ |
|
| 814 | + public function getReadMark($objectType, $objectId, IUser $user) { |
|
| 815 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 816 | + $resultStatement = $qb->select('marker_datetime') |
|
| 817 | + ->from('comments_read_markers') |
|
| 818 | + ->where($qb->expr()->eq('user_id', $qb->createParameter('user_id'))) |
|
| 819 | + ->andWhere($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
| 820 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
| 821 | + ->setParameter('user_id', $user->getUID(), IQueryBuilder::PARAM_STR) |
|
| 822 | + ->setParameter('object_type', $objectType, IQueryBuilder::PARAM_STR) |
|
| 823 | + ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) |
|
| 824 | + ->execute(); |
|
| 825 | + |
|
| 826 | + $data = $resultStatement->fetch(); |
|
| 827 | + $resultStatement->closeCursor(); |
|
| 828 | + if (!$data || is_null($data['marker_datetime'])) { |
|
| 829 | + return null; |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + return new \DateTime($data['marker_datetime']); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * deletes the read markers on the specified object |
|
| 837 | + * |
|
| 838 | + * @param string $objectType |
|
| 839 | + * @param string $objectId |
|
| 840 | + * @return bool |
|
| 841 | + * @since 9.0.0 |
|
| 842 | + */ |
|
| 843 | + public function deleteReadMarksOnObject($objectType, $objectId) { |
|
| 844 | + $this->checkRoleParameters('Object', $objectType, $objectId); |
|
| 845 | + |
|
| 846 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 847 | + $query = $qb->delete('comments_read_markers') |
|
| 848 | + ->where($qb->expr()->eq('object_type', $qb->createParameter('object_type'))) |
|
| 849 | + ->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id'))) |
|
| 850 | + ->setParameter('object_type', $objectType) |
|
| 851 | + ->setParameter('object_id', $objectId); |
|
| 852 | + |
|
| 853 | + try { |
|
| 854 | + $affectedRows = $query->execute(); |
|
| 855 | + } catch (DriverException $e) { |
|
| 856 | + $this->logger->logException($e, ['app' => 'core_comments']); |
|
| 857 | + return false; |
|
| 858 | + } |
|
| 859 | + return ($affectedRows > 0); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * registers an Entity to the manager, so event notifications can be send |
|
| 864 | + * to consumers of the comments infrastructure |
|
| 865 | + * |
|
| 866 | + * @param \Closure $closure |
|
| 867 | + */ |
|
| 868 | + public function registerEventHandler(\Closure $closure) { |
|
| 869 | + $this->eventHandlerClosures[] = $closure; |
|
| 870 | + $this->eventHandlers = []; |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * registers a method that resolves an ID to a display name for a given type |
|
| 875 | + * |
|
| 876 | + * @param string $type |
|
| 877 | + * @param \Closure $closure |
|
| 878 | + * @throws \OutOfBoundsException |
|
| 879 | + * @since 11.0.0 |
|
| 880 | + * |
|
| 881 | + * Only one resolver shall be registered per type. Otherwise a |
|
| 882 | + * \OutOfBoundsException has to thrown. |
|
| 883 | + */ |
|
| 884 | + public function registerDisplayNameResolver($type, \Closure $closure) { |
|
| 885 | + if (!is_string($type)) { |
|
| 886 | + throw new \InvalidArgumentException('String expected.'); |
|
| 887 | + } |
|
| 888 | + if (isset($this->displayNameResolvers[$type])) { |
|
| 889 | + throw new \OutOfBoundsException('Displayname resolver for this type already registered'); |
|
| 890 | + } |
|
| 891 | + $this->displayNameResolvers[$type] = $closure; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /** |
|
| 895 | + * resolves a given ID of a given Type to a display name. |
|
| 896 | + * |
|
| 897 | + * @param string $type |
|
| 898 | + * @param string $id |
|
| 899 | + * @return string |
|
| 900 | + * @throws \OutOfBoundsException |
|
| 901 | + * @since 11.0.0 |
|
| 902 | + * |
|
| 903 | + * If a provided type was not registered, an \OutOfBoundsException shall |
|
| 904 | + * be thrown. It is upon the resolver discretion what to return of the |
|
| 905 | + * provided ID is unknown. It must be ensured that a string is returned. |
|
| 906 | + */ |
|
| 907 | + public function resolveDisplayName($type, $id) { |
|
| 908 | + if (!is_string($type)) { |
|
| 909 | + throw new \InvalidArgumentException('String expected.'); |
|
| 910 | + } |
|
| 911 | + if (!isset($this->displayNameResolvers[$type])) { |
|
| 912 | + throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
|
| 913 | + } |
|
| 914 | + return (string)$this->displayNameResolvers[$type]($id); |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * returns valid, registered entities |
|
| 919 | + * |
|
| 920 | + * @return \OCP\Comments\ICommentsEventHandler[] |
|
| 921 | + */ |
|
| 922 | + private function getEventHandlers() { |
|
| 923 | + if (!empty($this->eventHandlers)) { |
|
| 924 | + return $this->eventHandlers; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + $this->eventHandlers = []; |
|
| 928 | + foreach ($this->eventHandlerClosures as $name => $closure) { |
|
| 929 | + $entity = $closure(); |
|
| 930 | + if (!($entity instanceof ICommentsEventHandler)) { |
|
| 931 | + throw new \InvalidArgumentException('The given entity does not implement the ICommentsEntity interface'); |
|
| 932 | + } |
|
| 933 | + $this->eventHandlers[$name] = $entity; |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + return $this->eventHandlers; |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * sends notifications to the registered entities |
|
| 941 | + * |
|
| 942 | + * @param $eventType |
|
| 943 | + * @param IComment $comment |
|
| 944 | + */ |
|
| 945 | + private function sendEvent($eventType, IComment $comment) { |
|
| 946 | + $entities = $this->getEventHandlers(); |
|
| 947 | + $event = new CommentsEvent($eventType, $comment); |
|
| 948 | + foreach ($entities as $entity) { |
|
| 949 | + $entity->handle($event); |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | 952 | } |
@@ -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,18 +363,18 @@ discard block |
||
| 363 | 363 | * |
| 364 | 364 | */ |
| 365 | 365 | protected function extractActor(array $node, array &$actors) { |
| 366 | - if(isset($node['replies'])) { |
|
| 366 | + if (isset($node['replies'])) { |
|
| 367 | 367 | foreach ($node['replies'] as $subNode) { |
| 368 | 368 | $this->extractActor($subNode, $actors); |
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | - if(isset($node['comment']) && $node['comment'] instanceof IComment) { |
|
| 371 | + if (isset($node['comment']) && $node['comment'] instanceof IComment) { |
|
| 372 | 372 | /** @var IComment $comment */ |
| 373 | 373 | $comment = $node['comment']; |
| 374 | - if(!isset($actors[$comment->getActorType()])) { |
|
| 374 | + if (!isset($actors[$comment->getActorType()])) { |
|
| 375 | 375 | $actors[$comment->getActorType()] = []; |
| 376 | 376 | } |
| 377 | - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
| 377 | + if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
| 378 | 378 | $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
| 379 | 379 | } else { |
| 380 | 380 | $actors[$comment->getActorType()][$comment->getActorId()] += 1; |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | $qb = $this->dbConn->getQueryBuilder(); |
| 479 | 479 | $query = $qb->select('f.fileid') |
| 480 | 480 | ->selectAlias( |
| 481 | - $qb->createFunction('COUNT(' . $qb->getColumnName('c.id') . ')'), |
|
| 481 | + $qb->createFunction('COUNT('.$qb->getColumnName('c.id').')'), |
|
| 482 | 482 | 'num_ids' |
| 483 | 483 | ) |
| 484 | 484 | ->from('comments', 'c') |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @param IComment $comment |
| 612 | 612 | * @return bool |
| 613 | 613 | */ |
| 614 | - protected function insert(IComment &$comment) { |
|
| 614 | + protected function insert(IComment & $comment) { |
|
| 615 | 615 | $qb = $this->dbConn->getQueryBuilder(); |
| 616 | 616 | $affectedRows = $qb |
| 617 | 617 | ->insert('comments') |
@@ -911,7 +911,7 @@ discard block |
||
| 911 | 911 | if (!isset($this->displayNameResolvers[$type])) { |
| 912 | 912 | throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
| 913 | 913 | } |
| 914 | - return (string)$this->displayNameResolvers[$type]($id); |
|
| 914 | + return (string) $this->displayNameResolvers[$type]($id); |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | /** |
@@ -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; |