@@ -33,68 +33,68 @@ |
||
| 33 | 33 | use OCA\Files\Controller\ViewController; |
| 34 | 34 | |
| 35 | 35 | class Application extends App { |
| 36 | - public function __construct(array $urlParams=array()) { |
|
| 37 | - parent::__construct('files', $urlParams); |
|
| 38 | - $container = $this->getContainer(); |
|
| 39 | - $server = $container->getServer(); |
|
| 36 | + public function __construct(array $urlParams=array()) { |
|
| 37 | + parent::__construct('files', $urlParams); |
|
| 38 | + $container = $this->getContainer(); |
|
| 39 | + $server = $container->getServer(); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Controllers |
|
| 43 | - */ |
|
| 44 | - $container->registerService('APIController', function (IContainer $c) use ($server) { |
|
| 45 | - return new ApiController( |
|
| 46 | - $c->query('AppName'), |
|
| 47 | - $c->query('Request'), |
|
| 48 | - $server->getUserSession(), |
|
| 49 | - $c->query('TagService'), |
|
| 50 | - $server->getPreviewManager(), |
|
| 51 | - $server->getShareManager(), |
|
| 52 | - $server->getConfig(), |
|
| 53 | - $server->getUserFolder() |
|
| 54 | - ); |
|
| 55 | - }); |
|
| 41 | + /** |
|
| 42 | + * Controllers |
|
| 43 | + */ |
|
| 44 | + $container->registerService('APIController', function (IContainer $c) use ($server) { |
|
| 45 | + return new ApiController( |
|
| 46 | + $c->query('AppName'), |
|
| 47 | + $c->query('Request'), |
|
| 48 | + $server->getUserSession(), |
|
| 49 | + $c->query('TagService'), |
|
| 50 | + $server->getPreviewManager(), |
|
| 51 | + $server->getShareManager(), |
|
| 52 | + $server->getConfig(), |
|
| 53 | + $server->getUserFolder() |
|
| 54 | + ); |
|
| 55 | + }); |
|
| 56 | 56 | |
| 57 | - $container->registerService('ViewController', function (IContainer $c) use ($server) { |
|
| 58 | - return new ViewController( |
|
| 59 | - $c->query('AppName'), |
|
| 60 | - $c->query('Request'), |
|
| 61 | - $server->getURLGenerator(), |
|
| 62 | - $c->query('L10N'), |
|
| 63 | - $server->getConfig(), |
|
| 64 | - $server->getEventDispatcher(), |
|
| 65 | - $server->getUserSession(), |
|
| 66 | - $server->getAppManager(), |
|
| 67 | - $server->getRootFolder() |
|
| 68 | - ); |
|
| 69 | - }); |
|
| 57 | + $container->registerService('ViewController', function (IContainer $c) use ($server) { |
|
| 58 | + return new ViewController( |
|
| 59 | + $c->query('AppName'), |
|
| 60 | + $c->query('Request'), |
|
| 61 | + $server->getURLGenerator(), |
|
| 62 | + $c->query('L10N'), |
|
| 63 | + $server->getConfig(), |
|
| 64 | + $server->getEventDispatcher(), |
|
| 65 | + $server->getUserSession(), |
|
| 66 | + $server->getAppManager(), |
|
| 67 | + $server->getRootFolder() |
|
| 68 | + ); |
|
| 69 | + }); |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Core |
|
| 73 | - */ |
|
| 74 | - $container->registerService('L10N', function(IContainer $c) { |
|
| 75 | - return $c->query('ServerContainer')->getL10N($c->query('AppName')); |
|
| 76 | - }); |
|
| 71 | + /** |
|
| 72 | + * Core |
|
| 73 | + */ |
|
| 74 | + $container->registerService('L10N', function(IContainer $c) { |
|
| 75 | + return $c->query('ServerContainer')->getL10N($c->query('AppName')); |
|
| 76 | + }); |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Services |
|
| 80 | - */ |
|
| 81 | - $container->registerService('Tagger', function(IContainer $c) { |
|
| 82 | - return $c->query('ServerContainer')->getTagManager()->load('files'); |
|
| 83 | - }); |
|
| 84 | - $container->registerService('TagService', function(IContainer $c) use ($server) { |
|
| 85 | - $homeFolder = $c->query('ServerContainer')->getUserFolder(); |
|
| 86 | - return new TagService( |
|
| 87 | - $c->query('ServerContainer')->getUserSession(), |
|
| 88 | - $c->query('ServerContainer')->getActivityManager(), |
|
| 89 | - $c->query('Tagger'), |
|
| 90 | - $homeFolder, |
|
| 91 | - $server->getEventDispatcher() |
|
| 92 | - ); |
|
| 93 | - }); |
|
| 78 | + /** |
|
| 79 | + * Services |
|
| 80 | + */ |
|
| 81 | + $container->registerService('Tagger', function(IContainer $c) { |
|
| 82 | + return $c->query('ServerContainer')->getTagManager()->load('files'); |
|
| 83 | + }); |
|
| 84 | + $container->registerService('TagService', function(IContainer $c) use ($server) { |
|
| 85 | + $homeFolder = $c->query('ServerContainer')->getUserFolder(); |
|
| 86 | + return new TagService( |
|
| 87 | + $c->query('ServerContainer')->getUserSession(), |
|
| 88 | + $c->query('ServerContainer')->getActivityManager(), |
|
| 89 | + $c->query('Tagger'), |
|
| 90 | + $homeFolder, |
|
| 91 | + $server->getEventDispatcher() |
|
| 92 | + ); |
|
| 93 | + }); |
|
| 94 | 94 | |
| 95 | - /* |
|
| 95 | + /* |
|
| 96 | 96 | * Register capabilities |
| 97 | 97 | */ |
| 98 | - $container->registerCapability('OCA\Files\Capabilities'); |
|
| 99 | - } |
|
| 98 | + $container->registerCapability('OCA\Files\Capabilities'); |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | use OCA\Files\Controller\ViewController; |
| 34 | 34 | |
| 35 | 35 | class Application extends App { |
| 36 | - public function __construct(array $urlParams=array()) { |
|
| 36 | + public function __construct(array $urlParams = array()) { |
|
| 37 | 37 | parent::__construct('files', $urlParams); |
| 38 | 38 | $container = $this->getContainer(); |
| 39 | 39 | $server = $container->getServer(); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * Controllers |
| 43 | 43 | */ |
| 44 | - $container->registerService('APIController', function (IContainer $c) use ($server) { |
|
| 44 | + $container->registerService('APIController', function(IContainer $c) use ($server) { |
|
| 45 | 45 | return new ApiController( |
| 46 | 46 | $c->query('AppName'), |
| 47 | 47 | $c->query('Request'), |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | ); |
| 55 | 55 | }); |
| 56 | 56 | |
| 57 | - $container->registerService('ViewController', function (IContainer $c) use ($server) { |
|
| 57 | + $container->registerService('ViewController', function(IContainer $c) use ($server) { |
|
| 58 | 58 | return new ViewController( |
| 59 | 59 | $c->query('AppName'), |
| 60 | 60 | $c->query('Request'), |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | /** |
| 79 | 79 | * Services |
| 80 | 80 | */ |
| 81 | - $container->registerService('Tagger', function(IContainer $c) { |
|
| 81 | + $container->registerService('Tagger', function(IContainer $c) { |
|
| 82 | 82 | return $c->query('ServerContainer')->getTagManager()->load('files'); |
| 83 | 83 | }); |
| 84 | 84 | $container->registerService('TagService', function(IContainer $c) use ($server) { |
@@ -39,111 +39,111 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class TagService { |
| 41 | 41 | |
| 42 | - /** @var IUserSession */ |
|
| 43 | - private $userSession; |
|
| 44 | - /** @var IManager */ |
|
| 45 | - private $activityManager; |
|
| 46 | - /** @var ITags */ |
|
| 47 | - private $tagger; |
|
| 48 | - /** @var Folder */ |
|
| 49 | - private $homeFolder; |
|
| 50 | - /** @var EventDispatcherInterface */ |
|
| 51 | - private $dispatcher; |
|
| 42 | + /** @var IUserSession */ |
|
| 43 | + private $userSession; |
|
| 44 | + /** @var IManager */ |
|
| 45 | + private $activityManager; |
|
| 46 | + /** @var ITags */ |
|
| 47 | + private $tagger; |
|
| 48 | + /** @var Folder */ |
|
| 49 | + private $homeFolder; |
|
| 50 | + /** @var EventDispatcherInterface */ |
|
| 51 | + private $dispatcher; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param IUserSession $userSession |
|
| 55 | - * @param IManager $activityManager |
|
| 56 | - * @param ITags $tagger |
|
| 57 | - * @param Folder $homeFolder |
|
| 58 | - * @param EventDispatcherInterface $dispatcher |
|
| 59 | - */ |
|
| 60 | - public function __construct( |
|
| 61 | - IUserSession $userSession, |
|
| 62 | - IManager $activityManager, |
|
| 63 | - ITags $tagger, |
|
| 64 | - Folder $homeFolder, |
|
| 65 | - EventDispatcherInterface $dispatcher |
|
| 66 | - ) { |
|
| 67 | - $this->userSession = $userSession; |
|
| 68 | - $this->activityManager = $activityManager; |
|
| 69 | - $this->tagger = $tagger; |
|
| 70 | - $this->homeFolder = $homeFolder; |
|
| 71 | - $this->dispatcher = $dispatcher; |
|
| 72 | - } |
|
| 53 | + /** |
|
| 54 | + * @param IUserSession $userSession |
|
| 55 | + * @param IManager $activityManager |
|
| 56 | + * @param ITags $tagger |
|
| 57 | + * @param Folder $homeFolder |
|
| 58 | + * @param EventDispatcherInterface $dispatcher |
|
| 59 | + */ |
|
| 60 | + public function __construct( |
|
| 61 | + IUserSession $userSession, |
|
| 62 | + IManager $activityManager, |
|
| 63 | + ITags $tagger, |
|
| 64 | + Folder $homeFolder, |
|
| 65 | + EventDispatcherInterface $dispatcher |
|
| 66 | + ) { |
|
| 67 | + $this->userSession = $userSession; |
|
| 68 | + $this->activityManager = $activityManager; |
|
| 69 | + $this->tagger = $tagger; |
|
| 70 | + $this->homeFolder = $homeFolder; |
|
| 71 | + $this->dispatcher = $dispatcher; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Updates the tags of the specified file path. |
|
| 76 | - * The passed tags are absolute, which means they will |
|
| 77 | - * replace the actual tag selection. |
|
| 78 | - * |
|
| 79 | - * @param string $path path |
|
| 80 | - * @param array $tags array of tags |
|
| 81 | - * @return array list of tags |
|
| 82 | - * @throws \OCP\Files\NotFoundException if the file does not exist |
|
| 83 | - */ |
|
| 84 | - public function updateFileTags($path, $tags) { |
|
| 85 | - $fileId = $this->homeFolder->get($path)->getId(); |
|
| 74 | + /** |
|
| 75 | + * Updates the tags of the specified file path. |
|
| 76 | + * The passed tags are absolute, which means they will |
|
| 77 | + * replace the actual tag selection. |
|
| 78 | + * |
|
| 79 | + * @param string $path path |
|
| 80 | + * @param array $tags array of tags |
|
| 81 | + * @return array list of tags |
|
| 82 | + * @throws \OCP\Files\NotFoundException if the file does not exist |
|
| 83 | + */ |
|
| 84 | + public function updateFileTags($path, $tags) { |
|
| 85 | + $fileId = $this->homeFolder->get($path)->getId(); |
|
| 86 | 86 | |
| 87 | - $currentTags = $this->tagger->getTagsForObjects(array($fileId)); |
|
| 87 | + $currentTags = $this->tagger->getTagsForObjects(array($fileId)); |
|
| 88 | 88 | |
| 89 | - if (!empty($currentTags)) { |
|
| 90 | - $currentTags = current($currentTags); |
|
| 91 | - } |
|
| 89 | + if (!empty($currentTags)) { |
|
| 90 | + $currentTags = current($currentTags); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $newTags = array_diff($tags, $currentTags); |
|
| 94 | - foreach ($newTags as $tag) { |
|
| 95 | - if ($tag === Tags::TAG_FAVORITE) { |
|
| 96 | - $this->addActivity(true, $fileId, $path); |
|
| 97 | - } |
|
| 98 | - $this->tagger->tagAs($fileId, $tag); |
|
| 99 | - } |
|
| 100 | - $deletedTags = array_diff($currentTags, $tags); |
|
| 101 | - foreach ($deletedTags as $tag) { |
|
| 102 | - if ($tag === Tags::TAG_FAVORITE) { |
|
| 103 | - $this->addActivity(false, $fileId, $path); |
|
| 104 | - } |
|
| 105 | - $this->tagger->unTag($fileId, $tag); |
|
| 106 | - } |
|
| 93 | + $newTags = array_diff($tags, $currentTags); |
|
| 94 | + foreach ($newTags as $tag) { |
|
| 95 | + if ($tag === Tags::TAG_FAVORITE) { |
|
| 96 | + $this->addActivity(true, $fileId, $path); |
|
| 97 | + } |
|
| 98 | + $this->tagger->tagAs($fileId, $tag); |
|
| 99 | + } |
|
| 100 | + $deletedTags = array_diff($currentTags, $tags); |
|
| 101 | + foreach ($deletedTags as $tag) { |
|
| 102 | + if ($tag === Tags::TAG_FAVORITE) { |
|
| 103 | + $this->addActivity(false, $fileId, $path); |
|
| 104 | + } |
|
| 105 | + $this->tagger->unTag($fileId, $tag); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - // TODO: re-read from tagger to make sure the |
|
| 109 | - // list is up to date, in case of concurrent changes ? |
|
| 110 | - return $tags; |
|
| 111 | - } |
|
| 108 | + // TODO: re-read from tagger to make sure the |
|
| 109 | + // list is up to date, in case of concurrent changes ? |
|
| 110 | + return $tags; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * @param bool $addToFavorite |
|
| 115 | - * @param int $fileId |
|
| 116 | - * @param string $path |
|
| 117 | - */ |
|
| 118 | - protected function addActivity($addToFavorite, $fileId, $path) { |
|
| 119 | - $user = $this->userSession->getUser(); |
|
| 120 | - if (!$user instanceof IUser) { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 113 | + /** |
|
| 114 | + * @param bool $addToFavorite |
|
| 115 | + * @param int $fileId |
|
| 116 | + * @param string $path |
|
| 117 | + */ |
|
| 118 | + protected function addActivity($addToFavorite, $fileId, $path) { |
|
| 119 | + $user = $this->userSession->getUser(); |
|
| 120 | + if (!$user instanceof IUser) { |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - $eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite'; |
|
| 125 | - $this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [ |
|
| 126 | - 'userId' => $user->getUID(), |
|
| 127 | - 'fileId' => $fileId, |
|
| 128 | - 'path' => $path, |
|
| 129 | - ])); |
|
| 124 | + $eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite'; |
|
| 125 | + $this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [ |
|
| 126 | + 'userId' => $user->getUID(), |
|
| 127 | + 'fileId' => $fileId, |
|
| 128 | + 'path' => $path, |
|
| 129 | + ])); |
|
| 130 | 130 | |
| 131 | - $event = $this->activityManager->generateEvent(); |
|
| 132 | - try { |
|
| 133 | - $event->setApp('files') |
|
| 134 | - ->setObject('files', $fileId, $path) |
|
| 135 | - ->setType('favorite') |
|
| 136 | - ->setAuthor($user->getUID()) |
|
| 137 | - ->setAffectedUser($user->getUID()) |
|
| 138 | - ->setTimestamp(time()) |
|
| 139 | - ->setSubject( |
|
| 140 | - $addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED, |
|
| 141 | - ['id' => $fileId, 'path' => $path] |
|
| 142 | - ); |
|
| 143 | - $this->activityManager->publish($event); |
|
| 144 | - } catch (\InvalidArgumentException $e) { |
|
| 145 | - } catch (\BadMethodCallException $e) { |
|
| 146 | - } |
|
| 147 | - } |
|
| 131 | + $event = $this->activityManager->generateEvent(); |
|
| 132 | + try { |
|
| 133 | + $event->setApp('files') |
|
| 134 | + ->setObject('files', $fileId, $path) |
|
| 135 | + ->setType('favorite') |
|
| 136 | + ->setAuthor($user->getUID()) |
|
| 137 | + ->setAffectedUser($user->getUID()) |
|
| 138 | + ->setTimestamp(time()) |
|
| 139 | + ->setSubject( |
|
| 140 | + $addToFavorite ? FavoriteProvider::SUBJECT_ADDED : FavoriteProvider::SUBJECT_REMOVED, |
|
| 141 | + ['id' => $fileId, 'path' => $path] |
|
| 142 | + ); |
|
| 143 | + $this->activityManager->publish($event); |
|
| 144 | + } catch (\InvalidArgumentException $e) { |
|
| 145 | + } catch (\BadMethodCallException $e) { |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | } |
| 149 | 149 | |
@@ -122,7 +122,7 @@ |
||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | $eventName = $addToFavorite ? 'addFavorite' : 'removeFavorite'; |
| 125 | - $this->dispatcher->dispatch(self::class . '::' . $eventName, new GenericEvent(null, [ |
|
| 125 | + $this->dispatcher->dispatch(self::class.'::'.$eventName, new GenericEvent(null, [ |
|
| 126 | 126 | 'userId' => $user->getUID(), |
| 127 | 127 | 'fileId' => $fileId, |
| 128 | 128 | 'path' => $path, |