@@ -40,114 +40,114 @@ |
||
40 | 40 | */ |
41 | 41 | class QuotaPlugin extends \Sabre\DAV\ServerPlugin { |
42 | 42 | |
43 | - /** |
|
44 | - * @var \OC\Files\View |
|
45 | - */ |
|
46 | - private $view; |
|
43 | + /** |
|
44 | + * @var \OC\Files\View |
|
45 | + */ |
|
46 | + private $view; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Reference to main server object |
|
50 | - * |
|
51 | - * @var \Sabre\DAV\Server |
|
52 | - */ |
|
53 | - private $server; |
|
48 | + /** |
|
49 | + * Reference to main server object |
|
50 | + * |
|
51 | + * @var \Sabre\DAV\Server |
|
52 | + */ |
|
53 | + private $server; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param \OC\Files\View $view |
|
57 | - */ |
|
58 | - public function __construct($view) { |
|
59 | - $this->view = $view; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @param \OC\Files\View $view |
|
57 | + */ |
|
58 | + public function __construct($view) { |
|
59 | + $this->view = $view; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * This initializes the plugin. |
|
64 | - * |
|
65 | - * This function is called by \Sabre\DAV\Server, after |
|
66 | - * addPlugin is called. |
|
67 | - * |
|
68 | - * This method should set up the requires event subscriptions. |
|
69 | - * |
|
70 | - * @param \Sabre\DAV\Server $server |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function initialize(\Sabre\DAV\Server $server) { |
|
62 | + /** |
|
63 | + * This initializes the plugin. |
|
64 | + * |
|
65 | + * This function is called by \Sabre\DAV\Server, after |
|
66 | + * addPlugin is called. |
|
67 | + * |
|
68 | + * This method should set up the requires event subscriptions. |
|
69 | + * |
|
70 | + * @param \Sabre\DAV\Server $server |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function initialize(\Sabre\DAV\Server $server) { |
|
74 | 74 | |
75 | - $this->server = $server; |
|
75 | + $this->server = $server; |
|
76 | 76 | |
77 | - $server->on('beforeWriteContent', array($this, 'checkQuota'), 10); |
|
78 | - $server->on('beforeCreateFile', array($this, 'checkQuota'), 10); |
|
79 | - } |
|
77 | + $server->on('beforeWriteContent', array($this, 'checkQuota'), 10); |
|
78 | + $server->on('beforeCreateFile', array($this, 'checkQuota'), 10); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * This method is called before any HTTP method and validates there is enough free space to store the file |
|
83 | - * |
|
84 | - * @param string $uri |
|
85 | - * @throws InsufficientStorage |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function checkQuota($uri) { |
|
89 | - $length = $this->getLength(); |
|
90 | - if ($length) { |
|
91 | - if (substr($uri, 0, 1) !== '/') { |
|
92 | - $uri = '/' . $uri; |
|
93 | - } |
|
94 | - list($parentUri, $newName) = URLUtil::splitPath($uri); |
|
95 | - if(is_null($parentUri)) { |
|
96 | - $parentUri = ''; |
|
97 | - } |
|
98 | - $req = $this->server->httpRequest; |
|
99 | - if ($req->getHeader('OC-Chunked')) { |
|
100 | - $info = \OC_FileChunking::decodeName($newName); |
|
101 | - $chunkHandler = $this->getFileChunking($info); |
|
102 | - // subtract the already uploaded size to see whether |
|
103 | - // there is still enough space for the remaining chunks |
|
104 | - $length -= $chunkHandler->getCurrentSize(); |
|
105 | - // use target file name for free space check in case of shared files |
|
106 | - $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
107 | - } |
|
108 | - $freeSpace = $this->getFreeSpace($uri); |
|
109 | - if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) { |
|
110 | - if (isset($chunkHandler)) { |
|
111 | - $chunkHandler->cleanup(); |
|
112 | - } |
|
113 | - throw new InsufficientStorage(); |
|
114 | - } |
|
115 | - } |
|
116 | - return true; |
|
117 | - } |
|
81 | + /** |
|
82 | + * This method is called before any HTTP method and validates there is enough free space to store the file |
|
83 | + * |
|
84 | + * @param string $uri |
|
85 | + * @throws InsufficientStorage |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function checkQuota($uri) { |
|
89 | + $length = $this->getLength(); |
|
90 | + if ($length) { |
|
91 | + if (substr($uri, 0, 1) !== '/') { |
|
92 | + $uri = '/' . $uri; |
|
93 | + } |
|
94 | + list($parentUri, $newName) = URLUtil::splitPath($uri); |
|
95 | + if(is_null($parentUri)) { |
|
96 | + $parentUri = ''; |
|
97 | + } |
|
98 | + $req = $this->server->httpRequest; |
|
99 | + if ($req->getHeader('OC-Chunked')) { |
|
100 | + $info = \OC_FileChunking::decodeName($newName); |
|
101 | + $chunkHandler = $this->getFileChunking($info); |
|
102 | + // subtract the already uploaded size to see whether |
|
103 | + // there is still enough space for the remaining chunks |
|
104 | + $length -= $chunkHandler->getCurrentSize(); |
|
105 | + // use target file name for free space check in case of shared files |
|
106 | + $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
107 | + } |
|
108 | + $freeSpace = $this->getFreeSpace($uri); |
|
109 | + if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) { |
|
110 | + if (isset($chunkHandler)) { |
|
111 | + $chunkHandler->cleanup(); |
|
112 | + } |
|
113 | + throw new InsufficientStorage(); |
|
114 | + } |
|
115 | + } |
|
116 | + return true; |
|
117 | + } |
|
118 | 118 | |
119 | - public function getFileChunking($info) { |
|
120 | - // FIXME: need a factory for better mocking support |
|
121 | - return new \OC_FileChunking($info); |
|
122 | - } |
|
119 | + public function getFileChunking($info) { |
|
120 | + // FIXME: need a factory for better mocking support |
|
121 | + return new \OC_FileChunking($info); |
|
122 | + } |
|
123 | 123 | |
124 | - public function getLength() { |
|
125 | - $req = $this->server->httpRequest; |
|
126 | - $length = $req->getHeader('X-Expected-Entity-Length'); |
|
127 | - if (!is_numeric($length)) { |
|
128 | - $length = $req->getHeader('Content-Length'); |
|
129 | - $length = is_numeric($length) ? $length : null; |
|
130 | - } |
|
124 | + public function getLength() { |
|
125 | + $req = $this->server->httpRequest; |
|
126 | + $length = $req->getHeader('X-Expected-Entity-Length'); |
|
127 | + if (!is_numeric($length)) { |
|
128 | + $length = $req->getHeader('Content-Length'); |
|
129 | + $length = is_numeric($length) ? $length : null; |
|
130 | + } |
|
131 | 131 | |
132 | - $ocLength = $req->getHeader('OC-Total-Length'); |
|
133 | - if (is_numeric($length) && is_numeric($ocLength)) { |
|
134 | - return max($length, $ocLength); |
|
135 | - } |
|
132 | + $ocLength = $req->getHeader('OC-Total-Length'); |
|
133 | + if (is_numeric($length) && is_numeric($ocLength)) { |
|
134 | + return max($length, $ocLength); |
|
135 | + } |
|
136 | 136 | |
137 | - return $length; |
|
138 | - } |
|
137 | + return $length; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @param string $uri |
|
142 | - * @return mixed |
|
143 | - * @throws ServiceUnavailable |
|
144 | - */ |
|
145 | - public function getFreeSpace($uri) { |
|
146 | - try { |
|
147 | - $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
148 | - return $freeSpace; |
|
149 | - } catch (StorageNotAvailableException $e) { |
|
150 | - throw new ServiceUnavailable($e->getMessage()); |
|
151 | - } |
|
152 | - } |
|
140 | + /** |
|
141 | + * @param string $uri |
|
142 | + * @return mixed |
|
143 | + * @throws ServiceUnavailable |
|
144 | + */ |
|
145 | + public function getFreeSpace($uri) { |
|
146 | + try { |
|
147 | + $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
148 | + return $freeSpace; |
|
149 | + } catch (StorageNotAvailableException $e) { |
|
150 | + throw new ServiceUnavailable($e->getMessage()); |
|
151 | + } |
|
152 | + } |
|
153 | 153 | } |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | $length = $this->getLength(); |
90 | 90 | if ($length) { |
91 | 91 | if (substr($uri, 0, 1) !== '/') { |
92 | - $uri = '/' . $uri; |
|
92 | + $uri = '/'.$uri; |
|
93 | 93 | } |
94 | 94 | list($parentUri, $newName) = URLUtil::splitPath($uri); |
95 | - if(is_null($parentUri)) { |
|
95 | + if (is_null($parentUri)) { |
|
96 | 96 | $parentUri = ''; |
97 | 97 | } |
98 | 98 | $req = $this->server->httpRequest; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | // there is still enough space for the remaining chunks |
104 | 104 | $length -= $chunkHandler->getCurrentSize(); |
105 | 105 | // use target file name for free space check in case of shared files |
106 | - $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
106 | + $uri = rtrim($parentUri, '/').'/'.$info['name']; |
|
107 | 107 | } |
108 | 108 | $freeSpace = $this->getFreeSpace($uri); |
109 | 109 | if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) { |
@@ -32,88 +32,88 @@ |
||
32 | 32 | use Sabre\HTTP\Response; |
33 | 33 | |
34 | 34 | class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { |
35 | - protected $nonFatalExceptions = [ |
|
36 | - 'Sabre\DAV\Exception\NotAuthenticated' => true, |
|
37 | - // If tokenauth can throw this exception (which is basically as |
|
38 | - // NotAuthenticated. So not fatal. |
|
39 | - 'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true, |
|
40 | - // the sync client uses this to find out whether files exist, |
|
41 | - // so it is not always an error, log it as debug |
|
42 | - 'Sabre\DAV\Exception\NotFound' => true, |
|
43 | - // this one mostly happens when the same file is uploaded at |
|
44 | - // exactly the same time from two clients, only one client |
|
45 | - // wins, the second one gets "Precondition failed" |
|
46 | - 'Sabre\DAV\Exception\PreconditionFailed' => true, |
|
47 | - // forbidden can be expected when trying to upload to |
|
48 | - // read-only folders for example |
|
49 | - 'Sabre\DAV\Exception\Forbidden' => true, |
|
50 | - // Happens when an external storage or federated share is temporarily |
|
51 | - // not available |
|
52 | - 'Sabre\DAV\Exception\StorageNotAvailableException' => true, |
|
53 | - ]; |
|
35 | + protected $nonFatalExceptions = [ |
|
36 | + 'Sabre\DAV\Exception\NotAuthenticated' => true, |
|
37 | + // If tokenauth can throw this exception (which is basically as |
|
38 | + // NotAuthenticated. So not fatal. |
|
39 | + 'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true, |
|
40 | + // the sync client uses this to find out whether files exist, |
|
41 | + // so it is not always an error, log it as debug |
|
42 | + 'Sabre\DAV\Exception\NotFound' => true, |
|
43 | + // this one mostly happens when the same file is uploaded at |
|
44 | + // exactly the same time from two clients, only one client |
|
45 | + // wins, the second one gets "Precondition failed" |
|
46 | + 'Sabre\DAV\Exception\PreconditionFailed' => true, |
|
47 | + // forbidden can be expected when trying to upload to |
|
48 | + // read-only folders for example |
|
49 | + 'Sabre\DAV\Exception\Forbidden' => true, |
|
50 | + // Happens when an external storage or federated share is temporarily |
|
51 | + // not available |
|
52 | + 'Sabre\DAV\Exception\StorageNotAvailableException' => true, |
|
53 | + ]; |
|
54 | 54 | |
55 | - /** @var string */ |
|
56 | - private $appName; |
|
55 | + /** @var string */ |
|
56 | + private $appName; |
|
57 | 57 | |
58 | - /** @var ILogger */ |
|
59 | - private $logger; |
|
58 | + /** @var ILogger */ |
|
59 | + private $logger; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param string $loggerAppName app name to use when logging |
|
63 | - * @param ILogger $logger |
|
64 | - */ |
|
65 | - public function __construct($loggerAppName, $logger) { |
|
66 | - $this->appName = $loggerAppName; |
|
67 | - $this->logger = $logger; |
|
68 | - } |
|
61 | + /** |
|
62 | + * @param string $loggerAppName app name to use when logging |
|
63 | + * @param ILogger $logger |
|
64 | + */ |
|
65 | + public function __construct($loggerAppName, $logger) { |
|
66 | + $this->appName = $loggerAppName; |
|
67 | + $this->logger = $logger; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * This initializes the plugin. |
|
72 | - * |
|
73 | - * This function is called by \Sabre\DAV\Server, after |
|
74 | - * addPlugin is called. |
|
75 | - * |
|
76 | - * This method should set up the required event subscriptions. |
|
77 | - * |
|
78 | - * @param \Sabre\DAV\Server $server |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public function initialize(\Sabre\DAV\Server $server) { |
|
70 | + /** |
|
71 | + * This initializes the plugin. |
|
72 | + * |
|
73 | + * This function is called by \Sabre\DAV\Server, after |
|
74 | + * addPlugin is called. |
|
75 | + * |
|
76 | + * This method should set up the required event subscriptions. |
|
77 | + * |
|
78 | + * @param \Sabre\DAV\Server $server |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public function initialize(\Sabre\DAV\Server $server) { |
|
82 | 82 | |
83 | - $server->on('exception', array($this, 'logException'), 10); |
|
84 | - } |
|
83 | + $server->on('exception', array($this, 'logException'), 10); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Log exception |
|
88 | - * |
|
89 | - */ |
|
90 | - public function logException(\Exception $ex) { |
|
91 | - $exceptionClass = get_class($ex); |
|
92 | - $level = \OCP\Util::FATAL; |
|
93 | - if (isset($this->nonFatalExceptions[$exceptionClass])) { |
|
94 | - $level = \OCP\Util::DEBUG; |
|
95 | - } |
|
86 | + /** |
|
87 | + * Log exception |
|
88 | + * |
|
89 | + */ |
|
90 | + public function logException(\Exception $ex) { |
|
91 | + $exceptionClass = get_class($ex); |
|
92 | + $level = \OCP\Util::FATAL; |
|
93 | + if (isset($this->nonFatalExceptions[$exceptionClass])) { |
|
94 | + $level = \OCP\Util::DEBUG; |
|
95 | + } |
|
96 | 96 | |
97 | - $message = $ex->getMessage(); |
|
98 | - if ($ex instanceof Exception) { |
|
99 | - if (empty($message)) { |
|
100 | - $response = new Response($ex->getHTTPCode()); |
|
101 | - $message = $response->getStatusText(); |
|
102 | - } |
|
103 | - $message = "HTTP/1.1 {$ex->getHTTPCode()} $message"; |
|
104 | - } |
|
97 | + $message = $ex->getMessage(); |
|
98 | + if ($ex instanceof Exception) { |
|
99 | + if (empty($message)) { |
|
100 | + $response = new Response($ex->getHTTPCode()); |
|
101 | + $message = $response->getStatusText(); |
|
102 | + } |
|
103 | + $message = "HTTP/1.1 {$ex->getHTTPCode()} $message"; |
|
104 | + } |
|
105 | 105 | |
106 | - $user = \OC_User::getUser(); |
|
106 | + $user = \OC_User::getUser(); |
|
107 | 107 | |
108 | - $exception = [ |
|
109 | - 'Message' => $message, |
|
110 | - 'Exception' => $exceptionClass, |
|
111 | - 'Code' => $ex->getCode(), |
|
112 | - 'Trace' => $ex->getTraceAsString(), |
|
113 | - 'File' => $ex->getFile(), |
|
114 | - 'Line' => $ex->getLine(), |
|
115 | - 'User' => $user, |
|
116 | - ]; |
|
117 | - $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); |
|
118 | - } |
|
108 | + $exception = [ |
|
109 | + 'Message' => $message, |
|
110 | + 'Exception' => $exceptionClass, |
|
111 | + 'Code' => $ex->getCode(), |
|
112 | + 'Trace' => $ex->getTraceAsString(), |
|
113 | + 'File' => $ex->getFile(), |
|
114 | + 'Line' => $ex->getLine(), |
|
115 | + 'User' => $user, |
|
116 | + ]; |
|
117 | + $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); |
|
118 | + } |
|
119 | 119 | } |
@@ -114,6 +114,6 @@ |
||
114 | 114 | 'Line' => $ex->getLine(), |
115 | 115 | 'User' => $user, |
116 | 116 | ]; |
117 | - $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); |
|
117 | + $this->logger->log($level, 'Exception: '.json_encode($exception), ['app' => $this->appName]); |
|
118 | 118 | } |
119 | 119 | } |
@@ -32,181 +32,181 @@ |
||
32 | 32 | */ |
33 | 33 | class SharesPlugin extends \Sabre\DAV\ServerPlugin { |
34 | 34 | |
35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | - const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Reference to main server object |
|
40 | - * |
|
41 | - * @var \Sabre\DAV\Server |
|
42 | - */ |
|
43 | - private $server; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var \OCP\Share\IManager |
|
47 | - */ |
|
48 | - private $shareManager; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var \Sabre\DAV\Tree |
|
52 | - */ |
|
53 | - private $tree; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - private $userId; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var \OCP\Files\Folder |
|
62 | - */ |
|
63 | - private $userFolder; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var IShare[] |
|
67 | - */ |
|
68 | - private $cachedShareTypes; |
|
69 | - |
|
70 | - private $cachedFolders = []; |
|
71 | - |
|
72 | - /** |
|
73 | - * @param \Sabre\DAV\Tree $tree tree |
|
74 | - * @param IUserSession $userSession user session |
|
75 | - * @param \OCP\Files\Folder $userFolder user home folder |
|
76 | - * @param \OCP\Share\IManager $shareManager share manager |
|
77 | - */ |
|
78 | - public function __construct( |
|
79 | - \Sabre\DAV\Tree $tree, |
|
80 | - IUserSession $userSession, |
|
81 | - \OCP\Files\Folder $userFolder, |
|
82 | - \OCP\Share\IManager $shareManager |
|
83 | - ) { |
|
84 | - $this->tree = $tree; |
|
85 | - $this->shareManager = $shareManager; |
|
86 | - $this->userFolder = $userFolder; |
|
87 | - $this->userId = $userSession->getUser()->getUID(); |
|
88 | - $this->cachedShareTypes = []; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * This initializes the plugin. |
|
93 | - * |
|
94 | - * This function is called by \Sabre\DAV\Server, after |
|
95 | - * addPlugin is called. |
|
96 | - * |
|
97 | - * This method should set up the required event subscriptions. |
|
98 | - * |
|
99 | - * @param \Sabre\DAV\Server $server |
|
100 | - */ |
|
101 | - public function initialize(\Sabre\DAV\Server $server) { |
|
102 | - $server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc'; |
|
103 | - $server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\ShareTypeList'; |
|
104 | - $server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME; |
|
105 | - |
|
106 | - $this->server = $server; |
|
107 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Return a list of share types for outgoing shares |
|
112 | - * |
|
113 | - * @param \OCP\Files\Node $node file node |
|
114 | - * |
|
115 | - * @return int[] array of share types |
|
116 | - */ |
|
117 | - private function getShareTypes(\OCP\Files\Node $node) { |
|
118 | - $shareTypes = []; |
|
119 | - $requestedShareTypes = [ |
|
120 | - \OCP\Share::SHARE_TYPE_USER, |
|
121 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
122 | - \OCP\Share::SHARE_TYPE_LINK, |
|
123 | - \OCP\Share::SHARE_TYPE_REMOTE, |
|
124 | - \OCP\Share::SHARE_TYPE_EMAIL, |
|
125 | - ]; |
|
126 | - foreach ($requestedShareTypes as $requestedShareType) { |
|
127 | - // one of each type is enough to find out about the types |
|
128 | - $shares = $this->shareManager->getSharesBy( |
|
129 | - $this->userId, |
|
130 | - $requestedShareType, |
|
131 | - $node, |
|
132 | - false, |
|
133 | - 1 |
|
134 | - ); |
|
135 | - if (!empty($shares)) { |
|
136 | - $shareTypes[] = $requestedShareType; |
|
137 | - } |
|
138 | - } |
|
139 | - return $shareTypes; |
|
140 | - } |
|
141 | - |
|
142 | - private function getSharesTypesInFolder(\OCP\Files\Folder $node) { |
|
143 | - $shares = $this->shareManager->getSharesInFolder( |
|
144 | - $this->userId, |
|
145 | - $node, |
|
146 | - false |
|
147 | - ); |
|
148 | - |
|
149 | - $shareTypesByFileId = []; |
|
150 | - |
|
151 | - foreach($shares as $fileId => $sharesForFile) { |
|
152 | - $types = array_map(function(IShare $share) { |
|
153 | - return $share->getShareType(); |
|
154 | - }, $sharesForFile); |
|
155 | - $types = array_unique($types); |
|
156 | - sort($types); |
|
157 | - $shareTypesByFileId[$fileId] = $types; |
|
158 | - } |
|
159 | - |
|
160 | - return $shareTypesByFileId; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Adds shares to propfind response |
|
165 | - * |
|
166 | - * @param PropFind $propFind propfind object |
|
167 | - * @param \Sabre\DAV\INode $sabreNode sabre node |
|
168 | - */ |
|
169 | - public function handleGetProperties( |
|
170 | - PropFind $propFind, |
|
171 | - \Sabre\DAV\INode $sabreNode |
|
172 | - ) { |
|
173 | - if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - // need prefetch ? |
|
178 | - if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory |
|
179 | - && $propFind->getDepth() !== 0 |
|
180 | - && !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME)) |
|
181 | - ) { |
|
182 | - $folderNode = $this->userFolder->get($sabreNode->getPath()); |
|
183 | - |
|
184 | - $childShares = $this->getSharesTypesInFolder($folderNode); |
|
185 | - $this->cachedFolders[] = $sabreNode->getPath(); |
|
186 | - $this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode); |
|
187 | - foreach ($childShares as $id => $shares) { |
|
188 | - $this->cachedShareTypes[$id] = $shares; |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) { |
|
193 | - if (isset($this->cachedShareTypes[$sabreNode->getId()])) { |
|
194 | - $shareTypes = $this->cachedShareTypes[$sabreNode->getId()]; |
|
195 | - } else { |
|
196 | - list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath()); |
|
197 | - if ($parentPath === '') { |
|
198 | - $parentPath = '/'; |
|
199 | - } |
|
200 | - // if we already cached the folder this file is in we know there are no shares for this file |
|
201 | - if (array_search($parentPath, $this->cachedFolders) === false) { |
|
202 | - $node = $this->userFolder->get($sabreNode->getPath()); |
|
203 | - $shareTypes = $this->getShareTypes($node); |
|
204 | - } else { |
|
205 | - return []; |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - return new ShareTypeList($shareTypes); |
|
210 | - }); |
|
211 | - } |
|
35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | + const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Reference to main server object |
|
40 | + * |
|
41 | + * @var \Sabre\DAV\Server |
|
42 | + */ |
|
43 | + private $server; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var \OCP\Share\IManager |
|
47 | + */ |
|
48 | + private $shareManager; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var \Sabre\DAV\Tree |
|
52 | + */ |
|
53 | + private $tree; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + private $userId; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var \OCP\Files\Folder |
|
62 | + */ |
|
63 | + private $userFolder; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var IShare[] |
|
67 | + */ |
|
68 | + private $cachedShareTypes; |
|
69 | + |
|
70 | + private $cachedFolders = []; |
|
71 | + |
|
72 | + /** |
|
73 | + * @param \Sabre\DAV\Tree $tree tree |
|
74 | + * @param IUserSession $userSession user session |
|
75 | + * @param \OCP\Files\Folder $userFolder user home folder |
|
76 | + * @param \OCP\Share\IManager $shareManager share manager |
|
77 | + */ |
|
78 | + public function __construct( |
|
79 | + \Sabre\DAV\Tree $tree, |
|
80 | + IUserSession $userSession, |
|
81 | + \OCP\Files\Folder $userFolder, |
|
82 | + \OCP\Share\IManager $shareManager |
|
83 | + ) { |
|
84 | + $this->tree = $tree; |
|
85 | + $this->shareManager = $shareManager; |
|
86 | + $this->userFolder = $userFolder; |
|
87 | + $this->userId = $userSession->getUser()->getUID(); |
|
88 | + $this->cachedShareTypes = []; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * This initializes the plugin. |
|
93 | + * |
|
94 | + * This function is called by \Sabre\DAV\Server, after |
|
95 | + * addPlugin is called. |
|
96 | + * |
|
97 | + * This method should set up the required event subscriptions. |
|
98 | + * |
|
99 | + * @param \Sabre\DAV\Server $server |
|
100 | + */ |
|
101 | + public function initialize(\Sabre\DAV\Server $server) { |
|
102 | + $server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc'; |
|
103 | + $server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\ShareTypeList'; |
|
104 | + $server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME; |
|
105 | + |
|
106 | + $this->server = $server; |
|
107 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Return a list of share types for outgoing shares |
|
112 | + * |
|
113 | + * @param \OCP\Files\Node $node file node |
|
114 | + * |
|
115 | + * @return int[] array of share types |
|
116 | + */ |
|
117 | + private function getShareTypes(\OCP\Files\Node $node) { |
|
118 | + $shareTypes = []; |
|
119 | + $requestedShareTypes = [ |
|
120 | + \OCP\Share::SHARE_TYPE_USER, |
|
121 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
122 | + \OCP\Share::SHARE_TYPE_LINK, |
|
123 | + \OCP\Share::SHARE_TYPE_REMOTE, |
|
124 | + \OCP\Share::SHARE_TYPE_EMAIL, |
|
125 | + ]; |
|
126 | + foreach ($requestedShareTypes as $requestedShareType) { |
|
127 | + // one of each type is enough to find out about the types |
|
128 | + $shares = $this->shareManager->getSharesBy( |
|
129 | + $this->userId, |
|
130 | + $requestedShareType, |
|
131 | + $node, |
|
132 | + false, |
|
133 | + 1 |
|
134 | + ); |
|
135 | + if (!empty($shares)) { |
|
136 | + $shareTypes[] = $requestedShareType; |
|
137 | + } |
|
138 | + } |
|
139 | + return $shareTypes; |
|
140 | + } |
|
141 | + |
|
142 | + private function getSharesTypesInFolder(\OCP\Files\Folder $node) { |
|
143 | + $shares = $this->shareManager->getSharesInFolder( |
|
144 | + $this->userId, |
|
145 | + $node, |
|
146 | + false |
|
147 | + ); |
|
148 | + |
|
149 | + $shareTypesByFileId = []; |
|
150 | + |
|
151 | + foreach($shares as $fileId => $sharesForFile) { |
|
152 | + $types = array_map(function(IShare $share) { |
|
153 | + return $share->getShareType(); |
|
154 | + }, $sharesForFile); |
|
155 | + $types = array_unique($types); |
|
156 | + sort($types); |
|
157 | + $shareTypesByFileId[$fileId] = $types; |
|
158 | + } |
|
159 | + |
|
160 | + return $shareTypesByFileId; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Adds shares to propfind response |
|
165 | + * |
|
166 | + * @param PropFind $propFind propfind object |
|
167 | + * @param \Sabre\DAV\INode $sabreNode sabre node |
|
168 | + */ |
|
169 | + public function handleGetProperties( |
|
170 | + PropFind $propFind, |
|
171 | + \Sabre\DAV\INode $sabreNode |
|
172 | + ) { |
|
173 | + if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + // need prefetch ? |
|
178 | + if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory |
|
179 | + && $propFind->getDepth() !== 0 |
|
180 | + && !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME)) |
|
181 | + ) { |
|
182 | + $folderNode = $this->userFolder->get($sabreNode->getPath()); |
|
183 | + |
|
184 | + $childShares = $this->getSharesTypesInFolder($folderNode); |
|
185 | + $this->cachedFolders[] = $sabreNode->getPath(); |
|
186 | + $this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode); |
|
187 | + foreach ($childShares as $id => $shares) { |
|
188 | + $this->cachedShareTypes[$id] = $shares; |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) { |
|
193 | + if (isset($this->cachedShareTypes[$sabreNode->getId()])) { |
|
194 | + $shareTypes = $this->cachedShareTypes[$sabreNode->getId()]; |
|
195 | + } else { |
|
196 | + list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath()); |
|
197 | + if ($parentPath === '') { |
|
198 | + $parentPath = '/'; |
|
199 | + } |
|
200 | + // if we already cached the folder this file is in we know there are no shares for this file |
|
201 | + if (array_search($parentPath, $this->cachedFolders) === false) { |
|
202 | + $node = $this->userFolder->get($sabreNode->getPath()); |
|
203 | + $shareTypes = $this->getShareTypes($node); |
|
204 | + } else { |
|
205 | + return []; |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + return new ShareTypeList($shareTypes); |
|
210 | + }); |
|
211 | + } |
|
212 | 212 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | |
149 | 149 | $shareTypesByFileId = []; |
150 | 150 | |
151 | - foreach($shares as $fileId => $sharesForFile) { |
|
151 | + foreach ($shares as $fileId => $sharesForFile) { |
|
152 | 152 | $types = array_map(function(IShare $share) { |
153 | 153 | return $share->getShareType(); |
154 | 154 | }, $sharesForFile); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | - $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) { |
|
192 | + $propFind->handle(self::SHARETYPES_PROPERTYNAME, function() use ($sabreNode) { |
|
193 | 193 | if (isset($this->cachedShareTypes[$sabreNode->getId()])) { |
194 | 194 | $shareTypes = $this->cachedShareTypes[$sabreNode->getId()]; |
195 | 195 | } else { |
@@ -32,42 +32,42 @@ |
||
32 | 32 | |
33 | 33 | class LegacyDAVACL extends DavAclPlugin { |
34 | 34 | |
35 | - /** |
|
36 | - * @inheritdoc |
|
37 | - */ |
|
38 | - public function getCurrentUserPrincipals() { |
|
39 | - $principalV2 = $this->getCurrentUserPrincipal(); |
|
35 | + /** |
|
36 | + * @inheritdoc |
|
37 | + */ |
|
38 | + public function getCurrentUserPrincipals() { |
|
39 | + $principalV2 = $this->getCurrentUserPrincipal(); |
|
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) return []; |
|
42 | 42 | |
43 | - $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | - return array_merge( |
|
45 | - [ |
|
46 | - $principalV2, |
|
47 | - $principalV1 |
|
48 | - ], |
|
49 | - $this->getPrincipalMembership($principalV1) |
|
50 | - ); |
|
51 | - } |
|
43 | + $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | + return array_merge( |
|
45 | + [ |
|
46 | + $principalV2, |
|
47 | + $principalV1 |
|
48 | + ], |
|
49 | + $this->getPrincipalMembership($principalV1) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - private function convertPrincipal($principal, $toV2) { |
|
54 | - list(, $name) = URLUtil::splitPath($principal); |
|
55 | - if ($toV2) { |
|
56 | - return "principals/users/$name"; |
|
57 | - } |
|
58 | - return "principals/$name"; |
|
59 | - } |
|
53 | + private function convertPrincipal($principal, $toV2) { |
|
54 | + list(, $name) = URLUtil::splitPath($principal); |
|
55 | + if ($toV2) { |
|
56 | + return "principals/users/$name"; |
|
57 | + } |
|
58 | + return "principals/$name"; |
|
59 | + } |
|
60 | 60 | |
61 | - public function propFind(PropFind $propFind, INode $node) { |
|
62 | - /* Overload current-user-principal */ |
|
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | - if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
66 | - } else { |
|
67 | - return new Principal(Principal::UNAUTHENTICATED); |
|
68 | - } |
|
69 | - }); |
|
61 | + public function propFind(PropFind $propFind, INode $node) { |
|
62 | + /* Overload current-user-principal */ |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | + if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | + return new Principal(Principal::HREF, $url . '/'); |
|
66 | + } else { |
|
67 | + return new Principal(Principal::UNAUTHENTICATED); |
|
68 | + } |
|
69 | + }); |
|
70 | 70 | |
71 | - return parent::propFind($propFind, $node); |
|
72 | - } |
|
71 | + return parent::propFind($propFind, $node); |
|
72 | + } |
|
73 | 73 | } |
@@ -60,9 +60,9 @@ |
||
60 | 60 | |
61 | 61 | public function propFind(PropFind $propFind, INode $node) { |
62 | 62 | /* Overload current-user-principal */ |
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function() { |
|
64 | 64 | if ($url = parent::getCurrentUserPrincipal()) { |
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
65 | + return new Principal(Principal::HREF, $url.'/'); |
|
66 | 66 | } else { |
67 | 67 | return new Principal(Principal::UNAUTHENTICATED); |
68 | 68 | } |
@@ -38,7 +38,9 @@ |
||
38 | 38 | public function getCurrentUserPrincipals() { |
39 | 39 | $principalV2 = $this->getCurrentUserPrincipal(); |
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) { |
|
42 | + return []; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | $principalV1 = $this->convertPrincipal($principalV2, false); |
44 | 46 | return array_merge( |
@@ -29,43 +29,43 @@ |
||
29 | 29 | |
30 | 30 | class ValueFix extends QueuedJob { |
31 | 31 | |
32 | - /** @var CalDavBackend */ |
|
33 | - private $calDavBackend; |
|
32 | + /** @var CalDavBackend */ |
|
33 | + private $calDavBackend; |
|
34 | 34 | |
35 | - /** @var ILogger */ |
|
36 | - private $logger; |
|
35 | + /** @var ILogger */ |
|
36 | + private $logger; |
|
37 | 37 | |
38 | - public function __construct(CalDavBackend $calDavBackend, ILogger $logger) { |
|
39 | - $this->calDavBackend = $calDavBackend; |
|
40 | - $this->logger = $logger; |
|
41 | - } |
|
38 | + public function __construct(CalDavBackend $calDavBackend, ILogger $logger) { |
|
39 | + $this->calDavBackend = $calDavBackend; |
|
40 | + $this->logger = $logger; |
|
41 | + } |
|
42 | 42 | |
43 | - public function run($argument) { |
|
44 | - $user = $argument['user']; |
|
43 | + public function run($argument) { |
|
44 | + $user = $argument['user']; |
|
45 | 45 | |
46 | - $pattern = '/;VALUE=:/'; |
|
47 | - $principal = 'principals/users/' . $user; |
|
48 | - $calendars = $this->calDavBackend->getCalendarsForUser($principal); |
|
49 | - foreach ($calendars as $calendar) { |
|
50 | - $objects = $this->calDavBackend->getCalendarObjects($calendar['id']); |
|
51 | - foreach ($objects as $object) { |
|
52 | - $calObject = $this->calDavBackend->getCalendarObject($calendar['id'], $object['uri']); |
|
53 | - $data = preg_replace($pattern, ':', $calObject['calendardata']); |
|
54 | - if ($data !== $calObject['calendardata']) { |
|
55 | - try { |
|
56 | - $this->calDavBackend->getDenormalizedData($data); |
|
57 | - } catch (InvalidDataException $e) { |
|
58 | - $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
|
59 | - 'app'=> 'dav', |
|
60 | - 'cal' => $calendar['id'], |
|
61 | - 'uri' => $object['uri'], |
|
62 | - ]); |
|
63 | - continue; |
|
64 | - } |
|
65 | - $this->calDavBackend->updateCalendarObject($calendar['id'], $object['uri'], $data); |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
69 | - } |
|
46 | + $pattern = '/;VALUE=:/'; |
|
47 | + $principal = 'principals/users/' . $user; |
|
48 | + $calendars = $this->calDavBackend->getCalendarsForUser($principal); |
|
49 | + foreach ($calendars as $calendar) { |
|
50 | + $objects = $this->calDavBackend->getCalendarObjects($calendar['id']); |
|
51 | + foreach ($objects as $object) { |
|
52 | + $calObject = $this->calDavBackend->getCalendarObject($calendar['id'], $object['uri']); |
|
53 | + $data = preg_replace($pattern, ':', $calObject['calendardata']); |
|
54 | + if ($data !== $calObject['calendardata']) { |
|
55 | + try { |
|
56 | + $this->calDavBackend->getDenormalizedData($data); |
|
57 | + } catch (InvalidDataException $e) { |
|
58 | + $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
|
59 | + 'app'=> 'dav', |
|
60 | + 'cal' => $calendar['id'], |
|
61 | + 'uri' => $object['uri'], |
|
62 | + ]); |
|
63 | + continue; |
|
64 | + } |
|
65 | + $this->calDavBackend->updateCalendarObject($calendar['id'], $object['uri'], $data); |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | 71 | } |
@@ -44,7 +44,7 @@ |
||
44 | 44 | $user = $argument['user']; |
45 | 45 | |
46 | 46 | $pattern = '/;VALUE=:/'; |
47 | - $principal = 'principals/users/' . $user; |
|
47 | + $principal = 'principals/users/'.$user; |
|
48 | 48 | $calendars = $this->calDavBackend->getCalendarsForUser($principal); |
49 | 49 | foreach ($calendars as $calendar) { |
50 | 50 | $objects = $this->calDavBackend->getCalendarObjects($calendar['id']); |
@@ -31,33 +31,33 @@ |
||
31 | 31 | |
32 | 32 | class ValueFixInsert implements IRepairStep { |
33 | 33 | |
34 | - /** @var IUserManager */ |
|
35 | - private $userManager; |
|
36 | - |
|
37 | - /** @var IJobList */ |
|
38 | - private $jobList; |
|
39 | - |
|
40 | - /** @var IConfig */ |
|
41 | - private $config; |
|
42 | - |
|
43 | - public function __construct(IUserManager $userManager, |
|
44 | - IJobList $jobList, |
|
45 | - IConfig $config) { |
|
46 | - $this->userManager = $userManager; |
|
47 | - $this->jobList = $jobList; |
|
48 | - $this->config = $config; |
|
49 | - } |
|
50 | - |
|
51 | - public function getName() { |
|
52 | - return 'Insert ValueFix background job for each user'; |
|
53 | - } |
|
54 | - |
|
55 | - public function run(IOutput $output) { |
|
56 | - if ($this->config->getAppValue('dav', self::class . '_ran', 'false') !== 'true') { |
|
57 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
58 | - $this->jobList->add(ValueFix::class, ['user' => $user->getUID()]); |
|
59 | - }); |
|
60 | - $this->config->setAppValue('dav', self::class . '_ran', 'true'); |
|
61 | - } |
|
62 | - } |
|
34 | + /** @var IUserManager */ |
|
35 | + private $userManager; |
|
36 | + |
|
37 | + /** @var IJobList */ |
|
38 | + private $jobList; |
|
39 | + |
|
40 | + /** @var IConfig */ |
|
41 | + private $config; |
|
42 | + |
|
43 | + public function __construct(IUserManager $userManager, |
|
44 | + IJobList $jobList, |
|
45 | + IConfig $config) { |
|
46 | + $this->userManager = $userManager; |
|
47 | + $this->jobList = $jobList; |
|
48 | + $this->config = $config; |
|
49 | + } |
|
50 | + |
|
51 | + public function getName() { |
|
52 | + return 'Insert ValueFix background job for each user'; |
|
53 | + } |
|
54 | + |
|
55 | + public function run(IOutput $output) { |
|
56 | + if ($this->config->getAppValue('dav', self::class . '_ran', 'false') !== 'true') { |
|
57 | + $this->userManager->callForSeenUsers(function (IUser $user) { |
|
58 | + $this->jobList->add(ValueFix::class, ['user' => $user->getUID()]); |
|
59 | + }); |
|
60 | + $this->config->setAppValue('dav', self::class . '_ran', 'true'); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | } |
@@ -53,11 +53,11 @@ |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | public function run(IOutput $output) { |
56 | - if ($this->config->getAppValue('dav', self::class . '_ran', 'false') !== 'true') { |
|
57 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
56 | + if ($this->config->getAppValue('dav', self::class.'_ran', 'false') !== 'true') { |
|
57 | + $this->userManager->callForSeenUsers(function(IUser $user) { |
|
58 | 58 | $this->jobList->add(ValueFix::class, ['user' => $user->getUID()]); |
59 | 59 | }); |
60 | - $this->config->setAppValue('dav', self::class . '_ran', 'true'); |
|
60 | + $this->config->setAppValue('dav', self::class.'_ran', 'true'); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | } |
@@ -28,35 +28,35 @@ |
||
28 | 28 | |
29 | 29 | class FixBirthdayCalendarComponent implements IRepairStep { |
30 | 30 | |
31 | - /** @var IDBConnection */ |
|
32 | - private $connection; |
|
33 | - |
|
34 | - /** |
|
35 | - * FixBirthdayCalendarComponent constructor. |
|
36 | - * |
|
37 | - * @param IDBConnection $connection |
|
38 | - */ |
|
39 | - public function __construct(IDBConnection $connection) { |
|
40 | - $this->connection = $connection; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @inheritdoc |
|
45 | - */ |
|
46 | - public function getName() { |
|
47 | - return 'Fix component of birthday calendars'; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function run(IOutput $output) { |
|
54 | - $query = $this->connection->getQueryBuilder(); |
|
55 | - $updated = $query->update('calendars') |
|
56 | - ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | - ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | - ->execute(); |
|
59 | - |
|
60 | - $output->info("$updated birthday calendars updated."); |
|
61 | - } |
|
31 | + /** @var IDBConnection */ |
|
32 | + private $connection; |
|
33 | + |
|
34 | + /** |
|
35 | + * FixBirthdayCalendarComponent constructor. |
|
36 | + * |
|
37 | + * @param IDBConnection $connection |
|
38 | + */ |
|
39 | + public function __construct(IDBConnection $connection) { |
|
40 | + $this->connection = $connection; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @inheritdoc |
|
45 | + */ |
|
46 | + public function getName() { |
|
47 | + return 'Fix component of birthday calendars'; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function run(IOutput $output) { |
|
54 | + $query = $this->connection->getQueryBuilder(); |
|
55 | + $updated = $query->update('calendars') |
|
56 | + ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | + ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | + ->execute(); |
|
59 | + |
|
60 | + $output->info("$updated birthday calendars updated."); |
|
61 | + } |
|
62 | 62 | } |
@@ -33,55 +33,55 @@ |
||
33 | 33 | |
34 | 34 | class SyncBirthdayCalendar extends Command { |
35 | 35 | |
36 | - /** @var BirthdayService */ |
|
37 | - private $birthdayService; |
|
36 | + /** @var BirthdayService */ |
|
37 | + private $birthdayService; |
|
38 | 38 | |
39 | - /** @var IUserManager */ |
|
40 | - private $userManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + private $userManager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param IUserManager $userManager |
|
44 | - * @param BirthdayService $birthdayService |
|
45 | - */ |
|
46 | - function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
47 | - parent::__construct(); |
|
48 | - $this->birthdayService = $birthdayService; |
|
49 | - $this->userManager = $userManager; |
|
50 | - } |
|
42 | + /** |
|
43 | + * @param IUserManager $userManager |
|
44 | + * @param BirthdayService $birthdayService |
|
45 | + */ |
|
46 | + function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
47 | + parent::__construct(); |
|
48 | + $this->birthdayService = $birthdayService; |
|
49 | + $this->userManager = $userManager; |
|
50 | + } |
|
51 | 51 | |
52 | - protected function configure() { |
|
53 | - $this |
|
54 | - ->setName('dav:sync-birthday-calendar') |
|
55 | - ->setDescription('Synchronizes the birthday calendar') |
|
56 | - ->addArgument('user', |
|
57 | - InputArgument::OPTIONAL, |
|
58 | - 'User for whom the birthday calendar will be synchronized'); |
|
59 | - } |
|
52 | + protected function configure() { |
|
53 | + $this |
|
54 | + ->setName('dav:sync-birthday-calendar') |
|
55 | + ->setDescription('Synchronizes the birthday calendar') |
|
56 | + ->addArgument('user', |
|
57 | + InputArgument::OPTIONAL, |
|
58 | + 'User for whom the birthday calendar will be synchronized'); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param InputInterface $input |
|
63 | - * @param OutputInterface $output |
|
64 | - */ |
|
65 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | - $user = $input->getArgument('user'); |
|
67 | - if (!is_null($user)) { |
|
68 | - if (!$this->userManager->userExists($user)) { |
|
69 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
70 | - } |
|
71 | - $output->writeln("Start birthday calendar sync for $user"); |
|
72 | - $this->birthdayService->syncUser($user); |
|
73 | - return; |
|
74 | - } |
|
75 | - $output->writeln("Start birthday calendar sync for all users ..."); |
|
76 | - $p = new ProgressBar($output); |
|
77 | - $p->start(); |
|
78 | - $this->userManager->callForAllUsers(function($user) use ($p) { |
|
79 | - $p->advance(); |
|
80 | - /** @var IUser $user */ |
|
81 | - $this->birthdayService->syncUser($user->getUID()); |
|
82 | - }); |
|
61 | + /** |
|
62 | + * @param InputInterface $input |
|
63 | + * @param OutputInterface $output |
|
64 | + */ |
|
65 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | + $user = $input->getArgument('user'); |
|
67 | + if (!is_null($user)) { |
|
68 | + if (!$this->userManager->userExists($user)) { |
|
69 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
70 | + } |
|
71 | + $output->writeln("Start birthday calendar sync for $user"); |
|
72 | + $this->birthdayService->syncUser($user); |
|
73 | + return; |
|
74 | + } |
|
75 | + $output->writeln("Start birthday calendar sync for all users ..."); |
|
76 | + $p = new ProgressBar($output); |
|
77 | + $p->start(); |
|
78 | + $this->userManager->callForAllUsers(function($user) use ($p) { |
|
79 | + $p->advance(); |
|
80 | + /** @var IUser $user */ |
|
81 | + $this->birthdayService->syncUser($user->getUID()); |
|
82 | + }); |
|
83 | 83 | |
84 | - $p->finish(); |
|
85 | - $output->writeln(''); |
|
86 | - } |
|
84 | + $p->finish(); |
|
85 | + $output->writeln(''); |
|
86 | + } |
|
87 | 87 | } |
@@ -33,53 +33,53 @@ |
||
33 | 33 | |
34 | 34 | class CreateCalendar extends Command { |
35 | 35 | |
36 | - /** @var IUserManager */ |
|
37 | - protected $userManager; |
|
36 | + /** @var IUserManager */ |
|
37 | + protected $userManager; |
|
38 | 38 | |
39 | - /** @var IGroupManager $groupManager */ |
|
40 | - private $groupManager; |
|
39 | + /** @var IGroupManager $groupManager */ |
|
40 | + private $groupManager; |
|
41 | 41 | |
42 | - /** @var \OCP\IDBConnection */ |
|
43 | - protected $dbConnection; |
|
42 | + /** @var \OCP\IDBConnection */ |
|
43 | + protected $dbConnection; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param IUserManager $userManager |
|
47 | - * @param IGroupManager $groupManager |
|
48 | - * @param IDBConnection $dbConnection |
|
49 | - */ |
|
50 | - function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { |
|
51 | - parent::__construct(); |
|
52 | - $this->userManager = $userManager; |
|
53 | - $this->groupManager = $groupManager; |
|
54 | - $this->dbConnection = $dbConnection; |
|
55 | - } |
|
45 | + /** |
|
46 | + * @param IUserManager $userManager |
|
47 | + * @param IGroupManager $groupManager |
|
48 | + * @param IDBConnection $dbConnection |
|
49 | + */ |
|
50 | + function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { |
|
51 | + parent::__construct(); |
|
52 | + $this->userManager = $userManager; |
|
53 | + $this->groupManager = $groupManager; |
|
54 | + $this->dbConnection = $dbConnection; |
|
55 | + } |
|
56 | 56 | |
57 | - protected function configure() { |
|
58 | - $this |
|
59 | - ->setName('dav:create-calendar') |
|
60 | - ->setDescription('Create a dav calendar') |
|
61 | - ->addArgument('user', |
|
62 | - InputArgument::REQUIRED, |
|
63 | - 'User for whom the calendar will be created') |
|
64 | - ->addArgument('name', |
|
65 | - InputArgument::REQUIRED, |
|
66 | - 'Name of the calendar'); |
|
67 | - } |
|
57 | + protected function configure() { |
|
58 | + $this |
|
59 | + ->setName('dav:create-calendar') |
|
60 | + ->setDescription('Create a dav calendar') |
|
61 | + ->addArgument('user', |
|
62 | + InputArgument::REQUIRED, |
|
63 | + 'User for whom the calendar will be created') |
|
64 | + ->addArgument('name', |
|
65 | + InputArgument::REQUIRED, |
|
66 | + 'Name of the calendar'); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | - $user = $input->getArgument('user'); |
|
71 | - if (!$this->userManager->userExists($user)) { |
|
72 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | - } |
|
74 | - $principalBackend = new Principal( |
|
75 | - $this->userManager, |
|
76 | - $this->groupManager |
|
77 | - ); |
|
78 | - $random = \OC::$server->getSecureRandom(); |
|
79 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | + $user = $input->getArgument('user'); |
|
71 | + if (!$this->userManager->userExists($user)) { |
|
72 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | + } |
|
74 | + $principalBackend = new Principal( |
|
75 | + $this->userManager, |
|
76 | + $this->groupManager |
|
77 | + ); |
|
78 | + $random = \OC::$server->getSecureRandom(); |
|
79 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
80 | 80 | |
81 | - $name = $input->getArgument('name'); |
|
82 | - $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher); |
|
83 | - $caldav->createCalendar("principals/users/$user", $name, []); |
|
84 | - } |
|
81 | + $name = $input->getArgument('name'); |
|
82 | + $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher); |
|
83 | + $caldav->createCalendar("principals/users/$user", $name, []); |
|
84 | + } |
|
85 | 85 | } |