@@ -25,11 +25,11 @@ |
||
25 | 25 | * @since 13.0.0 |
26 | 26 | */ |
27 | 27 | interface IInstanceFactory { |
28 | - /** |
|
29 | - * @param string $url |
|
30 | - * @return IInstance |
|
31 | - * |
|
32 | - * @since 13.0.0 |
|
33 | - */ |
|
34 | - public function getInstance($url); |
|
28 | + /** |
|
29 | + * @param string $url |
|
30 | + * @return IInstance |
|
31 | + * |
|
32 | + * @since 13.0.0 |
|
33 | + */ |
|
34 | + public function getInstance($url); |
|
35 | 35 | } |
@@ -28,14 +28,14 @@ |
||
28 | 28 | use OCP\Remote\IInstance; |
29 | 29 | |
30 | 30 | class ApiFactory implements IApiFactory { |
31 | - /** @var IClientService */ |
|
32 | - private $clientService; |
|
31 | + /** @var IClientService */ |
|
32 | + private $clientService; |
|
33 | 33 | |
34 | - public function __construct(IClientService $clientService) { |
|
35 | - $this->clientService = $clientService; |
|
36 | - } |
|
34 | + public function __construct(IClientService $clientService) { |
|
35 | + $this->clientService = $clientService; |
|
36 | + } |
|
37 | 37 | |
38 | - public function getApiCollection(IInstance $instance, ICredentials $credentials) { |
|
39 | - return new ApiCollection($instance, $credentials, $this->clientService); |
|
40 | - } |
|
38 | + public function getApiCollection(IInstance $instance, ICredentials $credentials) { |
|
39 | + return new ApiCollection($instance, $credentials, $this->clientService); |
|
40 | + } |
|
41 | 41 | } |
@@ -28,24 +28,24 @@ |
||
28 | 28 | use OCP\Remote\IInstance; |
29 | 29 | |
30 | 30 | class ApiCollection implements IApiCollection { |
31 | - /** @var IInstance */ |
|
32 | - private $instance; |
|
33 | - /** @var ICredentials */ |
|
34 | - private $credentials; |
|
35 | - /** @var IClientService */ |
|
36 | - private $clientService; |
|
31 | + /** @var IInstance */ |
|
32 | + private $instance; |
|
33 | + /** @var ICredentials */ |
|
34 | + private $credentials; |
|
35 | + /** @var IClientService */ |
|
36 | + private $clientService; |
|
37 | 37 | |
38 | - public function __construct(IInstance $instance, ICredentials $credentials, IClientService $clientService) { |
|
39 | - $this->instance = $instance; |
|
40 | - $this->credentials = $credentials; |
|
41 | - $this->clientService = $clientService; |
|
42 | - } |
|
38 | + public function __construct(IInstance $instance, ICredentials $credentials, IClientService $clientService) { |
|
39 | + $this->instance = $instance; |
|
40 | + $this->credentials = $credentials; |
|
41 | + $this->clientService = $clientService; |
|
42 | + } |
|
43 | 43 | |
44 | - public function getCapabilitiesApi() { |
|
45 | - return new OCS($this->instance, $this->credentials, $this->clientService); |
|
46 | - } |
|
44 | + public function getCapabilitiesApi() { |
|
45 | + return new OCS($this->instance, $this->credentials, $this->clientService); |
|
46 | + } |
|
47 | 47 | |
48 | - public function getUserApi() { |
|
49 | - return new OCS($this->instance, $this->credentials, $this->clientService); |
|
50 | - } |
|
48 | + public function getUserApi() { |
|
49 | + return new OCS($this->instance, $this->credentials, $this->clientService); |
|
50 | + } |
|
51 | 51 | } |
@@ -27,17 +27,17 @@ |
||
27 | 27 | use OCP\Remote\IInstanceFactory; |
28 | 28 | |
29 | 29 | class InstanceFactory implements IInstanceFactory { |
30 | - /** @var ICache */ |
|
31 | - private $cache; |
|
32 | - /** @var IClientService */ |
|
33 | - private $clientService; |
|
30 | + /** @var ICache */ |
|
31 | + private $cache; |
|
32 | + /** @var IClientService */ |
|
33 | + private $clientService; |
|
34 | 34 | |
35 | - public function __construct(ICache $cache, IClientService $clientService) { |
|
36 | - $this->cache = $cache; |
|
37 | - $this->clientService = $clientService; |
|
38 | - } |
|
35 | + public function __construct(ICache $cache, IClientService $clientService) { |
|
36 | + $this->cache = $cache; |
|
37 | + $this->clientService = $clientService; |
|
38 | + } |
|
39 | 39 | |
40 | - public function getInstance($url) { |
|
41 | - return new Instance($url, $this->cache, $this->clientService); |
|
42 | - } |
|
40 | + public function getInstance($url) { |
|
41 | + return new Instance($url, $this->cache, $this->clientService); |
|
42 | + } |
|
43 | 43 | } |
@@ -104,7 +104,7 @@ |
||
104 | 104 | * @param RequestInterface $request |
105 | 105 | * @param ResponseInterface $response |
106 | 106 | * |
107 | - * @return bool|void |
|
107 | + * @return null|false |
|
108 | 108 | */ |
109 | 109 | public function httpPost(RequestInterface $request, ResponseInterface $response) { |
110 | 110 | $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
@@ -78,7 +78,7 @@ |
||
78 | 78 | * |
79 | 79 | * @return string |
80 | 80 | */ |
81 | - public function getPluginName() { |
|
81 | + public function getPluginName() { |
|
82 | 82 | return 'nc-enable-birthday-calendar'; |
83 | 83 | } |
84 | 84 |
@@ -38,102 +38,102 @@ |
||
38 | 38 | * @package OCA\DAV\CalDAV\BirthdayCalendar |
39 | 39 | */ |
40 | 40 | class EnablePlugin extends ServerPlugin { |
41 | - const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var IConfig |
|
45 | - */ |
|
46 | - protected $config; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var BirthdayService |
|
50 | - */ |
|
51 | - protected $birthdayService; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var Server |
|
55 | - */ |
|
56 | - protected $server; |
|
57 | - |
|
58 | - /** |
|
59 | - * PublishPlugin constructor. |
|
60 | - * |
|
61 | - * @param IConfig $config |
|
62 | - * @param BirthdayService $birthdayService |
|
63 | - */ |
|
64 | - public function __construct(IConfig $config, BirthdayService $birthdayService) { |
|
65 | - $this->config = $config; |
|
66 | - $this->birthdayService = $birthdayService; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * This method should return a list of server-features. |
|
71 | - * |
|
72 | - * This is for example 'versioning' and is added to the DAV: header |
|
73 | - * in an OPTIONS response. |
|
74 | - * |
|
75 | - * @return string[] |
|
76 | - */ |
|
77 | - public function getFeatures() { |
|
78 | - return ['nc-enable-birthday-calendar']; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Returns a plugin name. |
|
83 | - * |
|
84 | - * Using this name other plugins will be able to access other plugins |
|
85 | - * using Sabre\DAV\Server::getPlugin |
|
86 | - * |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function getPluginName() { |
|
90 | - return 'nc-enable-birthday-calendar'; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * This initializes the plugin. |
|
95 | - * |
|
96 | - * This function is called by Sabre\DAV\Server, after |
|
97 | - * addPlugin is called. |
|
98 | - * |
|
99 | - * This method should set up the required event subscriptions. |
|
100 | - * |
|
101 | - * @param Server $server |
|
102 | - */ |
|
103 | - public function initialize(Server $server) { |
|
104 | - $this->server = $server; |
|
105 | - |
|
106 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * We intercept this to handle POST requests on calendar homes. |
|
111 | - * |
|
112 | - * @param RequestInterface $request |
|
113 | - * @param ResponseInterface $response |
|
114 | - * |
|
115 | - * @return bool|void |
|
116 | - */ |
|
117 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
118 | - $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
119 | - if (!($node instanceof CalendarHome)) { |
|
120 | - return; |
|
121 | - } |
|
122 | - |
|
123 | - $requestBody = $request->getBodyAsString(); |
|
124 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
125 | - if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') { |
|
126 | - return; |
|
127 | - } |
|
128 | - |
|
129 | - $principalUri = $node->getOwner(); |
|
130 | - $userId = substr($principalUri, 17); |
|
131 | - |
|
132 | - $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
133 | - $this->birthdayService->syncUser($userId); |
|
134 | - |
|
135 | - $this->server->httpResponse->setStatus(204); |
|
136 | - |
|
137 | - return false; |
|
138 | - } |
|
41 | + const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var IConfig |
|
45 | + */ |
|
46 | + protected $config; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var BirthdayService |
|
50 | + */ |
|
51 | + protected $birthdayService; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var Server |
|
55 | + */ |
|
56 | + protected $server; |
|
57 | + |
|
58 | + /** |
|
59 | + * PublishPlugin constructor. |
|
60 | + * |
|
61 | + * @param IConfig $config |
|
62 | + * @param BirthdayService $birthdayService |
|
63 | + */ |
|
64 | + public function __construct(IConfig $config, BirthdayService $birthdayService) { |
|
65 | + $this->config = $config; |
|
66 | + $this->birthdayService = $birthdayService; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * This method should return a list of server-features. |
|
71 | + * |
|
72 | + * This is for example 'versioning' and is added to the DAV: header |
|
73 | + * in an OPTIONS response. |
|
74 | + * |
|
75 | + * @return string[] |
|
76 | + */ |
|
77 | + public function getFeatures() { |
|
78 | + return ['nc-enable-birthday-calendar']; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Returns a plugin name. |
|
83 | + * |
|
84 | + * Using this name other plugins will be able to access other plugins |
|
85 | + * using Sabre\DAV\Server::getPlugin |
|
86 | + * |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function getPluginName() { |
|
90 | + return 'nc-enable-birthday-calendar'; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * This initializes the plugin. |
|
95 | + * |
|
96 | + * This function is called by Sabre\DAV\Server, after |
|
97 | + * addPlugin is called. |
|
98 | + * |
|
99 | + * This method should set up the required event subscriptions. |
|
100 | + * |
|
101 | + * @param Server $server |
|
102 | + */ |
|
103 | + public function initialize(Server $server) { |
|
104 | + $this->server = $server; |
|
105 | + |
|
106 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * We intercept this to handle POST requests on calendar homes. |
|
111 | + * |
|
112 | + * @param RequestInterface $request |
|
113 | + * @param ResponseInterface $response |
|
114 | + * |
|
115 | + * @return bool|void |
|
116 | + */ |
|
117 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
118 | + $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
119 | + if (!($node instanceof CalendarHome)) { |
|
120 | + return; |
|
121 | + } |
|
122 | + |
|
123 | + $requestBody = $request->getBodyAsString(); |
|
124 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
125 | + if ($documentType !== '{'.self::NS_Nextcloud.'}enable-birthday-calendar') { |
|
126 | + return; |
|
127 | + } |
|
128 | + |
|
129 | + $principalUri = $node->getOwner(); |
|
130 | + $userId = substr($principalUri, 17); |
|
131 | + |
|
132 | + $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
133 | + $this->birthdayService->syncUser($userId); |
|
134 | + |
|
135 | + $this->server->httpResponse->setStatus(204); |
|
136 | + |
|
137 | + return false; |
|
138 | + } |
|
139 | 139 | } |
@@ -30,70 +30,70 @@ |
||
30 | 30 | use OCP\Remote\Api\IUserApi; |
31 | 31 | |
32 | 32 | class OCS extends ApiBase implements ICapabilitiesApi, IUserApi { |
33 | - /** |
|
34 | - * @param string $method |
|
35 | - * @param string $url |
|
36 | - * @param array $body |
|
37 | - * @param array $query |
|
38 | - * @param array $headers |
|
39 | - * @return array |
|
40 | - * @throws ForbiddenException |
|
41 | - * @throws NotFoundException |
|
42 | - * @throws \Exception |
|
43 | - */ |
|
44 | - protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { |
|
45 | - try { |
|
46 | - $response = json_decode(parent::request($method, 'ocs/v2.php/' . $url, $body, $query, $headers), true); |
|
47 | - } catch (ClientException $e) { |
|
48 | - if ($e->getResponse()->getStatusCode() === 404) { |
|
49 | - throw new NotFoundException(); |
|
50 | - } else if ($e->getResponse()->getStatusCode() === 403 || $e->getResponse()->getStatusCode() === 401) { |
|
51 | - throw new ForbiddenException(); |
|
52 | - } else { |
|
53 | - throw $e; |
|
54 | - } |
|
55 | - } |
|
56 | - if (!isset($response['ocs']) || !isset($response['ocs']['meta'])) { |
|
57 | - throw new \Exception('Invalid ocs response'); |
|
58 | - } |
|
59 | - if ($response['ocs']['meta']['statuscode'] === API::RESPOND_UNAUTHORISED) { |
|
60 | - throw new ForbiddenException(); |
|
61 | - } |
|
62 | - if ($response['ocs']['meta']['statuscode'] === API::RESPOND_NOT_FOUND) { |
|
63 | - throw new NotFoundException(); |
|
64 | - } |
|
65 | - if ($response['ocs']['meta']['status'] !== 'ok') { |
|
66 | - throw new \Exception('Unknown ocs error ' . $response['ocs']['meta']['message']); |
|
67 | - } |
|
33 | + /** |
|
34 | + * @param string $method |
|
35 | + * @param string $url |
|
36 | + * @param array $body |
|
37 | + * @param array $query |
|
38 | + * @param array $headers |
|
39 | + * @return array |
|
40 | + * @throws ForbiddenException |
|
41 | + * @throws NotFoundException |
|
42 | + * @throws \Exception |
|
43 | + */ |
|
44 | + protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { |
|
45 | + try { |
|
46 | + $response = json_decode(parent::request($method, 'ocs/v2.php/' . $url, $body, $query, $headers), true); |
|
47 | + } catch (ClientException $e) { |
|
48 | + if ($e->getResponse()->getStatusCode() === 404) { |
|
49 | + throw new NotFoundException(); |
|
50 | + } else if ($e->getResponse()->getStatusCode() === 403 || $e->getResponse()->getStatusCode() === 401) { |
|
51 | + throw new ForbiddenException(); |
|
52 | + } else { |
|
53 | + throw $e; |
|
54 | + } |
|
55 | + } |
|
56 | + if (!isset($response['ocs']) || !isset($response['ocs']['meta'])) { |
|
57 | + throw new \Exception('Invalid ocs response'); |
|
58 | + } |
|
59 | + if ($response['ocs']['meta']['statuscode'] === API::RESPOND_UNAUTHORISED) { |
|
60 | + throw new ForbiddenException(); |
|
61 | + } |
|
62 | + if ($response['ocs']['meta']['statuscode'] === API::RESPOND_NOT_FOUND) { |
|
63 | + throw new NotFoundException(); |
|
64 | + } |
|
65 | + if ($response['ocs']['meta']['status'] !== 'ok') { |
|
66 | + throw new \Exception('Unknown ocs error ' . $response['ocs']['meta']['message']); |
|
67 | + } |
|
68 | 68 | |
69 | - return $response['ocs']['data']; |
|
70 | - } |
|
69 | + return $response['ocs']['data']; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param array $data |
|
74 | - * @param string $type |
|
75 | - * @param string[] $keys |
|
76 | - * @throws \Exception |
|
77 | - */ |
|
78 | - private function checkResponseArray(array $data, $type, array $keys) { |
|
79 | - foreach ($keys as $key) { |
|
80 | - if (!array_key_exists($key, $data)) { |
|
81 | - throw new \Exception('Invalid ' . $type . ' response, expected field ' . $key . ' not found'); |
|
82 | - } |
|
83 | - } |
|
84 | - } |
|
72 | + /** |
|
73 | + * @param array $data |
|
74 | + * @param string $type |
|
75 | + * @param string[] $keys |
|
76 | + * @throws \Exception |
|
77 | + */ |
|
78 | + private function checkResponseArray(array $data, $type, array $keys) { |
|
79 | + foreach ($keys as $key) { |
|
80 | + if (!array_key_exists($key, $data)) { |
|
81 | + throw new \Exception('Invalid ' . $type . ' response, expected field ' . $key . ' not found'); |
|
82 | + } |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - public function getUser($userId) { |
|
87 | - $result = $this->request('get', 'cloud/users/' . $userId); |
|
88 | - $this->checkResponseArray($result, 'user', User::EXPECTED_KEYS); |
|
89 | - return new User($result); |
|
90 | - } |
|
86 | + public function getUser($userId) { |
|
87 | + $result = $this->request('get', 'cloud/users/' . $userId); |
|
88 | + $this->checkResponseArray($result, 'user', User::EXPECTED_KEYS); |
|
89 | + return new User($result); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array The capabilities in the form of [$appId => [$capability => $value]] |
|
94 | - */ |
|
95 | - public function getCapabilities() { |
|
96 | - $result = $this->request('get', 'cloud/capabilities'); |
|
97 | - return $result['capabilities']; |
|
98 | - } |
|
92 | + /** |
|
93 | + * @return array The capabilities in the form of [$appId => [$capability => $value]] |
|
94 | + */ |
|
95 | + public function getCapabilities() { |
|
96 | + $result = $this->request('get', 'cloud/capabilities'); |
|
97 | + return $result['capabilities']; |
|
98 | + } |
|
99 | 99 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | protected function request($method, $url, array $body = [], array $query = [], array $headers = []) { |
45 | 45 | try { |
46 | - $response = json_decode(parent::request($method, 'ocs/v2.php/' . $url, $body, $query, $headers), true); |
|
46 | + $response = json_decode(parent::request($method, 'ocs/v2.php/'.$url, $body, $query, $headers), true); |
|
47 | 47 | } catch (ClientException $e) { |
48 | 48 | if ($e->getResponse()->getStatusCode() === 404) { |
49 | 49 | throw new NotFoundException(); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | throw new NotFoundException(); |
64 | 64 | } |
65 | 65 | if ($response['ocs']['meta']['status'] !== 'ok') { |
66 | - throw new \Exception('Unknown ocs error ' . $response['ocs']['meta']['message']); |
|
66 | + throw new \Exception('Unknown ocs error '.$response['ocs']['meta']['message']); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return $response['ocs']['data']; |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | private function checkResponseArray(array $data, $type, array $keys) { |
79 | 79 | foreach ($keys as $key) { |
80 | 80 | if (!array_key_exists($key, $data)) { |
81 | - throw new \Exception('Invalid ' . $type . ' response, expected field ' . $key . ' not found'); |
|
81 | + throw new \Exception('Invalid '.$type.' response, expected field '.$key.' not found'); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | 86 | public function getUser($userId) { |
87 | - $result = $this->request('get', 'cloud/users/' . $userId); |
|
87 | + $result = $this->request('get', 'cloud/users/'.$userId); |
|
88 | 88 | $this->checkResponseArray($result, 'user', User::EXPECTED_KEYS); |
89 | 89 | return new User($result); |
90 | 90 | } |
@@ -25,114 +25,114 @@ |
||
25 | 25 | use OCP\Remote\IUser; |
26 | 26 | |
27 | 27 | class User implements IUser { |
28 | - const EXPECTED_KEYS = [ |
|
29 | - 'id', |
|
30 | - 'email', |
|
31 | - 'displayname', |
|
32 | - 'phone', |
|
33 | - 'address', |
|
34 | - 'website', |
|
35 | - 'groups', |
|
36 | - 'language', |
|
37 | - 'quota' |
|
38 | - ]; |
|
39 | - |
|
40 | - /** @var array */ |
|
41 | - private $data; |
|
42 | - |
|
43 | - public function __construct(array $data) { |
|
44 | - $this->data = $data; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function getUserId() { |
|
52 | - return $this->data['id']; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function getEmail() { |
|
59 | - return $this->data['email']; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getDisplayName() { |
|
66 | - return $this->data['displayname']; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function getPhone() { |
|
73 | - return $this->data['phone']; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getAddress() { |
|
80 | - return $this->data['address']; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function getWebsite() { |
|
87 | - return $this->data['website']; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public function getTwitter() { |
|
94 | - return isset($this->data['twitter']) ? $this->data['twitter'] : ''; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return string[] |
|
99 | - */ |
|
100 | - public function getGroups() { |
|
101 | - return $this->data['groups']; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function getLanguage() { |
|
108 | - return $this->data['language']; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @return int |
|
113 | - */ |
|
114 | - public function getUsedSpace() { |
|
115 | - return $this->data['quota']['used']; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function getFreeSpace() { |
|
122 | - return $this->data['quota']['free']; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return int |
|
127 | - */ |
|
128 | - public function getTotalSpace() { |
|
129 | - return $this->data['quota']['total']; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function getQuota() { |
|
136 | - return $this->data['quota']['quota']; |
|
137 | - } |
|
28 | + const EXPECTED_KEYS = [ |
|
29 | + 'id', |
|
30 | + 'email', |
|
31 | + 'displayname', |
|
32 | + 'phone', |
|
33 | + 'address', |
|
34 | + 'website', |
|
35 | + 'groups', |
|
36 | + 'language', |
|
37 | + 'quota' |
|
38 | + ]; |
|
39 | + |
|
40 | + /** @var array */ |
|
41 | + private $data; |
|
42 | + |
|
43 | + public function __construct(array $data) { |
|
44 | + $this->data = $data; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function getUserId() { |
|
52 | + return $this->data['id']; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function getEmail() { |
|
59 | + return $this->data['email']; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getDisplayName() { |
|
66 | + return $this->data['displayname']; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function getPhone() { |
|
73 | + return $this->data['phone']; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getAddress() { |
|
80 | + return $this->data['address']; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function getWebsite() { |
|
87 | + return $this->data['website']; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public function getTwitter() { |
|
94 | + return isset($this->data['twitter']) ? $this->data['twitter'] : ''; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return string[] |
|
99 | + */ |
|
100 | + public function getGroups() { |
|
101 | + return $this->data['groups']; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function getLanguage() { |
|
108 | + return $this->data['language']; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @return int |
|
113 | + */ |
|
114 | + public function getUsedSpace() { |
|
115 | + return $this->data['quota']['used']; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function getFreeSpace() { |
|
122 | + return $this->data['quota']['free']; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return int |
|
127 | + */ |
|
128 | + public function getTotalSpace() { |
|
129 | + return $this->data['quota']['total']; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function getQuota() { |
|
136 | + return $this->data['quota']['quota']; |
|
137 | + } |
|
138 | 138 | } |
@@ -34,86 +34,86 @@ |
||
34 | 34 | |
35 | 35 | class SyncBirthdayCalendar extends Command { |
36 | 36 | |
37 | - /** @var BirthdayService */ |
|
38 | - private $birthdayService; |
|
39 | - |
|
40 | - /** @var IConfig */ |
|
41 | - private $config; |
|
42 | - |
|
43 | - /** @var IUserManager */ |
|
44 | - private $userManager; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param IUserManager $userManager |
|
48 | - * @param IConfig $config |
|
49 | - * @param BirthdayService $birthdayService |
|
50 | - */ |
|
51 | - function __construct(IUserManager $userManager, IConfig $config, |
|
52 | - BirthdayService $birthdayService) { |
|
53 | - parent::__construct(); |
|
54 | - $this->birthdayService = $birthdayService; |
|
55 | - $this->config = $config; |
|
56 | - $this->userManager = $userManager; |
|
57 | - } |
|
58 | - |
|
59 | - protected function configure() { |
|
60 | - $this |
|
61 | - ->setName('dav:sync-birthday-calendar') |
|
62 | - ->setDescription('Synchronizes the birthday calendar') |
|
63 | - ->addArgument('user', |
|
64 | - InputArgument::OPTIONAL, |
|
65 | - 'User for whom the birthday calendar will be synchronized'); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param InputInterface $input |
|
70 | - * @param OutputInterface $output |
|
71 | - */ |
|
72 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
73 | - $this->verifyEnabled(); |
|
74 | - |
|
75 | - $user = $input->getArgument('user'); |
|
76 | - if (!is_null($user)) { |
|
77 | - if (!$this->userManager->userExists($user)) { |
|
78 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
79 | - } |
|
80 | - |
|
81 | - // re-enable the birthday calendar in case it's called directly with a user name |
|
82 | - $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
83 | - if ($isEnabled !== 'yes') { |
|
84 | - $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
85 | - $output->writeln("Re-enabling birthday calendar for $user"); |
|
86 | - } |
|
87 | - |
|
88 | - $output->writeln("Start birthday calendar sync for $user"); |
|
89 | - $this->birthdayService->syncUser($user); |
|
90 | - return; |
|
91 | - } |
|
92 | - $output->writeln("Start birthday calendar sync for all users ..."); |
|
93 | - $p = new ProgressBar($output); |
|
94 | - $p->start(); |
|
95 | - $this->userManager->callForAllUsers(function($user) use ($p) { |
|
96 | - $p->advance(); |
|
97 | - |
|
98 | - $userId = $user->getUID(); |
|
99 | - $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
100 | - if ($isEnabled !== 'yes') { |
|
101 | - return; |
|
102 | - } |
|
103 | - |
|
104 | - /** @var IUser $user */ |
|
105 | - $this->birthdayService->syncUser($user->getUID()); |
|
106 | - }); |
|
107 | - |
|
108 | - $p->finish(); |
|
109 | - $output->writeln(''); |
|
110 | - } |
|
111 | - |
|
112 | - protected function verifyEnabled () { |
|
113 | - $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
114 | - |
|
115 | - if ($isEnabled !== 'yes') { |
|
116 | - throw new \InvalidArgumentException('Birthday calendars are disabled'); |
|
117 | - } |
|
118 | - } |
|
37 | + /** @var BirthdayService */ |
|
38 | + private $birthdayService; |
|
39 | + |
|
40 | + /** @var IConfig */ |
|
41 | + private $config; |
|
42 | + |
|
43 | + /** @var IUserManager */ |
|
44 | + private $userManager; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param IUserManager $userManager |
|
48 | + * @param IConfig $config |
|
49 | + * @param BirthdayService $birthdayService |
|
50 | + */ |
|
51 | + function __construct(IUserManager $userManager, IConfig $config, |
|
52 | + BirthdayService $birthdayService) { |
|
53 | + parent::__construct(); |
|
54 | + $this->birthdayService = $birthdayService; |
|
55 | + $this->config = $config; |
|
56 | + $this->userManager = $userManager; |
|
57 | + } |
|
58 | + |
|
59 | + protected function configure() { |
|
60 | + $this |
|
61 | + ->setName('dav:sync-birthday-calendar') |
|
62 | + ->setDescription('Synchronizes the birthday calendar') |
|
63 | + ->addArgument('user', |
|
64 | + InputArgument::OPTIONAL, |
|
65 | + 'User for whom the birthday calendar will be synchronized'); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param InputInterface $input |
|
70 | + * @param OutputInterface $output |
|
71 | + */ |
|
72 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
73 | + $this->verifyEnabled(); |
|
74 | + |
|
75 | + $user = $input->getArgument('user'); |
|
76 | + if (!is_null($user)) { |
|
77 | + if (!$this->userManager->userExists($user)) { |
|
78 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
79 | + } |
|
80 | + |
|
81 | + // re-enable the birthday calendar in case it's called directly with a user name |
|
82 | + $isEnabled = $this->config->getUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
83 | + if ($isEnabled !== 'yes') { |
|
84 | + $this->config->setUserValue($user, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
85 | + $output->writeln("Re-enabling birthday calendar for $user"); |
|
86 | + } |
|
87 | + |
|
88 | + $output->writeln("Start birthday calendar sync for $user"); |
|
89 | + $this->birthdayService->syncUser($user); |
|
90 | + return; |
|
91 | + } |
|
92 | + $output->writeln("Start birthday calendar sync for all users ..."); |
|
93 | + $p = new ProgressBar($output); |
|
94 | + $p->start(); |
|
95 | + $this->userManager->callForAllUsers(function($user) use ($p) { |
|
96 | + $p->advance(); |
|
97 | + |
|
98 | + $userId = $user->getUID(); |
|
99 | + $isEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
100 | + if ($isEnabled !== 'yes') { |
|
101 | + return; |
|
102 | + } |
|
103 | + |
|
104 | + /** @var IUser $user */ |
|
105 | + $this->birthdayService->syncUser($user->getUID()); |
|
106 | + }); |
|
107 | + |
|
108 | + $p->finish(); |
|
109 | + $output->writeln(''); |
|
110 | + } |
|
111 | + |
|
112 | + protected function verifyEnabled () { |
|
113 | + $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
114 | + |
|
115 | + if ($isEnabled !== 'yes') { |
|
116 | + throw new \InvalidArgumentException('Birthday calendars are disabled'); |
|
117 | + } |
|
118 | + } |
|
119 | 119 | } |
@@ -109,7 +109,7 @@ |
||
109 | 109 | $output->writeln(''); |
110 | 110 | } |
111 | 111 | |
112 | - protected function verifyEnabled () { |
|
112 | + protected function verifyEnabled() { |
|
113 | 113 | $isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
114 | 114 | |
115 | 115 | if ($isEnabled !== 'yes') { |
@@ -72,19 +72,19 @@ discard block |
||
72 | 72 | private static function createConfidentialObject(Component\VCalendar $vObject) { |
73 | 73 | /** @var Component $vElement */ |
74 | 74 | $vElement = null; |
75 | - if(isset($vObject->VEVENT)) { |
|
75 | + if (isset($vObject->VEVENT)) { |
|
76 | 76 | $vElement = $vObject->VEVENT; |
77 | 77 | } |
78 | - if(isset($vObject->VJOURNAL)) { |
|
78 | + if (isset($vObject->VJOURNAL)) { |
|
79 | 79 | $vElement = $vObject->VJOURNAL; |
80 | 80 | } |
81 | - if(isset($vObject->VTODO)) { |
|
81 | + if (isset($vObject->VTODO)) { |
|
82 | 82 | $vElement = $vObject->VTODO; |
83 | 83 | } |
84 | - if(!is_null($vElement)) { |
|
84 | + if (!is_null($vElement)) { |
|
85 | 85 | foreach ($vElement->children() as &$property) { |
86 | 86 | /** @var Property $property */ |
87 | - switch($property->name) { |
|
87 | + switch ($property->name) { |
|
88 | 88 | case 'CREATED': |
89 | 89 | case 'DTSTART': |
90 | 90 | case 'RRULE': |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | private function removeVAlarms(Component\VCalendar $vObject) { |
113 | 113 | $subcomponents = $vObject->getComponents(); |
114 | 114 | |
115 | - foreach($subcomponents as $subcomponent) { |
|
115 | + foreach ($subcomponents as $subcomponent) { |
|
116 | 116 | unset($subcomponent->VALARM); |
117 | 117 | } |
118 | 118 | } |
@@ -32,114 +32,114 @@ |
||
32 | 32 | |
33 | 33 | class CalendarObject extends \Sabre\CalDAV\CalendarObject { |
34 | 34 | |
35 | - /** |
|
36 | - * CalendarObject constructor. |
|
37 | - * |
|
38 | - * @param CalDavBackend $caldavBackend |
|
39 | - * @param array $calendarInfo |
|
40 | - * @param array $objectData |
|
41 | - */ |
|
42 | - public function __construct(CalDavBackend $caldavBackend, array $calendarInfo, |
|
43 | - array $objectData) { |
|
44 | - parent::__construct($caldavBackend, $calendarInfo, $objectData); |
|
45 | - |
|
46 | - if ($this->isShared()) { |
|
47 | - unset($this->objectData['size']); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @inheritdoc |
|
53 | - */ |
|
54 | - function get() { |
|
55 | - $data = parent::get(); |
|
56 | - |
|
57 | - if (!$this->isShared()) { |
|
58 | - return $data; |
|
59 | - } |
|
60 | - |
|
61 | - $vObject = Reader::read($data); |
|
62 | - |
|
63 | - // remove VAlarms if calendar is shared read-only |
|
64 | - if (!$this->canWrite()) { |
|
65 | - $this->removeVAlarms($vObject); |
|
66 | - } |
|
67 | - |
|
68 | - // shows as busy if event is declared confidential |
|
69 | - if ($this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) { |
|
70 | - $this->createConfidentialObject($vObject); |
|
71 | - } |
|
72 | - |
|
73 | - return $vObject->serialize(); |
|
74 | - } |
|
75 | - |
|
76 | - protected function isShared() { |
|
77 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
78 | - return false; |
|
79 | - } |
|
80 | - |
|
81 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param Component\VCalendar $vObject |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - private static function createConfidentialObject(Component\VCalendar $vObject) { |
|
89 | - /** @var Component $vElement */ |
|
90 | - $vElement = null; |
|
91 | - if(isset($vObject->VEVENT)) { |
|
92 | - $vElement = $vObject->VEVENT; |
|
93 | - } |
|
94 | - if(isset($vObject->VJOURNAL)) { |
|
95 | - $vElement = $vObject->VJOURNAL; |
|
96 | - } |
|
97 | - if(isset($vObject->VTODO)) { |
|
98 | - $vElement = $vObject->VTODO; |
|
99 | - } |
|
100 | - if(!is_null($vElement)) { |
|
101 | - foreach ($vElement->children() as &$property) { |
|
102 | - /** @var Property $property */ |
|
103 | - switch($property->name) { |
|
104 | - case 'CREATED': |
|
105 | - case 'DTSTART': |
|
106 | - case 'RRULE': |
|
107 | - case 'DURATION': |
|
108 | - case 'DTEND': |
|
109 | - case 'CLASS': |
|
110 | - case 'UID': |
|
111 | - break; |
|
112 | - case 'SUMMARY': |
|
113 | - $property->setValue('Busy'); |
|
114 | - break; |
|
115 | - default: |
|
116 | - $vElement->__unset($property->name); |
|
117 | - unset($property); |
|
118 | - break; |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param Component\VCalendar $vObject |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - private function removeVAlarms(Component\VCalendar $vObject) { |
|
129 | - $subcomponents = $vObject->getComponents(); |
|
130 | - |
|
131 | - foreach($subcomponents as $subcomponent) { |
|
132 | - unset($subcomponent->VALARM); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - private function canWrite() { |
|
140 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
141 | - return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
142 | - } |
|
143 | - return true; |
|
144 | - } |
|
35 | + /** |
|
36 | + * CalendarObject constructor. |
|
37 | + * |
|
38 | + * @param CalDavBackend $caldavBackend |
|
39 | + * @param array $calendarInfo |
|
40 | + * @param array $objectData |
|
41 | + */ |
|
42 | + public function __construct(CalDavBackend $caldavBackend, array $calendarInfo, |
|
43 | + array $objectData) { |
|
44 | + parent::__construct($caldavBackend, $calendarInfo, $objectData); |
|
45 | + |
|
46 | + if ($this->isShared()) { |
|
47 | + unset($this->objectData['size']); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @inheritdoc |
|
53 | + */ |
|
54 | + function get() { |
|
55 | + $data = parent::get(); |
|
56 | + |
|
57 | + if (!$this->isShared()) { |
|
58 | + return $data; |
|
59 | + } |
|
60 | + |
|
61 | + $vObject = Reader::read($data); |
|
62 | + |
|
63 | + // remove VAlarms if calendar is shared read-only |
|
64 | + if (!$this->canWrite()) { |
|
65 | + $this->removeVAlarms($vObject); |
|
66 | + } |
|
67 | + |
|
68 | + // shows as busy if event is declared confidential |
|
69 | + if ($this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) { |
|
70 | + $this->createConfidentialObject($vObject); |
|
71 | + } |
|
72 | + |
|
73 | + return $vObject->serialize(); |
|
74 | + } |
|
75 | + |
|
76 | + protected function isShared() { |
|
77 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
78 | + return false; |
|
79 | + } |
|
80 | + |
|
81 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param Component\VCalendar $vObject |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + private static function createConfidentialObject(Component\VCalendar $vObject) { |
|
89 | + /** @var Component $vElement */ |
|
90 | + $vElement = null; |
|
91 | + if(isset($vObject->VEVENT)) { |
|
92 | + $vElement = $vObject->VEVENT; |
|
93 | + } |
|
94 | + if(isset($vObject->VJOURNAL)) { |
|
95 | + $vElement = $vObject->VJOURNAL; |
|
96 | + } |
|
97 | + if(isset($vObject->VTODO)) { |
|
98 | + $vElement = $vObject->VTODO; |
|
99 | + } |
|
100 | + if(!is_null($vElement)) { |
|
101 | + foreach ($vElement->children() as &$property) { |
|
102 | + /** @var Property $property */ |
|
103 | + switch($property->name) { |
|
104 | + case 'CREATED': |
|
105 | + case 'DTSTART': |
|
106 | + case 'RRULE': |
|
107 | + case 'DURATION': |
|
108 | + case 'DTEND': |
|
109 | + case 'CLASS': |
|
110 | + case 'UID': |
|
111 | + break; |
|
112 | + case 'SUMMARY': |
|
113 | + $property->setValue('Busy'); |
|
114 | + break; |
|
115 | + default: |
|
116 | + $vElement->__unset($property->name); |
|
117 | + unset($property); |
|
118 | + break; |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param Component\VCalendar $vObject |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + private function removeVAlarms(Component\VCalendar $vObject) { |
|
129 | + $subcomponents = $vObject->getComponents(); |
|
130 | + |
|
131 | + foreach($subcomponents as $subcomponent) { |
|
132 | + unset($subcomponent->VALARM); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + private function canWrite() { |
|
140 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
141 | + return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
142 | + } |
|
143 | + return true; |
|
144 | + } |
|
145 | 145 | } |