@@ -37,86 +37,86 @@ |
||
| 37 | 37 | |
| 38 | 38 | class RootCollection extends SimpleCollection { |
| 39 | 39 | |
| 40 | - public function __construct() { |
|
| 41 | - $config = \OC::$server->getConfig(); |
|
| 42 | - $random = \OC::$server->getSecureRandom(); |
|
| 43 | - $userManager = \OC::$server->getUserManager(); |
|
| 44 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 45 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 46 | - $userPrincipalBackend = new Principal( |
|
| 47 | - $userManager, |
|
| 48 | - \OC::$server->getGroupManager() |
|
| 49 | - ); |
|
| 50 | - $groupPrincipalBackend = new GroupPrincipalBackend( |
|
| 51 | - \OC::$server->getGroupManager() |
|
| 52 | - ); |
|
| 53 | - // as soon as debug mode is enabled we allow listing of principals |
|
| 54 | - $disableListing = !$config->getSystemValue('debug', false); |
|
| 40 | + public function __construct() { |
|
| 41 | + $config = \OC::$server->getConfig(); |
|
| 42 | + $random = \OC::$server->getSecureRandom(); |
|
| 43 | + $userManager = \OC::$server->getUserManager(); |
|
| 44 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 45 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 46 | + $userPrincipalBackend = new Principal( |
|
| 47 | + $userManager, |
|
| 48 | + \OC::$server->getGroupManager() |
|
| 49 | + ); |
|
| 50 | + $groupPrincipalBackend = new GroupPrincipalBackend( |
|
| 51 | + \OC::$server->getGroupManager() |
|
| 52 | + ); |
|
| 53 | + // as soon as debug mode is enabled we allow listing of principals |
|
| 54 | + $disableListing = !$config->getSystemValue('debug', false); |
|
| 55 | 55 | |
| 56 | - // setup the first level of the dav tree |
|
| 57 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 58 | - $userPrincipals->disableListing = $disableListing; |
|
| 59 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 60 | - $groupPrincipals->disableListing = $disableListing; |
|
| 61 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 62 | - $systemPrincipals->disableListing = $disableListing; |
|
| 63 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 64 | - $filesCollection->disableListing = $disableListing; |
|
| 65 | - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $random, $dispatcher); |
|
| 66 | - $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 67 | - $calendarRoot->disableListing = $disableListing; |
|
| 68 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
|
| 69 | - $publicCalendarRoot->disableListing = $disableListing; |
|
| 56 | + // setup the first level of the dav tree |
|
| 57 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 58 | + $userPrincipals->disableListing = $disableListing; |
|
| 59 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 60 | + $groupPrincipals->disableListing = $disableListing; |
|
| 61 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 62 | + $systemPrincipals->disableListing = $disableListing; |
|
| 63 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 64 | + $filesCollection->disableListing = $disableListing; |
|
| 65 | + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $random, $dispatcher); |
|
| 66 | + $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 67 | + $calendarRoot->disableListing = $disableListing; |
|
| 68 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
|
| 69 | + $publicCalendarRoot->disableListing = $disableListing; |
|
| 70 | 70 | |
| 71 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 72 | - \OC::$server->getSystemTagManager(), |
|
| 73 | - \OC::$server->getUserSession(), |
|
| 74 | - \OC::$server->getGroupManager() |
|
| 75 | - ); |
|
| 76 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 77 | - \OC::$server->getSystemTagManager(), |
|
| 78 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 79 | - \OC::$server->getUserSession(), |
|
| 80 | - \OC::$server->getGroupManager(), |
|
| 81 | - \OC::$server->getEventDispatcher() |
|
| 82 | - ); |
|
| 83 | - $commentsCollection = new Comments\RootCollection( |
|
| 84 | - \OC::$server->getCommentsManager(), |
|
| 85 | - \OC::$server->getUserManager(), |
|
| 86 | - \OC::$server->getUserSession(), |
|
| 87 | - \OC::$server->getEventDispatcher(), |
|
| 88 | - \OC::$server->getLogger() |
|
| 89 | - ); |
|
| 71 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 72 | + \OC::$server->getSystemTagManager(), |
|
| 73 | + \OC::$server->getUserSession(), |
|
| 74 | + \OC::$server->getGroupManager() |
|
| 75 | + ); |
|
| 76 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 77 | + \OC::$server->getSystemTagManager(), |
|
| 78 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 79 | + \OC::$server->getUserSession(), |
|
| 80 | + \OC::$server->getGroupManager(), |
|
| 81 | + \OC::$server->getEventDispatcher() |
|
| 82 | + ); |
|
| 83 | + $commentsCollection = new Comments\RootCollection( |
|
| 84 | + \OC::$server->getCommentsManager(), |
|
| 85 | + \OC::$server->getUserManager(), |
|
| 86 | + \OC::$server->getUserSession(), |
|
| 87 | + \OC::$server->getEventDispatcher(), |
|
| 88 | + \OC::$server->getLogger() |
|
| 89 | + ); |
|
| 90 | 90 | |
| 91 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 92 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 93 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
| 91 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 92 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 93 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
| 94 | 94 | |
| 95 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 96 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 97 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
| 95 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 96 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 97 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
| 98 | 98 | |
| 99 | - $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 100 | - $uploadCollection->disableListing = $disableListing; |
|
| 99 | + $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 100 | + $uploadCollection->disableListing = $disableListing; |
|
| 101 | 101 | |
| 102 | - $children = [ |
|
| 103 | - new SimpleCollection('principals', [ |
|
| 104 | - $userPrincipals, |
|
| 105 | - $groupPrincipals, |
|
| 106 | - $systemPrincipals]), |
|
| 107 | - $filesCollection, |
|
| 108 | - $calendarRoot, |
|
| 109 | - $publicCalendarRoot, |
|
| 110 | - new SimpleCollection('addressbooks', [ |
|
| 111 | - $usersAddressBookRoot, |
|
| 112 | - $systemAddressBookRoot]), |
|
| 113 | - $systemTagCollection, |
|
| 114 | - $systemTagRelationsCollection, |
|
| 115 | - $commentsCollection, |
|
| 116 | - $uploadCollection, |
|
| 117 | - ]; |
|
| 102 | + $children = [ |
|
| 103 | + new SimpleCollection('principals', [ |
|
| 104 | + $userPrincipals, |
|
| 105 | + $groupPrincipals, |
|
| 106 | + $systemPrincipals]), |
|
| 107 | + $filesCollection, |
|
| 108 | + $calendarRoot, |
|
| 109 | + $publicCalendarRoot, |
|
| 110 | + new SimpleCollection('addressbooks', [ |
|
| 111 | + $usersAddressBookRoot, |
|
| 112 | + $systemAddressBookRoot]), |
|
| 113 | + $systemTagCollection, |
|
| 114 | + $systemTagRelationsCollection, |
|
| 115 | + $commentsCollection, |
|
| 116 | + $uploadCollection, |
|
| 117 | + ]; |
|
| 118 | 118 | |
| 119 | - parent::__construct('root', $children); |
|
| 120 | - } |
|
| 119 | + parent::__construct('root', $children); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | } |
@@ -27,33 +27,33 @@ |
||
| 27 | 27 | |
| 28 | 28 | class FilesHome extends Directory { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - private $principalInfo; |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + private $principalInfo; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * FilesHome constructor. |
|
| 37 | - * |
|
| 38 | - * @param array $principalInfo |
|
| 39 | - */ |
|
| 40 | - public function __construct($principalInfo) { |
|
| 41 | - $this->principalInfo = $principalInfo; |
|
| 42 | - $view = \OC\Files\Filesystem::getView(); |
|
| 43 | - $rootInfo = $view->getFileInfo(''); |
|
| 44 | - parent::__construct($view, $rootInfo); |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * FilesHome constructor. |
|
| 37 | + * |
|
| 38 | + * @param array $principalInfo |
|
| 39 | + */ |
|
| 40 | + public function __construct($principalInfo) { |
|
| 41 | + $this->principalInfo = $principalInfo; |
|
| 42 | + $view = \OC\Files\Filesystem::getView(); |
|
| 43 | + $rootInfo = $view->getFileInfo(''); |
|
| 44 | + parent::__construct($view, $rootInfo); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - function delete() { |
|
| 48 | - throw new Forbidden('Permission denied to delete home folder'); |
|
| 49 | - } |
|
| 47 | + function delete() { |
|
| 48 | + throw new Forbidden('Permission denied to delete home folder'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - function getName() { |
|
| 52 | - list(,$name) = URLUtil::splitPath($this->principalInfo['uri']); |
|
| 53 | - return $name; |
|
| 54 | - } |
|
| 51 | + function getName() { |
|
| 52 | + list(,$name) = URLUtil::splitPath($this->principalInfo['uri']); |
|
| 53 | + return $name; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - function setName($name) { |
|
| 57 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 58 | - } |
|
| 56 | + function setName($name) { |
|
| 57 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -31,78 +31,78 @@ |
||
| 31 | 31 | use Sabre\DAV\ServerPlugin; |
| 32 | 32 | |
| 33 | 33 | class BrowserErrorPagePlugin extends ServerPlugin { |
| 34 | - /** @var Server */ |
|
| 35 | - private $server; |
|
| 34 | + /** @var Server */ |
|
| 35 | + private $server; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * This initializes the plugin. |
|
| 39 | - * |
|
| 40 | - * This function is called by Sabre\DAV\Server, after |
|
| 41 | - * addPlugin is called. |
|
| 42 | - * |
|
| 43 | - * This method should set up the required event subscriptions. |
|
| 44 | - * |
|
| 45 | - * @param Server $server |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - function initialize(Server $server) { |
|
| 49 | - $this->server = $server; |
|
| 50 | - $server->on('exception', array($this, 'logException'), 1000); |
|
| 51 | - } |
|
| 37 | + /** |
|
| 38 | + * This initializes the plugin. |
|
| 39 | + * |
|
| 40 | + * This function is called by Sabre\DAV\Server, after |
|
| 41 | + * addPlugin is called. |
|
| 42 | + * |
|
| 43 | + * This method should set up the required event subscriptions. |
|
| 44 | + * |
|
| 45 | + * @param Server $server |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + function initialize(Server $server) { |
|
| 49 | + $this->server = $server; |
|
| 50 | + $server->on('exception', array($this, 'logException'), 1000); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param IRequest $request |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public static function isBrowserRequest(IRequest $request) { |
|
| 58 | - if ($request->getMethod() !== 'GET') { |
|
| 59 | - return false; |
|
| 60 | - } |
|
| 61 | - return $request->isUserAgent([ |
|
| 62 | - Request::USER_AGENT_IE, |
|
| 63 | - Request::USER_AGENT_MS_EDGE, |
|
| 64 | - Request::USER_AGENT_CHROME, |
|
| 65 | - Request::USER_AGENT_FIREFOX, |
|
| 66 | - Request::USER_AGENT_SAFARI, |
|
| 67 | - ]); |
|
| 68 | - } |
|
| 53 | + /** |
|
| 54 | + * @param IRequest $request |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public static function isBrowserRequest(IRequest $request) { |
|
| 58 | + if ($request->getMethod() !== 'GET') { |
|
| 59 | + return false; |
|
| 60 | + } |
|
| 61 | + return $request->isUserAgent([ |
|
| 62 | + Request::USER_AGENT_IE, |
|
| 63 | + Request::USER_AGENT_MS_EDGE, |
|
| 64 | + Request::USER_AGENT_CHROME, |
|
| 65 | + Request::USER_AGENT_FIREFOX, |
|
| 66 | + Request::USER_AGENT_SAFARI, |
|
| 67 | + ]); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @param \Exception $ex |
|
| 72 | - */ |
|
| 73 | - public function logException(\Exception $ex) { |
|
| 74 | - if ($ex instanceof Exception) { |
|
| 75 | - $httpCode = $ex->getHTTPCode(); |
|
| 76 | - $headers = $ex->getHTTPHeaders($this->server); |
|
| 77 | - } else { |
|
| 78 | - $httpCode = 500; |
|
| 79 | - $headers = []; |
|
| 80 | - } |
|
| 81 | - $this->server->httpResponse->addHeaders($headers); |
|
| 82 | - $this->server->httpResponse->setStatus($httpCode); |
|
| 83 | - $body = $this->generateBody(); |
|
| 84 | - $this->server->httpResponse->setBody($body); |
|
| 85 | - $this->sendResponse(); |
|
| 86 | - } |
|
| 70 | + /** |
|
| 71 | + * @param \Exception $ex |
|
| 72 | + */ |
|
| 73 | + public function logException(\Exception $ex) { |
|
| 74 | + if ($ex instanceof Exception) { |
|
| 75 | + $httpCode = $ex->getHTTPCode(); |
|
| 76 | + $headers = $ex->getHTTPHeaders($this->server); |
|
| 77 | + } else { |
|
| 78 | + $httpCode = 500; |
|
| 79 | + $headers = []; |
|
| 80 | + } |
|
| 81 | + $this->server->httpResponse->addHeaders($headers); |
|
| 82 | + $this->server->httpResponse->setStatus($httpCode); |
|
| 83 | + $body = $this->generateBody(); |
|
| 84 | + $this->server->httpResponse->setBody($body); |
|
| 85 | + $this->sendResponse(); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @codeCoverageIgnore |
|
| 90 | - * @return bool|string |
|
| 91 | - */ |
|
| 92 | - public function generateBody() { |
|
| 93 | - $request = \OC::$server->getRequest(); |
|
| 94 | - $content = new OC_Template('dav', 'exception', 'guest'); |
|
| 95 | - $content->assign('title', $this->server->httpResponse->getStatusText()); |
|
| 96 | - $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
| 97 | - $content->assign('requestID', $request->getId()); |
|
| 98 | - return $content->fetchPage(); |
|
| 99 | - } |
|
| 88 | + /** |
|
| 89 | + * @codeCoverageIgnore |
|
| 90 | + * @return bool|string |
|
| 91 | + */ |
|
| 92 | + public function generateBody() { |
|
| 93 | + $request = \OC::$server->getRequest(); |
|
| 94 | + $content = new OC_Template('dav', 'exception', 'guest'); |
|
| 95 | + $content->assign('title', $this->server->httpResponse->getStatusText()); |
|
| 96 | + $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
| 97 | + $content->assign('requestID', $request->getId()); |
|
| 98 | + return $content->fetchPage(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @codeCoverageIgnore |
|
| 103 | - */ |
|
| 104 | - public function sendResponse() { |
|
| 105 | - $this->server->sapi->sendResponse($this->server->httpResponse); |
|
| 106 | - exit(); |
|
| 107 | - } |
|
| 101 | + /** |
|
| 102 | + * @codeCoverageIgnore |
|
| 103 | + */ |
|
| 104 | + public function sendResponse() { |
|
| 105 | + $this->server->sapi->sendResponse($this->server->httpResponse); |
|
| 106 | + exit(); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -28,30 +28,30 @@ |
||
| 28 | 28 | |
| 29 | 29 | class RootCollection extends AbstractPrincipalCollection { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * This method returns a node for a principal. |
|
| 33 | - * |
|
| 34 | - * The passed array contains principal information, and is guaranteed to |
|
| 35 | - * at least contain a uri item. Other properties may or may not be |
|
| 36 | - * supplied by the authentication backend. |
|
| 37 | - * |
|
| 38 | - * @param array $principalInfo |
|
| 39 | - * @return INode |
|
| 40 | - */ |
|
| 41 | - function getChildForPrincipal(array $principalInfo) { |
|
| 42 | - list(,$name) = URLUtil::splitPath($principalInfo['uri']); |
|
| 43 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 44 | - if (is_null($user) || $name !== $user->getUID()) { |
|
| 45 | - // a user is only allowed to see their own home contents, so in case another collection |
|
| 46 | - // is accessed, we return a simple empty collection for now |
|
| 47 | - // in the future this could be considered to be used for accessing shared files |
|
| 48 | - return new SimpleCollection($name); |
|
| 49 | - } |
|
| 50 | - return new FilesHome($principalInfo); |
|
| 51 | - } |
|
| 31 | + /** |
|
| 32 | + * This method returns a node for a principal. |
|
| 33 | + * |
|
| 34 | + * The passed array contains principal information, and is guaranteed to |
|
| 35 | + * at least contain a uri item. Other properties may or may not be |
|
| 36 | + * supplied by the authentication backend. |
|
| 37 | + * |
|
| 38 | + * @param array $principalInfo |
|
| 39 | + * @return INode |
|
| 40 | + */ |
|
| 41 | + function getChildForPrincipal(array $principalInfo) { |
|
| 42 | + list(,$name) = URLUtil::splitPath($principalInfo['uri']); |
|
| 43 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 44 | + if (is_null($user) || $name !== $user->getUID()) { |
|
| 45 | + // a user is only allowed to see their own home contents, so in case another collection |
|
| 46 | + // is accessed, we return a simple empty collection for now |
|
| 47 | + // in the future this could be considered to be used for accessing shared files |
|
| 48 | + return new SimpleCollection($name); |
|
| 49 | + } |
|
| 50 | + return new FilesHome($principalInfo); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - function getName() { |
|
| 54 | - return 'files'; |
|
| 55 | - } |
|
| 53 | + function getName() { |
|
| 54 | + return 'files'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | } |
@@ -32,238 +32,238 @@ |
||
| 32 | 32 | |
| 33 | 33 | class CustomPropertiesBackend implements BackendInterface { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Ignored properties |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - private $ignoredProperties = array( |
|
| 41 | - '{DAV:}getcontentlength', |
|
| 42 | - '{DAV:}getcontenttype', |
|
| 43 | - '{DAV:}getetag', |
|
| 44 | - '{DAV:}quota-used-bytes', |
|
| 45 | - '{DAV:}quota-available-bytes', |
|
| 46 | - '{http://owncloud.org/ns}permissions', |
|
| 47 | - '{http://owncloud.org/ns}downloadURL', |
|
| 48 | - '{http://owncloud.org/ns}dDC', |
|
| 49 | - '{http://owncloud.org/ns}size', |
|
| 50 | - ); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var Tree |
|
| 54 | - */ |
|
| 55 | - private $tree; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var IDBConnection |
|
| 59 | - */ |
|
| 60 | - private $connection; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var string |
|
| 64 | - */ |
|
| 65 | - private $user; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Properties cache |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - private $cache = []; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param Tree $tree node tree |
|
| 76 | - * @param IDBConnection $connection database connection |
|
| 77 | - * @param IUser $user owner of the tree and properties |
|
| 78 | - */ |
|
| 79 | - public function __construct( |
|
| 80 | - Tree $tree, |
|
| 81 | - IDBConnection $connection, |
|
| 82 | - IUser $user) { |
|
| 83 | - $this->tree = $tree; |
|
| 84 | - $this->connection = $connection; |
|
| 85 | - $this->user = $user->getUID(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Fetches properties for a path. |
|
| 90 | - * |
|
| 91 | - * @param string $path |
|
| 92 | - * @param PropFind $propFind |
|
| 93 | - * @return void |
|
| 94 | - */ |
|
| 95 | - public function propFind($path, PropFind $propFind) { |
|
| 96 | - |
|
| 97 | - $requestedProps = $propFind->get404Properties(); |
|
| 98 | - |
|
| 99 | - // these might appear |
|
| 100 | - $requestedProps = array_diff( |
|
| 101 | - $requestedProps, |
|
| 102 | - $this->ignoredProperties |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - if (empty($requestedProps)) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $props = $this->getProperties($path, $requestedProps); |
|
| 110 | - foreach ($props as $propName => $propValue) { |
|
| 111 | - $propFind->set($propName, $propValue); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Updates properties for a path |
|
| 117 | - * |
|
| 118 | - * @param string $path |
|
| 119 | - * @param PropPatch $propPatch |
|
| 120 | - * |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - public function propPatch($path, PropPatch $propPatch) { |
|
| 124 | - $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
| 125 | - return $this->updateProperties($path, $changedProps); |
|
| 126 | - }); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * This method is called after a node is deleted. |
|
| 131 | - * |
|
| 132 | - * @param string $path path of node for which to delete properties |
|
| 133 | - */ |
|
| 134 | - public function delete($path) { |
|
| 135 | - $statement = $this->connection->prepare( |
|
| 136 | - 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
| 137 | - ); |
|
| 138 | - $statement->execute(array($this->user, $path)); |
|
| 139 | - $statement->closeCursor(); |
|
| 140 | - |
|
| 141 | - unset($this->cache[$path]); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * This method is called after a successful MOVE |
|
| 146 | - * |
|
| 147 | - * @param string $source |
|
| 148 | - * @param string $destination |
|
| 149 | - * |
|
| 150 | - * @return void |
|
| 151 | - */ |
|
| 152 | - public function move($source, $destination) { |
|
| 153 | - $statement = $this->connection->prepare( |
|
| 154 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 155 | - ' WHERE `userid` = ? AND `propertypath` = ?' |
|
| 156 | - ); |
|
| 157 | - $statement->execute(array($destination, $this->user, $source)); |
|
| 158 | - $statement->closeCursor(); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Returns a list of properties for this nodes.; |
|
| 163 | - * @param string $path |
|
| 164 | - * @param array $requestedProperties requested properties or empty array for "all" |
|
| 165 | - * @return array |
|
| 166 | - * @note The properties list is a list of propertynames the client |
|
| 167 | - * requested, encoded as xmlnamespace#tagName, for example: |
|
| 168 | - * http://www.example.org/namespace#author If the array is empty, all |
|
| 169 | - * properties should be returned |
|
| 170 | - */ |
|
| 171 | - private function getProperties($path, array $requestedProperties) { |
|
| 172 | - if (isset($this->cache[$path])) { |
|
| 173 | - return $this->cache[$path]; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // TODO: chunking if more than 1000 properties |
|
| 177 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
| 178 | - |
|
| 179 | - $whereValues = array($this->user, $path); |
|
| 180 | - $whereTypes = array(null, null); |
|
| 181 | - |
|
| 182 | - if (!empty($requestedProperties)) { |
|
| 183 | - // request only a subset |
|
| 184 | - $sql .= ' AND `propertyname` in (?)'; |
|
| 185 | - $whereValues[] = $requestedProperties; |
|
| 186 | - $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $result = $this->connection->executeQuery( |
|
| 190 | - $sql, |
|
| 191 | - $whereValues, |
|
| 192 | - $whereTypes |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - $props = []; |
|
| 196 | - while ($row = $result->fetch()) { |
|
| 197 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $result->closeCursor(); |
|
| 201 | - |
|
| 202 | - $this->cache[$path] = $props; |
|
| 203 | - return $props; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Update properties |
|
| 208 | - * |
|
| 209 | - * @param string $path node for which to update properties |
|
| 210 | - * @param array $properties array of properties to update |
|
| 211 | - * |
|
| 212 | - * @return bool |
|
| 213 | - */ |
|
| 214 | - private function updateProperties($path, $properties) { |
|
| 215 | - |
|
| 216 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 217 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 218 | - |
|
| 219 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 220 | - ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
| 221 | - |
|
| 222 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 223 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 224 | - |
|
| 225 | - // TODO: use "insert or update" strategy ? |
|
| 226 | - $existing = $this->getProperties($path, array()); |
|
| 227 | - $this->connection->beginTransaction(); |
|
| 228 | - foreach ($properties as $propertyName => $propertyValue) { |
|
| 229 | - // If it was null, we need to delete the property |
|
| 230 | - if (is_null($propertyValue)) { |
|
| 231 | - if (array_key_exists($propertyName, $existing)) { |
|
| 232 | - $this->connection->executeUpdate($deleteStatement, |
|
| 233 | - array( |
|
| 234 | - $this->user, |
|
| 235 | - $path, |
|
| 236 | - $propertyName |
|
| 237 | - ) |
|
| 238 | - ); |
|
| 239 | - } |
|
| 240 | - } else { |
|
| 241 | - if (!array_key_exists($propertyName, $existing)) { |
|
| 242 | - $this->connection->executeUpdate($insertStatement, |
|
| 243 | - array( |
|
| 244 | - $this->user, |
|
| 245 | - $path, |
|
| 246 | - $propertyName, |
|
| 247 | - $propertyValue |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - } else { |
|
| 251 | - $this->connection->executeUpdate($updateStatement, |
|
| 252 | - array( |
|
| 253 | - $propertyValue, |
|
| 254 | - $this->user, |
|
| 255 | - $path, |
|
| 256 | - $propertyName |
|
| 257 | - ) |
|
| 258 | - ); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - $this->connection->commit(); |
|
| 264 | - unset($this->cache[$path]); |
|
| 265 | - |
|
| 266 | - return true; |
|
| 267 | - } |
|
| 35 | + /** |
|
| 36 | + * Ignored properties |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + private $ignoredProperties = array( |
|
| 41 | + '{DAV:}getcontentlength', |
|
| 42 | + '{DAV:}getcontenttype', |
|
| 43 | + '{DAV:}getetag', |
|
| 44 | + '{DAV:}quota-used-bytes', |
|
| 45 | + '{DAV:}quota-available-bytes', |
|
| 46 | + '{http://owncloud.org/ns}permissions', |
|
| 47 | + '{http://owncloud.org/ns}downloadURL', |
|
| 48 | + '{http://owncloud.org/ns}dDC', |
|
| 49 | + '{http://owncloud.org/ns}size', |
|
| 50 | + ); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var Tree |
|
| 54 | + */ |
|
| 55 | + private $tree; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var IDBConnection |
|
| 59 | + */ |
|
| 60 | + private $connection; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var string |
|
| 64 | + */ |
|
| 65 | + private $user; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Properties cache |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + private $cache = []; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param Tree $tree node tree |
|
| 76 | + * @param IDBConnection $connection database connection |
|
| 77 | + * @param IUser $user owner of the tree and properties |
|
| 78 | + */ |
|
| 79 | + public function __construct( |
|
| 80 | + Tree $tree, |
|
| 81 | + IDBConnection $connection, |
|
| 82 | + IUser $user) { |
|
| 83 | + $this->tree = $tree; |
|
| 84 | + $this->connection = $connection; |
|
| 85 | + $this->user = $user->getUID(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Fetches properties for a path. |
|
| 90 | + * |
|
| 91 | + * @param string $path |
|
| 92 | + * @param PropFind $propFind |
|
| 93 | + * @return void |
|
| 94 | + */ |
|
| 95 | + public function propFind($path, PropFind $propFind) { |
|
| 96 | + |
|
| 97 | + $requestedProps = $propFind->get404Properties(); |
|
| 98 | + |
|
| 99 | + // these might appear |
|
| 100 | + $requestedProps = array_diff( |
|
| 101 | + $requestedProps, |
|
| 102 | + $this->ignoredProperties |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + if (empty($requestedProps)) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $props = $this->getProperties($path, $requestedProps); |
|
| 110 | + foreach ($props as $propName => $propValue) { |
|
| 111 | + $propFind->set($propName, $propValue); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Updates properties for a path |
|
| 117 | + * |
|
| 118 | + * @param string $path |
|
| 119 | + * @param PropPatch $propPatch |
|
| 120 | + * |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + public function propPatch($path, PropPatch $propPatch) { |
|
| 124 | + $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
| 125 | + return $this->updateProperties($path, $changedProps); |
|
| 126 | + }); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * This method is called after a node is deleted. |
|
| 131 | + * |
|
| 132 | + * @param string $path path of node for which to delete properties |
|
| 133 | + */ |
|
| 134 | + public function delete($path) { |
|
| 135 | + $statement = $this->connection->prepare( |
|
| 136 | + 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
| 137 | + ); |
|
| 138 | + $statement->execute(array($this->user, $path)); |
|
| 139 | + $statement->closeCursor(); |
|
| 140 | + |
|
| 141 | + unset($this->cache[$path]); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * This method is called after a successful MOVE |
|
| 146 | + * |
|
| 147 | + * @param string $source |
|
| 148 | + * @param string $destination |
|
| 149 | + * |
|
| 150 | + * @return void |
|
| 151 | + */ |
|
| 152 | + public function move($source, $destination) { |
|
| 153 | + $statement = $this->connection->prepare( |
|
| 154 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 155 | + ' WHERE `userid` = ? AND `propertypath` = ?' |
|
| 156 | + ); |
|
| 157 | + $statement->execute(array($destination, $this->user, $source)); |
|
| 158 | + $statement->closeCursor(); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Returns a list of properties for this nodes.; |
|
| 163 | + * @param string $path |
|
| 164 | + * @param array $requestedProperties requested properties or empty array for "all" |
|
| 165 | + * @return array |
|
| 166 | + * @note The properties list is a list of propertynames the client |
|
| 167 | + * requested, encoded as xmlnamespace#tagName, for example: |
|
| 168 | + * http://www.example.org/namespace#author If the array is empty, all |
|
| 169 | + * properties should be returned |
|
| 170 | + */ |
|
| 171 | + private function getProperties($path, array $requestedProperties) { |
|
| 172 | + if (isset($this->cache[$path])) { |
|
| 173 | + return $this->cache[$path]; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // TODO: chunking if more than 1000 properties |
|
| 177 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
| 178 | + |
|
| 179 | + $whereValues = array($this->user, $path); |
|
| 180 | + $whereTypes = array(null, null); |
|
| 181 | + |
|
| 182 | + if (!empty($requestedProperties)) { |
|
| 183 | + // request only a subset |
|
| 184 | + $sql .= ' AND `propertyname` in (?)'; |
|
| 185 | + $whereValues[] = $requestedProperties; |
|
| 186 | + $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $result = $this->connection->executeQuery( |
|
| 190 | + $sql, |
|
| 191 | + $whereValues, |
|
| 192 | + $whereTypes |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + $props = []; |
|
| 196 | + while ($row = $result->fetch()) { |
|
| 197 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $result->closeCursor(); |
|
| 201 | + |
|
| 202 | + $this->cache[$path] = $props; |
|
| 203 | + return $props; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Update properties |
|
| 208 | + * |
|
| 209 | + * @param string $path node for which to update properties |
|
| 210 | + * @param array $properties array of properties to update |
|
| 211 | + * |
|
| 212 | + * @return bool |
|
| 213 | + */ |
|
| 214 | + private function updateProperties($path, $properties) { |
|
| 215 | + |
|
| 216 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 217 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 218 | + |
|
| 219 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 220 | + ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
| 221 | + |
|
| 222 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 223 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 224 | + |
|
| 225 | + // TODO: use "insert or update" strategy ? |
|
| 226 | + $existing = $this->getProperties($path, array()); |
|
| 227 | + $this->connection->beginTransaction(); |
|
| 228 | + foreach ($properties as $propertyName => $propertyValue) { |
|
| 229 | + // If it was null, we need to delete the property |
|
| 230 | + if (is_null($propertyValue)) { |
|
| 231 | + if (array_key_exists($propertyName, $existing)) { |
|
| 232 | + $this->connection->executeUpdate($deleteStatement, |
|
| 233 | + array( |
|
| 234 | + $this->user, |
|
| 235 | + $path, |
|
| 236 | + $propertyName |
|
| 237 | + ) |
|
| 238 | + ); |
|
| 239 | + } |
|
| 240 | + } else { |
|
| 241 | + if (!array_key_exists($propertyName, $existing)) { |
|
| 242 | + $this->connection->executeUpdate($insertStatement, |
|
| 243 | + array( |
|
| 244 | + $this->user, |
|
| 245 | + $path, |
|
| 246 | + $propertyName, |
|
| 247 | + $propertyValue |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + } else { |
|
| 251 | + $this->connection->executeUpdate($updateStatement, |
|
| 252 | + array( |
|
| 253 | + $propertyValue, |
|
| 254 | + $this->user, |
|
| 255 | + $path, |
|
| 256 | + $propertyName |
|
| 257 | + ) |
|
| 258 | + ); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + $this->connection->commit(); |
|
| 264 | + unset($this->cache[$path]); |
|
| 265 | + |
|
| 266 | + return true; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | 269 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public function move($source, $destination) { |
| 153 | 153 | $statement = $this->connection->prepare( |
| 154 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 154 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?'. |
|
| 155 | 155 | ' WHERE `userid` = ? AND `propertypath` = ?' |
| 156 | 156 | ); |
| 157 | 157 | $statement->execute(array($destination, $this->user, $source)); |
@@ -213,13 +213,13 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | private function updateProperties($path, $properties) { |
| 215 | 215 | |
| 216 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 216 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`'. |
|
| 217 | 217 | ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
| 218 | 218 | |
| 219 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 219 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`'. |
|
| 220 | 220 | ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
| 221 | 221 | |
| 222 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 222 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?'. |
|
| 223 | 223 | ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
| 224 | 224 | |
| 225 | 225 | // TODO: use "insert or update" strategy ? |
@@ -32,33 +32,33 @@ |
||
| 32 | 32 | * Verify that the public link share is valid |
| 33 | 33 | */ |
| 34 | 34 | class PublicLinkCheckPlugin extends ServerPlugin { |
| 35 | - /** |
|
| 36 | - * @var FileInfo |
|
| 37 | - */ |
|
| 38 | - private $fileInfo; |
|
| 35 | + /** |
|
| 36 | + * @var FileInfo |
|
| 37 | + */ |
|
| 38 | + private $fileInfo; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param FileInfo $fileInfo |
|
| 42 | - */ |
|
| 43 | - public function setFileInfo($fileInfo) { |
|
| 44 | - $this->fileInfo = $fileInfo; |
|
| 45 | - } |
|
| 40 | + /** |
|
| 41 | + * @param FileInfo $fileInfo |
|
| 42 | + */ |
|
| 43 | + public function setFileInfo($fileInfo) { |
|
| 44 | + $this->fileInfo = $fileInfo; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * This initializes the plugin. |
|
| 49 | - * |
|
| 50 | - * @param \Sabre\DAV\Server $server Sabre server |
|
| 51 | - * |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 54 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 55 | - $server->on('beforeMethod', [$this, 'beforeMethod']); |
|
| 56 | - } |
|
| 47 | + /** |
|
| 48 | + * This initializes the plugin. |
|
| 49 | + * |
|
| 50 | + * @param \Sabre\DAV\Server $server Sabre server |
|
| 51 | + * |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 55 | + $server->on('beforeMethod', [$this, 'beforeMethod']); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
| 59 | - // verify that the owner didn't have his share permissions revoked |
|
| 60 | - if ($this->fileInfo && !$this->fileInfo->isShareable()) { |
|
| 61 | - throw new NotFound(); |
|
| 62 | - } |
|
| 63 | - } |
|
| 58 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
| 59 | + // verify that the owner didn't have his share permissions revoked |
|
| 60 | + if ($this->fileInfo && !$this->fileInfo->isShareable()) { |
|
| 61 | + throw new NotFound(); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | $server->on('beforeMethod', [$this, 'beforeMethod']); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
| 58 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
| 59 | 59 | // verify that the owner didn't have his share permissions revoked |
| 60 | 60 | if ($this->fileInfo && !$this->fileInfo->isShareable()) { |
| 61 | 61 | throw new NotFound(); |
@@ -33,52 +33,52 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class FilesDropPlugin extends ServerPlugin { |
| 35 | 35 | |
| 36 | - /** @var View */ |
|
| 37 | - private $view; |
|
| 36 | + /** @var View */ |
|
| 37 | + private $view; |
|
| 38 | 38 | |
| 39 | - /** @var bool */ |
|
| 40 | - private $enabled = false; |
|
| 39 | + /** @var bool */ |
|
| 40 | + private $enabled = false; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param View $view |
|
| 44 | - */ |
|
| 45 | - public function setView($view) { |
|
| 46 | - $this->view = $view; |
|
| 47 | - } |
|
| 42 | + /** |
|
| 43 | + * @param View $view |
|
| 44 | + */ |
|
| 45 | + public function setView($view) { |
|
| 46 | + $this->view = $view; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function enable() { |
|
| 50 | - $this->enabled = true; |
|
| 51 | - } |
|
| 49 | + public function enable() { |
|
| 50 | + $this->enabled = true; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * This initializes the plugin. |
|
| 56 | - * |
|
| 57 | - * @param \Sabre\DAV\Server $server Sabre server |
|
| 58 | - * |
|
| 59 | - * @return void |
|
| 60 | - * @throws MethodNotAllowed |
|
| 61 | - */ |
|
| 62 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 63 | - $server->on('beforeMethod', [$this, 'beforeMethod'], 999); |
|
| 64 | - $this->enabled = false; |
|
| 65 | - } |
|
| 54 | + /** |
|
| 55 | + * This initializes the plugin. |
|
| 56 | + * |
|
| 57 | + * @param \Sabre\DAV\Server $server Sabre server |
|
| 58 | + * |
|
| 59 | + * @return void |
|
| 60 | + * @throws MethodNotAllowed |
|
| 61 | + */ |
|
| 62 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 63 | + $server->on('beforeMethod', [$this, 'beforeMethod'], 999); |
|
| 64 | + $this->enabled = false; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
| 67 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
| 68 | 68 | |
| 69 | - if (!$this->enabled) { |
|
| 70 | - return; |
|
| 71 | - } |
|
| 69 | + if (!$this->enabled) { |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - if ($request->getMethod() !== 'PUT') { |
|
| 74 | - throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
| 75 | - } |
|
| 73 | + if ($request->getMethod() !== 'PUT') { |
|
| 74 | + throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - $path = explode('/', $request->getPath()); |
|
| 78 | - $path = array_pop($path); |
|
| 77 | + $path = explode('/', $request->getPath()); |
|
| 78 | + $path = array_pop($path); |
|
| 79 | 79 | |
| 80 | - $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
| 81 | - $url = $request->getBaseUrl() . $newName; |
|
| 82 | - $request->setUrl($url); |
|
| 83 | - } |
|
| 80 | + $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
| 81 | + $url = $request->getBaseUrl() . $newName; |
|
| 82 | + $request->setUrl($url); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $this->enabled = false; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
| 67 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
| 68 | 68 | |
| 69 | 69 | if (!$this->enabled) { |
| 70 | 70 | return; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $path = array_pop($path); |
| 79 | 79 | |
| 80 | 80 | $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
| 81 | - $url = $request->getBaseUrl() . $newName; |
|
| 81 | + $url = $request->getBaseUrl().$newName; |
|
| 82 | 82 | $request->setUrl($url); |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -28,54 +28,54 @@ |
||
| 28 | 28 | |
| 29 | 29 | class UploadFolder implements ICollection { |
| 30 | 30 | |
| 31 | - private $node; |
|
| 31 | + private $node; |
|
| 32 | 32 | |
| 33 | - function __construct(Directory $node) { |
|
| 34 | - $this->node = $node; |
|
| 35 | - } |
|
| 33 | + function __construct(Directory $node) { |
|
| 34 | + $this->node = $node; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - function createFile($name, $data = null) { |
|
| 38 | - // TODO: verify name - should be a simple number |
|
| 39 | - $this->node->createFile($name, $data); |
|
| 40 | - } |
|
| 37 | + function createFile($name, $data = null) { |
|
| 38 | + // TODO: verify name - should be a simple number |
|
| 39 | + $this->node->createFile($name, $data); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - function createDirectory($name) { |
|
| 43 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 44 | - } |
|
| 42 | + function createDirectory($name) { |
|
| 43 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - function getChild($name) { |
|
| 47 | - if ($name === '.file') { |
|
| 48 | - return new FutureFile($this->node, '.file'); |
|
| 49 | - } |
|
| 50 | - return $this->node->getChild($name); |
|
| 51 | - } |
|
| 46 | + function getChild($name) { |
|
| 47 | + if ($name === '.file') { |
|
| 48 | + return new FutureFile($this->node, '.file'); |
|
| 49 | + } |
|
| 50 | + return $this->node->getChild($name); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - function getChildren() { |
|
| 54 | - $children = $this->node->getChildren(); |
|
| 55 | - $children[] = new FutureFile($this->node, '.file'); |
|
| 56 | - return $children; |
|
| 57 | - } |
|
| 53 | + function getChildren() { |
|
| 54 | + $children = $this->node->getChildren(); |
|
| 55 | + $children[] = new FutureFile($this->node, '.file'); |
|
| 56 | + return $children; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - function childExists($name) { |
|
| 60 | - if ($name === '.file') { |
|
| 61 | - return true; |
|
| 62 | - } |
|
| 63 | - return $this->node->childExists($name); |
|
| 64 | - } |
|
| 59 | + function childExists($name) { |
|
| 60 | + if ($name === '.file') { |
|
| 61 | + return true; |
|
| 62 | + } |
|
| 63 | + return $this->node->childExists($name); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - function delete() { |
|
| 67 | - $this->node->delete(); |
|
| 68 | - } |
|
| 66 | + function delete() { |
|
| 67 | + $this->node->delete(); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - function getName() { |
|
| 71 | - return $this->node->getName(); |
|
| 72 | - } |
|
| 70 | + function getName() { |
|
| 71 | + return $this->node->getName(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - function setName($name) { |
|
| 75 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 76 | - } |
|
| 74 | + function setName($name) { |
|
| 75 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - function getLastModified() { |
|
| 79 | - return $this->node->getLastModified(); |
|
| 80 | - } |
|
| 78 | + function getLastModified() { |
|
| 79 | + return $this->node->getLastModified(); |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function createDirectory($name) { |
| 43 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 43 | + throw new Forbidden('Permission denied to create file (filename '.$name.')'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | function getChild($name) { |
@@ -29,66 +29,66 @@ |
||
| 29 | 29 | use Sabre\DAV\ICollection; |
| 30 | 30 | |
| 31 | 31 | class UploadHome implements ICollection { |
| 32 | - /** |
|
| 33 | - * UploadHome constructor. |
|
| 34 | - * |
|
| 35 | - * @param array $principalInfo |
|
| 36 | - */ |
|
| 37 | - public function __construct($principalInfo) { |
|
| 38 | - $this->principalInfo = $principalInfo; |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * UploadHome constructor. |
|
| 34 | + * |
|
| 35 | + * @param array $principalInfo |
|
| 36 | + */ |
|
| 37 | + public function __construct($principalInfo) { |
|
| 38 | + $this->principalInfo = $principalInfo; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - function createFile($name, $data = null) { |
|
| 42 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 43 | - } |
|
| 41 | + function createFile($name, $data = null) { |
|
| 42 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - function createDirectory($name) { |
|
| 46 | - $this->impl()->createDirectory($name); |
|
| 47 | - } |
|
| 45 | + function createDirectory($name) { |
|
| 46 | + $this->impl()->createDirectory($name); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - function getChild($name) { |
|
| 50 | - return new UploadFolder($this->impl()->getChild($name)); |
|
| 51 | - } |
|
| 49 | + function getChild($name) { |
|
| 50 | + return new UploadFolder($this->impl()->getChild($name)); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - function getChildren() { |
|
| 54 | - return array_map(function($node) { |
|
| 55 | - return new UploadFolder($node); |
|
| 56 | - }, $this->impl()->getChildren()); |
|
| 57 | - } |
|
| 53 | + function getChildren() { |
|
| 54 | + return array_map(function($node) { |
|
| 55 | + return new UploadFolder($node); |
|
| 56 | + }, $this->impl()->getChildren()); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - function childExists($name) { |
|
| 60 | - return !is_null($this->getChild($name)); |
|
| 61 | - } |
|
| 59 | + function childExists($name) { |
|
| 60 | + return !is_null($this->getChild($name)); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - function delete() { |
|
| 64 | - $this->impl()->delete(); |
|
| 65 | - } |
|
| 63 | + function delete() { |
|
| 64 | + $this->impl()->delete(); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - function getName() { |
|
| 68 | - return 'uploads'; |
|
| 69 | - } |
|
| 67 | + function getName() { |
|
| 68 | + return 'uploads'; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - function setName($name) { |
|
| 72 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 73 | - } |
|
| 71 | + function setName($name) { |
|
| 72 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - function getLastModified() { |
|
| 76 | - return $this->impl()->getLastModified(); |
|
| 77 | - } |
|
| 75 | + function getLastModified() { |
|
| 76 | + return $this->impl()->getLastModified(); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @return Directory |
|
| 81 | - */ |
|
| 82 | - private function impl() { |
|
| 83 | - $rootView = new View(); |
|
| 84 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 85 | - Filesystem::initMountPoints($user->getUID()); |
|
| 86 | - if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { |
|
| 87 | - $rootView->mkdir('/' . $user->getUID() . '/uploads'); |
|
| 88 | - } |
|
| 89 | - $view = new View('/' . $user->getUID() . '/uploads'); |
|
| 90 | - $rootInfo = $view->getFileInfo(''); |
|
| 91 | - $impl = new Directory($view, $rootInfo); |
|
| 92 | - return $impl; |
|
| 93 | - } |
|
| 79 | + /** |
|
| 80 | + * @return Directory |
|
| 81 | + */ |
|
| 82 | + private function impl() { |
|
| 83 | + $rootView = new View(); |
|
| 84 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 85 | + Filesystem::initMountPoints($user->getUID()); |
|
| 86 | + if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { |
|
| 87 | + $rootView->mkdir('/' . $user->getUID() . '/uploads'); |
|
| 88 | + } |
|
| 89 | + $view = new View('/' . $user->getUID() . '/uploads'); |
|
| 90 | + $rootInfo = $view->getFileInfo(''); |
|
| 91 | + $impl = new Directory($view, $rootInfo); |
|
| 92 | + return $impl; |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function createFile($name, $data = null) { |
| 42 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
| 42 | + throw new Forbidden('Permission denied to create file (filename '.$name.')'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function createDirectory($name) { |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | $rootView = new View(); |
| 84 | 84 | $user = \OC::$server->getUserSession()->getUser(); |
| 85 | 85 | Filesystem::initMountPoints($user->getUID()); |
| 86 | - if (!$rootView->file_exists('/' . $user->getUID() . '/uploads')) { |
|
| 87 | - $rootView->mkdir('/' . $user->getUID() . '/uploads'); |
|
| 86 | + if (!$rootView->file_exists('/'.$user->getUID().'/uploads')) { |
|
| 87 | + $rootView->mkdir('/'.$user->getUID().'/uploads'); |
|
| 88 | 88 | } |
| 89 | - $view = new View('/' . $user->getUID() . '/uploads'); |
|
| 89 | + $view = new View('/'.$user->getUID().'/uploads'); |
|
| 90 | 90 | $rootInfo = $view->getFileInfo(''); |
| 91 | 91 | $impl = new Directory($view, $rootInfo); |
| 92 | 92 | return $impl; |