@@ -28,42 +28,42 @@ |
||
| 28 | 28 | |
| 29 | 29 | class GenerateBirthdayCalendarBackgroundJob extends QueuedJob { |
| 30 | 30 | |
| 31 | - /** @var BirthdayService */ |
|
| 32 | - private $birthdayService; |
|
| 31 | + /** @var BirthdayService */ |
|
| 32 | + private $birthdayService; |
|
| 33 | 33 | |
| 34 | - /** @var IConfig */ |
|
| 35 | - private $config; |
|
| 34 | + /** @var IConfig */ |
|
| 35 | + private $config; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * GenerateAllBirthdayCalendarsBackgroundJob constructor. |
|
| 39 | - * |
|
| 40 | - * @param BirthdayService $birthdayService |
|
| 41 | - * @param IConfig $config |
|
| 42 | - */ |
|
| 43 | - public function __construct(BirthdayService $birthdayService, |
|
| 44 | - IConfig $config) { |
|
| 45 | - $this->birthdayService = $birthdayService; |
|
| 46 | - $this->config = $config; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * GenerateAllBirthdayCalendarsBackgroundJob constructor. |
|
| 39 | + * |
|
| 40 | + * @param BirthdayService $birthdayService |
|
| 41 | + * @param IConfig $config |
|
| 42 | + */ |
|
| 43 | + public function __construct(BirthdayService $birthdayService, |
|
| 44 | + IConfig $config) { |
|
| 45 | + $this->birthdayService = $birthdayService; |
|
| 46 | + $this->config = $config; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param array $arguments |
|
| 51 | - */ |
|
| 52 | - public function run($arguments) { |
|
| 53 | - $userId = $arguments['userId']; |
|
| 49 | + /** |
|
| 50 | + * @param array $arguments |
|
| 51 | + */ |
|
| 52 | + public function run($arguments) { |
|
| 53 | + $userId = $arguments['userId']; |
|
| 54 | 54 | |
| 55 | - // make sure admin didn't change his mind |
|
| 56 | - $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
| 57 | - if ($isGloballyEnabled !== 'yes') { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 55 | + // make sure admin didn't change his mind |
|
| 56 | + $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
| 57 | + if ($isGloballyEnabled !== 'yes') { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - // did the user opt out? |
|
| 62 | - $isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
| 63 | - if ($isUserEnabled !== 'yes') { |
|
| 64 | - return; |
|
| 65 | - } |
|
| 61 | + // did the user opt out? |
|
| 62 | + $isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
| 63 | + if ($isUserEnabled !== 'yes') { |
|
| 64 | + return; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $this->birthdayService->syncUser($userId); |
|
| 68 | - } |
|
| 67 | + $this->birthdayService->syncUser($userId); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <div class="ldapWizardControls"> |
| 2 | - <span class="ldap_saving hidden"><?php p($l->t('Saving'));?> <img class="wizSpinner" src="<?php p(image_path('core', 'loading.gif')); ?>"/></span> |
|
| 2 | + <span class="ldap_saving hidden"><?php p($l->t('Saving')); ?> <img class="wizSpinner" src="<?php p(image_path('core', 'loading.gif')); ?>"/></span> |
|
| 3 | 3 | <span class="ldap_config_state_indicator"></span> <span class="ldap_config_state_indicator_sign"></span> |
| 4 | 4 | <button class="ldap_action_back invisible" name="ldap_action_back" |
| 5 | 5 | type="button"> |
| 6 | - <?php p($l->t('Back'));?> |
|
| 6 | + <?php p($l->t('Back')); ?> |
|
| 7 | 7 | </button> |
| 8 | 8 | <button class="ldap_action_continue primary" name="ldap_action_continue" type="button"> |
| 9 | - <?php p($l->t('Continue'));?> |
|
| 9 | + <?php p($l->t('Continue')); ?> |
|
| 10 | 10 | </button> |
| 11 | 11 | <a href="<?php p(link_to_docs('admin-ldap')); ?>" |
| 12 | 12 | target="_blank" rel="noreferrer noopener"> |
| 13 | 13 | <img src="<?php print_unescaped(image_path('', 'actions/info.svg')); ?>" |
| 14 | 14 | style="height:1.75ex" /> |
| 15 | - <span class="ldap_grey"><?php p($l->t('Help'));?></span> |
|
| 15 | + <span class="ldap_grey"><?php p($l->t('Help')); ?></span> |
|
| 16 | 16 | </a> |
| 17 | 17 | </div> |
@@ -30,20 +30,20 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | interface IRegistry { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Register a reporter instance |
|
| 35 | - * |
|
| 36 | - * @since 13.0.0 |
|
| 37 | - * @param IReporter $reporter |
|
| 38 | - */ |
|
| 39 | - public function register(IReporter $reporter); |
|
| 33 | + /** |
|
| 34 | + * Register a reporter instance |
|
| 35 | + * |
|
| 36 | + * @since 13.0.0 |
|
| 37 | + * @param IReporter $reporter |
|
| 38 | + */ |
|
| 39 | + public function register(IReporter $reporter); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Delegate crash reporting to all registered reporters |
|
| 43 | - * |
|
| 44 | - * @since 13.0.0 |
|
| 45 | - * @param Exception|Throwable $exception |
|
| 46 | - * @param array $context |
|
| 47 | - */ |
|
| 48 | - public function delegateReport($exception, array $context = []); |
|
| 41 | + /** |
|
| 42 | + * Delegate crash reporting to all registered reporters |
|
| 43 | + * |
|
| 44 | + * @since 13.0.0 |
|
| 45 | + * @param Exception|Throwable $exception |
|
| 46 | + * @param array $context |
|
| 47 | + */ |
|
| 48 | + public function delegateReport($exception, array $context = []); |
|
| 49 | 49 | } |
@@ -30,12 +30,12 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | interface IReporter { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Report an (unhandled) exception |
|
| 35 | - * |
|
| 36 | - * @since 13.0.0 |
|
| 37 | - * @param Exception|Throwable $exception |
|
| 38 | - * @param array $context |
|
| 39 | - */ |
|
| 40 | - public function report($exception, array $context = []); |
|
| 33 | + /** |
|
| 34 | + * Report an (unhandled) exception |
|
| 35 | + * |
|
| 36 | + * @since 13.0.0 |
|
| 37 | + * @param Exception|Throwable $exception |
|
| 38 | + * @param array $context |
|
| 39 | + */ |
|
| 40 | + public function report($exception, array $context = []); |
|
| 41 | 41 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | </p> |
| 35 | 35 | <input class="primary" type="submit" id="submit" value="<?php p($l->t('Reset password')); ?>" /> |
| 36 | 36 | <p class="text-center"> |
| 37 | - <img class="hidden" id="float-spinner" src="<?php p(image_path('core', 'loading-dark.gif'));?>"/> |
|
| 37 | + <img class="hidden" id="float-spinner" src="<?php p(image_path('core', 'loading-dark.gif')); ?>"/> |
|
| 38 | 38 | </p> |
| 39 | 39 | </fieldset> |
| 40 | 40 | </form> |
@@ -71,34 +71,34 @@ |
||
| 71 | 71 | * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
| 72 | 72 | */ |
| 73 | 73 | public function prepare(INotification $notification, $languageCode) { |
| 74 | - if($notification->getApp() !== 'comments') { |
|
| 74 | + if ($notification->getApp() !== 'comments') { |
|
| 75 | 75 | throw new \InvalidArgumentException(); |
| 76 | 76 | } |
| 77 | 77 | try { |
| 78 | 78 | $comment = $this->commentsManager->get($notification->getObjectId()); |
| 79 | - } catch(NotFoundException $e) { |
|
| 79 | + } catch (NotFoundException $e) { |
|
| 80 | 80 | // needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all |
| 81 | 81 | throw new \InvalidArgumentException('Comment not found', 0, $e); |
| 82 | 82 | } |
| 83 | 83 | $l = $this->l10nFactory->get('comments', $languageCode); |
| 84 | 84 | $displayName = $comment->getActorId(); |
| 85 | 85 | $isDeletedActor = $comment->getActorType() === ICommentsManager::DELETED_USER; |
| 86 | - if($comment->getActorType() === 'users') { |
|
| 86 | + if ($comment->getActorType() === 'users') { |
|
| 87 | 87 | $commenter = $this->userManager->get($comment->getActorId()); |
| 88 | - if(!is_null($commenter)) { |
|
| 88 | + if (!is_null($commenter)) { |
|
| 89 | 89 | $displayName = $commenter->getDisplayName(); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - switch($notification->getSubject()) { |
|
| 93 | + switch ($notification->getSubject()) { |
|
| 94 | 94 | case 'mention': |
| 95 | 95 | $parameters = $notification->getSubjectParameters(); |
| 96 | - if($parameters[0] !== 'files') { |
|
| 96 | + if ($parameters[0] !== 'files') { |
|
| 97 | 97 | throw new \InvalidArgumentException('Unsupported comment object'); |
| 98 | 98 | } |
| 99 | 99 | $userFolder = $this->rootFolder->getUserFolder($notification->getUser()); |
| 100 | - $nodes = $userFolder->getById((int)$parameters[1]); |
|
| 101 | - if(empty($nodes)) { |
|
| 100 | + $nodes = $userFolder->getById((int) $parameters[1]); |
|
| 101 | + if (empty($nodes)) { |
|
| 102 | 102 | throw new \InvalidArgumentException('Cannot resolve file ID to node instance'); |
| 103 | 103 | } |
| 104 | 104 | $node = $nodes[0]; |
@@ -35,126 +35,126 @@ |
||
| 35 | 35 | |
| 36 | 36 | class Notifier implements INotifier { |
| 37 | 37 | |
| 38 | - /** @var IFactory */ |
|
| 39 | - protected $l10nFactory; |
|
| 38 | + /** @var IFactory */ |
|
| 39 | + protected $l10nFactory; |
|
| 40 | 40 | |
| 41 | - /** @var IRootFolder */ |
|
| 42 | - protected $rootFolder; |
|
| 41 | + /** @var IRootFolder */ |
|
| 42 | + protected $rootFolder; |
|
| 43 | 43 | |
| 44 | - /** @var ICommentsManager */ |
|
| 45 | - protected $commentsManager; |
|
| 44 | + /** @var ICommentsManager */ |
|
| 45 | + protected $commentsManager; |
|
| 46 | 46 | |
| 47 | - /** @var IURLGenerator */ |
|
| 48 | - protected $url; |
|
| 47 | + /** @var IURLGenerator */ |
|
| 48 | + protected $url; |
|
| 49 | 49 | |
| 50 | - /** @var IUserManager */ |
|
| 51 | - protected $userManager; |
|
| 50 | + /** @var IUserManager */ |
|
| 51 | + protected $userManager; |
|
| 52 | 52 | |
| 53 | - public function __construct( |
|
| 54 | - IFactory $l10nFactory, |
|
| 55 | - IRootFolder $rootFolder, |
|
| 56 | - ICommentsManager $commentsManager, |
|
| 57 | - IURLGenerator $url, |
|
| 58 | - IUserManager $userManager |
|
| 59 | - ) { |
|
| 60 | - $this->l10nFactory = $l10nFactory; |
|
| 61 | - $this->rootFolder = $rootFolder; |
|
| 62 | - $this->commentsManager = $commentsManager; |
|
| 63 | - $this->url = $url; |
|
| 64 | - $this->userManager = $userManager; |
|
| 65 | - } |
|
| 53 | + public function __construct( |
|
| 54 | + IFactory $l10nFactory, |
|
| 55 | + IRootFolder $rootFolder, |
|
| 56 | + ICommentsManager $commentsManager, |
|
| 57 | + IURLGenerator $url, |
|
| 58 | + IUserManager $userManager |
|
| 59 | + ) { |
|
| 60 | + $this->l10nFactory = $l10nFactory; |
|
| 61 | + $this->rootFolder = $rootFolder; |
|
| 62 | + $this->commentsManager = $commentsManager; |
|
| 63 | + $this->url = $url; |
|
| 64 | + $this->userManager = $userManager; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param INotification $notification |
|
| 69 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 70 | - * @return INotification |
|
| 71 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
| 72 | - */ |
|
| 73 | - public function prepare(INotification $notification, $languageCode) { |
|
| 74 | - if($notification->getApp() !== 'comments') { |
|
| 75 | - throw new \InvalidArgumentException(); |
|
| 76 | - } |
|
| 77 | - try { |
|
| 78 | - $comment = $this->commentsManager->get($notification->getObjectId()); |
|
| 79 | - } catch(NotFoundException $e) { |
|
| 80 | - // needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all |
|
| 81 | - throw new \InvalidArgumentException('Comment not found', 0, $e); |
|
| 82 | - } |
|
| 83 | - $l = $this->l10nFactory->get('comments', $languageCode); |
|
| 84 | - $displayName = $comment->getActorId(); |
|
| 85 | - $isDeletedActor = $comment->getActorType() === ICommentsManager::DELETED_USER; |
|
| 86 | - if($comment->getActorType() === 'users') { |
|
| 87 | - $commenter = $this->userManager->get($comment->getActorId()); |
|
| 88 | - if(!is_null($commenter)) { |
|
| 89 | - $displayName = $commenter->getDisplayName(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 67 | + /** |
|
| 68 | + * @param INotification $notification |
|
| 69 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 70 | + * @return INotification |
|
| 71 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
| 72 | + */ |
|
| 73 | + public function prepare(INotification $notification, $languageCode) { |
|
| 74 | + if($notification->getApp() !== 'comments') { |
|
| 75 | + throw new \InvalidArgumentException(); |
|
| 76 | + } |
|
| 77 | + try { |
|
| 78 | + $comment = $this->commentsManager->get($notification->getObjectId()); |
|
| 79 | + } catch(NotFoundException $e) { |
|
| 80 | + // needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all |
|
| 81 | + throw new \InvalidArgumentException('Comment not found', 0, $e); |
|
| 82 | + } |
|
| 83 | + $l = $this->l10nFactory->get('comments', $languageCode); |
|
| 84 | + $displayName = $comment->getActorId(); |
|
| 85 | + $isDeletedActor = $comment->getActorType() === ICommentsManager::DELETED_USER; |
|
| 86 | + if($comment->getActorType() === 'users') { |
|
| 87 | + $commenter = $this->userManager->get($comment->getActorId()); |
|
| 88 | + if(!is_null($commenter)) { |
|
| 89 | + $displayName = $commenter->getDisplayName(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - switch($notification->getSubject()) { |
|
| 94 | - case 'mention': |
|
| 95 | - $parameters = $notification->getSubjectParameters(); |
|
| 96 | - if($parameters[0] !== 'files') { |
|
| 97 | - throw new \InvalidArgumentException('Unsupported comment object'); |
|
| 98 | - } |
|
| 99 | - $userFolder = $this->rootFolder->getUserFolder($notification->getUser()); |
|
| 100 | - $nodes = $userFolder->getById((int)$parameters[1]); |
|
| 101 | - if(empty($nodes)) { |
|
| 102 | - throw new \InvalidArgumentException('Cannot resolve file ID to node instance'); |
|
| 103 | - } |
|
| 104 | - $node = $nodes[0]; |
|
| 93 | + switch($notification->getSubject()) { |
|
| 94 | + case 'mention': |
|
| 95 | + $parameters = $notification->getSubjectParameters(); |
|
| 96 | + if($parameters[0] !== 'files') { |
|
| 97 | + throw new \InvalidArgumentException('Unsupported comment object'); |
|
| 98 | + } |
|
| 99 | + $userFolder = $this->rootFolder->getUserFolder($notification->getUser()); |
|
| 100 | + $nodes = $userFolder->getById((int)$parameters[1]); |
|
| 101 | + if(empty($nodes)) { |
|
| 102 | + throw new \InvalidArgumentException('Cannot resolve file ID to node instance'); |
|
| 103 | + } |
|
| 104 | + $node = $nodes[0]; |
|
| 105 | 105 | |
| 106 | - if ($isDeletedActor) { |
|
| 107 | - $notification->setParsedSubject($l->t( |
|
| 108 | - 'You were mentioned on “%s”, in a comment by a user that has since been deleted', |
|
| 109 | - [$node->getName()] |
|
| 110 | - )) |
|
| 111 | - ->setRichSubject( |
|
| 112 | - $l->t('You were mentioned on “{file}”, in a comment by a user that has since been deleted'), |
|
| 113 | - [ |
|
| 114 | - 'file' => [ |
|
| 115 | - 'type' => 'file', |
|
| 116 | - 'id' => $comment->getObjectId(), |
|
| 117 | - 'name' => $node->getName(), |
|
| 118 | - 'path' => $node->getPath(), |
|
| 119 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), |
|
| 120 | - ], |
|
| 121 | - ] |
|
| 122 | - ); |
|
| 123 | - } else { |
|
| 124 | - $notification->setParsedSubject($l->t( |
|
| 125 | - '%1$s mentioned you in a comment on “%2$s”', |
|
| 126 | - [$displayName, $node->getName()] |
|
| 127 | - )) |
|
| 128 | - ->setRichSubject( |
|
| 129 | - $l->t('{user} mentioned you in a comment on “{file}”'), |
|
| 130 | - [ |
|
| 131 | - 'user' => [ |
|
| 132 | - 'type' => 'user', |
|
| 133 | - 'id' => $comment->getActorId(), |
|
| 134 | - 'name' => $displayName, |
|
| 135 | - ], |
|
| 136 | - 'file' => [ |
|
| 137 | - 'type' => 'file', |
|
| 138 | - 'id' => $comment->getObjectId(), |
|
| 139 | - 'name' => $node->getName(), |
|
| 140 | - 'path' => $node->getPath(), |
|
| 141 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), |
|
| 142 | - ], |
|
| 143 | - ] |
|
| 144 | - ); |
|
| 145 | - } |
|
| 146 | - $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'))) |
|
| 147 | - ->setLink($this->url->linkToRouteAbsolute( |
|
| 148 | - 'comments.Notifications.view', |
|
| 149 | - ['id' => $comment->getId()]) |
|
| 150 | - ); |
|
| 106 | + if ($isDeletedActor) { |
|
| 107 | + $notification->setParsedSubject($l->t( |
|
| 108 | + 'You were mentioned on “%s”, in a comment by a user that has since been deleted', |
|
| 109 | + [$node->getName()] |
|
| 110 | + )) |
|
| 111 | + ->setRichSubject( |
|
| 112 | + $l->t('You were mentioned on “{file}”, in a comment by a user that has since been deleted'), |
|
| 113 | + [ |
|
| 114 | + 'file' => [ |
|
| 115 | + 'type' => 'file', |
|
| 116 | + 'id' => $comment->getObjectId(), |
|
| 117 | + 'name' => $node->getName(), |
|
| 118 | + 'path' => $node->getPath(), |
|
| 119 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), |
|
| 120 | + ], |
|
| 121 | + ] |
|
| 122 | + ); |
|
| 123 | + } else { |
|
| 124 | + $notification->setParsedSubject($l->t( |
|
| 125 | + '%1$s mentioned you in a comment on “%2$s”', |
|
| 126 | + [$displayName, $node->getName()] |
|
| 127 | + )) |
|
| 128 | + ->setRichSubject( |
|
| 129 | + $l->t('{user} mentioned you in a comment on “{file}”'), |
|
| 130 | + [ |
|
| 131 | + 'user' => [ |
|
| 132 | + 'type' => 'user', |
|
| 133 | + 'id' => $comment->getActorId(), |
|
| 134 | + 'name' => $displayName, |
|
| 135 | + ], |
|
| 136 | + 'file' => [ |
|
| 137 | + 'type' => 'file', |
|
| 138 | + 'id' => $comment->getObjectId(), |
|
| 139 | + 'name' => $node->getName(), |
|
| 140 | + 'path' => $node->getPath(), |
|
| 141 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $comment->getObjectId()]), |
|
| 142 | + ], |
|
| 143 | + ] |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg'))) |
|
| 147 | + ->setLink($this->url->linkToRouteAbsolute( |
|
| 148 | + 'comments.Notifications.view', |
|
| 149 | + ['id' => $comment->getId()]) |
|
| 150 | + ); |
|
| 151 | 151 | |
| 152 | - return $notification; |
|
| 153 | - break; |
|
| 152 | + return $notification; |
|
| 153 | + break; |
|
| 154 | 154 | |
| 155 | - default: |
|
| 156 | - throw new \InvalidArgumentException('Invalid subject'); |
|
| 157 | - } |
|
| 155 | + default: |
|
| 156 | + throw new \InvalidArgumentException('Invalid subject'); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -261,6 +261,9 @@ discard block |
||
| 261 | 261 | return '"' . $this->info->getEtag() . '"'; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | + /** |
|
| 265 | + * @param string $path |
|
| 266 | + */ |
|
| 264 | 267 | private function getPartFileBasePath($path) { |
| 265 | 268 | $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); |
| 266 | 269 | if ($partFileInStorage) { |
@@ -606,6 +609,9 @@ discard block |
||
| 606 | 609 | return $this->info->getChecksum(); |
| 607 | 610 | } |
| 608 | 611 | |
| 612 | + /** |
|
| 613 | + * @param string $string |
|
| 614 | + */ |
|
| 609 | 615 | protected function header($string) { |
| 610 | 616 | \header($string); |
| 611 | 617 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | throw new Forbidden(); |
| 122 | 122 | } |
| 123 | 123 | } catch (StorageNotAvailableException $e) { |
| 124 | - throw new ServiceUnavailable("File is not updatable: " . $e->getMessage()); |
|
| 124 | + throw new ServiceUnavailable("File is not updatable: ".$e->getMessage()); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // verify path of the target |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | if ($needsPartFile) { |
| 144 | 144 | // mark file as partial while uploading (ignored by the scanner) |
| 145 | - $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; |
|
| 145 | + $partFilePath = $this->getPartFileBasePath($this->path).'.ocTransferId'.rand().'.part'; |
|
| 146 | 146 | } else { |
| 147 | 147 | // upload file directly as the final path |
| 148 | 148 | $partFilePath = $this->path; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | if (isset($_SERVER['CONTENT_LENGTH'])) { |
| 180 | 180 | $expected = $_SERVER['CONTENT_LENGTH']; |
| 181 | 181 | } |
| 182 | - throw new Exception('Error while copying file to target location (copied bytes: ' . $count . ', expected filesize: ' . $expected . ' )'); |
|
| 182 | + throw new Exception('Error while copying file to target location (copied bytes: '.$count.', expected filesize: '.$expected.' )'); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // if content length is sent by client: |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
| 189 | 189 | $expected = (int) $_SERVER['CONTENT_LENGTH']; |
| 190 | 190 | if ($count !== $expected) { |
| 191 | - throw new BadRequest('expected filesize ' . $expected . ' got ' . $count); |
|
| 191 | + throw new BadRequest('expected filesize '.$expected.' got '.$count); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); |
| 221 | 221 | $fileExists = $storage->file_exists($internalPath); |
| 222 | 222 | if ($renameOkay === false || $fileExists === false) { |
| 223 | - \OC::$server->getLogger()->error('renaming part file to final file failed ($run: ' . ( $run ? 'true' : 'false' ) . ', $renameOkay: ' . ( $renameOkay ? 'true' : 'false' ) . ', $fileExists: ' . ( $fileExists ? 'true' : 'false' ) . ')', ['app' => 'webdav']); |
|
| 223 | + \OC::$server->getLogger()->error('renaming part file to final file failed ($run: '.($run ? 'true' : 'false').', $renameOkay: '.($renameOkay ? 'true' : 'false').', $fileExists: '.($fileExists ? 'true' : 'false').')', ['app' => 'webdav']); |
|
| 224 | 224 | throw new Exception('Could not rename part file to final file'); |
| 225 | 225 | } |
| 226 | 226 | } catch (ForbiddenException $ex) { |
@@ -264,10 +264,10 @@ discard block |
||
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | } catch (StorageNotAvailableException $e) { |
| 267 | - throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage()); |
|
| 267 | + throw new ServiceUnavailable("Failed to check file size: ".$e->getMessage()); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - return '"' . $this->info->getEtag() . '"'; |
|
| 270 | + return '"'.$this->info->getEtag().'"'; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | private function getPartFileBasePath($path) { |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | return $res; |
| 355 | 355 | } catch (GenericEncryptionException $e) { |
| 356 | 356 | // returning 503 will allow retry of the operation at a later point in time |
| 357 | - throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage()); |
|
| 357 | + throw new ServiceUnavailable("Encryption not ready: ".$e->getMessage()); |
|
| 358 | 358 | } catch (StorageNotAvailableException $e) { |
| 359 | - throw new ServiceUnavailable("Failed to open file: " . $e->getMessage()); |
|
| 359 | + throw new ServiceUnavailable("Failed to open file: ".$e->getMessage()); |
|
| 360 | 360 | } catch (ForbiddenException $ex) { |
| 361 | 361 | throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
| 362 | 362 | } catch (LockedException $e) { |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | throw new Forbidden(); |
| 382 | 382 | } |
| 383 | 383 | } catch (StorageNotAvailableException $e) { |
| 384 | - throw new ServiceUnavailable("Failed to unlink: " . $e->getMessage()); |
|
| 384 | + throw new ServiceUnavailable("Failed to unlink: ".$e->getMessage()); |
|
| 385 | 385 | } catch (ForbiddenException $ex) { |
| 386 | 386 | throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
| 387 | 387 | } catch (LockedException $e) { |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | if ($bytesWritten !== $expected) { |
| 449 | 449 | $chunk_handler->remove($info['index']); |
| 450 | 450 | throw new BadRequest( |
| 451 | - 'expected filesize ' . $expected . ' got ' . $bytesWritten); |
|
| 451 | + 'expected filesize '.$expected.' got '.$bytesWritten); |
|
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | } |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | $needsPartFile = $storage->needsPartFile(); |
| 460 | 460 | $partFile = null; |
| 461 | 461 | |
| 462 | - $targetPath = $path . '/' . $info['name']; |
|
| 462 | + $targetPath = $path.'/'.$info['name']; |
|
| 463 | 463 | /** @var \OC\Files\Storage\Storage $targetStorage */ |
| 464 | 464 | list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath); |
| 465 | 465 | |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | if ($needsPartFile) { |
| 477 | 477 | // we first assembly the target file as a part file |
| 478 | - $partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part'; |
|
| 478 | + $partFile = $this->getPartFileBasePath($path.'/'.$info['name']).'.ocTransferId'.$info['transferid'].'.part'; |
|
| 479 | 479 | /** @var \OC\Files\Storage\Storage $targetStorage */ |
| 480 | 480 | list($partStorage, $partInternalPath) = $this->fileView->resolvePath($partFile); |
| 481 | 481 | |
@@ -579,10 +579,10 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | if ($e instanceof GenericEncryptionException) { |
| 581 | 581 | // returning 503 will allow retry of the operation at a later point in time |
| 582 | - throw new ServiceUnavailable('Encryption not ready: ' . $e->getMessage(), 0, $e); |
|
| 582 | + throw new ServiceUnavailable('Encryption not ready: '.$e->getMessage(), 0, $e); |
|
| 583 | 583 | } |
| 584 | 584 | if ($e instanceof StorageNotAvailableException) { |
| 585 | - throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e); |
|
| 585 | + throw new ServiceUnavailable('Failed to write file contents: '.$e->getMessage(), 0, $e); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e); |
@@ -66,538 +66,538 @@ |
||
| 66 | 66 | |
| 67 | 67 | class File extends Node implements IFile { |
| 68 | 68 | |
| 69 | - protected $request; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Sets up the node, expects a full path name |
|
| 73 | - * |
|
| 74 | - * @param \OC\Files\View $view |
|
| 75 | - * @param \OCP\Files\FileInfo $info |
|
| 76 | - * @param \OCP\Share\IManager $shareManager |
|
| 77 | - * @param \OC\AppFramework\Http\Request $request |
|
| 78 | - */ |
|
| 79 | - public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) { |
|
| 80 | - parent::__construct($view, $info, $shareManager); |
|
| 81 | - |
|
| 82 | - if (isset($request)) { |
|
| 83 | - $this->request = $request; |
|
| 84 | - } else { |
|
| 85 | - $this->request = \OC::$server->getRequest(); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Updates the data |
|
| 91 | - * |
|
| 92 | - * The data argument is a readable stream resource. |
|
| 93 | - * |
|
| 94 | - * After a successful put operation, you may choose to return an ETag. The |
|
| 95 | - * etag must always be surrounded by double-quotes. These quotes must |
|
| 96 | - * appear in the actual string you're returning. |
|
| 97 | - * |
|
| 98 | - * Clients may use the ETag from a PUT request to later on make sure that |
|
| 99 | - * when they update the file, the contents haven't changed in the mean |
|
| 100 | - * time. |
|
| 101 | - * |
|
| 102 | - * If you don't plan to store the file byte-by-byte, and you return a |
|
| 103 | - * different object on a subsequent GET you are strongly recommended to not |
|
| 104 | - * return an ETag, and just return null. |
|
| 105 | - * |
|
| 106 | - * @param resource $data |
|
| 107 | - * |
|
| 108 | - * @throws Forbidden |
|
| 109 | - * @throws UnsupportedMediaType |
|
| 110 | - * @throws BadRequest |
|
| 111 | - * @throws Exception |
|
| 112 | - * @throws EntityTooLarge |
|
| 113 | - * @throws ServiceUnavailable |
|
| 114 | - * @throws FileLocked |
|
| 115 | - * @return string|null |
|
| 116 | - */ |
|
| 117 | - public function put($data) { |
|
| 118 | - try { |
|
| 119 | - $exists = $this->fileView->file_exists($this->path); |
|
| 120 | - if ($this->info && $exists && !$this->info->isUpdateable()) { |
|
| 121 | - throw new Forbidden(); |
|
| 122 | - } |
|
| 123 | - } catch (StorageNotAvailableException $e) { |
|
| 124 | - throw new ServiceUnavailable("File is not updatable: " . $e->getMessage()); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // verify path of the target |
|
| 128 | - $this->verifyPath(); |
|
| 129 | - |
|
| 130 | - // chunked handling |
|
| 131 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 132 | - try { |
|
| 133 | - return $this->createFileChunked($data); |
|
| 134 | - } catch (\Exception $e) { |
|
| 135 | - $this->convertToSabreException($e); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** @var Storage $partStorage */ |
|
| 140 | - list($partStorage) = $this->fileView->resolvePath($this->path); |
|
| 141 | - $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); |
|
| 142 | - |
|
| 143 | - if ($needsPartFile) { |
|
| 144 | - // mark file as partial while uploading (ignored by the scanner) |
|
| 145 | - $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; |
|
| 146 | - } else { |
|
| 147 | - // upload file directly as the final path |
|
| 148 | - $partFilePath = $this->path; |
|
| 149 | - |
|
| 150 | - $this->emitPreHooks($exists); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $view = \OC\Files\Filesystem::getView(); |
|
| 154 | - |
|
| 155 | - // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) |
|
| 156 | - /** @var \OC\Files\Storage\Storage $partStorage */ |
|
| 157 | - list($partStorage, $internalPartPath) = $this->fileView->resolvePath($partFilePath); |
|
| 158 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
| 159 | - list($storage, $internalPath) = $this->fileView->resolvePath($this->path); |
|
| 160 | - try { |
|
| 161 | - if (!$needsPartFile) { |
|
| 162 | - if ($view && !$this->emitPreHooks($exists)) { |
|
| 163 | - throw new Exception('Could not write to final file, canceled by hook'); |
|
| 164 | - } |
|
| 165 | - $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $target = $partStorage->fopen($internalPartPath, 'wb'); |
|
| 169 | - if ($target === false) { |
|
| 170 | - \OC::$server->getLogger()->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); |
|
| 171 | - // because we have no clue about the cause we can only throw back a 500/Internal Server Error |
|
| 172 | - throw new Exception('Could not write file contents'); |
|
| 173 | - } |
|
| 174 | - list($count, $result) = \OC_Helper::streamCopy($data, $target); |
|
| 175 | - fclose($target); |
|
| 176 | - |
|
| 177 | - if ($result === false) { |
|
| 178 | - $expected = -1; |
|
| 179 | - if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
| 180 | - $expected = $_SERVER['CONTENT_LENGTH']; |
|
| 181 | - } |
|
| 182 | - throw new Exception('Error while copying file to target location (copied bytes: ' . $count . ', expected filesize: ' . $expected . ' )'); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // if content length is sent by client: |
|
| 186 | - // double check if the file was fully received |
|
| 187 | - // compare expected and actual size |
|
| 188 | - if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
| 189 | - $expected = (int) $_SERVER['CONTENT_LENGTH']; |
|
| 190 | - if ($count !== $expected) { |
|
| 191 | - throw new BadRequest('expected filesize ' . $expected . ' got ' . $count); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - } catch (\Exception $e) { |
|
| 196 | - \OC::$server->getLogger()->logException($e); |
|
| 197 | - if ($needsPartFile) { |
|
| 198 | - $partStorage->unlink($internalPartPath); |
|
| 199 | - } |
|
| 200 | - $this->convertToSabreException($e); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - try { |
|
| 204 | - if ($needsPartFile) { |
|
| 205 | - if ($view && !$this->emitPreHooks($exists)) { |
|
| 206 | - $partStorage->unlink($internalPartPath); |
|
| 207 | - throw new Exception('Could not rename part file to final file, canceled by hook'); |
|
| 208 | - } |
|
| 209 | - try { |
|
| 210 | - $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 211 | - } catch (LockedException $e) { |
|
| 212 | - if ($needsPartFile) { |
|
| 213 | - $partStorage->unlink($internalPartPath); |
|
| 214 | - } |
|
| 215 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // rename to correct path |
|
| 219 | - try { |
|
| 220 | - $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); |
|
| 221 | - $fileExists = $storage->file_exists($internalPath); |
|
| 222 | - if ($renameOkay === false || $fileExists === false) { |
|
| 223 | - \OC::$server->getLogger()->error('renaming part file to final file failed ($run: ' . ( $run ? 'true' : 'false' ) . ', $renameOkay: ' . ( $renameOkay ? 'true' : 'false' ) . ', $fileExists: ' . ( $fileExists ? 'true' : 'false' ) . ')', ['app' => 'webdav']); |
|
| 224 | - throw new Exception('Could not rename part file to final file'); |
|
| 225 | - } |
|
| 226 | - } catch (ForbiddenException $ex) { |
|
| 227 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 228 | - } catch (\Exception $e) { |
|
| 229 | - $partStorage->unlink($internalPartPath); |
|
| 230 | - $this->convertToSabreException($e); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // since we skipped the view we need to scan and emit the hooks ourselves |
|
| 235 | - $storage->getUpdater()->update($internalPath); |
|
| 236 | - |
|
| 237 | - try { |
|
| 238 | - $this->changeLock(ILockingProvider::LOCK_SHARED); |
|
| 239 | - } catch (LockedException $e) { |
|
| 240 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // allow sync clients to send the mtime along in a header |
|
| 244 | - if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
| 245 | - $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
| 246 | - if ($this->fileView->touch($this->path, $mtime)) { |
|
| 247 | - $this->header('X-OC-MTime: accepted'); |
|
| 248 | - } |
|
| 249 | - } |
|
| 69 | + protected $request; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Sets up the node, expects a full path name |
|
| 73 | + * |
|
| 74 | + * @param \OC\Files\View $view |
|
| 75 | + * @param \OCP\Files\FileInfo $info |
|
| 76 | + * @param \OCP\Share\IManager $shareManager |
|
| 77 | + * @param \OC\AppFramework\Http\Request $request |
|
| 78 | + */ |
|
| 79 | + public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) { |
|
| 80 | + parent::__construct($view, $info, $shareManager); |
|
| 81 | + |
|
| 82 | + if (isset($request)) { |
|
| 83 | + $this->request = $request; |
|
| 84 | + } else { |
|
| 85 | + $this->request = \OC::$server->getRequest(); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Updates the data |
|
| 91 | + * |
|
| 92 | + * The data argument is a readable stream resource. |
|
| 93 | + * |
|
| 94 | + * After a successful put operation, you may choose to return an ETag. The |
|
| 95 | + * etag must always be surrounded by double-quotes. These quotes must |
|
| 96 | + * appear in the actual string you're returning. |
|
| 97 | + * |
|
| 98 | + * Clients may use the ETag from a PUT request to later on make sure that |
|
| 99 | + * when they update the file, the contents haven't changed in the mean |
|
| 100 | + * time. |
|
| 101 | + * |
|
| 102 | + * If you don't plan to store the file byte-by-byte, and you return a |
|
| 103 | + * different object on a subsequent GET you are strongly recommended to not |
|
| 104 | + * return an ETag, and just return null. |
|
| 105 | + * |
|
| 106 | + * @param resource $data |
|
| 107 | + * |
|
| 108 | + * @throws Forbidden |
|
| 109 | + * @throws UnsupportedMediaType |
|
| 110 | + * @throws BadRequest |
|
| 111 | + * @throws Exception |
|
| 112 | + * @throws EntityTooLarge |
|
| 113 | + * @throws ServiceUnavailable |
|
| 114 | + * @throws FileLocked |
|
| 115 | + * @return string|null |
|
| 116 | + */ |
|
| 117 | + public function put($data) { |
|
| 118 | + try { |
|
| 119 | + $exists = $this->fileView->file_exists($this->path); |
|
| 120 | + if ($this->info && $exists && !$this->info->isUpdateable()) { |
|
| 121 | + throw new Forbidden(); |
|
| 122 | + } |
|
| 123 | + } catch (StorageNotAvailableException $e) { |
|
| 124 | + throw new ServiceUnavailable("File is not updatable: " . $e->getMessage()); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // verify path of the target |
|
| 128 | + $this->verifyPath(); |
|
| 129 | + |
|
| 130 | + // chunked handling |
|
| 131 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 132 | + try { |
|
| 133 | + return $this->createFileChunked($data); |
|
| 134 | + } catch (\Exception $e) { |
|
| 135 | + $this->convertToSabreException($e); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** @var Storage $partStorage */ |
|
| 140 | + list($partStorage) = $this->fileView->resolvePath($this->path); |
|
| 141 | + $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); |
|
| 142 | + |
|
| 143 | + if ($needsPartFile) { |
|
| 144 | + // mark file as partial while uploading (ignored by the scanner) |
|
| 145 | + $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; |
|
| 146 | + } else { |
|
| 147 | + // upload file directly as the final path |
|
| 148 | + $partFilePath = $this->path; |
|
| 149 | + |
|
| 150 | + $this->emitPreHooks($exists); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $view = \OC\Files\Filesystem::getView(); |
|
| 154 | + |
|
| 155 | + // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) |
|
| 156 | + /** @var \OC\Files\Storage\Storage $partStorage */ |
|
| 157 | + list($partStorage, $internalPartPath) = $this->fileView->resolvePath($partFilePath); |
|
| 158 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
| 159 | + list($storage, $internalPath) = $this->fileView->resolvePath($this->path); |
|
| 160 | + try { |
|
| 161 | + if (!$needsPartFile) { |
|
| 162 | + if ($view && !$this->emitPreHooks($exists)) { |
|
| 163 | + throw new Exception('Could not write to final file, canceled by hook'); |
|
| 164 | + } |
|
| 165 | + $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $target = $partStorage->fopen($internalPartPath, 'wb'); |
|
| 169 | + if ($target === false) { |
|
| 170 | + \OC::$server->getLogger()->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); |
|
| 171 | + // because we have no clue about the cause we can only throw back a 500/Internal Server Error |
|
| 172 | + throw new Exception('Could not write file contents'); |
|
| 173 | + } |
|
| 174 | + list($count, $result) = \OC_Helper::streamCopy($data, $target); |
|
| 175 | + fclose($target); |
|
| 176 | + |
|
| 177 | + if ($result === false) { |
|
| 178 | + $expected = -1; |
|
| 179 | + if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
| 180 | + $expected = $_SERVER['CONTENT_LENGTH']; |
|
| 181 | + } |
|
| 182 | + throw new Exception('Error while copying file to target location (copied bytes: ' . $count . ', expected filesize: ' . $expected . ' )'); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // if content length is sent by client: |
|
| 186 | + // double check if the file was fully received |
|
| 187 | + // compare expected and actual size |
|
| 188 | + if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
| 189 | + $expected = (int) $_SERVER['CONTENT_LENGTH']; |
|
| 190 | + if ($count !== $expected) { |
|
| 191 | + throw new BadRequest('expected filesize ' . $expected . ' got ' . $count); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + } catch (\Exception $e) { |
|
| 196 | + \OC::$server->getLogger()->logException($e); |
|
| 197 | + if ($needsPartFile) { |
|
| 198 | + $partStorage->unlink($internalPartPath); |
|
| 199 | + } |
|
| 200 | + $this->convertToSabreException($e); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + try { |
|
| 204 | + if ($needsPartFile) { |
|
| 205 | + if ($view && !$this->emitPreHooks($exists)) { |
|
| 206 | + $partStorage->unlink($internalPartPath); |
|
| 207 | + throw new Exception('Could not rename part file to final file, canceled by hook'); |
|
| 208 | + } |
|
| 209 | + try { |
|
| 210 | + $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 211 | + } catch (LockedException $e) { |
|
| 212 | + if ($needsPartFile) { |
|
| 213 | + $partStorage->unlink($internalPartPath); |
|
| 214 | + } |
|
| 215 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // rename to correct path |
|
| 219 | + try { |
|
| 220 | + $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); |
|
| 221 | + $fileExists = $storage->file_exists($internalPath); |
|
| 222 | + if ($renameOkay === false || $fileExists === false) { |
|
| 223 | + \OC::$server->getLogger()->error('renaming part file to final file failed ($run: ' . ( $run ? 'true' : 'false' ) . ', $renameOkay: ' . ( $renameOkay ? 'true' : 'false' ) . ', $fileExists: ' . ( $fileExists ? 'true' : 'false' ) . ')', ['app' => 'webdav']); |
|
| 224 | + throw new Exception('Could not rename part file to final file'); |
|
| 225 | + } |
|
| 226 | + } catch (ForbiddenException $ex) { |
|
| 227 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 228 | + } catch (\Exception $e) { |
|
| 229 | + $partStorage->unlink($internalPartPath); |
|
| 230 | + $this->convertToSabreException($e); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // since we skipped the view we need to scan and emit the hooks ourselves |
|
| 235 | + $storage->getUpdater()->update($internalPath); |
|
| 236 | + |
|
| 237 | + try { |
|
| 238 | + $this->changeLock(ILockingProvider::LOCK_SHARED); |
|
| 239 | + } catch (LockedException $e) { |
|
| 240 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // allow sync clients to send the mtime along in a header |
|
| 244 | + if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
| 245 | + $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
| 246 | + if ($this->fileView->touch($this->path, $mtime)) { |
|
| 247 | + $this->header('X-OC-MTime: accepted'); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - if ($view) { |
|
| 252 | - $this->emitPostHooks($exists); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $this->refreshInfo(); |
|
| 256 | - |
|
| 257 | - if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
| 258 | - $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
| 259 | - $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); |
|
| 260 | - $this->refreshInfo(); |
|
| 261 | - } else if ($this->getChecksum() !== null && $this->getChecksum() !== '') { |
|
| 262 | - $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
|
| 263 | - $this->refreshInfo(); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - } catch (StorageNotAvailableException $e) { |
|
| 267 | - throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage()); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return '"' . $this->info->getEtag() . '"'; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - private function getPartFileBasePath($path) { |
|
| 274 | - $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); |
|
| 275 | - if ($partFileInStorage) { |
|
| 276 | - return $path; |
|
| 277 | - } else { |
|
| 278 | - return md5($path); // will place it in the root of the view with a unique name |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @param string $path |
|
| 284 | - */ |
|
| 285 | - private function emitPreHooks($exists, $path = null) { |
|
| 286 | - if (is_null($path)) { |
|
| 287 | - $path = $this->path; |
|
| 288 | - } |
|
| 289 | - $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
| 290 | - $run = true; |
|
| 291 | - |
|
| 292 | - if (!$exists) { |
|
| 293 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, array( |
|
| 294 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 295 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 296 | - )); |
|
| 297 | - } else { |
|
| 298 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_update, array( |
|
| 299 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 300 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 301 | - )); |
|
| 302 | - } |
|
| 303 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, array( |
|
| 304 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 305 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 306 | - )); |
|
| 307 | - return $run; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @param string $path |
|
| 312 | - */ |
|
| 313 | - private function emitPostHooks($exists, $path = null) { |
|
| 314 | - if (is_null($path)) { |
|
| 315 | - $path = $this->path; |
|
| 316 | - } |
|
| 317 | - $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
| 318 | - if (!$exists) { |
|
| 319 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, array( |
|
| 320 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 321 | - )); |
|
| 322 | - } else { |
|
| 323 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_update, array( |
|
| 324 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 325 | - )); |
|
| 326 | - } |
|
| 327 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, array( |
|
| 328 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 329 | - )); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Returns the data |
|
| 334 | - * |
|
| 335 | - * @return resource |
|
| 336 | - * @throws Forbidden |
|
| 337 | - * @throws ServiceUnavailable |
|
| 338 | - */ |
|
| 339 | - public function get() { |
|
| 340 | - //throw exception if encryption is disabled but files are still encrypted |
|
| 341 | - try { |
|
| 342 | - if (!$this->info->isReadable()) { |
|
| 343 | - // do a if the file did not exist |
|
| 344 | - throw new NotFound(); |
|
| 345 | - } |
|
| 346 | - try { |
|
| 347 | - $res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); |
|
| 348 | - } catch (\Exception $e) { |
|
| 349 | - $this->convertToSabreException($e); |
|
| 350 | - } |
|
| 351 | - if ($res === false) { |
|
| 352 | - throw new ServiceUnavailable("Could not open file"); |
|
| 353 | - } |
|
| 354 | - return $res; |
|
| 355 | - } catch (GenericEncryptionException $e) { |
|
| 356 | - // returning 503 will allow retry of the operation at a later point in time |
|
| 357 | - throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage()); |
|
| 358 | - } catch (StorageNotAvailableException $e) { |
|
| 359 | - throw new ServiceUnavailable("Failed to open file: " . $e->getMessage()); |
|
| 360 | - } catch (ForbiddenException $ex) { |
|
| 361 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 362 | - } catch (LockedException $e) { |
|
| 363 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Delete the current file |
|
| 369 | - * |
|
| 370 | - * @throws Forbidden |
|
| 371 | - * @throws ServiceUnavailable |
|
| 372 | - */ |
|
| 373 | - public function delete() { |
|
| 374 | - if (!$this->info->isDeletable()) { |
|
| 375 | - throw new Forbidden(); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - try { |
|
| 379 | - if (!$this->fileView->unlink($this->path)) { |
|
| 380 | - // assume it wasn't possible to delete due to permissions |
|
| 381 | - throw new Forbidden(); |
|
| 382 | - } |
|
| 383 | - } catch (StorageNotAvailableException $e) { |
|
| 384 | - throw new ServiceUnavailable("Failed to unlink: " . $e->getMessage()); |
|
| 385 | - } catch (ForbiddenException $ex) { |
|
| 386 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 387 | - } catch (LockedException $e) { |
|
| 388 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Returns the mime-type for a file |
|
| 394 | - * |
|
| 395 | - * If null is returned, we'll assume application/octet-stream |
|
| 396 | - * |
|
| 397 | - * @return string |
|
| 398 | - */ |
|
| 399 | - public function getContentType() { |
|
| 400 | - $mimeType = $this->info->getMimetype(); |
|
| 401 | - |
|
| 402 | - // PROPFIND needs to return the correct mime type, for consistency with the web UI |
|
| 403 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 404 | - return $mimeType; |
|
| 405 | - } |
|
| 406 | - return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * @return array|false |
|
| 411 | - */ |
|
| 412 | - public function getDirectDownload() { |
|
| 413 | - if (\OCP\App::isEnabled('encryption')) { |
|
| 414 | - return []; |
|
| 415 | - } |
|
| 416 | - /** @var \OCP\Files\Storage $storage */ |
|
| 417 | - list($storage, $internalPath) = $this->fileView->resolvePath($this->path); |
|
| 418 | - if (is_null($storage)) { |
|
| 419 | - return []; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - return $storage->getDirectDownload($internalPath); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @param resource $data |
|
| 427 | - * @return null|string |
|
| 428 | - * @throws Exception |
|
| 429 | - * @throws BadRequest |
|
| 430 | - * @throws NotImplemented |
|
| 431 | - * @throws ServiceUnavailable |
|
| 432 | - */ |
|
| 433 | - private function createFileChunked($data) { |
|
| 434 | - list($path, $name) = \Sabre\Uri\split($this->path); |
|
| 435 | - |
|
| 436 | - $info = \OC_FileChunking::decodeName($name); |
|
| 437 | - if (empty($info)) { |
|
| 438 | - throw new NotImplemented('Invalid chunk name'); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $chunk_handler = new \OC_FileChunking($info); |
|
| 442 | - $bytesWritten = $chunk_handler->store($info['index'], $data); |
|
| 443 | - |
|
| 444 | - //detect aborted upload |
|
| 445 | - if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
| 446 | - if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
| 447 | - $expected = (int) $_SERVER['CONTENT_LENGTH']; |
|
| 448 | - if ($bytesWritten !== $expected) { |
|
| 449 | - $chunk_handler->remove($info['index']); |
|
| 450 | - throw new BadRequest( |
|
| 451 | - 'expected filesize ' . $expected . ' got ' . $bytesWritten); |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - if ($chunk_handler->isComplete()) { |
|
| 457 | - /** @var Storage $storage */ |
|
| 458 | - list($storage,) = $this->fileView->resolvePath($path); |
|
| 459 | - $needsPartFile = $storage->needsPartFile(); |
|
| 460 | - $partFile = null; |
|
| 461 | - |
|
| 462 | - $targetPath = $path . '/' . $info['name']; |
|
| 463 | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 464 | - list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath); |
|
| 465 | - |
|
| 466 | - $exists = $this->fileView->file_exists($targetPath); |
|
| 467 | - |
|
| 468 | - try { |
|
| 469 | - $this->fileView->lockFile($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 470 | - |
|
| 471 | - $this->emitPreHooks($exists, $targetPath); |
|
| 472 | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_EXCLUSIVE); |
|
| 473 | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 474 | - list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath); |
|
| 475 | - |
|
| 476 | - if ($needsPartFile) { |
|
| 477 | - // we first assembly the target file as a part file |
|
| 478 | - $partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part'; |
|
| 479 | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 480 | - list($partStorage, $partInternalPath) = $this->fileView->resolvePath($partFile); |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - $chunk_handler->file_assemble($partStorage, $partInternalPath); |
|
| 484 | - |
|
| 485 | - // here is the final atomic rename |
|
| 486 | - $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath); |
|
| 487 | - $fileExists = $targetStorage->file_exists($targetInternalPath); |
|
| 488 | - if ($renameOkay === false || $fileExists === false) { |
|
| 489 | - \OC::$server->getLogger()->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']); |
|
| 490 | - // only delete if an error occurred and the target file was already created |
|
| 491 | - if ($fileExists) { |
|
| 492 | - // set to null to avoid double-deletion when handling exception |
|
| 493 | - // stray part file |
|
| 494 | - $partFile = null; |
|
| 495 | - $targetStorage->unlink($targetInternalPath); |
|
| 496 | - } |
|
| 497 | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 498 | - throw new Exception('Could not rename part file assembled from chunks'); |
|
| 499 | - } |
|
| 500 | - } else { |
|
| 501 | - // assemble directly into the final file |
|
| 502 | - $chunk_handler->file_assemble($targetStorage, $targetInternalPath); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - // allow sync clients to send the mtime along in a header |
|
| 506 | - if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
| 507 | - $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
| 508 | - if ($targetStorage->touch($targetInternalPath, $mtime)) { |
|
| 509 | - $this->header('X-OC-MTime: accepted'); |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - // since we skipped the view we need to scan and emit the hooks ourselves |
|
| 514 | - $targetStorage->getUpdater()->update($targetInternalPath); |
|
| 515 | - |
|
| 516 | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 517 | - |
|
| 518 | - $this->emitPostHooks($exists, $targetPath); |
|
| 519 | - |
|
| 520 | - // FIXME: should call refreshInfo but can't because $this->path is not the of the final file |
|
| 521 | - $info = $this->fileView->getFileInfo($targetPath); |
|
| 522 | - |
|
| 523 | - if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
| 524 | - $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
| 525 | - $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); |
|
| 526 | - } else if ($info->getChecksum() !== null && $info->getChecksum() !== '') { |
|
| 527 | - $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 531 | - |
|
| 532 | - return $info->getEtag(); |
|
| 533 | - } catch (\Exception $e) { |
|
| 534 | - if ($partFile !== null) { |
|
| 535 | - $targetStorage->unlink($targetInternalPath); |
|
| 536 | - } |
|
| 537 | - $this->convertToSabreException($e); |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - return null; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Convert the given exception to a SabreException instance |
|
| 546 | - * |
|
| 547 | - * @param \Exception $e |
|
| 548 | - * |
|
| 549 | - * @throws \Sabre\DAV\Exception |
|
| 550 | - */ |
|
| 551 | - private function convertToSabreException(\Exception $e) { |
|
| 552 | - if ($e instanceof \Sabre\DAV\Exception) { |
|
| 553 | - throw $e; |
|
| 554 | - } |
|
| 555 | - if ($e instanceof NotPermittedException) { |
|
| 556 | - // a more general case - due to whatever reason the content could not be written |
|
| 557 | - throw new Forbidden($e->getMessage(), 0, $e); |
|
| 558 | - } |
|
| 559 | - if ($e instanceof ForbiddenException) { |
|
| 560 | - // the path for the file was forbidden |
|
| 561 | - throw new DAVForbiddenException($e->getMessage(), $e->getRetry(), $e); |
|
| 562 | - } |
|
| 563 | - if ($e instanceof EntityTooLargeException) { |
|
| 564 | - // the file is too big to be stored |
|
| 565 | - throw new EntityTooLarge($e->getMessage(), 0, $e); |
|
| 566 | - } |
|
| 567 | - if ($e instanceof InvalidContentException) { |
|
| 568 | - // the file content is not permitted |
|
| 569 | - throw new UnsupportedMediaType($e->getMessage(), 0, $e); |
|
| 570 | - } |
|
| 571 | - if ($e instanceof InvalidPathException) { |
|
| 572 | - // the path for the file was not valid |
|
| 573 | - // TODO: find proper http status code for this case |
|
| 574 | - throw new Forbidden($e->getMessage(), 0, $e); |
|
| 575 | - } |
|
| 576 | - if ($e instanceof LockedException || $e instanceof LockNotAcquiredException) { |
|
| 577 | - // the file is currently being written to by another process |
|
| 578 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 579 | - } |
|
| 580 | - if ($e instanceof GenericEncryptionException) { |
|
| 581 | - // returning 503 will allow retry of the operation at a later point in time |
|
| 582 | - throw new ServiceUnavailable('Encryption not ready: ' . $e->getMessage(), 0, $e); |
|
| 583 | - } |
|
| 584 | - if ($e instanceof StorageNotAvailableException) { |
|
| 585 | - throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * Get the checksum for this file |
|
| 593 | - * |
|
| 594 | - * @return string |
|
| 595 | - */ |
|
| 596 | - public function getChecksum() { |
|
| 597 | - return $this->info->getChecksum(); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - protected function header($string) { |
|
| 601 | - \header($string); |
|
| 602 | - } |
|
| 251 | + if ($view) { |
|
| 252 | + $this->emitPostHooks($exists); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $this->refreshInfo(); |
|
| 256 | + |
|
| 257 | + if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
| 258 | + $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
| 259 | + $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); |
|
| 260 | + $this->refreshInfo(); |
|
| 261 | + } else if ($this->getChecksum() !== null && $this->getChecksum() !== '') { |
|
| 262 | + $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
|
| 263 | + $this->refreshInfo(); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + } catch (StorageNotAvailableException $e) { |
|
| 267 | + throw new ServiceUnavailable("Failed to check file size: " . $e->getMessage()); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return '"' . $this->info->getEtag() . '"'; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + private function getPartFileBasePath($path) { |
|
| 274 | + $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); |
|
| 275 | + if ($partFileInStorage) { |
|
| 276 | + return $path; |
|
| 277 | + } else { |
|
| 278 | + return md5($path); // will place it in the root of the view with a unique name |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @param string $path |
|
| 284 | + */ |
|
| 285 | + private function emitPreHooks($exists, $path = null) { |
|
| 286 | + if (is_null($path)) { |
|
| 287 | + $path = $this->path; |
|
| 288 | + } |
|
| 289 | + $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
| 290 | + $run = true; |
|
| 291 | + |
|
| 292 | + if (!$exists) { |
|
| 293 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, array( |
|
| 294 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 295 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 296 | + )); |
|
| 297 | + } else { |
|
| 298 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_update, array( |
|
| 299 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 300 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 301 | + )); |
|
| 302 | + } |
|
| 303 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, array( |
|
| 304 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 305 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 306 | + )); |
|
| 307 | + return $run; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @param string $path |
|
| 312 | + */ |
|
| 313 | + private function emitPostHooks($exists, $path = null) { |
|
| 314 | + if (is_null($path)) { |
|
| 315 | + $path = $this->path; |
|
| 316 | + } |
|
| 317 | + $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
| 318 | + if (!$exists) { |
|
| 319 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, array( |
|
| 320 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 321 | + )); |
|
| 322 | + } else { |
|
| 323 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_update, array( |
|
| 324 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 325 | + )); |
|
| 326 | + } |
|
| 327 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, array( |
|
| 328 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 329 | + )); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Returns the data |
|
| 334 | + * |
|
| 335 | + * @return resource |
|
| 336 | + * @throws Forbidden |
|
| 337 | + * @throws ServiceUnavailable |
|
| 338 | + */ |
|
| 339 | + public function get() { |
|
| 340 | + //throw exception if encryption is disabled but files are still encrypted |
|
| 341 | + try { |
|
| 342 | + if (!$this->info->isReadable()) { |
|
| 343 | + // do a if the file did not exist |
|
| 344 | + throw new NotFound(); |
|
| 345 | + } |
|
| 346 | + try { |
|
| 347 | + $res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); |
|
| 348 | + } catch (\Exception $e) { |
|
| 349 | + $this->convertToSabreException($e); |
|
| 350 | + } |
|
| 351 | + if ($res === false) { |
|
| 352 | + throw new ServiceUnavailable("Could not open file"); |
|
| 353 | + } |
|
| 354 | + return $res; |
|
| 355 | + } catch (GenericEncryptionException $e) { |
|
| 356 | + // returning 503 will allow retry of the operation at a later point in time |
|
| 357 | + throw new ServiceUnavailable("Encryption not ready: " . $e->getMessage()); |
|
| 358 | + } catch (StorageNotAvailableException $e) { |
|
| 359 | + throw new ServiceUnavailable("Failed to open file: " . $e->getMessage()); |
|
| 360 | + } catch (ForbiddenException $ex) { |
|
| 361 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 362 | + } catch (LockedException $e) { |
|
| 363 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Delete the current file |
|
| 369 | + * |
|
| 370 | + * @throws Forbidden |
|
| 371 | + * @throws ServiceUnavailable |
|
| 372 | + */ |
|
| 373 | + public function delete() { |
|
| 374 | + if (!$this->info->isDeletable()) { |
|
| 375 | + throw new Forbidden(); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + try { |
|
| 379 | + if (!$this->fileView->unlink($this->path)) { |
|
| 380 | + // assume it wasn't possible to delete due to permissions |
|
| 381 | + throw new Forbidden(); |
|
| 382 | + } |
|
| 383 | + } catch (StorageNotAvailableException $e) { |
|
| 384 | + throw new ServiceUnavailable("Failed to unlink: " . $e->getMessage()); |
|
| 385 | + } catch (ForbiddenException $ex) { |
|
| 386 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 387 | + } catch (LockedException $e) { |
|
| 388 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Returns the mime-type for a file |
|
| 394 | + * |
|
| 395 | + * If null is returned, we'll assume application/octet-stream |
|
| 396 | + * |
|
| 397 | + * @return string |
|
| 398 | + */ |
|
| 399 | + public function getContentType() { |
|
| 400 | + $mimeType = $this->info->getMimetype(); |
|
| 401 | + |
|
| 402 | + // PROPFIND needs to return the correct mime type, for consistency with the web UI |
|
| 403 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 404 | + return $mimeType; |
|
| 405 | + } |
|
| 406 | + return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * @return array|false |
|
| 411 | + */ |
|
| 412 | + public function getDirectDownload() { |
|
| 413 | + if (\OCP\App::isEnabled('encryption')) { |
|
| 414 | + return []; |
|
| 415 | + } |
|
| 416 | + /** @var \OCP\Files\Storage $storage */ |
|
| 417 | + list($storage, $internalPath) = $this->fileView->resolvePath($this->path); |
|
| 418 | + if (is_null($storage)) { |
|
| 419 | + return []; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + return $storage->getDirectDownload($internalPath); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @param resource $data |
|
| 427 | + * @return null|string |
|
| 428 | + * @throws Exception |
|
| 429 | + * @throws BadRequest |
|
| 430 | + * @throws NotImplemented |
|
| 431 | + * @throws ServiceUnavailable |
|
| 432 | + */ |
|
| 433 | + private function createFileChunked($data) { |
|
| 434 | + list($path, $name) = \Sabre\Uri\split($this->path); |
|
| 435 | + |
|
| 436 | + $info = \OC_FileChunking::decodeName($name); |
|
| 437 | + if (empty($info)) { |
|
| 438 | + throw new NotImplemented('Invalid chunk name'); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $chunk_handler = new \OC_FileChunking($info); |
|
| 442 | + $bytesWritten = $chunk_handler->store($info['index'], $data); |
|
| 443 | + |
|
| 444 | + //detect aborted upload |
|
| 445 | + if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
| 446 | + if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
| 447 | + $expected = (int) $_SERVER['CONTENT_LENGTH']; |
|
| 448 | + if ($bytesWritten !== $expected) { |
|
| 449 | + $chunk_handler->remove($info['index']); |
|
| 450 | + throw new BadRequest( |
|
| 451 | + 'expected filesize ' . $expected . ' got ' . $bytesWritten); |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + if ($chunk_handler->isComplete()) { |
|
| 457 | + /** @var Storage $storage */ |
|
| 458 | + list($storage,) = $this->fileView->resolvePath($path); |
|
| 459 | + $needsPartFile = $storage->needsPartFile(); |
|
| 460 | + $partFile = null; |
|
| 461 | + |
|
| 462 | + $targetPath = $path . '/' . $info['name']; |
|
| 463 | + /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 464 | + list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath); |
|
| 465 | + |
|
| 466 | + $exists = $this->fileView->file_exists($targetPath); |
|
| 467 | + |
|
| 468 | + try { |
|
| 469 | + $this->fileView->lockFile($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 470 | + |
|
| 471 | + $this->emitPreHooks($exists, $targetPath); |
|
| 472 | + $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_EXCLUSIVE); |
|
| 473 | + /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 474 | + list($targetStorage, $targetInternalPath) = $this->fileView->resolvePath($targetPath); |
|
| 475 | + |
|
| 476 | + if ($needsPartFile) { |
|
| 477 | + // we first assembly the target file as a part file |
|
| 478 | + $partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part'; |
|
| 479 | + /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 480 | + list($partStorage, $partInternalPath) = $this->fileView->resolvePath($partFile); |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + $chunk_handler->file_assemble($partStorage, $partInternalPath); |
|
| 484 | + |
|
| 485 | + // here is the final atomic rename |
|
| 486 | + $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath); |
|
| 487 | + $fileExists = $targetStorage->file_exists($targetInternalPath); |
|
| 488 | + if ($renameOkay === false || $fileExists === false) { |
|
| 489 | + \OC::$server->getLogger()->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']); |
|
| 490 | + // only delete if an error occurred and the target file was already created |
|
| 491 | + if ($fileExists) { |
|
| 492 | + // set to null to avoid double-deletion when handling exception |
|
| 493 | + // stray part file |
|
| 494 | + $partFile = null; |
|
| 495 | + $targetStorage->unlink($targetInternalPath); |
|
| 496 | + } |
|
| 497 | + $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 498 | + throw new Exception('Could not rename part file assembled from chunks'); |
|
| 499 | + } |
|
| 500 | + } else { |
|
| 501 | + // assemble directly into the final file |
|
| 502 | + $chunk_handler->file_assemble($targetStorage, $targetInternalPath); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // allow sync clients to send the mtime along in a header |
|
| 506 | + if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
| 507 | + $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
| 508 | + if ($targetStorage->touch($targetInternalPath, $mtime)) { |
|
| 509 | + $this->header('X-OC-MTime: accepted'); |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + // since we skipped the view we need to scan and emit the hooks ourselves |
|
| 514 | + $targetStorage->getUpdater()->update($targetInternalPath); |
|
| 515 | + |
|
| 516 | + $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 517 | + |
|
| 518 | + $this->emitPostHooks($exists, $targetPath); |
|
| 519 | + |
|
| 520 | + // FIXME: should call refreshInfo but can't because $this->path is not the of the final file |
|
| 521 | + $info = $this->fileView->getFileInfo($targetPath); |
|
| 522 | + |
|
| 523 | + if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
| 524 | + $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
| 525 | + $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); |
|
| 526 | + } else if ($info->getChecksum() !== null && $info->getChecksum() !== '') { |
|
| 527 | + $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 531 | + |
|
| 532 | + return $info->getEtag(); |
|
| 533 | + } catch (\Exception $e) { |
|
| 534 | + if ($partFile !== null) { |
|
| 535 | + $targetStorage->unlink($targetInternalPath); |
|
| 536 | + } |
|
| 537 | + $this->convertToSabreException($e); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + return null; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Convert the given exception to a SabreException instance |
|
| 546 | + * |
|
| 547 | + * @param \Exception $e |
|
| 548 | + * |
|
| 549 | + * @throws \Sabre\DAV\Exception |
|
| 550 | + */ |
|
| 551 | + private function convertToSabreException(\Exception $e) { |
|
| 552 | + if ($e instanceof \Sabre\DAV\Exception) { |
|
| 553 | + throw $e; |
|
| 554 | + } |
|
| 555 | + if ($e instanceof NotPermittedException) { |
|
| 556 | + // a more general case - due to whatever reason the content could not be written |
|
| 557 | + throw new Forbidden($e->getMessage(), 0, $e); |
|
| 558 | + } |
|
| 559 | + if ($e instanceof ForbiddenException) { |
|
| 560 | + // the path for the file was forbidden |
|
| 561 | + throw new DAVForbiddenException($e->getMessage(), $e->getRetry(), $e); |
|
| 562 | + } |
|
| 563 | + if ($e instanceof EntityTooLargeException) { |
|
| 564 | + // the file is too big to be stored |
|
| 565 | + throw new EntityTooLarge($e->getMessage(), 0, $e); |
|
| 566 | + } |
|
| 567 | + if ($e instanceof InvalidContentException) { |
|
| 568 | + // the file content is not permitted |
|
| 569 | + throw new UnsupportedMediaType($e->getMessage(), 0, $e); |
|
| 570 | + } |
|
| 571 | + if ($e instanceof InvalidPathException) { |
|
| 572 | + // the path for the file was not valid |
|
| 573 | + // TODO: find proper http status code for this case |
|
| 574 | + throw new Forbidden($e->getMessage(), 0, $e); |
|
| 575 | + } |
|
| 576 | + if ($e instanceof LockedException || $e instanceof LockNotAcquiredException) { |
|
| 577 | + // the file is currently being written to by another process |
|
| 578 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 579 | + } |
|
| 580 | + if ($e instanceof GenericEncryptionException) { |
|
| 581 | + // returning 503 will allow retry of the operation at a later point in time |
|
| 582 | + throw new ServiceUnavailable('Encryption not ready: ' . $e->getMessage(), 0, $e); |
|
| 583 | + } |
|
| 584 | + if ($e instanceof StorageNotAvailableException) { |
|
| 585 | + throw new ServiceUnavailable('Failed to write file contents: ' . $e->getMessage(), 0, $e); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * Get the checksum for this file |
|
| 593 | + * |
|
| 594 | + * @return string |
|
| 595 | + */ |
|
| 596 | + public function getChecksum() { |
|
| 597 | + return $this->info->getChecksum(); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + protected function header($string) { |
|
| 601 | + \header($string); |
|
| 602 | + } |
|
| 603 | 603 | } |
@@ -73,7 +73,7 @@ |
||
| 73 | 73 | unset($results['exact']); |
| 74 | 74 | $results = array_merge_recursive($exactMatches, $results); |
| 75 | 75 | |
| 76 | - if($sorter !== null) { |
|
| 76 | + if ($sorter !== null) { |
|
| 77 | 77 | $sorters = array_reverse(explode('|', $sorter)); |
| 78 | 78 | $this->autoCompleteManager->runSorters($sorters, $results, [ |
| 79 | 79 | 'itemType' => $itemType, |
@@ -31,69 +31,69 @@ |
||
| 31 | 31 | use OCP\Share; |
| 32 | 32 | |
| 33 | 33 | class AutoCompleteController extends Controller { |
| 34 | - /** @var ISearch */ |
|
| 35 | - private $collaboratorSearch; |
|
| 36 | - /** @var IManager */ |
|
| 37 | - private $autoCompleteManager; |
|
| 34 | + /** @var ISearch */ |
|
| 35 | + private $collaboratorSearch; |
|
| 36 | + /** @var IManager */ |
|
| 37 | + private $autoCompleteManager; |
|
| 38 | 38 | |
| 39 | - public function __construct( |
|
| 40 | - $appName, |
|
| 41 | - IRequest $request, |
|
| 42 | - ISearch $collaboratorSearch, |
|
| 43 | - IManager $autoCompleteManager |
|
| 44 | - ) { |
|
| 45 | - parent::__construct($appName, $request); |
|
| 39 | + public function __construct( |
|
| 40 | + $appName, |
|
| 41 | + IRequest $request, |
|
| 42 | + ISearch $collaboratorSearch, |
|
| 43 | + IManager $autoCompleteManager |
|
| 44 | + ) { |
|
| 45 | + parent::__construct($appName, $request); |
|
| 46 | 46 | |
| 47 | - $this->collaboratorSearch = $collaboratorSearch; |
|
| 48 | - $this->autoCompleteManager = $autoCompleteManager; |
|
| 49 | - } |
|
| 47 | + $this->collaboratorSearch = $collaboratorSearch; |
|
| 48 | + $this->autoCompleteManager = $autoCompleteManager; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @NoAdminRequired |
|
| 53 | - * |
|
| 54 | - * @param string $search |
|
| 55 | - * @param string $itemType |
|
| 56 | - * @param string $itemId |
|
| 57 | - * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
| 58 | - * @param array $shareTypes |
|
| 59 | - * @param int $limit |
|
| 60 | - * @return DataResponse |
|
| 61 | - */ |
|
| 62 | - public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10) { |
|
| 63 | - // if enumeration/user listings are disabled, we'll receive an empty |
|
| 64 | - // result from search() – thus nothing else to do here. |
|
| 65 | - list($results,) = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
| 51 | + /** |
|
| 52 | + * @NoAdminRequired |
|
| 53 | + * |
|
| 54 | + * @param string $search |
|
| 55 | + * @param string $itemType |
|
| 56 | + * @param string $itemId |
|
| 57 | + * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" |
|
| 58 | + * @param array $shareTypes |
|
| 59 | + * @param int $limit |
|
| 60 | + * @return DataResponse |
|
| 61 | + */ |
|
| 62 | + public function get($search, $itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER], $limit = 10) { |
|
| 63 | + // if enumeration/user listings are disabled, we'll receive an empty |
|
| 64 | + // result from search() – thus nothing else to do here. |
|
| 65 | + list($results,) = $this->collaboratorSearch->search($search, $shareTypes, false, $limit, 0); |
|
| 66 | 66 | |
| 67 | - $exactMatches = $results['exact']; |
|
| 68 | - unset($results['exact']); |
|
| 69 | - $results = array_merge_recursive($exactMatches, $results); |
|
| 67 | + $exactMatches = $results['exact']; |
|
| 68 | + unset($results['exact']); |
|
| 69 | + $results = array_merge_recursive($exactMatches, $results); |
|
| 70 | 70 | |
| 71 | - if($sorter !== null) { |
|
| 72 | - $sorters = array_reverse(explode('|', $sorter)); |
|
| 73 | - $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
| 74 | - 'itemType' => $itemType, |
|
| 75 | - 'itemId' => $itemId, |
|
| 76 | - ]); |
|
| 77 | - } |
|
| 71 | + if($sorter !== null) { |
|
| 72 | + $sorters = array_reverse(explode('|', $sorter)); |
|
| 73 | + $this->autoCompleteManager->runSorters($sorters, $results, [ |
|
| 74 | + 'itemType' => $itemType, |
|
| 75 | + 'itemId' => $itemId, |
|
| 76 | + ]); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - // transform to expected format |
|
| 80 | - $results = $this->prepareResultArray($results); |
|
| 79 | + // transform to expected format |
|
| 80 | + $results = $this->prepareResultArray($results); |
|
| 81 | 81 | |
| 82 | - return new DataResponse($results); |
|
| 83 | - } |
|
| 82 | + return new DataResponse($results); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | - protected function prepareResultArray(array $results) { |
|
| 87 | - $output = []; |
|
| 88 | - foreach ($results as $type => $subResult) { |
|
| 89 | - foreach ($subResult as $result) { |
|
| 90 | - $output[] = [ |
|
| 91 | - 'id' => $result['value']['shareWith'], |
|
| 92 | - 'label' => $result['label'], |
|
| 93 | - 'source' => $type, |
|
| 94 | - ]; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - return $output; |
|
| 98 | - } |
|
| 86 | + protected function prepareResultArray(array $results) { |
|
| 87 | + $output = []; |
|
| 88 | + foreach ($results as $type => $subResult) { |
|
| 89 | + foreach ($subResult as $result) { |
|
| 90 | + $output[] = [ |
|
| 91 | + 'id' => $result['value']['shareWith'], |
|
| 92 | + 'label' => $result['label'], |
|
| 93 | + 'source' => $type, |
|
| 94 | + ]; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + return $output; |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -33,58 +33,58 @@ |
||
| 33 | 33 | |
| 34 | 34 | class MaintenancePlugin extends ServerPlugin { |
| 35 | 35 | |
| 36 | - /** @var IConfig */ |
|
| 37 | - private $config; |
|
| 36 | + /** @var IConfig */ |
|
| 37 | + private $config; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Reference to main server object |
|
| 41 | - * |
|
| 42 | - * @var Server |
|
| 43 | - */ |
|
| 44 | - private $server; |
|
| 39 | + /** |
|
| 40 | + * Reference to main server object |
|
| 41 | + * |
|
| 42 | + * @var Server |
|
| 43 | + */ |
|
| 44 | + private $server; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param IConfig $config |
|
| 48 | - */ |
|
| 49 | - public function __construct(IConfig $config = null) { |
|
| 50 | - $this->config = $config; |
|
| 51 | - if (is_null($config)) { |
|
| 52 | - $this->config = \OC::$server->getConfig(); |
|
| 53 | - } |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * @param IConfig $config |
|
| 48 | + */ |
|
| 49 | + public function __construct(IConfig $config = null) { |
|
| 50 | + $this->config = $config; |
|
| 51 | + if (is_null($config)) { |
|
| 52 | + $this->config = \OC::$server->getConfig(); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * This initializes the plugin. |
|
| 59 | - * |
|
| 60 | - * This function is called by \Sabre\DAV\Server, after |
|
| 61 | - * addPlugin is called. |
|
| 62 | - * |
|
| 63 | - * This method should set up the required event subscriptions. |
|
| 64 | - * |
|
| 65 | - * @param \Sabre\DAV\Server $server |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 69 | - $this->server = $server; |
|
| 70 | - $this->server->on('beforeMethod', array($this, 'checkMaintenanceMode'), 1); |
|
| 71 | - } |
|
| 57 | + /** |
|
| 58 | + * This initializes the plugin. |
|
| 59 | + * |
|
| 60 | + * This function is called by \Sabre\DAV\Server, after |
|
| 61 | + * addPlugin is called. |
|
| 62 | + * |
|
| 63 | + * This method should set up the required event subscriptions. |
|
| 64 | + * |
|
| 65 | + * @param \Sabre\DAV\Server $server |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 69 | + $this->server = $server; |
|
| 70 | + $this->server->on('beforeMethod', array($this, 'checkMaintenanceMode'), 1); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * This method is called before any HTTP method and returns http status code 503 |
|
| 75 | - * in case the system is in maintenance mode. |
|
| 76 | - * |
|
| 77 | - * @throws ServiceUnavailable |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public function checkMaintenanceMode() { |
|
| 81 | - if ($this->config->getSystemValue('maintenance', false)) { |
|
| 82 | - throw new ServiceUnavailable('System in maintenance mode.'); |
|
| 83 | - } |
|
| 84 | - if (Util::needUpgrade()) { |
|
| 85 | - throw new ServiceUnavailable('Upgrade needed'); |
|
| 86 | - } |
|
| 73 | + /** |
|
| 74 | + * This method is called before any HTTP method and returns http status code 503 |
|
| 75 | + * in case the system is in maintenance mode. |
|
| 76 | + * |
|
| 77 | + * @throws ServiceUnavailable |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public function checkMaintenanceMode() { |
|
| 81 | + if ($this->config->getSystemValue('maintenance', false)) { |
|
| 82 | + throw new ServiceUnavailable('System in maintenance mode.'); |
|
| 83 | + } |
|
| 84 | + if (Util::needUpgrade()) { |
|
| 85 | + throw new ServiceUnavailable('Upgrade needed'); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - return true; |
|
| 89 | - } |
|
| 88 | + return true; |
|
| 89 | + } |
|
| 90 | 90 | } |