@@ -84,7 +84,7 @@ |
||
84 | 84 | * @param string $reportName |
85 | 85 | * @param mixed $report |
86 | 86 | * @param mixed $path |
87 | - * @return bool |
|
87 | + * @return false|null |
|
88 | 88 | */ |
89 | 89 | function report($reportName, $report, $path) { |
90 | 90 | switch ($reportName) { |
@@ -25,135 +25,135 @@ |
||
25 | 25 | use OCA\DAV\CalDAV\CalendarHome; |
26 | 26 | |
27 | 27 | class SearchPlugin extends ServerPlugin { |
28 | - const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Reference to SabreDAV server object. |
|
32 | - * |
|
33 | - * @var \Sabre\DAV\Server |
|
34 | - */ |
|
35 | - protected $server; |
|
36 | - |
|
37 | - /** |
|
38 | - * This method should return a list of server-features. |
|
39 | - * |
|
40 | - * This is for example 'versioning' and is added to the DAV: header |
|
41 | - * in an OPTIONS response. |
|
42 | - * |
|
43 | - * @return string[] |
|
44 | - */ |
|
45 | - public function getFeatures() { |
|
46 | - // May have to be changed to be detected |
|
47 | - return ['nc-calendar-search']; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Returns a plugin name. |
|
52 | - * |
|
53 | - * Using this name other plugins will be able to access other plugins |
|
54 | - * using Sabre\DAV\Server::getPlugin |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function getPluginName() { |
|
59 | - return 'nc-calendar-search'; |
|
60 | - } |
|
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 required event subscriptions. |
|
69 | - * |
|
70 | - * @param Server $server |
|
71 | - */ |
|
72 | - public function initialize(Server $server) { |
|
73 | - $this->server = $server; |
|
74 | - |
|
75 | - $server->on('report', [$this, 'report']); |
|
76 | - |
|
77 | - $server->xml->elementMap['{' . self::NS_Nextcloud . '}calendar-search'] = |
|
78 | - 'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport'; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * This functions handles REPORT requests specific to CalDAV |
|
83 | - * |
|
84 | - * @param string $reportName |
|
85 | - * @param mixed $report |
|
86 | - * @param mixed $path |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - function report($reportName, $report, $path) { |
|
90 | - switch ($reportName) { |
|
91 | - case '{' . self::NS_Nextcloud . '}calendar-search' : |
|
92 | - $this->server->transactionType = 'report-nc-calendar-search'; |
|
93 | - $this->calendarSearch($report); |
|
94 | - return false; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Returns a list of reports this plugin supports. |
|
100 | - * |
|
101 | - * This will be used in the {DAV:}supported-report-set property. |
|
102 | - * Note that you still need to subscribe to the 'report' event to actually |
|
103 | - * implement them |
|
104 | - * |
|
105 | - * @param string $uri |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public function getSupportedReportSet($uri) { |
|
109 | - $node = $this->server->tree->getNodeForPath($uri); |
|
110 | - |
|
111 | - $reports = []; |
|
112 | - if ($node instanceof CalendarHome) { |
|
113 | - $reports[] = '{' . self::NS_Nextcloud . '}calendar-search'; |
|
114 | - } |
|
115 | - |
|
116 | - return $reports; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * This function handles the calendar-query REPORT |
|
121 | - * |
|
122 | - * This report is used by clients to request calendar objects based on |
|
123 | - * complex conditions. |
|
124 | - * |
|
125 | - * @param Xml\Request\CalendarSearchReport $report |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - private function calendarSearch($report) { |
|
129 | - $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
130 | - $depth = $this->server->getHTTPDepth(0); |
|
131 | - |
|
132 | - // The default result is an empty array |
|
133 | - $result = []; |
|
134 | - |
|
135 | - // If we're dealing with the calendar home, the calendar home itself is |
|
136 | - // responsible for the calendar-query |
|
137 | - if ($node instanceof CalendarHome && $depth == 2) { |
|
138 | - |
|
139 | - $nodePaths = $node->calendarSearch($report->filters, $report->limit, $report->offset); |
|
140 | - |
|
141 | - foreach ($nodePaths as $path) { |
|
142 | - list($properties) = $this->server->getPropertiesForPath( |
|
143 | - $this->server->getRequestUri() . '/' . $path, |
|
144 | - $report->properties); |
|
145 | - $result[] = $properties; |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - $prefer = $this->server->getHTTPPrefer(); |
|
150 | - |
|
151 | - $this->server->httpResponse->setStatus(207); |
|
152 | - $this->server->httpResponse->setHeader('Content-Type', |
|
153 | - 'application/xml; charset=utf-8'); |
|
154 | - $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); |
|
155 | - $this->server->httpResponse->setBody( |
|
156 | - $this->server->generateMultiStatus($result, |
|
157 | - $prefer['return'] === 'minimal')); |
|
158 | - } |
|
28 | + const NS_Nextcloud = 'http://nextcloud.com/ns'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Reference to SabreDAV server object. |
|
32 | + * |
|
33 | + * @var \Sabre\DAV\Server |
|
34 | + */ |
|
35 | + protected $server; |
|
36 | + |
|
37 | + /** |
|
38 | + * This method should return a list of server-features. |
|
39 | + * |
|
40 | + * This is for example 'versioning' and is added to the DAV: header |
|
41 | + * in an OPTIONS response. |
|
42 | + * |
|
43 | + * @return string[] |
|
44 | + */ |
|
45 | + public function getFeatures() { |
|
46 | + // May have to be changed to be detected |
|
47 | + return ['nc-calendar-search']; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Returns a plugin name. |
|
52 | + * |
|
53 | + * Using this name other plugins will be able to access other plugins |
|
54 | + * using Sabre\DAV\Server::getPlugin |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function getPluginName() { |
|
59 | + return 'nc-calendar-search'; |
|
60 | + } |
|
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 required event subscriptions. |
|
69 | + * |
|
70 | + * @param Server $server |
|
71 | + */ |
|
72 | + public function initialize(Server $server) { |
|
73 | + $this->server = $server; |
|
74 | + |
|
75 | + $server->on('report', [$this, 'report']); |
|
76 | + |
|
77 | + $server->xml->elementMap['{' . self::NS_Nextcloud . '}calendar-search'] = |
|
78 | + 'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport'; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * This functions handles REPORT requests specific to CalDAV |
|
83 | + * |
|
84 | + * @param string $reportName |
|
85 | + * @param mixed $report |
|
86 | + * @param mixed $path |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + function report($reportName, $report, $path) { |
|
90 | + switch ($reportName) { |
|
91 | + case '{' . self::NS_Nextcloud . '}calendar-search' : |
|
92 | + $this->server->transactionType = 'report-nc-calendar-search'; |
|
93 | + $this->calendarSearch($report); |
|
94 | + return false; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Returns a list of reports this plugin supports. |
|
100 | + * |
|
101 | + * This will be used in the {DAV:}supported-report-set property. |
|
102 | + * Note that you still need to subscribe to the 'report' event to actually |
|
103 | + * implement them |
|
104 | + * |
|
105 | + * @param string $uri |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public function getSupportedReportSet($uri) { |
|
109 | + $node = $this->server->tree->getNodeForPath($uri); |
|
110 | + |
|
111 | + $reports = []; |
|
112 | + if ($node instanceof CalendarHome) { |
|
113 | + $reports[] = '{' . self::NS_Nextcloud . '}calendar-search'; |
|
114 | + } |
|
115 | + |
|
116 | + return $reports; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * This function handles the calendar-query REPORT |
|
121 | + * |
|
122 | + * This report is used by clients to request calendar objects based on |
|
123 | + * complex conditions. |
|
124 | + * |
|
125 | + * @param Xml\Request\CalendarSearchReport $report |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + private function calendarSearch($report) { |
|
129 | + $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); |
|
130 | + $depth = $this->server->getHTTPDepth(0); |
|
131 | + |
|
132 | + // The default result is an empty array |
|
133 | + $result = []; |
|
134 | + |
|
135 | + // If we're dealing with the calendar home, the calendar home itself is |
|
136 | + // responsible for the calendar-query |
|
137 | + if ($node instanceof CalendarHome && $depth == 2) { |
|
138 | + |
|
139 | + $nodePaths = $node->calendarSearch($report->filters, $report->limit, $report->offset); |
|
140 | + |
|
141 | + foreach ($nodePaths as $path) { |
|
142 | + list($properties) = $this->server->getPropertiesForPath( |
|
143 | + $this->server->getRequestUri() . '/' . $path, |
|
144 | + $report->properties); |
|
145 | + $result[] = $properties; |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + $prefer = $this->server->getHTTPPrefer(); |
|
150 | + |
|
151 | + $this->server->httpResponse->setStatus(207); |
|
152 | + $this->server->httpResponse->setHeader('Content-Type', |
|
153 | + 'application/xml; charset=utf-8'); |
|
154 | + $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); |
|
155 | + $this->server->httpResponse->setBody( |
|
156 | + $this->server->generateMultiStatus($result, |
|
157 | + $prefer['return'] === 'minimal')); |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | \ No newline at end of file |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $server->on('report', [$this, 'report']); |
76 | 76 | |
77 | - $server->xml->elementMap['{' . self::NS_Nextcloud . '}calendar-search'] = |
|
77 | + $server->xml->elementMap['{'.self::NS_Nextcloud.'}calendar-search'] = |
|
78 | 78 | 'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport'; |
79 | 79 | } |
80 | 80 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | function report($reportName, $report, $path) { |
90 | 90 | switch ($reportName) { |
91 | - case '{' . self::NS_Nextcloud . '}calendar-search' : |
|
91 | + case '{'.self::NS_Nextcloud.'}calendar-search' : |
|
92 | 92 | $this->server->transactionType = 'report-nc-calendar-search'; |
93 | 93 | $this->calendarSearch($report); |
94 | 94 | return false; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | $reports = []; |
112 | 112 | if ($node instanceof CalendarHome) { |
113 | - $reports[] = '{' . self::NS_Nextcloud . '}calendar-search'; |
|
113 | + $reports[] = '{'.self::NS_Nextcloud.'}calendar-search'; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | return $reports; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | foreach ($nodePaths as $path) { |
142 | 142 | list($properties) = $this->server->getPropertiesForPath( |
143 | - $this->server->getRequestUri() . '/' . $path, |
|
143 | + $this->server->getRequestUri().'/'.$path, |
|
144 | 144 | $report->properties); |
145 | 145 | $result[] = $properties; |
146 | 146 | } |
@@ -79,7 +79,7 @@ |
||
79 | 79 | * the next element. |
80 | 80 | * |
81 | 81 | * @param Reader $reader |
82 | - * @return mixed |
|
82 | + * @return CalendarSearchReport |
|
83 | 83 | */ |
84 | 84 | static function xmlDeserialize(Reader $reader) { |
85 | 85 | $elems = $reader->parseInnerTree([ |
@@ -36,128 +36,128 @@ |
||
36 | 36 | */ |
37 | 37 | class CalendarSearchReport implements XmlDeserializable { |
38 | 38 | |
39 | - /** |
|
40 | - * An array with requested properties. |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - public $properties; |
|
39 | + /** |
|
40 | + * An array with requested properties. |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + public $properties; |
|
45 | 45 | |
46 | - /** |
|
47 | - * List of property/component filters. |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - public $filters; |
|
46 | + /** |
|
47 | + * List of property/component filters. |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + public $filters; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var int |
|
55 | - */ |
|
56 | - public $limit; |
|
53 | + /** |
|
54 | + * @var int |
|
55 | + */ |
|
56 | + public $limit; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @var int |
|
60 | - */ |
|
61 | - public $offset; |
|
58 | + /** |
|
59 | + * @var int |
|
60 | + */ |
|
61 | + public $offset; |
|
62 | 62 | |
63 | - /** |
|
64 | - * The deserialize method is called during xml parsing. |
|
65 | - * |
|
66 | - * This method is called statically, this is because in theory this method |
|
67 | - * may be used as a type of constructor, or factory method. |
|
68 | - * |
|
69 | - * Often you want to return an instance of the current class, but you are |
|
70 | - * free to return other data as well. |
|
71 | - * |
|
72 | - * You are responsible for advancing the reader to the next element. Not |
|
73 | - * doing anything will result in a never-ending loop. |
|
74 | - * |
|
75 | - * If you just want to skip parsing for this element altogether, you can |
|
76 | - * just call $reader->next(); |
|
77 | - * |
|
78 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
79 | - * the next element. |
|
80 | - * |
|
81 | - * @param Reader $reader |
|
82 | - * @return mixed |
|
83 | - */ |
|
84 | - static function xmlDeserialize(Reader $reader) { |
|
85 | - $elems = $reader->parseInnerTree([ |
|
86 | - '{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter', |
|
87 | - '{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter', |
|
88 | - '{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter', |
|
89 | - '{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter', |
|
90 | - '{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter', |
|
91 | - '{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter', |
|
92 | - '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
93 | - ]); |
|
63 | + /** |
|
64 | + * The deserialize method is called during xml parsing. |
|
65 | + * |
|
66 | + * This method is called statically, this is because in theory this method |
|
67 | + * may be used as a type of constructor, or factory method. |
|
68 | + * |
|
69 | + * Often you want to return an instance of the current class, but you are |
|
70 | + * free to return other data as well. |
|
71 | + * |
|
72 | + * You are responsible for advancing the reader to the next element. Not |
|
73 | + * doing anything will result in a never-ending loop. |
|
74 | + * |
|
75 | + * If you just want to skip parsing for this element altogether, you can |
|
76 | + * just call $reader->next(); |
|
77 | + * |
|
78 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
79 | + * the next element. |
|
80 | + * |
|
81 | + * @param Reader $reader |
|
82 | + * @return mixed |
|
83 | + */ |
|
84 | + static function xmlDeserialize(Reader $reader) { |
|
85 | + $elems = $reader->parseInnerTree([ |
|
86 | + '{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter', |
|
87 | + '{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter', |
|
88 | + '{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter', |
|
89 | + '{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter', |
|
90 | + '{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter', |
|
91 | + '{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter', |
|
92 | + '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
93 | + ]); |
|
94 | 94 | |
95 | - $newProps = [ |
|
96 | - 'filters' => [], |
|
97 | - 'properties' => [], |
|
98 | - 'limit' => null, |
|
99 | - 'offset' => null |
|
100 | - ]; |
|
95 | + $newProps = [ |
|
96 | + 'filters' => [], |
|
97 | + 'properties' => [], |
|
98 | + 'limit' => null, |
|
99 | + 'offset' => null |
|
100 | + ]; |
|
101 | 101 | |
102 | - if (!is_array($elems)) { |
|
103 | - $elems = []; |
|
104 | - } |
|
102 | + if (!is_array($elems)) { |
|
103 | + $elems = []; |
|
104 | + } |
|
105 | 105 | |
106 | - foreach ($elems as $elem) { |
|
107 | - switch ($elem['name']) { |
|
108 | - case '{DAV:}prop': |
|
109 | - $newProps['properties'] = array_keys($elem['value']); |
|
110 | - if (isset($elem['value']['{' . Plugin::NS_CALDAV . '}calendar-data'])) { |
|
111 | - $newProps += $elem['value']['{' . Plugin::NS_CALDAV . '}calendar-data']; |
|
112 | - } |
|
113 | - break; |
|
114 | - case '{' . SearchPlugin::NS_Nextcloud . '}filter': |
|
115 | - foreach ($elem['value'] as $subElem) { |
|
116 | - if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') { |
|
117 | - if (!is_array($newProps['filters']['comps'])) { |
|
118 | - $newProps['filters']['comps'] = []; |
|
119 | - } |
|
120 | - $newProps['filters']['comps'][] = $subElem['value']; |
|
121 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') { |
|
122 | - if (!is_array($newProps['filters']['props'])) { |
|
123 | - $newProps['filters']['props'] = []; |
|
124 | - } |
|
125 | - $newProps['filters']['props'][] = $subElem['value']; |
|
126 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') { |
|
127 | - if (!is_array($newProps['filters']['params'])) { |
|
128 | - $newProps['filters']['params'] = []; |
|
129 | - } |
|
130 | - $newProps['filters']['params'][] = $subElem['value']; |
|
131 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') { |
|
132 | - $newProps['filters']['search-term'] = $subElem['value']; |
|
133 | - } |
|
134 | - } |
|
135 | - break; |
|
136 | - case '{' . SearchPlugin::NS_Nextcloud . '}limit': |
|
137 | - $newProps['limit'] = $elem['value']; |
|
138 | - break; |
|
139 | - case '{' . SearchPlugin::NS_Nextcloud . '}offset': |
|
140 | - $newProps['offset'] = $elem['value']; |
|
141 | - break; |
|
106 | + foreach ($elems as $elem) { |
|
107 | + switch ($elem['name']) { |
|
108 | + case '{DAV:}prop': |
|
109 | + $newProps['properties'] = array_keys($elem['value']); |
|
110 | + if (isset($elem['value']['{' . Plugin::NS_CALDAV . '}calendar-data'])) { |
|
111 | + $newProps += $elem['value']['{' . Plugin::NS_CALDAV . '}calendar-data']; |
|
112 | + } |
|
113 | + break; |
|
114 | + case '{' . SearchPlugin::NS_Nextcloud . '}filter': |
|
115 | + foreach ($elem['value'] as $subElem) { |
|
116 | + if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') { |
|
117 | + if (!is_array($newProps['filters']['comps'])) { |
|
118 | + $newProps['filters']['comps'] = []; |
|
119 | + } |
|
120 | + $newProps['filters']['comps'][] = $subElem['value']; |
|
121 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') { |
|
122 | + if (!is_array($newProps['filters']['props'])) { |
|
123 | + $newProps['filters']['props'] = []; |
|
124 | + } |
|
125 | + $newProps['filters']['props'][] = $subElem['value']; |
|
126 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') { |
|
127 | + if (!is_array($newProps['filters']['params'])) { |
|
128 | + $newProps['filters']['params'] = []; |
|
129 | + } |
|
130 | + $newProps['filters']['params'][] = $subElem['value']; |
|
131 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') { |
|
132 | + $newProps['filters']['search-term'] = $subElem['value']; |
|
133 | + } |
|
134 | + } |
|
135 | + break; |
|
136 | + case '{' . SearchPlugin::NS_Nextcloud . '}limit': |
|
137 | + $newProps['limit'] = $elem['value']; |
|
138 | + break; |
|
139 | + case '{' . SearchPlugin::NS_Nextcloud . '}offset': |
|
140 | + $newProps['offset'] = $elem['value']; |
|
141 | + break; |
|
142 | 142 | |
143 | - } |
|
144 | - } |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - if (empty($newProps['filters'])) { |
|
147 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request'); |
|
148 | - } |
|
146 | + if (empty($newProps['filters'])) { |
|
147 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request'); |
|
148 | + } |
|
149 | 149 | |
150 | - $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters'])); |
|
151 | - $noCompsDefined = empty($newProps['filters']['comps']); |
|
152 | - if ($propsOrParamsDefined && $noCompsDefined) { |
|
153 | - throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter'); |
|
154 | - } |
|
150 | + $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters'])); |
|
151 | + $noCompsDefined = empty($newProps['filters']['comps']); |
|
152 | + if ($propsOrParamsDefined && $noCompsDefined) { |
|
153 | + throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter'); |
|
154 | + } |
|
155 | 155 | |
156 | 156 | |
157 | - $obj = new self(); |
|
158 | - foreach ($newProps as $key => $value) { |
|
159 | - $obj->$key = $value; |
|
160 | - } |
|
161 | - return $obj; |
|
162 | - } |
|
157 | + $obj = new self(); |
|
158 | + foreach ($newProps as $key => $value) { |
|
159 | + $obj->$key = $value; |
|
160 | + } |
|
161 | + return $obj; |
|
162 | + } |
|
163 | 163 | } |
@@ -107,36 +107,36 @@ discard block |
||
107 | 107 | switch ($elem['name']) { |
108 | 108 | case '{DAV:}prop': |
109 | 109 | $newProps['properties'] = array_keys($elem['value']); |
110 | - if (isset($elem['value']['{' . Plugin::NS_CALDAV . '}calendar-data'])) { |
|
111 | - $newProps += $elem['value']['{' . Plugin::NS_CALDAV . '}calendar-data']; |
|
110 | + if (isset($elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data'])) { |
|
111 | + $newProps += $elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data']; |
|
112 | 112 | } |
113 | 113 | break; |
114 | - case '{' . SearchPlugin::NS_Nextcloud . '}filter': |
|
114 | + case '{'.SearchPlugin::NS_Nextcloud.'}filter': |
|
115 | 115 | foreach ($elem['value'] as $subElem) { |
116 | - if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') { |
|
116 | + if ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}comp-filter') { |
|
117 | 117 | if (!is_array($newProps['filters']['comps'])) { |
118 | 118 | $newProps['filters']['comps'] = []; |
119 | 119 | } |
120 | 120 | $newProps['filters']['comps'][] = $subElem['value']; |
121 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') { |
|
121 | + } elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}prop-filter') { |
|
122 | 122 | if (!is_array($newProps['filters']['props'])) { |
123 | 123 | $newProps['filters']['props'] = []; |
124 | 124 | } |
125 | 125 | $newProps['filters']['props'][] = $subElem['value']; |
126 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') { |
|
126 | + } elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}param-filter') { |
|
127 | 127 | if (!is_array($newProps['filters']['params'])) { |
128 | 128 | $newProps['filters']['params'] = []; |
129 | 129 | } |
130 | 130 | $newProps['filters']['params'][] = $subElem['value']; |
131 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') { |
|
131 | + } elseif ($subElem['name'] === '{'.SearchPlugin::NS_Nextcloud.'}search-term') { |
|
132 | 132 | $newProps['filters']['search-term'] = $subElem['value']; |
133 | 133 | } |
134 | 134 | } |
135 | 135 | break; |
136 | - case '{' . SearchPlugin::NS_Nextcloud . '}limit': |
|
136 | + case '{'.SearchPlugin::NS_Nextcloud.'}limit': |
|
137 | 137 | $newProps['limit'] = $elem['value']; |
138 | 138 | break; |
139 | - case '{' . SearchPlugin::NS_Nextcloud . '}offset': |
|
139 | + case '{'.SearchPlugin::NS_Nextcloud.'}offset': |
|
140 | 140 | $newProps['offset'] = $elem['value']; |
141 | 141 | break; |
142 | 142 | |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | if (empty($newProps['filters'])) { |
147 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request'); |
|
147 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}filter element is required for this request'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters'])); |
151 | 151 | $noCompsDefined = empty($newProps['filters']['comps']); |
152 | 152 | if ($propsOrParamsDefined && $noCompsDefined) { |
153 | - throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter'); |
|
153 | + throw new BadRequest('{'.SearchPlugin::NS_Nextcloud.'}prop-filter or {'.SearchPlugin::NS_Nextcloud.'}param-filter given without any {'.SearchPlugin::NS_Nextcloud.'}comp-filter'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 |
@@ -59,1864 +59,1864 @@ |
||
59 | 59 | */ |
60 | 60 | class CalDavBackend extends AbstractBackend implements SyncSupport, SubscriptionSupport, SchedulingSupport { |
61 | 61 | |
62 | - const PERSONAL_CALENDAR_URI = 'personal'; |
|
63 | - const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
64 | - |
|
65 | - /** |
|
66 | - * We need to specify a max date, because we need to stop *somewhere* |
|
67 | - * |
|
68 | - * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
69 | - * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
70 | - * in 2038-01-19 to avoid problems when the date is converted |
|
71 | - * to a unix timestamp. |
|
72 | - */ |
|
73 | - const MAX_DATE = '2038-01-01'; |
|
74 | - |
|
75 | - const ACCESS_PUBLIC = 4; |
|
76 | - const CLASSIFICATION_PUBLIC = 0; |
|
77 | - const CLASSIFICATION_PRIVATE = 1; |
|
78 | - const CLASSIFICATION_CONFIDENTIAL = 2; |
|
79 | - |
|
80 | - /** |
|
81 | - * List of CalDAV properties, and how they map to database field names |
|
82 | - * Add your own properties by simply adding on to this array. |
|
83 | - * |
|
84 | - * Note that only string-based properties are supported here. |
|
85 | - * |
|
86 | - * @var array |
|
87 | - */ |
|
88 | - public $propertyMap = [ |
|
89 | - '{DAV:}displayname' => 'displayname', |
|
90 | - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
91 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
92 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
93 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
94 | - ]; |
|
95 | - |
|
96 | - /** |
|
97 | - * List of subscription properties, and how they map to database field names. |
|
98 | - * |
|
99 | - * @var array |
|
100 | - */ |
|
101 | - public $subscriptionPropertyMap = [ |
|
102 | - '{DAV:}displayname' => 'displayname', |
|
103 | - '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
104 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
105 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
106 | - '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
107 | - '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
108 | - '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
109 | - ]; |
|
110 | - |
|
111 | - /** |
|
112 | - * @var string[] Map of uid => display name |
|
113 | - */ |
|
114 | - protected $userDisplayNames; |
|
115 | - |
|
116 | - /** @var IDBConnection */ |
|
117 | - private $db; |
|
118 | - |
|
119 | - /** @var Backend */ |
|
120 | - private $sharingBackend; |
|
121 | - |
|
122 | - /** @var Principal */ |
|
123 | - private $principalBackend; |
|
124 | - |
|
125 | - /** @var IUserManager */ |
|
126 | - private $userManager; |
|
127 | - |
|
128 | - /** @var ISecureRandom */ |
|
129 | - private $random; |
|
130 | - |
|
131 | - /** @var EventDispatcherInterface */ |
|
132 | - private $dispatcher; |
|
133 | - |
|
134 | - /** @var bool */ |
|
135 | - private $legacyEndpoint; |
|
136 | - |
|
137 | - /** |
|
138 | - * CalDavBackend constructor. |
|
139 | - * |
|
140 | - * @param IDBConnection $db |
|
141 | - * @param Principal $principalBackend |
|
142 | - * @param IUserManager $userManager |
|
143 | - * @param ISecureRandom $random |
|
144 | - * @param EventDispatcherInterface $dispatcher |
|
145 | - * @param bool $legacyEndpoint |
|
146 | - */ |
|
147 | - public function __construct(IDBConnection $db, |
|
148 | - Principal $principalBackend, |
|
149 | - IUserManager $userManager, |
|
150 | - ISecureRandom $random, |
|
151 | - EventDispatcherInterface $dispatcher, |
|
152 | - $legacyEndpoint = false) { |
|
153 | - $this->db = $db; |
|
154 | - $this->principalBackend = $principalBackend; |
|
155 | - $this->userManager = $userManager; |
|
156 | - $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
|
157 | - $this->random = $random; |
|
158 | - $this->dispatcher = $dispatcher; |
|
159 | - $this->legacyEndpoint = $legacyEndpoint; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Return the number of calendars for a principal |
|
164 | - * |
|
165 | - * By default this excludes the automatically generated birthday calendar |
|
166 | - * |
|
167 | - * @param $principalUri |
|
168 | - * @param bool $excludeBirthday |
|
169 | - * @return int |
|
170 | - */ |
|
171 | - public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
172 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
173 | - $query = $this->db->getQueryBuilder(); |
|
174 | - $query->select($query->createFunction('COUNT(*)')) |
|
175 | - ->from('calendars') |
|
176 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
177 | - |
|
178 | - if ($excludeBirthday) { |
|
179 | - $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
180 | - } |
|
181 | - |
|
182 | - return (int)$query->execute()->fetchColumn(); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns a list of calendars for a principal. |
|
187 | - * |
|
188 | - * Every project is an array with the following keys: |
|
189 | - * * id, a unique id that will be used by other functions to modify the |
|
190 | - * calendar. This can be the same as the uri or a database key. |
|
191 | - * * uri, which the basename of the uri with which the calendar is |
|
192 | - * accessed. |
|
193 | - * * principaluri. The owner of the calendar. Almost always the same as |
|
194 | - * principalUri passed to this method. |
|
195 | - * |
|
196 | - * Furthermore it can contain webdav properties in clark notation. A very |
|
197 | - * common one is '{DAV:}displayname'. |
|
198 | - * |
|
199 | - * Many clients also require: |
|
200 | - * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
201 | - * For this property, you can just return an instance of |
|
202 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
203 | - * |
|
204 | - * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
205 | - * ACL will automatically be put in read-only mode. |
|
206 | - * |
|
207 | - * @param string $principalUri |
|
208 | - * @return array |
|
209 | - */ |
|
210 | - function getCalendarsForUser($principalUri) { |
|
211 | - $principalUriOriginal = $principalUri; |
|
212 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
213 | - $fields = array_values($this->propertyMap); |
|
214 | - $fields[] = 'id'; |
|
215 | - $fields[] = 'uri'; |
|
216 | - $fields[] = 'synctoken'; |
|
217 | - $fields[] = 'components'; |
|
218 | - $fields[] = 'principaluri'; |
|
219 | - $fields[] = 'transparent'; |
|
220 | - |
|
221 | - // Making fields a comma-delimited list |
|
222 | - $query = $this->db->getQueryBuilder(); |
|
223 | - $query->select($fields)->from('calendars') |
|
224 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
225 | - ->orderBy('calendarorder', 'ASC'); |
|
226 | - $stmt = $query->execute(); |
|
227 | - |
|
228 | - $calendars = []; |
|
229 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | - |
|
231 | - $components = []; |
|
232 | - if ($row['components']) { |
|
233 | - $components = explode(',',$row['components']); |
|
234 | - } |
|
235 | - |
|
236 | - $calendar = [ |
|
237 | - 'id' => $row['id'], |
|
238 | - 'uri' => $row['uri'], |
|
239 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
240 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | - ]; |
|
246 | - |
|
247 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
248 | - $calendar[$xmlName] = $row[$dbName]; |
|
249 | - } |
|
250 | - |
|
251 | - if (!isset($calendars[$calendar['id']])) { |
|
252 | - $calendars[$calendar['id']] = $calendar; |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - $stmt->closeCursor(); |
|
257 | - |
|
258 | - // query for shared calendars |
|
259 | - $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
260 | - $principals[]= $principalUri; |
|
261 | - |
|
262 | - $fields = array_values($this->propertyMap); |
|
263 | - $fields[] = 'a.id'; |
|
264 | - $fields[] = 'a.uri'; |
|
265 | - $fields[] = 'a.synctoken'; |
|
266 | - $fields[] = 'a.components'; |
|
267 | - $fields[] = 'a.principaluri'; |
|
268 | - $fields[] = 'a.transparent'; |
|
269 | - $fields[] = 's.access'; |
|
270 | - $query = $this->db->getQueryBuilder(); |
|
271 | - $result = $query->select($fields) |
|
272 | - ->from('dav_shares', 's') |
|
273 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
274 | - ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
275 | - ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
276 | - ->setParameter('type', 'calendar') |
|
277 | - ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
278 | - ->execute(); |
|
279 | - |
|
280 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
281 | - while($row = $result->fetch()) { |
|
282 | - $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
283 | - if (isset($calendars[$row['id']])) { |
|
284 | - if ($readOnly) { |
|
285 | - // New share can not have more permissions then the old one. |
|
286 | - continue; |
|
287 | - } |
|
288 | - if (isset($calendars[$row['id']][$readOnlyPropertyName]) && |
|
289 | - $calendars[$row['id']][$readOnlyPropertyName] === 0) { |
|
290 | - // Old share is already read-write, no more permissions can be gained |
|
291 | - continue; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
296 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
297 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
298 | - $components = []; |
|
299 | - if ($row['components']) { |
|
300 | - $components = explode(',',$row['components']); |
|
301 | - } |
|
302 | - $calendar = [ |
|
303 | - 'id' => $row['id'], |
|
304 | - 'uri' => $uri, |
|
305 | - 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
306 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
307 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
308 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
309 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
310 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
311 | - $readOnlyPropertyName => $readOnly, |
|
312 | - ]; |
|
313 | - |
|
314 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
315 | - $calendar[$xmlName] = $row[$dbName]; |
|
316 | - } |
|
317 | - |
|
318 | - $calendars[$calendar['id']] = $calendar; |
|
319 | - } |
|
320 | - $result->closeCursor(); |
|
321 | - |
|
322 | - return array_values($calendars); |
|
323 | - } |
|
324 | - |
|
325 | - public function getUsersOwnCalendars($principalUri) { |
|
326 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
327 | - $fields = array_values($this->propertyMap); |
|
328 | - $fields[] = 'id'; |
|
329 | - $fields[] = 'uri'; |
|
330 | - $fields[] = 'synctoken'; |
|
331 | - $fields[] = 'components'; |
|
332 | - $fields[] = 'principaluri'; |
|
333 | - $fields[] = 'transparent'; |
|
334 | - // Making fields a comma-delimited list |
|
335 | - $query = $this->db->getQueryBuilder(); |
|
336 | - $query->select($fields)->from('calendars') |
|
337 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
338 | - ->orderBy('calendarorder', 'ASC'); |
|
339 | - $stmt = $query->execute(); |
|
340 | - $calendars = []; |
|
341 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
342 | - $components = []; |
|
343 | - if ($row['components']) { |
|
344 | - $components = explode(',',$row['components']); |
|
345 | - } |
|
346 | - $calendar = [ |
|
347 | - 'id' => $row['id'], |
|
348 | - 'uri' => $row['uri'], |
|
349 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
350 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
351 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
352 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
353 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
354 | - ]; |
|
355 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
356 | - $calendar[$xmlName] = $row[$dbName]; |
|
357 | - } |
|
358 | - if (!isset($calendars[$calendar['id']])) { |
|
359 | - $calendars[$calendar['id']] = $calendar; |
|
360 | - } |
|
361 | - } |
|
362 | - $stmt->closeCursor(); |
|
363 | - return array_values($calendars); |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - private function getUserDisplayName($uid) { |
|
368 | - if (!isset($this->userDisplayNames[$uid])) { |
|
369 | - $user = $this->userManager->get($uid); |
|
370 | - |
|
371 | - if ($user instanceof IUser) { |
|
372 | - $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
373 | - } else { |
|
374 | - $this->userDisplayNames[$uid] = $uid; |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - return $this->userDisplayNames[$uid]; |
|
379 | - } |
|
62 | + const PERSONAL_CALENDAR_URI = 'personal'; |
|
63 | + const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
64 | + |
|
65 | + /** |
|
66 | + * We need to specify a max date, because we need to stop *somewhere* |
|
67 | + * |
|
68 | + * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
69 | + * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
70 | + * in 2038-01-19 to avoid problems when the date is converted |
|
71 | + * to a unix timestamp. |
|
72 | + */ |
|
73 | + const MAX_DATE = '2038-01-01'; |
|
74 | + |
|
75 | + const ACCESS_PUBLIC = 4; |
|
76 | + const CLASSIFICATION_PUBLIC = 0; |
|
77 | + const CLASSIFICATION_PRIVATE = 1; |
|
78 | + const CLASSIFICATION_CONFIDENTIAL = 2; |
|
79 | + |
|
80 | + /** |
|
81 | + * List of CalDAV properties, and how they map to database field names |
|
82 | + * Add your own properties by simply adding on to this array. |
|
83 | + * |
|
84 | + * Note that only string-based properties are supported here. |
|
85 | + * |
|
86 | + * @var array |
|
87 | + */ |
|
88 | + public $propertyMap = [ |
|
89 | + '{DAV:}displayname' => 'displayname', |
|
90 | + '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
91 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
92 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
93 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
94 | + ]; |
|
95 | + |
|
96 | + /** |
|
97 | + * List of subscription properties, and how they map to database field names. |
|
98 | + * |
|
99 | + * @var array |
|
100 | + */ |
|
101 | + public $subscriptionPropertyMap = [ |
|
102 | + '{DAV:}displayname' => 'displayname', |
|
103 | + '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
104 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
105 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
106 | + '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
107 | + '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
108 | + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
109 | + ]; |
|
110 | + |
|
111 | + /** |
|
112 | + * @var string[] Map of uid => display name |
|
113 | + */ |
|
114 | + protected $userDisplayNames; |
|
115 | + |
|
116 | + /** @var IDBConnection */ |
|
117 | + private $db; |
|
118 | + |
|
119 | + /** @var Backend */ |
|
120 | + private $sharingBackend; |
|
121 | + |
|
122 | + /** @var Principal */ |
|
123 | + private $principalBackend; |
|
124 | + |
|
125 | + /** @var IUserManager */ |
|
126 | + private $userManager; |
|
127 | + |
|
128 | + /** @var ISecureRandom */ |
|
129 | + private $random; |
|
130 | + |
|
131 | + /** @var EventDispatcherInterface */ |
|
132 | + private $dispatcher; |
|
133 | + |
|
134 | + /** @var bool */ |
|
135 | + private $legacyEndpoint; |
|
136 | + |
|
137 | + /** |
|
138 | + * CalDavBackend constructor. |
|
139 | + * |
|
140 | + * @param IDBConnection $db |
|
141 | + * @param Principal $principalBackend |
|
142 | + * @param IUserManager $userManager |
|
143 | + * @param ISecureRandom $random |
|
144 | + * @param EventDispatcherInterface $dispatcher |
|
145 | + * @param bool $legacyEndpoint |
|
146 | + */ |
|
147 | + public function __construct(IDBConnection $db, |
|
148 | + Principal $principalBackend, |
|
149 | + IUserManager $userManager, |
|
150 | + ISecureRandom $random, |
|
151 | + EventDispatcherInterface $dispatcher, |
|
152 | + $legacyEndpoint = false) { |
|
153 | + $this->db = $db; |
|
154 | + $this->principalBackend = $principalBackend; |
|
155 | + $this->userManager = $userManager; |
|
156 | + $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
|
157 | + $this->random = $random; |
|
158 | + $this->dispatcher = $dispatcher; |
|
159 | + $this->legacyEndpoint = $legacyEndpoint; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Return the number of calendars for a principal |
|
164 | + * |
|
165 | + * By default this excludes the automatically generated birthday calendar |
|
166 | + * |
|
167 | + * @param $principalUri |
|
168 | + * @param bool $excludeBirthday |
|
169 | + * @return int |
|
170 | + */ |
|
171 | + public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
172 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
173 | + $query = $this->db->getQueryBuilder(); |
|
174 | + $query->select($query->createFunction('COUNT(*)')) |
|
175 | + ->from('calendars') |
|
176 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
177 | + |
|
178 | + if ($excludeBirthday) { |
|
179 | + $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
180 | + } |
|
181 | + |
|
182 | + return (int)$query->execute()->fetchColumn(); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns a list of calendars for a principal. |
|
187 | + * |
|
188 | + * Every project is an array with the following keys: |
|
189 | + * * id, a unique id that will be used by other functions to modify the |
|
190 | + * calendar. This can be the same as the uri or a database key. |
|
191 | + * * uri, which the basename of the uri with which the calendar is |
|
192 | + * accessed. |
|
193 | + * * principaluri. The owner of the calendar. Almost always the same as |
|
194 | + * principalUri passed to this method. |
|
195 | + * |
|
196 | + * Furthermore it can contain webdav properties in clark notation. A very |
|
197 | + * common one is '{DAV:}displayname'. |
|
198 | + * |
|
199 | + * Many clients also require: |
|
200 | + * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
201 | + * For this property, you can just return an instance of |
|
202 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
203 | + * |
|
204 | + * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
205 | + * ACL will automatically be put in read-only mode. |
|
206 | + * |
|
207 | + * @param string $principalUri |
|
208 | + * @return array |
|
209 | + */ |
|
210 | + function getCalendarsForUser($principalUri) { |
|
211 | + $principalUriOriginal = $principalUri; |
|
212 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
213 | + $fields = array_values($this->propertyMap); |
|
214 | + $fields[] = 'id'; |
|
215 | + $fields[] = 'uri'; |
|
216 | + $fields[] = 'synctoken'; |
|
217 | + $fields[] = 'components'; |
|
218 | + $fields[] = 'principaluri'; |
|
219 | + $fields[] = 'transparent'; |
|
220 | + |
|
221 | + // Making fields a comma-delimited list |
|
222 | + $query = $this->db->getQueryBuilder(); |
|
223 | + $query->select($fields)->from('calendars') |
|
224 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
225 | + ->orderBy('calendarorder', 'ASC'); |
|
226 | + $stmt = $query->execute(); |
|
227 | + |
|
228 | + $calendars = []; |
|
229 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | + |
|
231 | + $components = []; |
|
232 | + if ($row['components']) { |
|
233 | + $components = explode(',',$row['components']); |
|
234 | + } |
|
235 | + |
|
236 | + $calendar = [ |
|
237 | + 'id' => $row['id'], |
|
238 | + 'uri' => $row['uri'], |
|
239 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
240 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | + ]; |
|
246 | + |
|
247 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
248 | + $calendar[$xmlName] = $row[$dbName]; |
|
249 | + } |
|
250 | + |
|
251 | + if (!isset($calendars[$calendar['id']])) { |
|
252 | + $calendars[$calendar['id']] = $calendar; |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + $stmt->closeCursor(); |
|
257 | + |
|
258 | + // query for shared calendars |
|
259 | + $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
260 | + $principals[]= $principalUri; |
|
261 | + |
|
262 | + $fields = array_values($this->propertyMap); |
|
263 | + $fields[] = 'a.id'; |
|
264 | + $fields[] = 'a.uri'; |
|
265 | + $fields[] = 'a.synctoken'; |
|
266 | + $fields[] = 'a.components'; |
|
267 | + $fields[] = 'a.principaluri'; |
|
268 | + $fields[] = 'a.transparent'; |
|
269 | + $fields[] = 's.access'; |
|
270 | + $query = $this->db->getQueryBuilder(); |
|
271 | + $result = $query->select($fields) |
|
272 | + ->from('dav_shares', 's') |
|
273 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
274 | + ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
275 | + ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
276 | + ->setParameter('type', 'calendar') |
|
277 | + ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
278 | + ->execute(); |
|
279 | + |
|
280 | + $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
281 | + while($row = $result->fetch()) { |
|
282 | + $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
283 | + if (isset($calendars[$row['id']])) { |
|
284 | + if ($readOnly) { |
|
285 | + // New share can not have more permissions then the old one. |
|
286 | + continue; |
|
287 | + } |
|
288 | + if (isset($calendars[$row['id']][$readOnlyPropertyName]) && |
|
289 | + $calendars[$row['id']][$readOnlyPropertyName] === 0) { |
|
290 | + // Old share is already read-write, no more permissions can be gained |
|
291 | + continue; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
296 | + $uri = $row['uri'] . '_shared_by_' . $name; |
|
297 | + $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
298 | + $components = []; |
|
299 | + if ($row['components']) { |
|
300 | + $components = explode(',',$row['components']); |
|
301 | + } |
|
302 | + $calendar = [ |
|
303 | + 'id' => $row['id'], |
|
304 | + 'uri' => $uri, |
|
305 | + 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
306 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
307 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
308 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
309 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
310 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
311 | + $readOnlyPropertyName => $readOnly, |
|
312 | + ]; |
|
313 | + |
|
314 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
315 | + $calendar[$xmlName] = $row[$dbName]; |
|
316 | + } |
|
317 | + |
|
318 | + $calendars[$calendar['id']] = $calendar; |
|
319 | + } |
|
320 | + $result->closeCursor(); |
|
321 | + |
|
322 | + return array_values($calendars); |
|
323 | + } |
|
324 | + |
|
325 | + public function getUsersOwnCalendars($principalUri) { |
|
326 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
327 | + $fields = array_values($this->propertyMap); |
|
328 | + $fields[] = 'id'; |
|
329 | + $fields[] = 'uri'; |
|
330 | + $fields[] = 'synctoken'; |
|
331 | + $fields[] = 'components'; |
|
332 | + $fields[] = 'principaluri'; |
|
333 | + $fields[] = 'transparent'; |
|
334 | + // Making fields a comma-delimited list |
|
335 | + $query = $this->db->getQueryBuilder(); |
|
336 | + $query->select($fields)->from('calendars') |
|
337 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
338 | + ->orderBy('calendarorder', 'ASC'); |
|
339 | + $stmt = $query->execute(); |
|
340 | + $calendars = []; |
|
341 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
342 | + $components = []; |
|
343 | + if ($row['components']) { |
|
344 | + $components = explode(',',$row['components']); |
|
345 | + } |
|
346 | + $calendar = [ |
|
347 | + 'id' => $row['id'], |
|
348 | + 'uri' => $row['uri'], |
|
349 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
350 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
351 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
352 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
353 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
354 | + ]; |
|
355 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
356 | + $calendar[$xmlName] = $row[$dbName]; |
|
357 | + } |
|
358 | + if (!isset($calendars[$calendar['id']])) { |
|
359 | + $calendars[$calendar['id']] = $calendar; |
|
360 | + } |
|
361 | + } |
|
362 | + $stmt->closeCursor(); |
|
363 | + return array_values($calendars); |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + private function getUserDisplayName($uid) { |
|
368 | + if (!isset($this->userDisplayNames[$uid])) { |
|
369 | + $user = $this->userManager->get($uid); |
|
370 | + |
|
371 | + if ($user instanceof IUser) { |
|
372 | + $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
373 | + } else { |
|
374 | + $this->userDisplayNames[$uid] = $uid; |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + return $this->userDisplayNames[$uid]; |
|
379 | + } |
|
380 | 380 | |
381 | - /** |
|
382 | - * @return array |
|
383 | - */ |
|
384 | - public function getPublicCalendars() { |
|
385 | - $fields = array_values($this->propertyMap); |
|
386 | - $fields[] = 'a.id'; |
|
387 | - $fields[] = 'a.uri'; |
|
388 | - $fields[] = 'a.synctoken'; |
|
389 | - $fields[] = 'a.components'; |
|
390 | - $fields[] = 'a.principaluri'; |
|
391 | - $fields[] = 'a.transparent'; |
|
392 | - $fields[] = 's.access'; |
|
393 | - $fields[] = 's.publicuri'; |
|
394 | - $calendars = []; |
|
395 | - $query = $this->db->getQueryBuilder(); |
|
396 | - $result = $query->select($fields) |
|
397 | - ->from('dav_shares', 's') |
|
398 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
399 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
400 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
401 | - ->execute(); |
|
402 | - |
|
403 | - while($row = $result->fetch()) { |
|
404 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
405 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
406 | - $components = []; |
|
407 | - if ($row['components']) { |
|
408 | - $components = explode(',',$row['components']); |
|
409 | - } |
|
410 | - $calendar = [ |
|
411 | - 'id' => $row['id'], |
|
412 | - 'uri' => $row['publicuri'], |
|
413 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
414 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
415 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
416 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
417 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
418 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
419 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
420 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
421 | - ]; |
|
422 | - |
|
423 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
424 | - $calendar[$xmlName] = $row[$dbName]; |
|
425 | - } |
|
426 | - |
|
427 | - if (!isset($calendars[$calendar['id']])) { |
|
428 | - $calendars[$calendar['id']] = $calendar; |
|
429 | - } |
|
430 | - } |
|
431 | - $result->closeCursor(); |
|
432 | - |
|
433 | - return array_values($calendars); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * @param string $uri |
|
438 | - * @return array |
|
439 | - * @throws NotFound |
|
440 | - */ |
|
441 | - public function getPublicCalendar($uri) { |
|
442 | - $fields = array_values($this->propertyMap); |
|
443 | - $fields[] = 'a.id'; |
|
444 | - $fields[] = 'a.uri'; |
|
445 | - $fields[] = 'a.synctoken'; |
|
446 | - $fields[] = 'a.components'; |
|
447 | - $fields[] = 'a.principaluri'; |
|
448 | - $fields[] = 'a.transparent'; |
|
449 | - $fields[] = 's.access'; |
|
450 | - $fields[] = 's.publicuri'; |
|
451 | - $query = $this->db->getQueryBuilder(); |
|
452 | - $result = $query->select($fields) |
|
453 | - ->from('dav_shares', 's') |
|
454 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
455 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
456 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
457 | - ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
458 | - ->execute(); |
|
459 | - |
|
460 | - $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
461 | - |
|
462 | - $result->closeCursor(); |
|
463 | - |
|
464 | - if ($row === false) { |
|
465 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
466 | - } |
|
467 | - |
|
468 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
469 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
470 | - $components = []; |
|
471 | - if ($row['components']) { |
|
472 | - $components = explode(',',$row['components']); |
|
473 | - } |
|
474 | - $calendar = [ |
|
475 | - 'id' => $row['id'], |
|
476 | - 'uri' => $row['publicuri'], |
|
477 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
478 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
479 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
480 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
481 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
482 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
483 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
484 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
485 | - ]; |
|
486 | - |
|
487 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
488 | - $calendar[$xmlName] = $row[$dbName]; |
|
489 | - } |
|
490 | - |
|
491 | - return $calendar; |
|
492 | - |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * @param string $principal |
|
497 | - * @param string $uri |
|
498 | - * @return array|null |
|
499 | - */ |
|
500 | - public function getCalendarByUri($principal, $uri) { |
|
501 | - $fields = array_values($this->propertyMap); |
|
502 | - $fields[] = 'id'; |
|
503 | - $fields[] = 'uri'; |
|
504 | - $fields[] = 'synctoken'; |
|
505 | - $fields[] = 'components'; |
|
506 | - $fields[] = 'principaluri'; |
|
507 | - $fields[] = 'transparent'; |
|
508 | - |
|
509 | - // Making fields a comma-delimited list |
|
510 | - $query = $this->db->getQueryBuilder(); |
|
511 | - $query->select($fields)->from('calendars') |
|
512 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
513 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
514 | - ->setMaxResults(1); |
|
515 | - $stmt = $query->execute(); |
|
516 | - |
|
517 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
518 | - $stmt->closeCursor(); |
|
519 | - if ($row === false) { |
|
520 | - return null; |
|
521 | - } |
|
522 | - |
|
523 | - $components = []; |
|
524 | - if ($row['components']) { |
|
525 | - $components = explode(',',$row['components']); |
|
526 | - } |
|
527 | - |
|
528 | - $calendar = [ |
|
529 | - 'id' => $row['id'], |
|
530 | - 'uri' => $row['uri'], |
|
531 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
532 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
533 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
534 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
535 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
536 | - ]; |
|
537 | - |
|
538 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
539 | - $calendar[$xmlName] = $row[$dbName]; |
|
540 | - } |
|
541 | - |
|
542 | - return $calendar; |
|
543 | - } |
|
544 | - |
|
545 | - public function getCalendarById($calendarId) { |
|
546 | - $fields = array_values($this->propertyMap); |
|
547 | - $fields[] = 'id'; |
|
548 | - $fields[] = 'uri'; |
|
549 | - $fields[] = 'synctoken'; |
|
550 | - $fields[] = 'components'; |
|
551 | - $fields[] = 'principaluri'; |
|
552 | - $fields[] = 'transparent'; |
|
553 | - |
|
554 | - // Making fields a comma-delimited list |
|
555 | - $query = $this->db->getQueryBuilder(); |
|
556 | - $query->select($fields)->from('calendars') |
|
557 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
558 | - ->setMaxResults(1); |
|
559 | - $stmt = $query->execute(); |
|
560 | - |
|
561 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
562 | - $stmt->closeCursor(); |
|
563 | - if ($row === false) { |
|
564 | - return null; |
|
565 | - } |
|
566 | - |
|
567 | - $components = []; |
|
568 | - if ($row['components']) { |
|
569 | - $components = explode(',',$row['components']); |
|
570 | - } |
|
571 | - |
|
572 | - $calendar = [ |
|
573 | - 'id' => $row['id'], |
|
574 | - 'uri' => $row['uri'], |
|
575 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
576 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
577 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
578 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
579 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
580 | - ]; |
|
581 | - |
|
582 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
583 | - $calendar[$xmlName] = $row[$dbName]; |
|
584 | - } |
|
585 | - |
|
586 | - return $calendar; |
|
587 | - } |
|
588 | - |
|
589 | - /** |
|
590 | - * Creates a new calendar for a principal. |
|
591 | - * |
|
592 | - * If the creation was a success, an id must be returned that can be used to reference |
|
593 | - * this calendar in other methods, such as updateCalendar. |
|
594 | - * |
|
595 | - * @param string $principalUri |
|
596 | - * @param string $calendarUri |
|
597 | - * @param array $properties |
|
598 | - * @return int |
|
599 | - */ |
|
600 | - function createCalendar($principalUri, $calendarUri, array $properties) { |
|
601 | - $values = [ |
|
602 | - 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
603 | - 'uri' => $calendarUri, |
|
604 | - 'synctoken' => 1, |
|
605 | - 'transparent' => 0, |
|
606 | - 'components' => 'VEVENT,VTODO', |
|
607 | - 'displayname' => $calendarUri |
|
608 | - ]; |
|
609 | - |
|
610 | - // Default value |
|
611 | - $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
612 | - if (isset($properties[$sccs])) { |
|
613 | - if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
614 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
615 | - } |
|
616 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
617 | - } |
|
618 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
619 | - if (isset($properties[$transp])) { |
|
620 | - $values['transparent'] = $properties[$transp]->getValue()==='transparent'; |
|
621 | - } |
|
622 | - |
|
623 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
624 | - if (isset($properties[$xmlName])) { |
|
625 | - $values[$dbName] = $properties[$xmlName]; |
|
626 | - } |
|
627 | - } |
|
628 | - |
|
629 | - $query = $this->db->getQueryBuilder(); |
|
630 | - $query->insert('calendars'); |
|
631 | - foreach($values as $column => $value) { |
|
632 | - $query->setValue($column, $query->createNamedParameter($value)); |
|
633 | - } |
|
634 | - $query->execute(); |
|
635 | - $calendarId = $query->getLastInsertId(); |
|
636 | - |
|
637 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
638 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
639 | - [ |
|
640 | - 'calendarId' => $calendarId, |
|
641 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
642 | - ])); |
|
643 | - |
|
644 | - return $calendarId; |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Updates properties for a calendar. |
|
649 | - * |
|
650 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
651 | - * To do the actual updates, you must tell this object which properties |
|
652 | - * you're going to process with the handle() method. |
|
653 | - * |
|
654 | - * Calling the handle method is like telling the PropPatch object "I |
|
655 | - * promise I can handle updating this property". |
|
656 | - * |
|
657 | - * Read the PropPatch documentation for more info and examples. |
|
658 | - * |
|
659 | - * @param PropPatch $propPatch |
|
660 | - * @return void |
|
661 | - */ |
|
662 | - function updateCalendar($calendarId, PropPatch $propPatch) { |
|
663 | - $supportedProperties = array_keys($this->propertyMap); |
|
664 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
665 | - |
|
666 | - $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
667 | - $newValues = []; |
|
668 | - foreach ($mutations as $propertyName => $propertyValue) { |
|
669 | - |
|
670 | - switch ($propertyName) { |
|
671 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
672 | - $fieldName = 'transparent'; |
|
673 | - $newValues[$fieldName] = $propertyValue->getValue() === 'transparent'; |
|
674 | - break; |
|
675 | - default : |
|
676 | - $fieldName = $this->propertyMap[$propertyName]; |
|
677 | - $newValues[$fieldName] = $propertyValue; |
|
678 | - break; |
|
679 | - } |
|
680 | - |
|
681 | - } |
|
682 | - $query = $this->db->getQueryBuilder(); |
|
683 | - $query->update('calendars'); |
|
684 | - foreach ($newValues as $fieldName => $value) { |
|
685 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
686 | - } |
|
687 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
688 | - $query->execute(); |
|
689 | - |
|
690 | - $this->addChange($calendarId, "", 2); |
|
691 | - |
|
692 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
693 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
694 | - [ |
|
695 | - 'calendarId' => $calendarId, |
|
696 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
697 | - 'shares' => $this->getShares($calendarId), |
|
698 | - 'propertyMutations' => $mutations, |
|
699 | - ])); |
|
700 | - |
|
701 | - return true; |
|
702 | - }); |
|
703 | - } |
|
704 | - |
|
705 | - /** |
|
706 | - * Delete a calendar and all it's objects |
|
707 | - * |
|
708 | - * @param mixed $calendarId |
|
709 | - * @return void |
|
710 | - */ |
|
711 | - function deleteCalendar($calendarId) { |
|
712 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
713 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
714 | - [ |
|
715 | - 'calendarId' => $calendarId, |
|
716 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
717 | - 'shares' => $this->getShares($calendarId), |
|
718 | - ])); |
|
719 | - |
|
720 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
721 | - $stmt->execute([$calendarId]); |
|
722 | - |
|
723 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
724 | - $stmt->execute([$calendarId]); |
|
725 | - |
|
726 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
727 | - $stmt->execute([$calendarId]); |
|
728 | - |
|
729 | - $this->sharingBackend->deleteAllShares($calendarId); |
|
730 | - } |
|
731 | - |
|
732 | - /** |
|
733 | - * Delete all of an user's shares |
|
734 | - * |
|
735 | - * @param string $principaluri |
|
736 | - * @return void |
|
737 | - */ |
|
738 | - function deleteAllSharesByUser($principaluri) { |
|
739 | - $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Returns all calendar objects within a calendar. |
|
744 | - * |
|
745 | - * Every item contains an array with the following keys: |
|
746 | - * * calendardata - The iCalendar-compatible calendar data |
|
747 | - * * uri - a unique key which will be used to construct the uri. This can |
|
748 | - * be any arbitrary string, but making sure it ends with '.ics' is a |
|
749 | - * good idea. This is only the basename, or filename, not the full |
|
750 | - * path. |
|
751 | - * * lastmodified - a timestamp of the last modification time |
|
752 | - * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
753 | - * '"abcdef"') |
|
754 | - * * size - The size of the calendar objects, in bytes. |
|
755 | - * * component - optional, a string containing the type of object, such |
|
756 | - * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
757 | - * the Content-Type header. |
|
758 | - * |
|
759 | - * Note that the etag is optional, but it's highly encouraged to return for |
|
760 | - * speed reasons. |
|
761 | - * |
|
762 | - * The calendardata is also optional. If it's not returned |
|
763 | - * 'getCalendarObject' will be called later, which *is* expected to return |
|
764 | - * calendardata. |
|
765 | - * |
|
766 | - * If neither etag or size are specified, the calendardata will be |
|
767 | - * used/fetched to determine these numbers. If both are specified the |
|
768 | - * amount of times this is needed is reduced by a great degree. |
|
769 | - * |
|
770 | - * @param mixed $calendarId |
|
771 | - * @return array |
|
772 | - */ |
|
773 | - function getCalendarObjects($calendarId) { |
|
774 | - $query = $this->db->getQueryBuilder(); |
|
775 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
776 | - ->from('calendarobjects') |
|
777 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
778 | - $stmt = $query->execute(); |
|
779 | - |
|
780 | - $result = []; |
|
781 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
782 | - $result[] = [ |
|
783 | - 'id' => $row['id'], |
|
784 | - 'uri' => $row['uri'], |
|
785 | - 'lastmodified' => $row['lastmodified'], |
|
786 | - 'etag' => '"' . $row['etag'] . '"', |
|
787 | - 'calendarid' => $row['calendarid'], |
|
788 | - 'size' => (int)$row['size'], |
|
789 | - 'component' => strtolower($row['componenttype']), |
|
790 | - 'classification'=> (int)$row['classification'] |
|
791 | - ]; |
|
792 | - } |
|
793 | - |
|
794 | - return $result; |
|
795 | - } |
|
796 | - |
|
797 | - /** |
|
798 | - * Returns information from a single calendar object, based on it's object |
|
799 | - * uri. |
|
800 | - * |
|
801 | - * The object uri is only the basename, or filename and not a full path. |
|
802 | - * |
|
803 | - * The returned array must have the same keys as getCalendarObjects. The |
|
804 | - * 'calendardata' object is required here though, while it's not required |
|
805 | - * for getCalendarObjects. |
|
806 | - * |
|
807 | - * This method must return null if the object did not exist. |
|
808 | - * |
|
809 | - * @param mixed $calendarId |
|
810 | - * @param string $objectUri |
|
811 | - * @return array|null |
|
812 | - */ |
|
813 | - function getCalendarObject($calendarId, $objectUri) { |
|
814 | - |
|
815 | - $query = $this->db->getQueryBuilder(); |
|
816 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
817 | - ->from('calendarobjects') |
|
818 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
819 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
820 | - $stmt = $query->execute(); |
|
821 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
822 | - |
|
823 | - if(!$row) return null; |
|
824 | - |
|
825 | - return [ |
|
826 | - 'id' => $row['id'], |
|
827 | - 'uri' => $row['uri'], |
|
828 | - 'lastmodified' => $row['lastmodified'], |
|
829 | - 'etag' => '"' . $row['etag'] . '"', |
|
830 | - 'calendarid' => $row['calendarid'], |
|
831 | - 'size' => (int)$row['size'], |
|
832 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
833 | - 'component' => strtolower($row['componenttype']), |
|
834 | - 'classification'=> (int)$row['classification'] |
|
835 | - ]; |
|
836 | - } |
|
837 | - |
|
838 | - /** |
|
839 | - * Returns a list of calendar objects. |
|
840 | - * |
|
841 | - * This method should work identical to getCalendarObject, but instead |
|
842 | - * return all the calendar objects in the list as an array. |
|
843 | - * |
|
844 | - * If the backend supports this, it may allow for some speed-ups. |
|
845 | - * |
|
846 | - * @param mixed $calendarId |
|
847 | - * @param string[] $uris |
|
848 | - * @return array |
|
849 | - */ |
|
850 | - function getMultipleCalendarObjects($calendarId, array $uris) { |
|
851 | - if (empty($uris)) { |
|
852 | - return []; |
|
853 | - } |
|
854 | - |
|
855 | - $chunks = array_chunk($uris, 100); |
|
856 | - $objects = []; |
|
857 | - |
|
858 | - $query = $this->db->getQueryBuilder(); |
|
859 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
860 | - ->from('calendarobjects') |
|
861 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
862 | - ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
863 | - |
|
864 | - foreach ($chunks as $uris) { |
|
865 | - $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
866 | - $result = $query->execute(); |
|
867 | - |
|
868 | - while ($row = $result->fetch()) { |
|
869 | - $objects[] = [ |
|
870 | - 'id' => $row['id'], |
|
871 | - 'uri' => $row['uri'], |
|
872 | - 'lastmodified' => $row['lastmodified'], |
|
873 | - 'etag' => '"' . $row['etag'] . '"', |
|
874 | - 'calendarid' => $row['calendarid'], |
|
875 | - 'size' => (int)$row['size'], |
|
876 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
877 | - 'component' => strtolower($row['componenttype']), |
|
878 | - 'classification' => (int)$row['classification'] |
|
879 | - ]; |
|
880 | - } |
|
881 | - $result->closeCursor(); |
|
882 | - } |
|
883 | - return $objects; |
|
884 | - } |
|
885 | - |
|
886 | - /** |
|
887 | - * Creates a new calendar object. |
|
888 | - * |
|
889 | - * The object uri is only the basename, or filename and not a full path. |
|
890 | - * |
|
891 | - * It is possible return an etag from this function, which will be used in |
|
892 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
893 | - * by double-quotes. |
|
894 | - * |
|
895 | - * However, you should only really return this ETag if you don't mangle the |
|
896 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
897 | - * the exact same as this request body, you should omit the ETag. |
|
898 | - * |
|
899 | - * @param mixed $calendarId |
|
900 | - * @param string $objectUri |
|
901 | - * @param string $calendarData |
|
902 | - * @return string |
|
903 | - */ |
|
904 | - function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
905 | - $extraData = $this->getDenormalizedData($calendarData); |
|
906 | - |
|
907 | - $query = $this->db->getQueryBuilder(); |
|
908 | - $query->insert('calendarobjects') |
|
909 | - ->values([ |
|
910 | - 'calendarid' => $query->createNamedParameter($calendarId), |
|
911 | - 'uri' => $query->createNamedParameter($objectUri), |
|
912 | - 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
913 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
914 | - 'etag' => $query->createNamedParameter($extraData['etag']), |
|
915 | - 'size' => $query->createNamedParameter($extraData['size']), |
|
916 | - 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
917 | - 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
918 | - 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
919 | - 'classification' => $query->createNamedParameter($extraData['classification']), |
|
920 | - 'uid' => $query->createNamedParameter($extraData['uid']), |
|
921 | - ]) |
|
922 | - ->execute(); |
|
923 | - |
|
924 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
925 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
926 | - [ |
|
927 | - 'calendarId' => $calendarId, |
|
928 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
929 | - 'shares' => $this->getShares($calendarId), |
|
930 | - 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
931 | - ] |
|
932 | - )); |
|
933 | - $this->addChange($calendarId, $objectUri, 1); |
|
934 | - |
|
935 | - return '"' . $extraData['etag'] . '"'; |
|
936 | - } |
|
937 | - |
|
938 | - /** |
|
939 | - * Updates an existing calendarobject, based on it's uri. |
|
940 | - * |
|
941 | - * The object uri is only the basename, or filename and not a full path. |
|
942 | - * |
|
943 | - * It is possible return an etag from this function, which will be used in |
|
944 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
945 | - * by double-quotes. |
|
946 | - * |
|
947 | - * However, you should only really return this ETag if you don't mangle the |
|
948 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
949 | - * the exact same as this request body, you should omit the ETag. |
|
950 | - * |
|
951 | - * @param mixed $calendarId |
|
952 | - * @param string $objectUri |
|
953 | - * @param string $calendarData |
|
954 | - * @return string |
|
955 | - */ |
|
956 | - function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
957 | - $extraData = $this->getDenormalizedData($calendarData); |
|
958 | - |
|
959 | - $query = $this->db->getQueryBuilder(); |
|
960 | - $query->update('calendarobjects') |
|
961 | - ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
962 | - ->set('lastmodified', $query->createNamedParameter(time())) |
|
963 | - ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
964 | - ->set('size', $query->createNamedParameter($extraData['size'])) |
|
965 | - ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
966 | - ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
967 | - ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
968 | - ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
969 | - ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
970 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
971 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
972 | - ->execute(); |
|
973 | - |
|
974 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
975 | - if (is_array($data)) { |
|
976 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
977 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
978 | - [ |
|
979 | - 'calendarId' => $calendarId, |
|
980 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
981 | - 'shares' => $this->getShares($calendarId), |
|
982 | - 'objectData' => $data, |
|
983 | - ] |
|
984 | - )); |
|
985 | - } |
|
986 | - $this->addChange($calendarId, $objectUri, 2); |
|
987 | - |
|
988 | - return '"' . $extraData['etag'] . '"'; |
|
989 | - } |
|
990 | - |
|
991 | - /** |
|
992 | - * @param int $calendarObjectId |
|
993 | - * @param int $classification |
|
994 | - */ |
|
995 | - public function setClassification($calendarObjectId, $classification) { |
|
996 | - if (!in_array($classification, [ |
|
997 | - self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
998 | - ])) { |
|
999 | - throw new \InvalidArgumentException(); |
|
1000 | - } |
|
1001 | - $query = $this->db->getQueryBuilder(); |
|
1002 | - $query->update('calendarobjects') |
|
1003 | - ->set('classification', $query->createNamedParameter($classification)) |
|
1004 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
1005 | - ->execute(); |
|
1006 | - } |
|
1007 | - |
|
1008 | - /** |
|
1009 | - * Deletes an existing calendar object. |
|
1010 | - * |
|
1011 | - * The object uri is only the basename, or filename and not a full path. |
|
1012 | - * |
|
1013 | - * @param mixed $calendarId |
|
1014 | - * @param string $objectUri |
|
1015 | - * @return void |
|
1016 | - */ |
|
1017 | - function deleteCalendarObject($calendarId, $objectUri) { |
|
1018 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1019 | - if (is_array($data)) { |
|
1020 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
1021 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
1022 | - [ |
|
1023 | - 'calendarId' => $calendarId, |
|
1024 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1025 | - 'shares' => $this->getShares($calendarId), |
|
1026 | - 'objectData' => $data, |
|
1027 | - ] |
|
1028 | - )); |
|
1029 | - } |
|
1030 | - |
|
1031 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
1032 | - $stmt->execute([$calendarId, $objectUri]); |
|
1033 | - |
|
1034 | - $this->addChange($calendarId, $objectUri, 3); |
|
1035 | - } |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * Performs a calendar-query on the contents of this calendar. |
|
1039 | - * |
|
1040 | - * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
1041 | - * calendar-query it is possible for a client to request a specific set of |
|
1042 | - * object, based on contents of iCalendar properties, date-ranges and |
|
1043 | - * iCalendar component types (VTODO, VEVENT). |
|
1044 | - * |
|
1045 | - * This method should just return a list of (relative) urls that match this |
|
1046 | - * query. |
|
1047 | - * |
|
1048 | - * The list of filters are specified as an array. The exact array is |
|
1049 | - * documented by Sabre\CalDAV\CalendarQueryParser. |
|
1050 | - * |
|
1051 | - * Note that it is extremely likely that getCalendarObject for every path |
|
1052 | - * returned from this method will be called almost immediately after. You |
|
1053 | - * may want to anticipate this to speed up these requests. |
|
1054 | - * |
|
1055 | - * This method provides a default implementation, which parses *all* the |
|
1056 | - * iCalendar objects in the specified calendar. |
|
1057 | - * |
|
1058 | - * This default may well be good enough for personal use, and calendars |
|
1059 | - * that aren't very large. But if you anticipate high usage, big calendars |
|
1060 | - * or high loads, you are strongly advised to optimize certain paths. |
|
1061 | - * |
|
1062 | - * The best way to do so is override this method and to optimize |
|
1063 | - * specifically for 'common filters'. |
|
1064 | - * |
|
1065 | - * Requests that are extremely common are: |
|
1066 | - * * requests for just VEVENTS |
|
1067 | - * * requests for just VTODO |
|
1068 | - * * requests with a time-range-filter on either VEVENT or VTODO. |
|
1069 | - * |
|
1070 | - * ..and combinations of these requests. It may not be worth it to try to |
|
1071 | - * handle every possible situation and just rely on the (relatively |
|
1072 | - * easy to use) CalendarQueryValidator to handle the rest. |
|
1073 | - * |
|
1074 | - * Note that especially time-range-filters may be difficult to parse. A |
|
1075 | - * time-range filter specified on a VEVENT must for instance also handle |
|
1076 | - * recurrence rules correctly. |
|
1077 | - * A good example of how to interprete all these filters can also simply |
|
1078 | - * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
1079 | - * as possible, so it gives you a good idea on what type of stuff you need |
|
1080 | - * to think of. |
|
1081 | - * |
|
1082 | - * @param mixed $calendarId |
|
1083 | - * @param array $filters |
|
1084 | - * @return array |
|
1085 | - */ |
|
1086 | - function calendarQuery($calendarId, array $filters) { |
|
1087 | - $componentType = null; |
|
1088 | - $requirePostFilter = true; |
|
1089 | - $timeRange = null; |
|
1090 | - |
|
1091 | - // if no filters were specified, we don't need to filter after a query |
|
1092 | - if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
1093 | - $requirePostFilter = false; |
|
1094 | - } |
|
1095 | - |
|
1096 | - // Figuring out if there's a component filter |
|
1097 | - if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
1098 | - $componentType = $filters['comp-filters'][0]['name']; |
|
1099 | - |
|
1100 | - // Checking if we need post-filters |
|
1101 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
1102 | - $requirePostFilter = false; |
|
1103 | - } |
|
1104 | - // There was a time-range filter |
|
1105 | - if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
1106 | - $timeRange = $filters['comp-filters'][0]['time-range']; |
|
1107 | - |
|
1108 | - // If start time OR the end time is not specified, we can do a |
|
1109 | - // 100% accurate mysql query. |
|
1110 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
1111 | - $requirePostFilter = false; |
|
1112 | - } |
|
1113 | - } |
|
1114 | - |
|
1115 | - } |
|
1116 | - $columns = ['uri']; |
|
1117 | - if ($requirePostFilter) { |
|
1118 | - $columns = ['uri', 'calendardata']; |
|
1119 | - } |
|
1120 | - $query = $this->db->getQueryBuilder(); |
|
1121 | - $query->select($columns) |
|
1122 | - ->from('calendarobjects') |
|
1123 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
1124 | - |
|
1125 | - if ($componentType) { |
|
1126 | - $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
1127 | - } |
|
1128 | - |
|
1129 | - if ($timeRange && $timeRange['start']) { |
|
1130 | - $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
1131 | - } |
|
1132 | - if ($timeRange && $timeRange['end']) { |
|
1133 | - $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
1134 | - } |
|
1135 | - |
|
1136 | - $stmt = $query->execute(); |
|
1137 | - |
|
1138 | - $result = []; |
|
1139 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1140 | - if ($requirePostFilter) { |
|
1141 | - if (!$this->validateFilterForObject($row, $filters)) { |
|
1142 | - continue; |
|
1143 | - } |
|
1144 | - } |
|
1145 | - $result[] = $row['uri']; |
|
1146 | - } |
|
1147 | - |
|
1148 | - return $result; |
|
1149 | - } |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * custom Nextcloud search extension for CalDAV |
|
1153 | - * |
|
1154 | - * @param string $principalUri |
|
1155 | - * @param array $filters |
|
1156 | - * @param integer|null $limit |
|
1157 | - * @param integer|null $offset |
|
1158 | - * @return array |
|
1159 | - */ |
|
1160 | - public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1161 | - $calendars = $this->getCalendarsForUser($principalUri); |
|
1162 | - $ownCalendars = []; |
|
1163 | - $sharedCalendars = []; |
|
1164 | - |
|
1165 | - $uriMapper = []; |
|
1166 | - |
|
1167 | - foreach($calendars as $calendar) { |
|
1168 | - if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
|
1169 | - $ownCalendars[] = $calendar['id']; |
|
1170 | - } else { |
|
1171 | - $sharedCalendars[] = $calendar['id']; |
|
1172 | - } |
|
1173 | - $uriMapper[$calendar['id']] = $calendar['uri']; |
|
1174 | - } |
|
1175 | - if (count($ownCalendars) === 0 && count($sharedCalendars) === 0) { |
|
1176 | - return []; |
|
1177 | - } |
|
1178 | - |
|
1179 | - $query = $this->db->getQueryBuilder(); |
|
1180 | - |
|
1181 | - // Calendar id expressions |
|
1182 | - $calendarExpressions = []; |
|
1183 | - foreach($ownCalendars as $id) { |
|
1184 | - $calendarExpressions[] = $query->expr() |
|
1185 | - ->eq('calendarid', $query->createNamedParameter($id)); |
|
1186 | - } |
|
1187 | - foreach($sharedCalendars as $id) { |
|
1188 | - $calendarExpressions[] = $query->expr()->andX( |
|
1189 | - $query->expr()->eq('calendarid', |
|
1190 | - $query->createNamedParameter($id)), |
|
1191 | - $query->expr()->eq('classification', |
|
1192 | - $query->createNamedParameter(0)) |
|
1193 | - ); |
|
1194 | - } |
|
1195 | - |
|
1196 | - if (count($calendarExpressions) === 1) { |
|
1197 | - $calExpr = $calendarExpressions[0]; |
|
1198 | - } else { |
|
1199 | - $calExpr = call_user_func_array([$query->expr(), 'orX'], $calendarExpressions); |
|
1200 | - } |
|
1201 | - |
|
1202 | - // Component expressions |
|
1203 | - $compExpressions = []; |
|
1204 | - foreach($filters['comps'] as $comp) { |
|
1205 | - $compExpressions[] = $query->expr() |
|
1206 | - ->eq('componenttype', $query->createNamedParameter($comp)); |
|
1207 | - } |
|
1208 | - |
|
1209 | - if (count($compExpressions) === 1) { |
|
1210 | - $compExpr = $compExpressions[0]; |
|
1211 | - } else { |
|
1212 | - $compExpr = call_user_func_array([$query->expr(), 'orX'], $compExpressions); |
|
1213 | - } |
|
1214 | - |
|
1215 | - // property and filter expression |
|
1216 | - $searchTermFilter = $query->expr()->like('calendardata', |
|
1217 | - $query->createNamedParameter('%' . $this->db->escapeLikeParameter($filters['search-term']) . '%')); |
|
1218 | - |
|
1219 | - $query->select(['calendarid', 'uri', 'calendardata']) |
|
1220 | - ->from('calendarobjects') |
|
1221 | - ->where($calExpr) |
|
1222 | - ->andWhere($compExpr) |
|
1223 | - ->andWhere($searchTermFilter); |
|
1224 | - |
|
1225 | - $stmt = $query->execute(); |
|
1226 | - |
|
1227 | - $result = []; |
|
1228 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1229 | - if (!$this->validateFilterForCalendarSearch($row, $filters)) { |
|
1230 | - continue; |
|
1231 | - } |
|
1232 | - |
|
1233 | - $result[] = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1234 | - } |
|
1235 | - |
|
1236 | - return $result; |
|
1237 | - } |
|
1238 | - |
|
1239 | - /** |
|
1240 | - * This method validates if a filter (as passed to calendarSearch) matches |
|
1241 | - * the given object. |
|
1242 | - * |
|
1243 | - * @param array $object |
|
1244 | - * @param array $filters |
|
1245 | - * @return bool |
|
1246 | - */ |
|
1247 | - protected function validateFilterForCalendarSearch(array $object, array $filters) { |
|
1248 | - $vObject = Reader::read($object['calendardata']); |
|
1249 | - |
|
1250 | - $validator = new Search\CalendarSearchValidator(); |
|
1251 | - $result = $validator->validate($vObject, $filters); |
|
1252 | - |
|
1253 | - // Destroy circular references so PHP will GC the object. |
|
1254 | - $vObject->destroy(); |
|
1255 | - |
|
1256 | - return $result; |
|
1257 | - } |
|
1258 | - |
|
1259 | - /** |
|
1260 | - * Searches through all of a users calendars and calendar objects to find |
|
1261 | - * an object with a specific UID. |
|
1262 | - * |
|
1263 | - * This method should return the path to this object, relative to the |
|
1264 | - * calendar home, so this path usually only contains two parts: |
|
1265 | - * |
|
1266 | - * calendarpath/objectpath.ics |
|
1267 | - * |
|
1268 | - * If the uid is not found, return null. |
|
1269 | - * |
|
1270 | - * This method should only consider * objects that the principal owns, so |
|
1271 | - * any calendars owned by other principals that also appear in this |
|
1272 | - * collection should be ignored. |
|
1273 | - * |
|
1274 | - * @param string $principalUri |
|
1275 | - * @param string $uid |
|
1276 | - * @return string|null |
|
1277 | - */ |
|
1278 | - function getCalendarObjectByUID($principalUri, $uid) { |
|
1279 | - |
|
1280 | - $query = $this->db->getQueryBuilder(); |
|
1281 | - $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
1282 | - ->from('calendarobjects', 'co') |
|
1283 | - ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
1284 | - ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
1285 | - ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
1286 | - |
|
1287 | - $stmt = $query->execute(); |
|
1288 | - |
|
1289 | - if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1290 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1291 | - } |
|
1292 | - |
|
1293 | - return null; |
|
1294 | - } |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * The getChanges method returns all the changes that have happened, since |
|
1298 | - * the specified syncToken in the specified calendar. |
|
1299 | - * |
|
1300 | - * This function should return an array, such as the following: |
|
1301 | - * |
|
1302 | - * [ |
|
1303 | - * 'syncToken' => 'The current synctoken', |
|
1304 | - * 'added' => [ |
|
1305 | - * 'new.txt', |
|
1306 | - * ], |
|
1307 | - * 'modified' => [ |
|
1308 | - * 'modified.txt', |
|
1309 | - * ], |
|
1310 | - * 'deleted' => [ |
|
1311 | - * 'foo.php.bak', |
|
1312 | - * 'old.txt' |
|
1313 | - * ] |
|
1314 | - * ); |
|
1315 | - * |
|
1316 | - * The returned syncToken property should reflect the *current* syncToken |
|
1317 | - * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
1318 | - * property This is * needed here too, to ensure the operation is atomic. |
|
1319 | - * |
|
1320 | - * If the $syncToken argument is specified as null, this is an initial |
|
1321 | - * sync, and all members should be reported. |
|
1322 | - * |
|
1323 | - * The modified property is an array of nodenames that have changed since |
|
1324 | - * the last token. |
|
1325 | - * |
|
1326 | - * The deleted property is an array with nodenames, that have been deleted |
|
1327 | - * from collection. |
|
1328 | - * |
|
1329 | - * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
1330 | - * 1, you only have to report changes that happened only directly in |
|
1331 | - * immediate descendants. If it's 2, it should also include changes from |
|
1332 | - * the nodes below the child collections. (grandchildren) |
|
1333 | - * |
|
1334 | - * The $limit argument allows a client to specify how many results should |
|
1335 | - * be returned at most. If the limit is not specified, it should be treated |
|
1336 | - * as infinite. |
|
1337 | - * |
|
1338 | - * If the limit (infinite or not) is higher than you're willing to return, |
|
1339 | - * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
1340 | - * |
|
1341 | - * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
1342 | - * return null. |
|
1343 | - * |
|
1344 | - * The limit is 'suggestive'. You are free to ignore it. |
|
1345 | - * |
|
1346 | - * @param string $calendarId |
|
1347 | - * @param string $syncToken |
|
1348 | - * @param int $syncLevel |
|
1349 | - * @param int $limit |
|
1350 | - * @return array |
|
1351 | - */ |
|
1352 | - function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
1353 | - // Current synctoken |
|
1354 | - $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1355 | - $stmt->execute([ $calendarId ]); |
|
1356 | - $currentToken = $stmt->fetchColumn(0); |
|
1357 | - |
|
1358 | - if (is_null($currentToken)) { |
|
1359 | - return null; |
|
1360 | - } |
|
1361 | - |
|
1362 | - $result = [ |
|
1363 | - 'syncToken' => $currentToken, |
|
1364 | - 'added' => [], |
|
1365 | - 'modified' => [], |
|
1366 | - 'deleted' => [], |
|
1367 | - ]; |
|
1368 | - |
|
1369 | - if ($syncToken) { |
|
1370 | - |
|
1371 | - $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
1372 | - if ($limit>0) { |
|
1373 | - $query.= " `LIMIT` " . (int)$limit; |
|
1374 | - } |
|
1375 | - |
|
1376 | - // Fetching all changes |
|
1377 | - $stmt = $this->db->prepare($query); |
|
1378 | - $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
1379 | - |
|
1380 | - $changes = []; |
|
1381 | - |
|
1382 | - // This loop ensures that any duplicates are overwritten, only the |
|
1383 | - // last change on a node is relevant. |
|
1384 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1385 | - |
|
1386 | - $changes[$row['uri']] = $row['operation']; |
|
1387 | - |
|
1388 | - } |
|
1389 | - |
|
1390 | - foreach($changes as $uri => $operation) { |
|
1391 | - |
|
1392 | - switch($operation) { |
|
1393 | - case 1 : |
|
1394 | - $result['added'][] = $uri; |
|
1395 | - break; |
|
1396 | - case 2 : |
|
1397 | - $result['modified'][] = $uri; |
|
1398 | - break; |
|
1399 | - case 3 : |
|
1400 | - $result['deleted'][] = $uri; |
|
1401 | - break; |
|
1402 | - } |
|
1403 | - |
|
1404 | - } |
|
1405 | - } else { |
|
1406 | - // No synctoken supplied, this is the initial sync. |
|
1407 | - $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
1408 | - $stmt = $this->db->prepare($query); |
|
1409 | - $stmt->execute([$calendarId]); |
|
1410 | - |
|
1411 | - $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
1412 | - } |
|
1413 | - return $result; |
|
1414 | - |
|
1415 | - } |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * Returns a list of subscriptions for a principal. |
|
1419 | - * |
|
1420 | - * Every subscription is an array with the following keys: |
|
1421 | - * * id, a unique id that will be used by other functions to modify the |
|
1422 | - * subscription. This can be the same as the uri or a database key. |
|
1423 | - * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
1424 | - * * principaluri. The owner of the subscription. Almost always the same as |
|
1425 | - * principalUri passed to this method. |
|
1426 | - * |
|
1427 | - * Furthermore, all the subscription info must be returned too: |
|
1428 | - * |
|
1429 | - * 1. {DAV:}displayname |
|
1430 | - * 2. {http://apple.com/ns/ical/}refreshrate |
|
1431 | - * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
1432 | - * should not be stripped). |
|
1433 | - * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
1434 | - * should not be stripped). |
|
1435 | - * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
1436 | - * attachments should not be stripped). |
|
1437 | - * 6. {http://calendarserver.org/ns/}source (Must be a |
|
1438 | - * Sabre\DAV\Property\Href). |
|
1439 | - * 7. {http://apple.com/ns/ical/}calendar-color |
|
1440 | - * 8. {http://apple.com/ns/ical/}calendar-order |
|
1441 | - * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
1442 | - * (should just be an instance of |
|
1443 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
1444 | - * default components). |
|
1445 | - * |
|
1446 | - * @param string $principalUri |
|
1447 | - * @return array |
|
1448 | - */ |
|
1449 | - function getSubscriptionsForUser($principalUri) { |
|
1450 | - $fields = array_values($this->subscriptionPropertyMap); |
|
1451 | - $fields[] = 'id'; |
|
1452 | - $fields[] = 'uri'; |
|
1453 | - $fields[] = 'source'; |
|
1454 | - $fields[] = 'principaluri'; |
|
1455 | - $fields[] = 'lastmodified'; |
|
1456 | - |
|
1457 | - $query = $this->db->getQueryBuilder(); |
|
1458 | - $query->select($fields) |
|
1459 | - ->from('calendarsubscriptions') |
|
1460 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1461 | - ->orderBy('calendarorder', 'asc'); |
|
1462 | - $stmt =$query->execute(); |
|
1463 | - |
|
1464 | - $subscriptions = []; |
|
1465 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1466 | - |
|
1467 | - $subscription = [ |
|
1468 | - 'id' => $row['id'], |
|
1469 | - 'uri' => $row['uri'], |
|
1470 | - 'principaluri' => $row['principaluri'], |
|
1471 | - 'source' => $row['source'], |
|
1472 | - 'lastmodified' => $row['lastmodified'], |
|
1473 | - |
|
1474 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1475 | - ]; |
|
1476 | - |
|
1477 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1478 | - if (!is_null($row[$dbName])) { |
|
1479 | - $subscription[$xmlName] = $row[$dbName]; |
|
1480 | - } |
|
1481 | - } |
|
1482 | - |
|
1483 | - $subscriptions[] = $subscription; |
|
1484 | - |
|
1485 | - } |
|
1486 | - |
|
1487 | - return $subscriptions; |
|
1488 | - } |
|
1489 | - |
|
1490 | - /** |
|
1491 | - * Creates a new subscription for a principal. |
|
1492 | - * |
|
1493 | - * If the creation was a success, an id must be returned that can be used to reference |
|
1494 | - * this subscription in other methods, such as updateSubscription. |
|
1495 | - * |
|
1496 | - * @param string $principalUri |
|
1497 | - * @param string $uri |
|
1498 | - * @param array $properties |
|
1499 | - * @return mixed |
|
1500 | - */ |
|
1501 | - function createSubscription($principalUri, $uri, array $properties) { |
|
1502 | - |
|
1503 | - if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
1504 | - throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
1505 | - } |
|
1506 | - |
|
1507 | - $values = [ |
|
1508 | - 'principaluri' => $principalUri, |
|
1509 | - 'uri' => $uri, |
|
1510 | - 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
1511 | - 'lastmodified' => time(), |
|
1512 | - ]; |
|
1513 | - |
|
1514 | - $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
1515 | - |
|
1516 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1517 | - if (array_key_exists($xmlName, $properties)) { |
|
1518 | - $values[$dbName] = $properties[$xmlName]; |
|
1519 | - if (in_array($dbName, $propertiesBoolean)) { |
|
1520 | - $values[$dbName] = true; |
|
1521 | - } |
|
1522 | - } |
|
1523 | - } |
|
1524 | - |
|
1525 | - $valuesToInsert = array(); |
|
1526 | - |
|
1527 | - $query = $this->db->getQueryBuilder(); |
|
1528 | - |
|
1529 | - foreach (array_keys($values) as $name) { |
|
1530 | - $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
1531 | - } |
|
1532 | - |
|
1533 | - $query->insert('calendarsubscriptions') |
|
1534 | - ->values($valuesToInsert) |
|
1535 | - ->execute(); |
|
1536 | - |
|
1537 | - return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
1538 | - } |
|
1539 | - |
|
1540 | - /** |
|
1541 | - * Updates a subscription |
|
1542 | - * |
|
1543 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
1544 | - * To do the actual updates, you must tell this object which properties |
|
1545 | - * you're going to process with the handle() method. |
|
1546 | - * |
|
1547 | - * Calling the handle method is like telling the PropPatch object "I |
|
1548 | - * promise I can handle updating this property". |
|
1549 | - * |
|
1550 | - * Read the PropPatch documentation for more info and examples. |
|
1551 | - * |
|
1552 | - * @param mixed $subscriptionId |
|
1553 | - * @param PropPatch $propPatch |
|
1554 | - * @return void |
|
1555 | - */ |
|
1556 | - function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
1557 | - $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
1558 | - $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
1559 | - |
|
1560 | - $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
1561 | - |
|
1562 | - $newValues = []; |
|
1563 | - |
|
1564 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
1565 | - if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
1566 | - $newValues['source'] = $propertyValue->getHref(); |
|
1567 | - } else { |
|
1568 | - $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
1569 | - $newValues[$fieldName] = $propertyValue; |
|
1570 | - } |
|
1571 | - } |
|
1572 | - |
|
1573 | - $query = $this->db->getQueryBuilder(); |
|
1574 | - $query->update('calendarsubscriptions') |
|
1575 | - ->set('lastmodified', $query->createNamedParameter(time())); |
|
1576 | - foreach($newValues as $fieldName=>$value) { |
|
1577 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
1578 | - } |
|
1579 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1580 | - ->execute(); |
|
1581 | - |
|
1582 | - return true; |
|
1583 | - |
|
1584 | - }); |
|
1585 | - } |
|
1586 | - |
|
1587 | - /** |
|
1588 | - * Deletes a subscription. |
|
1589 | - * |
|
1590 | - * @param mixed $subscriptionId |
|
1591 | - * @return void |
|
1592 | - */ |
|
1593 | - function deleteSubscription($subscriptionId) { |
|
1594 | - $query = $this->db->getQueryBuilder(); |
|
1595 | - $query->delete('calendarsubscriptions') |
|
1596 | - ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1597 | - ->execute(); |
|
1598 | - } |
|
1599 | - |
|
1600 | - /** |
|
1601 | - * Returns a single scheduling object for the inbox collection. |
|
1602 | - * |
|
1603 | - * The returned array should contain the following elements: |
|
1604 | - * * uri - A unique basename for the object. This will be used to |
|
1605 | - * construct a full uri. |
|
1606 | - * * calendardata - The iCalendar object |
|
1607 | - * * lastmodified - The last modification date. Can be an int for a unix |
|
1608 | - * timestamp, or a PHP DateTime object. |
|
1609 | - * * etag - A unique token that must change if the object changed. |
|
1610 | - * * size - The size of the object, in bytes. |
|
1611 | - * |
|
1612 | - * @param string $principalUri |
|
1613 | - * @param string $objectUri |
|
1614 | - * @return array |
|
1615 | - */ |
|
1616 | - function getSchedulingObject($principalUri, $objectUri) { |
|
1617 | - $query = $this->db->getQueryBuilder(); |
|
1618 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1619 | - ->from('schedulingobjects') |
|
1620 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1621 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1622 | - ->execute(); |
|
1623 | - |
|
1624 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
1625 | - |
|
1626 | - if(!$row) { |
|
1627 | - return null; |
|
1628 | - } |
|
1629 | - |
|
1630 | - return [ |
|
1631 | - 'uri' => $row['uri'], |
|
1632 | - 'calendardata' => $row['calendardata'], |
|
1633 | - 'lastmodified' => $row['lastmodified'], |
|
1634 | - 'etag' => '"' . $row['etag'] . '"', |
|
1635 | - 'size' => (int)$row['size'], |
|
1636 | - ]; |
|
1637 | - } |
|
1638 | - |
|
1639 | - /** |
|
1640 | - * Returns all scheduling objects for the inbox collection. |
|
1641 | - * |
|
1642 | - * These objects should be returned as an array. Every item in the array |
|
1643 | - * should follow the same structure as returned from getSchedulingObject. |
|
1644 | - * |
|
1645 | - * The main difference is that 'calendardata' is optional. |
|
1646 | - * |
|
1647 | - * @param string $principalUri |
|
1648 | - * @return array |
|
1649 | - */ |
|
1650 | - function getSchedulingObjects($principalUri) { |
|
1651 | - $query = $this->db->getQueryBuilder(); |
|
1652 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1653 | - ->from('schedulingobjects') |
|
1654 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1655 | - ->execute(); |
|
1656 | - |
|
1657 | - $result = []; |
|
1658 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1659 | - $result[] = [ |
|
1660 | - 'calendardata' => $row['calendardata'], |
|
1661 | - 'uri' => $row['uri'], |
|
1662 | - 'lastmodified' => $row['lastmodified'], |
|
1663 | - 'etag' => '"' . $row['etag'] . '"', |
|
1664 | - 'size' => (int)$row['size'], |
|
1665 | - ]; |
|
1666 | - } |
|
1667 | - |
|
1668 | - return $result; |
|
1669 | - } |
|
1670 | - |
|
1671 | - /** |
|
1672 | - * Deletes a scheduling object from the inbox collection. |
|
1673 | - * |
|
1674 | - * @param string $principalUri |
|
1675 | - * @param string $objectUri |
|
1676 | - * @return void |
|
1677 | - */ |
|
1678 | - function deleteSchedulingObject($principalUri, $objectUri) { |
|
1679 | - $query = $this->db->getQueryBuilder(); |
|
1680 | - $query->delete('schedulingobjects') |
|
1681 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1682 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1683 | - ->execute(); |
|
1684 | - } |
|
1685 | - |
|
1686 | - /** |
|
1687 | - * Creates a new scheduling object. This should land in a users' inbox. |
|
1688 | - * |
|
1689 | - * @param string $principalUri |
|
1690 | - * @param string $objectUri |
|
1691 | - * @param string $objectData |
|
1692 | - * @return void |
|
1693 | - */ |
|
1694 | - function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
1695 | - $query = $this->db->getQueryBuilder(); |
|
1696 | - $query->insert('schedulingobjects') |
|
1697 | - ->values([ |
|
1698 | - 'principaluri' => $query->createNamedParameter($principalUri), |
|
1699 | - 'calendardata' => $query->createNamedParameter($objectData), |
|
1700 | - 'uri' => $query->createNamedParameter($objectUri), |
|
1701 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
1702 | - 'etag' => $query->createNamedParameter(md5($objectData)), |
|
1703 | - 'size' => $query->createNamedParameter(strlen($objectData)) |
|
1704 | - ]) |
|
1705 | - ->execute(); |
|
1706 | - } |
|
1707 | - |
|
1708 | - /** |
|
1709 | - * Adds a change record to the calendarchanges table. |
|
1710 | - * |
|
1711 | - * @param mixed $calendarId |
|
1712 | - * @param string $objectUri |
|
1713 | - * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
1714 | - * @return void |
|
1715 | - */ |
|
1716 | - protected function addChange($calendarId, $objectUri, $operation) { |
|
1717 | - |
|
1718 | - $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1719 | - $stmt->execute([ |
|
1720 | - $objectUri, |
|
1721 | - $calendarId, |
|
1722 | - $operation, |
|
1723 | - $calendarId |
|
1724 | - ]); |
|
1725 | - $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
1726 | - $stmt->execute([ |
|
1727 | - $calendarId |
|
1728 | - ]); |
|
1729 | - |
|
1730 | - } |
|
1731 | - |
|
1732 | - /** |
|
1733 | - * Parses some information from calendar objects, used for optimized |
|
1734 | - * calendar-queries. |
|
1735 | - * |
|
1736 | - * Returns an array with the following keys: |
|
1737 | - * * etag - An md5 checksum of the object without the quotes. |
|
1738 | - * * size - Size of the object in bytes |
|
1739 | - * * componentType - VEVENT, VTODO or VJOURNAL |
|
1740 | - * * firstOccurence |
|
1741 | - * * lastOccurence |
|
1742 | - * * uid - value of the UID property |
|
1743 | - * |
|
1744 | - * @param string $calendarData |
|
1745 | - * @return array |
|
1746 | - */ |
|
1747 | - public function getDenormalizedData($calendarData) { |
|
1748 | - |
|
1749 | - $vObject = Reader::read($calendarData); |
|
1750 | - $componentType = null; |
|
1751 | - $component = null; |
|
1752 | - $firstOccurrence = null; |
|
1753 | - $lastOccurrence = null; |
|
1754 | - $uid = null; |
|
1755 | - $classification = self::CLASSIFICATION_PUBLIC; |
|
1756 | - foreach($vObject->getComponents() as $component) { |
|
1757 | - if ($component->name!=='VTIMEZONE') { |
|
1758 | - $componentType = $component->name; |
|
1759 | - $uid = (string)$component->UID; |
|
1760 | - break; |
|
1761 | - } |
|
1762 | - } |
|
1763 | - if (!$componentType) { |
|
1764 | - throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
1765 | - } |
|
1766 | - if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
1767 | - $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
1768 | - // Finding the last occurrence is a bit harder |
|
1769 | - if (!isset($component->RRULE)) { |
|
1770 | - if (isset($component->DTEND)) { |
|
1771 | - $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
1772 | - } elseif (isset($component->DURATION)) { |
|
1773 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
1774 | - $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
1775 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
1776 | - } elseif (!$component->DTSTART->hasTime()) { |
|
1777 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
1778 | - $endDate->modify('+1 day'); |
|
1779 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
1780 | - } else { |
|
1781 | - $lastOccurrence = $firstOccurrence; |
|
1782 | - } |
|
1783 | - } else { |
|
1784 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
1785 | - $maxDate = new \DateTime(self::MAX_DATE); |
|
1786 | - if ($it->isInfinite()) { |
|
1787 | - $lastOccurrence = $maxDate->getTimestamp(); |
|
1788 | - } else { |
|
1789 | - $end = $it->getDtEnd(); |
|
1790 | - while($it->valid() && $end < $maxDate) { |
|
1791 | - $end = $it->getDtEnd(); |
|
1792 | - $it->next(); |
|
1793 | - |
|
1794 | - } |
|
1795 | - $lastOccurrence = $end->getTimestamp(); |
|
1796 | - } |
|
1797 | - |
|
1798 | - } |
|
1799 | - } |
|
1800 | - |
|
1801 | - if ($component->CLASS) { |
|
1802 | - $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
1803 | - switch ($component->CLASS->getValue()) { |
|
1804 | - case 'PUBLIC': |
|
1805 | - $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
1806 | - break; |
|
1807 | - case 'CONFIDENTIAL': |
|
1808 | - $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
1809 | - break; |
|
1810 | - } |
|
1811 | - } |
|
1812 | - return [ |
|
1813 | - 'etag' => md5($calendarData), |
|
1814 | - 'size' => strlen($calendarData), |
|
1815 | - 'componentType' => $componentType, |
|
1816 | - 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
1817 | - 'lastOccurence' => $lastOccurrence, |
|
1818 | - 'uid' => $uid, |
|
1819 | - 'classification' => $classification |
|
1820 | - ]; |
|
1821 | - |
|
1822 | - } |
|
1823 | - |
|
1824 | - private function readBlob($cardData) { |
|
1825 | - if (is_resource($cardData)) { |
|
1826 | - return stream_get_contents($cardData); |
|
1827 | - } |
|
1828 | - |
|
1829 | - return $cardData; |
|
1830 | - } |
|
1831 | - |
|
1832 | - /** |
|
1833 | - * @param IShareable $shareable |
|
1834 | - * @param array $add |
|
1835 | - * @param array $remove |
|
1836 | - */ |
|
1837 | - public function updateShares($shareable, $add, $remove) { |
|
1838 | - $calendarId = $shareable->getResourceId(); |
|
1839 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
1840 | - '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
1841 | - [ |
|
1842 | - 'calendarId' => $calendarId, |
|
1843 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1844 | - 'shares' => $this->getShares($calendarId), |
|
1845 | - 'add' => $add, |
|
1846 | - 'remove' => $remove, |
|
1847 | - ])); |
|
1848 | - $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
1849 | - } |
|
1850 | - |
|
1851 | - /** |
|
1852 | - * @param int $resourceId |
|
1853 | - * @return array |
|
1854 | - */ |
|
1855 | - public function getShares($resourceId) { |
|
1856 | - return $this->sharingBackend->getShares($resourceId); |
|
1857 | - } |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * @param boolean $value |
|
1861 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1862 | - * @return string|null |
|
1863 | - */ |
|
1864 | - public function setPublishStatus($value, $calendar) { |
|
1865 | - $query = $this->db->getQueryBuilder(); |
|
1866 | - if ($value) { |
|
1867 | - $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
1868 | - $query->insert('dav_shares') |
|
1869 | - ->values([ |
|
1870 | - 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
1871 | - 'type' => $query->createNamedParameter('calendar'), |
|
1872 | - 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
1873 | - 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
1874 | - 'publicuri' => $query->createNamedParameter($publicUri) |
|
1875 | - ]); |
|
1876 | - $query->execute(); |
|
1877 | - return $publicUri; |
|
1878 | - } |
|
1879 | - $query->delete('dav_shares') |
|
1880 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1881 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
1882 | - $query->execute(); |
|
1883 | - return null; |
|
1884 | - } |
|
1885 | - |
|
1886 | - /** |
|
1887 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1888 | - * @return mixed |
|
1889 | - */ |
|
1890 | - public function getPublishStatus($calendar) { |
|
1891 | - $query = $this->db->getQueryBuilder(); |
|
1892 | - $result = $query->select('publicuri') |
|
1893 | - ->from('dav_shares') |
|
1894 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1895 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
1896 | - ->execute(); |
|
1897 | - |
|
1898 | - $row = $result->fetch(); |
|
1899 | - $result->closeCursor(); |
|
1900 | - return $row ? reset($row) : false; |
|
1901 | - } |
|
1902 | - |
|
1903 | - /** |
|
1904 | - * @param int $resourceId |
|
1905 | - * @param array $acl |
|
1906 | - * @return array |
|
1907 | - */ |
|
1908 | - public function applyShareAcl($resourceId, $acl) { |
|
1909 | - return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
1910 | - } |
|
1911 | - |
|
1912 | - private function convertPrincipal($principalUri, $toV2) { |
|
1913 | - if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
1914 | - list(, $name) = URLUtil::splitPath($principalUri); |
|
1915 | - if ($toV2 === true) { |
|
1916 | - return "principals/users/$name"; |
|
1917 | - } |
|
1918 | - return "principals/$name"; |
|
1919 | - } |
|
1920 | - return $principalUri; |
|
1921 | - } |
|
381 | + /** |
|
382 | + * @return array |
|
383 | + */ |
|
384 | + public function getPublicCalendars() { |
|
385 | + $fields = array_values($this->propertyMap); |
|
386 | + $fields[] = 'a.id'; |
|
387 | + $fields[] = 'a.uri'; |
|
388 | + $fields[] = 'a.synctoken'; |
|
389 | + $fields[] = 'a.components'; |
|
390 | + $fields[] = 'a.principaluri'; |
|
391 | + $fields[] = 'a.transparent'; |
|
392 | + $fields[] = 's.access'; |
|
393 | + $fields[] = 's.publicuri'; |
|
394 | + $calendars = []; |
|
395 | + $query = $this->db->getQueryBuilder(); |
|
396 | + $result = $query->select($fields) |
|
397 | + ->from('dav_shares', 's') |
|
398 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
399 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
400 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
401 | + ->execute(); |
|
402 | + |
|
403 | + while($row = $result->fetch()) { |
|
404 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
405 | + $row['displayname'] = $row['displayname'] . "($name)"; |
|
406 | + $components = []; |
|
407 | + if ($row['components']) { |
|
408 | + $components = explode(',',$row['components']); |
|
409 | + } |
|
410 | + $calendar = [ |
|
411 | + 'id' => $row['id'], |
|
412 | + 'uri' => $row['publicuri'], |
|
413 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
414 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
415 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
416 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
417 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
418 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
419 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
420 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
421 | + ]; |
|
422 | + |
|
423 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
424 | + $calendar[$xmlName] = $row[$dbName]; |
|
425 | + } |
|
426 | + |
|
427 | + if (!isset($calendars[$calendar['id']])) { |
|
428 | + $calendars[$calendar['id']] = $calendar; |
|
429 | + } |
|
430 | + } |
|
431 | + $result->closeCursor(); |
|
432 | + |
|
433 | + return array_values($calendars); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * @param string $uri |
|
438 | + * @return array |
|
439 | + * @throws NotFound |
|
440 | + */ |
|
441 | + public function getPublicCalendar($uri) { |
|
442 | + $fields = array_values($this->propertyMap); |
|
443 | + $fields[] = 'a.id'; |
|
444 | + $fields[] = 'a.uri'; |
|
445 | + $fields[] = 'a.synctoken'; |
|
446 | + $fields[] = 'a.components'; |
|
447 | + $fields[] = 'a.principaluri'; |
|
448 | + $fields[] = 'a.transparent'; |
|
449 | + $fields[] = 's.access'; |
|
450 | + $fields[] = 's.publicuri'; |
|
451 | + $query = $this->db->getQueryBuilder(); |
|
452 | + $result = $query->select($fields) |
|
453 | + ->from('dav_shares', 's') |
|
454 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
455 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
456 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
457 | + ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
458 | + ->execute(); |
|
459 | + |
|
460 | + $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
461 | + |
|
462 | + $result->closeCursor(); |
|
463 | + |
|
464 | + if ($row === false) { |
|
465 | + throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
466 | + } |
|
467 | + |
|
468 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
469 | + $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
470 | + $components = []; |
|
471 | + if ($row['components']) { |
|
472 | + $components = explode(',',$row['components']); |
|
473 | + } |
|
474 | + $calendar = [ |
|
475 | + 'id' => $row['id'], |
|
476 | + 'uri' => $row['publicuri'], |
|
477 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
478 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
479 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
480 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
481 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
482 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
483 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
484 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
485 | + ]; |
|
486 | + |
|
487 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
488 | + $calendar[$xmlName] = $row[$dbName]; |
|
489 | + } |
|
490 | + |
|
491 | + return $calendar; |
|
492 | + |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * @param string $principal |
|
497 | + * @param string $uri |
|
498 | + * @return array|null |
|
499 | + */ |
|
500 | + public function getCalendarByUri($principal, $uri) { |
|
501 | + $fields = array_values($this->propertyMap); |
|
502 | + $fields[] = 'id'; |
|
503 | + $fields[] = 'uri'; |
|
504 | + $fields[] = 'synctoken'; |
|
505 | + $fields[] = 'components'; |
|
506 | + $fields[] = 'principaluri'; |
|
507 | + $fields[] = 'transparent'; |
|
508 | + |
|
509 | + // Making fields a comma-delimited list |
|
510 | + $query = $this->db->getQueryBuilder(); |
|
511 | + $query->select($fields)->from('calendars') |
|
512 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
513 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
514 | + ->setMaxResults(1); |
|
515 | + $stmt = $query->execute(); |
|
516 | + |
|
517 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
518 | + $stmt->closeCursor(); |
|
519 | + if ($row === false) { |
|
520 | + return null; |
|
521 | + } |
|
522 | + |
|
523 | + $components = []; |
|
524 | + if ($row['components']) { |
|
525 | + $components = explode(',',$row['components']); |
|
526 | + } |
|
527 | + |
|
528 | + $calendar = [ |
|
529 | + 'id' => $row['id'], |
|
530 | + 'uri' => $row['uri'], |
|
531 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
532 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
533 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
534 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
535 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
536 | + ]; |
|
537 | + |
|
538 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
539 | + $calendar[$xmlName] = $row[$dbName]; |
|
540 | + } |
|
541 | + |
|
542 | + return $calendar; |
|
543 | + } |
|
544 | + |
|
545 | + public function getCalendarById($calendarId) { |
|
546 | + $fields = array_values($this->propertyMap); |
|
547 | + $fields[] = 'id'; |
|
548 | + $fields[] = 'uri'; |
|
549 | + $fields[] = 'synctoken'; |
|
550 | + $fields[] = 'components'; |
|
551 | + $fields[] = 'principaluri'; |
|
552 | + $fields[] = 'transparent'; |
|
553 | + |
|
554 | + // Making fields a comma-delimited list |
|
555 | + $query = $this->db->getQueryBuilder(); |
|
556 | + $query->select($fields)->from('calendars') |
|
557 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
558 | + ->setMaxResults(1); |
|
559 | + $stmt = $query->execute(); |
|
560 | + |
|
561 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
562 | + $stmt->closeCursor(); |
|
563 | + if ($row === false) { |
|
564 | + return null; |
|
565 | + } |
|
566 | + |
|
567 | + $components = []; |
|
568 | + if ($row['components']) { |
|
569 | + $components = explode(',',$row['components']); |
|
570 | + } |
|
571 | + |
|
572 | + $calendar = [ |
|
573 | + 'id' => $row['id'], |
|
574 | + 'uri' => $row['uri'], |
|
575 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
576 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
577 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
578 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
579 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
580 | + ]; |
|
581 | + |
|
582 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
583 | + $calendar[$xmlName] = $row[$dbName]; |
|
584 | + } |
|
585 | + |
|
586 | + return $calendar; |
|
587 | + } |
|
588 | + |
|
589 | + /** |
|
590 | + * Creates a new calendar for a principal. |
|
591 | + * |
|
592 | + * If the creation was a success, an id must be returned that can be used to reference |
|
593 | + * this calendar in other methods, such as updateCalendar. |
|
594 | + * |
|
595 | + * @param string $principalUri |
|
596 | + * @param string $calendarUri |
|
597 | + * @param array $properties |
|
598 | + * @return int |
|
599 | + */ |
|
600 | + function createCalendar($principalUri, $calendarUri, array $properties) { |
|
601 | + $values = [ |
|
602 | + 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
603 | + 'uri' => $calendarUri, |
|
604 | + 'synctoken' => 1, |
|
605 | + 'transparent' => 0, |
|
606 | + 'components' => 'VEVENT,VTODO', |
|
607 | + 'displayname' => $calendarUri |
|
608 | + ]; |
|
609 | + |
|
610 | + // Default value |
|
611 | + $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
612 | + if (isset($properties[$sccs])) { |
|
613 | + if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
614 | + throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
615 | + } |
|
616 | + $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
617 | + } |
|
618 | + $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
619 | + if (isset($properties[$transp])) { |
|
620 | + $values['transparent'] = $properties[$transp]->getValue()==='transparent'; |
|
621 | + } |
|
622 | + |
|
623 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
624 | + if (isset($properties[$xmlName])) { |
|
625 | + $values[$dbName] = $properties[$xmlName]; |
|
626 | + } |
|
627 | + } |
|
628 | + |
|
629 | + $query = $this->db->getQueryBuilder(); |
|
630 | + $query->insert('calendars'); |
|
631 | + foreach($values as $column => $value) { |
|
632 | + $query->setValue($column, $query->createNamedParameter($value)); |
|
633 | + } |
|
634 | + $query->execute(); |
|
635 | + $calendarId = $query->getLastInsertId(); |
|
636 | + |
|
637 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
638 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
639 | + [ |
|
640 | + 'calendarId' => $calendarId, |
|
641 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
642 | + ])); |
|
643 | + |
|
644 | + return $calendarId; |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Updates properties for a calendar. |
|
649 | + * |
|
650 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
651 | + * To do the actual updates, you must tell this object which properties |
|
652 | + * you're going to process with the handle() method. |
|
653 | + * |
|
654 | + * Calling the handle method is like telling the PropPatch object "I |
|
655 | + * promise I can handle updating this property". |
|
656 | + * |
|
657 | + * Read the PropPatch documentation for more info and examples. |
|
658 | + * |
|
659 | + * @param PropPatch $propPatch |
|
660 | + * @return void |
|
661 | + */ |
|
662 | + function updateCalendar($calendarId, PropPatch $propPatch) { |
|
663 | + $supportedProperties = array_keys($this->propertyMap); |
|
664 | + $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
665 | + |
|
666 | + $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
667 | + $newValues = []; |
|
668 | + foreach ($mutations as $propertyName => $propertyValue) { |
|
669 | + |
|
670 | + switch ($propertyName) { |
|
671 | + case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
672 | + $fieldName = 'transparent'; |
|
673 | + $newValues[$fieldName] = $propertyValue->getValue() === 'transparent'; |
|
674 | + break; |
|
675 | + default : |
|
676 | + $fieldName = $this->propertyMap[$propertyName]; |
|
677 | + $newValues[$fieldName] = $propertyValue; |
|
678 | + break; |
|
679 | + } |
|
680 | + |
|
681 | + } |
|
682 | + $query = $this->db->getQueryBuilder(); |
|
683 | + $query->update('calendars'); |
|
684 | + foreach ($newValues as $fieldName => $value) { |
|
685 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
686 | + } |
|
687 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
688 | + $query->execute(); |
|
689 | + |
|
690 | + $this->addChange($calendarId, "", 2); |
|
691 | + |
|
692 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
693 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
694 | + [ |
|
695 | + 'calendarId' => $calendarId, |
|
696 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
697 | + 'shares' => $this->getShares($calendarId), |
|
698 | + 'propertyMutations' => $mutations, |
|
699 | + ])); |
|
700 | + |
|
701 | + return true; |
|
702 | + }); |
|
703 | + } |
|
704 | + |
|
705 | + /** |
|
706 | + * Delete a calendar and all it's objects |
|
707 | + * |
|
708 | + * @param mixed $calendarId |
|
709 | + * @return void |
|
710 | + */ |
|
711 | + function deleteCalendar($calendarId) { |
|
712 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
713 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
714 | + [ |
|
715 | + 'calendarId' => $calendarId, |
|
716 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
717 | + 'shares' => $this->getShares($calendarId), |
|
718 | + ])); |
|
719 | + |
|
720 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
721 | + $stmt->execute([$calendarId]); |
|
722 | + |
|
723 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
724 | + $stmt->execute([$calendarId]); |
|
725 | + |
|
726 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
727 | + $stmt->execute([$calendarId]); |
|
728 | + |
|
729 | + $this->sharingBackend->deleteAllShares($calendarId); |
|
730 | + } |
|
731 | + |
|
732 | + /** |
|
733 | + * Delete all of an user's shares |
|
734 | + * |
|
735 | + * @param string $principaluri |
|
736 | + * @return void |
|
737 | + */ |
|
738 | + function deleteAllSharesByUser($principaluri) { |
|
739 | + $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Returns all calendar objects within a calendar. |
|
744 | + * |
|
745 | + * Every item contains an array with the following keys: |
|
746 | + * * calendardata - The iCalendar-compatible calendar data |
|
747 | + * * uri - a unique key which will be used to construct the uri. This can |
|
748 | + * be any arbitrary string, but making sure it ends with '.ics' is a |
|
749 | + * good idea. This is only the basename, or filename, not the full |
|
750 | + * path. |
|
751 | + * * lastmodified - a timestamp of the last modification time |
|
752 | + * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
753 | + * '"abcdef"') |
|
754 | + * * size - The size of the calendar objects, in bytes. |
|
755 | + * * component - optional, a string containing the type of object, such |
|
756 | + * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
757 | + * the Content-Type header. |
|
758 | + * |
|
759 | + * Note that the etag is optional, but it's highly encouraged to return for |
|
760 | + * speed reasons. |
|
761 | + * |
|
762 | + * The calendardata is also optional. If it's not returned |
|
763 | + * 'getCalendarObject' will be called later, which *is* expected to return |
|
764 | + * calendardata. |
|
765 | + * |
|
766 | + * If neither etag or size are specified, the calendardata will be |
|
767 | + * used/fetched to determine these numbers. If both are specified the |
|
768 | + * amount of times this is needed is reduced by a great degree. |
|
769 | + * |
|
770 | + * @param mixed $calendarId |
|
771 | + * @return array |
|
772 | + */ |
|
773 | + function getCalendarObjects($calendarId) { |
|
774 | + $query = $this->db->getQueryBuilder(); |
|
775 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
776 | + ->from('calendarobjects') |
|
777 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
778 | + $stmt = $query->execute(); |
|
779 | + |
|
780 | + $result = []; |
|
781 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
782 | + $result[] = [ |
|
783 | + 'id' => $row['id'], |
|
784 | + 'uri' => $row['uri'], |
|
785 | + 'lastmodified' => $row['lastmodified'], |
|
786 | + 'etag' => '"' . $row['etag'] . '"', |
|
787 | + 'calendarid' => $row['calendarid'], |
|
788 | + 'size' => (int)$row['size'], |
|
789 | + 'component' => strtolower($row['componenttype']), |
|
790 | + 'classification'=> (int)$row['classification'] |
|
791 | + ]; |
|
792 | + } |
|
793 | + |
|
794 | + return $result; |
|
795 | + } |
|
796 | + |
|
797 | + /** |
|
798 | + * Returns information from a single calendar object, based on it's object |
|
799 | + * uri. |
|
800 | + * |
|
801 | + * The object uri is only the basename, or filename and not a full path. |
|
802 | + * |
|
803 | + * The returned array must have the same keys as getCalendarObjects. The |
|
804 | + * 'calendardata' object is required here though, while it's not required |
|
805 | + * for getCalendarObjects. |
|
806 | + * |
|
807 | + * This method must return null if the object did not exist. |
|
808 | + * |
|
809 | + * @param mixed $calendarId |
|
810 | + * @param string $objectUri |
|
811 | + * @return array|null |
|
812 | + */ |
|
813 | + function getCalendarObject($calendarId, $objectUri) { |
|
814 | + |
|
815 | + $query = $this->db->getQueryBuilder(); |
|
816 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
817 | + ->from('calendarobjects') |
|
818 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
819 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
820 | + $stmt = $query->execute(); |
|
821 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
822 | + |
|
823 | + if(!$row) return null; |
|
824 | + |
|
825 | + return [ |
|
826 | + 'id' => $row['id'], |
|
827 | + 'uri' => $row['uri'], |
|
828 | + 'lastmodified' => $row['lastmodified'], |
|
829 | + 'etag' => '"' . $row['etag'] . '"', |
|
830 | + 'calendarid' => $row['calendarid'], |
|
831 | + 'size' => (int)$row['size'], |
|
832 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
833 | + 'component' => strtolower($row['componenttype']), |
|
834 | + 'classification'=> (int)$row['classification'] |
|
835 | + ]; |
|
836 | + } |
|
837 | + |
|
838 | + /** |
|
839 | + * Returns a list of calendar objects. |
|
840 | + * |
|
841 | + * This method should work identical to getCalendarObject, but instead |
|
842 | + * return all the calendar objects in the list as an array. |
|
843 | + * |
|
844 | + * If the backend supports this, it may allow for some speed-ups. |
|
845 | + * |
|
846 | + * @param mixed $calendarId |
|
847 | + * @param string[] $uris |
|
848 | + * @return array |
|
849 | + */ |
|
850 | + function getMultipleCalendarObjects($calendarId, array $uris) { |
|
851 | + if (empty($uris)) { |
|
852 | + return []; |
|
853 | + } |
|
854 | + |
|
855 | + $chunks = array_chunk($uris, 100); |
|
856 | + $objects = []; |
|
857 | + |
|
858 | + $query = $this->db->getQueryBuilder(); |
|
859 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
860 | + ->from('calendarobjects') |
|
861 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
862 | + ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
863 | + |
|
864 | + foreach ($chunks as $uris) { |
|
865 | + $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
866 | + $result = $query->execute(); |
|
867 | + |
|
868 | + while ($row = $result->fetch()) { |
|
869 | + $objects[] = [ |
|
870 | + 'id' => $row['id'], |
|
871 | + 'uri' => $row['uri'], |
|
872 | + 'lastmodified' => $row['lastmodified'], |
|
873 | + 'etag' => '"' . $row['etag'] . '"', |
|
874 | + 'calendarid' => $row['calendarid'], |
|
875 | + 'size' => (int)$row['size'], |
|
876 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
877 | + 'component' => strtolower($row['componenttype']), |
|
878 | + 'classification' => (int)$row['classification'] |
|
879 | + ]; |
|
880 | + } |
|
881 | + $result->closeCursor(); |
|
882 | + } |
|
883 | + return $objects; |
|
884 | + } |
|
885 | + |
|
886 | + /** |
|
887 | + * Creates a new calendar object. |
|
888 | + * |
|
889 | + * The object uri is only the basename, or filename and not a full path. |
|
890 | + * |
|
891 | + * It is possible return an etag from this function, which will be used in |
|
892 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
893 | + * by double-quotes. |
|
894 | + * |
|
895 | + * However, you should only really return this ETag if you don't mangle the |
|
896 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
897 | + * the exact same as this request body, you should omit the ETag. |
|
898 | + * |
|
899 | + * @param mixed $calendarId |
|
900 | + * @param string $objectUri |
|
901 | + * @param string $calendarData |
|
902 | + * @return string |
|
903 | + */ |
|
904 | + function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
905 | + $extraData = $this->getDenormalizedData($calendarData); |
|
906 | + |
|
907 | + $query = $this->db->getQueryBuilder(); |
|
908 | + $query->insert('calendarobjects') |
|
909 | + ->values([ |
|
910 | + 'calendarid' => $query->createNamedParameter($calendarId), |
|
911 | + 'uri' => $query->createNamedParameter($objectUri), |
|
912 | + 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
913 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
914 | + 'etag' => $query->createNamedParameter($extraData['etag']), |
|
915 | + 'size' => $query->createNamedParameter($extraData['size']), |
|
916 | + 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
917 | + 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
918 | + 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
919 | + 'classification' => $query->createNamedParameter($extraData['classification']), |
|
920 | + 'uid' => $query->createNamedParameter($extraData['uid']), |
|
921 | + ]) |
|
922 | + ->execute(); |
|
923 | + |
|
924 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
925 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
926 | + [ |
|
927 | + 'calendarId' => $calendarId, |
|
928 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
929 | + 'shares' => $this->getShares($calendarId), |
|
930 | + 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
931 | + ] |
|
932 | + )); |
|
933 | + $this->addChange($calendarId, $objectUri, 1); |
|
934 | + |
|
935 | + return '"' . $extraData['etag'] . '"'; |
|
936 | + } |
|
937 | + |
|
938 | + /** |
|
939 | + * Updates an existing calendarobject, based on it's uri. |
|
940 | + * |
|
941 | + * The object uri is only the basename, or filename and not a full path. |
|
942 | + * |
|
943 | + * It is possible return an etag from this function, which will be used in |
|
944 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
945 | + * by double-quotes. |
|
946 | + * |
|
947 | + * However, you should only really return this ETag if you don't mangle the |
|
948 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
949 | + * the exact same as this request body, you should omit the ETag. |
|
950 | + * |
|
951 | + * @param mixed $calendarId |
|
952 | + * @param string $objectUri |
|
953 | + * @param string $calendarData |
|
954 | + * @return string |
|
955 | + */ |
|
956 | + function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
957 | + $extraData = $this->getDenormalizedData($calendarData); |
|
958 | + |
|
959 | + $query = $this->db->getQueryBuilder(); |
|
960 | + $query->update('calendarobjects') |
|
961 | + ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
962 | + ->set('lastmodified', $query->createNamedParameter(time())) |
|
963 | + ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
964 | + ->set('size', $query->createNamedParameter($extraData['size'])) |
|
965 | + ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
966 | + ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
967 | + ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
968 | + ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
969 | + ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
970 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
971 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
972 | + ->execute(); |
|
973 | + |
|
974 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
975 | + if (is_array($data)) { |
|
976 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
977 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
978 | + [ |
|
979 | + 'calendarId' => $calendarId, |
|
980 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
981 | + 'shares' => $this->getShares($calendarId), |
|
982 | + 'objectData' => $data, |
|
983 | + ] |
|
984 | + )); |
|
985 | + } |
|
986 | + $this->addChange($calendarId, $objectUri, 2); |
|
987 | + |
|
988 | + return '"' . $extraData['etag'] . '"'; |
|
989 | + } |
|
990 | + |
|
991 | + /** |
|
992 | + * @param int $calendarObjectId |
|
993 | + * @param int $classification |
|
994 | + */ |
|
995 | + public function setClassification($calendarObjectId, $classification) { |
|
996 | + if (!in_array($classification, [ |
|
997 | + self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
998 | + ])) { |
|
999 | + throw new \InvalidArgumentException(); |
|
1000 | + } |
|
1001 | + $query = $this->db->getQueryBuilder(); |
|
1002 | + $query->update('calendarobjects') |
|
1003 | + ->set('classification', $query->createNamedParameter($classification)) |
|
1004 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
1005 | + ->execute(); |
|
1006 | + } |
|
1007 | + |
|
1008 | + /** |
|
1009 | + * Deletes an existing calendar object. |
|
1010 | + * |
|
1011 | + * The object uri is only the basename, or filename and not a full path. |
|
1012 | + * |
|
1013 | + * @param mixed $calendarId |
|
1014 | + * @param string $objectUri |
|
1015 | + * @return void |
|
1016 | + */ |
|
1017 | + function deleteCalendarObject($calendarId, $objectUri) { |
|
1018 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1019 | + if (is_array($data)) { |
|
1020 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
1021 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
1022 | + [ |
|
1023 | + 'calendarId' => $calendarId, |
|
1024 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1025 | + 'shares' => $this->getShares($calendarId), |
|
1026 | + 'objectData' => $data, |
|
1027 | + ] |
|
1028 | + )); |
|
1029 | + } |
|
1030 | + |
|
1031 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
1032 | + $stmt->execute([$calendarId, $objectUri]); |
|
1033 | + |
|
1034 | + $this->addChange($calendarId, $objectUri, 3); |
|
1035 | + } |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * Performs a calendar-query on the contents of this calendar. |
|
1039 | + * |
|
1040 | + * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
1041 | + * calendar-query it is possible for a client to request a specific set of |
|
1042 | + * object, based on contents of iCalendar properties, date-ranges and |
|
1043 | + * iCalendar component types (VTODO, VEVENT). |
|
1044 | + * |
|
1045 | + * This method should just return a list of (relative) urls that match this |
|
1046 | + * query. |
|
1047 | + * |
|
1048 | + * The list of filters are specified as an array. The exact array is |
|
1049 | + * documented by Sabre\CalDAV\CalendarQueryParser. |
|
1050 | + * |
|
1051 | + * Note that it is extremely likely that getCalendarObject for every path |
|
1052 | + * returned from this method will be called almost immediately after. You |
|
1053 | + * may want to anticipate this to speed up these requests. |
|
1054 | + * |
|
1055 | + * This method provides a default implementation, which parses *all* the |
|
1056 | + * iCalendar objects in the specified calendar. |
|
1057 | + * |
|
1058 | + * This default may well be good enough for personal use, and calendars |
|
1059 | + * that aren't very large. But if you anticipate high usage, big calendars |
|
1060 | + * or high loads, you are strongly advised to optimize certain paths. |
|
1061 | + * |
|
1062 | + * The best way to do so is override this method and to optimize |
|
1063 | + * specifically for 'common filters'. |
|
1064 | + * |
|
1065 | + * Requests that are extremely common are: |
|
1066 | + * * requests for just VEVENTS |
|
1067 | + * * requests for just VTODO |
|
1068 | + * * requests with a time-range-filter on either VEVENT or VTODO. |
|
1069 | + * |
|
1070 | + * ..and combinations of these requests. It may not be worth it to try to |
|
1071 | + * handle every possible situation and just rely on the (relatively |
|
1072 | + * easy to use) CalendarQueryValidator to handle the rest. |
|
1073 | + * |
|
1074 | + * Note that especially time-range-filters may be difficult to parse. A |
|
1075 | + * time-range filter specified on a VEVENT must for instance also handle |
|
1076 | + * recurrence rules correctly. |
|
1077 | + * A good example of how to interprete all these filters can also simply |
|
1078 | + * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
1079 | + * as possible, so it gives you a good idea on what type of stuff you need |
|
1080 | + * to think of. |
|
1081 | + * |
|
1082 | + * @param mixed $calendarId |
|
1083 | + * @param array $filters |
|
1084 | + * @return array |
|
1085 | + */ |
|
1086 | + function calendarQuery($calendarId, array $filters) { |
|
1087 | + $componentType = null; |
|
1088 | + $requirePostFilter = true; |
|
1089 | + $timeRange = null; |
|
1090 | + |
|
1091 | + // if no filters were specified, we don't need to filter after a query |
|
1092 | + if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
1093 | + $requirePostFilter = false; |
|
1094 | + } |
|
1095 | + |
|
1096 | + // Figuring out if there's a component filter |
|
1097 | + if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
1098 | + $componentType = $filters['comp-filters'][0]['name']; |
|
1099 | + |
|
1100 | + // Checking if we need post-filters |
|
1101 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
1102 | + $requirePostFilter = false; |
|
1103 | + } |
|
1104 | + // There was a time-range filter |
|
1105 | + if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
1106 | + $timeRange = $filters['comp-filters'][0]['time-range']; |
|
1107 | + |
|
1108 | + // If start time OR the end time is not specified, we can do a |
|
1109 | + // 100% accurate mysql query. |
|
1110 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
1111 | + $requirePostFilter = false; |
|
1112 | + } |
|
1113 | + } |
|
1114 | + |
|
1115 | + } |
|
1116 | + $columns = ['uri']; |
|
1117 | + if ($requirePostFilter) { |
|
1118 | + $columns = ['uri', 'calendardata']; |
|
1119 | + } |
|
1120 | + $query = $this->db->getQueryBuilder(); |
|
1121 | + $query->select($columns) |
|
1122 | + ->from('calendarobjects') |
|
1123 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
1124 | + |
|
1125 | + if ($componentType) { |
|
1126 | + $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
1127 | + } |
|
1128 | + |
|
1129 | + if ($timeRange && $timeRange['start']) { |
|
1130 | + $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
1131 | + } |
|
1132 | + if ($timeRange && $timeRange['end']) { |
|
1133 | + $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
1134 | + } |
|
1135 | + |
|
1136 | + $stmt = $query->execute(); |
|
1137 | + |
|
1138 | + $result = []; |
|
1139 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1140 | + if ($requirePostFilter) { |
|
1141 | + if (!$this->validateFilterForObject($row, $filters)) { |
|
1142 | + continue; |
|
1143 | + } |
|
1144 | + } |
|
1145 | + $result[] = $row['uri']; |
|
1146 | + } |
|
1147 | + |
|
1148 | + return $result; |
|
1149 | + } |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * custom Nextcloud search extension for CalDAV |
|
1153 | + * |
|
1154 | + * @param string $principalUri |
|
1155 | + * @param array $filters |
|
1156 | + * @param integer|null $limit |
|
1157 | + * @param integer|null $offset |
|
1158 | + * @return array |
|
1159 | + */ |
|
1160 | + public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1161 | + $calendars = $this->getCalendarsForUser($principalUri); |
|
1162 | + $ownCalendars = []; |
|
1163 | + $sharedCalendars = []; |
|
1164 | + |
|
1165 | + $uriMapper = []; |
|
1166 | + |
|
1167 | + foreach($calendars as $calendar) { |
|
1168 | + if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
|
1169 | + $ownCalendars[] = $calendar['id']; |
|
1170 | + } else { |
|
1171 | + $sharedCalendars[] = $calendar['id']; |
|
1172 | + } |
|
1173 | + $uriMapper[$calendar['id']] = $calendar['uri']; |
|
1174 | + } |
|
1175 | + if (count($ownCalendars) === 0 && count($sharedCalendars) === 0) { |
|
1176 | + return []; |
|
1177 | + } |
|
1178 | + |
|
1179 | + $query = $this->db->getQueryBuilder(); |
|
1180 | + |
|
1181 | + // Calendar id expressions |
|
1182 | + $calendarExpressions = []; |
|
1183 | + foreach($ownCalendars as $id) { |
|
1184 | + $calendarExpressions[] = $query->expr() |
|
1185 | + ->eq('calendarid', $query->createNamedParameter($id)); |
|
1186 | + } |
|
1187 | + foreach($sharedCalendars as $id) { |
|
1188 | + $calendarExpressions[] = $query->expr()->andX( |
|
1189 | + $query->expr()->eq('calendarid', |
|
1190 | + $query->createNamedParameter($id)), |
|
1191 | + $query->expr()->eq('classification', |
|
1192 | + $query->createNamedParameter(0)) |
|
1193 | + ); |
|
1194 | + } |
|
1195 | + |
|
1196 | + if (count($calendarExpressions) === 1) { |
|
1197 | + $calExpr = $calendarExpressions[0]; |
|
1198 | + } else { |
|
1199 | + $calExpr = call_user_func_array([$query->expr(), 'orX'], $calendarExpressions); |
|
1200 | + } |
|
1201 | + |
|
1202 | + // Component expressions |
|
1203 | + $compExpressions = []; |
|
1204 | + foreach($filters['comps'] as $comp) { |
|
1205 | + $compExpressions[] = $query->expr() |
|
1206 | + ->eq('componenttype', $query->createNamedParameter($comp)); |
|
1207 | + } |
|
1208 | + |
|
1209 | + if (count($compExpressions) === 1) { |
|
1210 | + $compExpr = $compExpressions[0]; |
|
1211 | + } else { |
|
1212 | + $compExpr = call_user_func_array([$query->expr(), 'orX'], $compExpressions); |
|
1213 | + } |
|
1214 | + |
|
1215 | + // property and filter expression |
|
1216 | + $searchTermFilter = $query->expr()->like('calendardata', |
|
1217 | + $query->createNamedParameter('%' . $this->db->escapeLikeParameter($filters['search-term']) . '%')); |
|
1218 | + |
|
1219 | + $query->select(['calendarid', 'uri', 'calendardata']) |
|
1220 | + ->from('calendarobjects') |
|
1221 | + ->where($calExpr) |
|
1222 | + ->andWhere($compExpr) |
|
1223 | + ->andWhere($searchTermFilter); |
|
1224 | + |
|
1225 | + $stmt = $query->execute(); |
|
1226 | + |
|
1227 | + $result = []; |
|
1228 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1229 | + if (!$this->validateFilterForCalendarSearch($row, $filters)) { |
|
1230 | + continue; |
|
1231 | + } |
|
1232 | + |
|
1233 | + $result[] = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1234 | + } |
|
1235 | + |
|
1236 | + return $result; |
|
1237 | + } |
|
1238 | + |
|
1239 | + /** |
|
1240 | + * This method validates if a filter (as passed to calendarSearch) matches |
|
1241 | + * the given object. |
|
1242 | + * |
|
1243 | + * @param array $object |
|
1244 | + * @param array $filters |
|
1245 | + * @return bool |
|
1246 | + */ |
|
1247 | + protected function validateFilterForCalendarSearch(array $object, array $filters) { |
|
1248 | + $vObject = Reader::read($object['calendardata']); |
|
1249 | + |
|
1250 | + $validator = new Search\CalendarSearchValidator(); |
|
1251 | + $result = $validator->validate($vObject, $filters); |
|
1252 | + |
|
1253 | + // Destroy circular references so PHP will GC the object. |
|
1254 | + $vObject->destroy(); |
|
1255 | + |
|
1256 | + return $result; |
|
1257 | + } |
|
1258 | + |
|
1259 | + /** |
|
1260 | + * Searches through all of a users calendars and calendar objects to find |
|
1261 | + * an object with a specific UID. |
|
1262 | + * |
|
1263 | + * This method should return the path to this object, relative to the |
|
1264 | + * calendar home, so this path usually only contains two parts: |
|
1265 | + * |
|
1266 | + * calendarpath/objectpath.ics |
|
1267 | + * |
|
1268 | + * If the uid is not found, return null. |
|
1269 | + * |
|
1270 | + * This method should only consider * objects that the principal owns, so |
|
1271 | + * any calendars owned by other principals that also appear in this |
|
1272 | + * collection should be ignored. |
|
1273 | + * |
|
1274 | + * @param string $principalUri |
|
1275 | + * @param string $uid |
|
1276 | + * @return string|null |
|
1277 | + */ |
|
1278 | + function getCalendarObjectByUID($principalUri, $uid) { |
|
1279 | + |
|
1280 | + $query = $this->db->getQueryBuilder(); |
|
1281 | + $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
1282 | + ->from('calendarobjects', 'co') |
|
1283 | + ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
1284 | + ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
1285 | + ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
1286 | + |
|
1287 | + $stmt = $query->execute(); |
|
1288 | + |
|
1289 | + if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1290 | + return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1291 | + } |
|
1292 | + |
|
1293 | + return null; |
|
1294 | + } |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * The getChanges method returns all the changes that have happened, since |
|
1298 | + * the specified syncToken in the specified calendar. |
|
1299 | + * |
|
1300 | + * This function should return an array, such as the following: |
|
1301 | + * |
|
1302 | + * [ |
|
1303 | + * 'syncToken' => 'The current synctoken', |
|
1304 | + * 'added' => [ |
|
1305 | + * 'new.txt', |
|
1306 | + * ], |
|
1307 | + * 'modified' => [ |
|
1308 | + * 'modified.txt', |
|
1309 | + * ], |
|
1310 | + * 'deleted' => [ |
|
1311 | + * 'foo.php.bak', |
|
1312 | + * 'old.txt' |
|
1313 | + * ] |
|
1314 | + * ); |
|
1315 | + * |
|
1316 | + * The returned syncToken property should reflect the *current* syncToken |
|
1317 | + * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
1318 | + * property This is * needed here too, to ensure the operation is atomic. |
|
1319 | + * |
|
1320 | + * If the $syncToken argument is specified as null, this is an initial |
|
1321 | + * sync, and all members should be reported. |
|
1322 | + * |
|
1323 | + * The modified property is an array of nodenames that have changed since |
|
1324 | + * the last token. |
|
1325 | + * |
|
1326 | + * The deleted property is an array with nodenames, that have been deleted |
|
1327 | + * from collection. |
|
1328 | + * |
|
1329 | + * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
1330 | + * 1, you only have to report changes that happened only directly in |
|
1331 | + * immediate descendants. If it's 2, it should also include changes from |
|
1332 | + * the nodes below the child collections. (grandchildren) |
|
1333 | + * |
|
1334 | + * The $limit argument allows a client to specify how many results should |
|
1335 | + * be returned at most. If the limit is not specified, it should be treated |
|
1336 | + * as infinite. |
|
1337 | + * |
|
1338 | + * If the limit (infinite or not) is higher than you're willing to return, |
|
1339 | + * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
1340 | + * |
|
1341 | + * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
1342 | + * return null. |
|
1343 | + * |
|
1344 | + * The limit is 'suggestive'. You are free to ignore it. |
|
1345 | + * |
|
1346 | + * @param string $calendarId |
|
1347 | + * @param string $syncToken |
|
1348 | + * @param int $syncLevel |
|
1349 | + * @param int $limit |
|
1350 | + * @return array |
|
1351 | + */ |
|
1352 | + function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
1353 | + // Current synctoken |
|
1354 | + $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1355 | + $stmt->execute([ $calendarId ]); |
|
1356 | + $currentToken = $stmt->fetchColumn(0); |
|
1357 | + |
|
1358 | + if (is_null($currentToken)) { |
|
1359 | + return null; |
|
1360 | + } |
|
1361 | + |
|
1362 | + $result = [ |
|
1363 | + 'syncToken' => $currentToken, |
|
1364 | + 'added' => [], |
|
1365 | + 'modified' => [], |
|
1366 | + 'deleted' => [], |
|
1367 | + ]; |
|
1368 | + |
|
1369 | + if ($syncToken) { |
|
1370 | + |
|
1371 | + $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
1372 | + if ($limit>0) { |
|
1373 | + $query.= " `LIMIT` " . (int)$limit; |
|
1374 | + } |
|
1375 | + |
|
1376 | + // Fetching all changes |
|
1377 | + $stmt = $this->db->prepare($query); |
|
1378 | + $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
1379 | + |
|
1380 | + $changes = []; |
|
1381 | + |
|
1382 | + // This loop ensures that any duplicates are overwritten, only the |
|
1383 | + // last change on a node is relevant. |
|
1384 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1385 | + |
|
1386 | + $changes[$row['uri']] = $row['operation']; |
|
1387 | + |
|
1388 | + } |
|
1389 | + |
|
1390 | + foreach($changes as $uri => $operation) { |
|
1391 | + |
|
1392 | + switch($operation) { |
|
1393 | + case 1 : |
|
1394 | + $result['added'][] = $uri; |
|
1395 | + break; |
|
1396 | + case 2 : |
|
1397 | + $result['modified'][] = $uri; |
|
1398 | + break; |
|
1399 | + case 3 : |
|
1400 | + $result['deleted'][] = $uri; |
|
1401 | + break; |
|
1402 | + } |
|
1403 | + |
|
1404 | + } |
|
1405 | + } else { |
|
1406 | + // No synctoken supplied, this is the initial sync. |
|
1407 | + $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
1408 | + $stmt = $this->db->prepare($query); |
|
1409 | + $stmt->execute([$calendarId]); |
|
1410 | + |
|
1411 | + $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
1412 | + } |
|
1413 | + return $result; |
|
1414 | + |
|
1415 | + } |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * Returns a list of subscriptions for a principal. |
|
1419 | + * |
|
1420 | + * Every subscription is an array with the following keys: |
|
1421 | + * * id, a unique id that will be used by other functions to modify the |
|
1422 | + * subscription. This can be the same as the uri or a database key. |
|
1423 | + * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
1424 | + * * principaluri. The owner of the subscription. Almost always the same as |
|
1425 | + * principalUri passed to this method. |
|
1426 | + * |
|
1427 | + * Furthermore, all the subscription info must be returned too: |
|
1428 | + * |
|
1429 | + * 1. {DAV:}displayname |
|
1430 | + * 2. {http://apple.com/ns/ical/}refreshrate |
|
1431 | + * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
1432 | + * should not be stripped). |
|
1433 | + * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
1434 | + * should not be stripped). |
|
1435 | + * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
1436 | + * attachments should not be stripped). |
|
1437 | + * 6. {http://calendarserver.org/ns/}source (Must be a |
|
1438 | + * Sabre\DAV\Property\Href). |
|
1439 | + * 7. {http://apple.com/ns/ical/}calendar-color |
|
1440 | + * 8. {http://apple.com/ns/ical/}calendar-order |
|
1441 | + * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
1442 | + * (should just be an instance of |
|
1443 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
1444 | + * default components). |
|
1445 | + * |
|
1446 | + * @param string $principalUri |
|
1447 | + * @return array |
|
1448 | + */ |
|
1449 | + function getSubscriptionsForUser($principalUri) { |
|
1450 | + $fields = array_values($this->subscriptionPropertyMap); |
|
1451 | + $fields[] = 'id'; |
|
1452 | + $fields[] = 'uri'; |
|
1453 | + $fields[] = 'source'; |
|
1454 | + $fields[] = 'principaluri'; |
|
1455 | + $fields[] = 'lastmodified'; |
|
1456 | + |
|
1457 | + $query = $this->db->getQueryBuilder(); |
|
1458 | + $query->select($fields) |
|
1459 | + ->from('calendarsubscriptions') |
|
1460 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1461 | + ->orderBy('calendarorder', 'asc'); |
|
1462 | + $stmt =$query->execute(); |
|
1463 | + |
|
1464 | + $subscriptions = []; |
|
1465 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1466 | + |
|
1467 | + $subscription = [ |
|
1468 | + 'id' => $row['id'], |
|
1469 | + 'uri' => $row['uri'], |
|
1470 | + 'principaluri' => $row['principaluri'], |
|
1471 | + 'source' => $row['source'], |
|
1472 | + 'lastmodified' => $row['lastmodified'], |
|
1473 | + |
|
1474 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1475 | + ]; |
|
1476 | + |
|
1477 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1478 | + if (!is_null($row[$dbName])) { |
|
1479 | + $subscription[$xmlName] = $row[$dbName]; |
|
1480 | + } |
|
1481 | + } |
|
1482 | + |
|
1483 | + $subscriptions[] = $subscription; |
|
1484 | + |
|
1485 | + } |
|
1486 | + |
|
1487 | + return $subscriptions; |
|
1488 | + } |
|
1489 | + |
|
1490 | + /** |
|
1491 | + * Creates a new subscription for a principal. |
|
1492 | + * |
|
1493 | + * If the creation was a success, an id must be returned that can be used to reference |
|
1494 | + * this subscription in other methods, such as updateSubscription. |
|
1495 | + * |
|
1496 | + * @param string $principalUri |
|
1497 | + * @param string $uri |
|
1498 | + * @param array $properties |
|
1499 | + * @return mixed |
|
1500 | + */ |
|
1501 | + function createSubscription($principalUri, $uri, array $properties) { |
|
1502 | + |
|
1503 | + if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
1504 | + throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
1505 | + } |
|
1506 | + |
|
1507 | + $values = [ |
|
1508 | + 'principaluri' => $principalUri, |
|
1509 | + 'uri' => $uri, |
|
1510 | + 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
1511 | + 'lastmodified' => time(), |
|
1512 | + ]; |
|
1513 | + |
|
1514 | + $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
1515 | + |
|
1516 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1517 | + if (array_key_exists($xmlName, $properties)) { |
|
1518 | + $values[$dbName] = $properties[$xmlName]; |
|
1519 | + if (in_array($dbName, $propertiesBoolean)) { |
|
1520 | + $values[$dbName] = true; |
|
1521 | + } |
|
1522 | + } |
|
1523 | + } |
|
1524 | + |
|
1525 | + $valuesToInsert = array(); |
|
1526 | + |
|
1527 | + $query = $this->db->getQueryBuilder(); |
|
1528 | + |
|
1529 | + foreach (array_keys($values) as $name) { |
|
1530 | + $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
1531 | + } |
|
1532 | + |
|
1533 | + $query->insert('calendarsubscriptions') |
|
1534 | + ->values($valuesToInsert) |
|
1535 | + ->execute(); |
|
1536 | + |
|
1537 | + return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
1538 | + } |
|
1539 | + |
|
1540 | + /** |
|
1541 | + * Updates a subscription |
|
1542 | + * |
|
1543 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
1544 | + * To do the actual updates, you must tell this object which properties |
|
1545 | + * you're going to process with the handle() method. |
|
1546 | + * |
|
1547 | + * Calling the handle method is like telling the PropPatch object "I |
|
1548 | + * promise I can handle updating this property". |
|
1549 | + * |
|
1550 | + * Read the PropPatch documentation for more info and examples. |
|
1551 | + * |
|
1552 | + * @param mixed $subscriptionId |
|
1553 | + * @param PropPatch $propPatch |
|
1554 | + * @return void |
|
1555 | + */ |
|
1556 | + function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
1557 | + $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
1558 | + $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
1559 | + |
|
1560 | + $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
1561 | + |
|
1562 | + $newValues = []; |
|
1563 | + |
|
1564 | + foreach($mutations as $propertyName=>$propertyValue) { |
|
1565 | + if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
1566 | + $newValues['source'] = $propertyValue->getHref(); |
|
1567 | + } else { |
|
1568 | + $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
1569 | + $newValues[$fieldName] = $propertyValue; |
|
1570 | + } |
|
1571 | + } |
|
1572 | + |
|
1573 | + $query = $this->db->getQueryBuilder(); |
|
1574 | + $query->update('calendarsubscriptions') |
|
1575 | + ->set('lastmodified', $query->createNamedParameter(time())); |
|
1576 | + foreach($newValues as $fieldName=>$value) { |
|
1577 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
1578 | + } |
|
1579 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1580 | + ->execute(); |
|
1581 | + |
|
1582 | + return true; |
|
1583 | + |
|
1584 | + }); |
|
1585 | + } |
|
1586 | + |
|
1587 | + /** |
|
1588 | + * Deletes a subscription. |
|
1589 | + * |
|
1590 | + * @param mixed $subscriptionId |
|
1591 | + * @return void |
|
1592 | + */ |
|
1593 | + function deleteSubscription($subscriptionId) { |
|
1594 | + $query = $this->db->getQueryBuilder(); |
|
1595 | + $query->delete('calendarsubscriptions') |
|
1596 | + ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1597 | + ->execute(); |
|
1598 | + } |
|
1599 | + |
|
1600 | + /** |
|
1601 | + * Returns a single scheduling object for the inbox collection. |
|
1602 | + * |
|
1603 | + * The returned array should contain the following elements: |
|
1604 | + * * uri - A unique basename for the object. This will be used to |
|
1605 | + * construct a full uri. |
|
1606 | + * * calendardata - The iCalendar object |
|
1607 | + * * lastmodified - The last modification date. Can be an int for a unix |
|
1608 | + * timestamp, or a PHP DateTime object. |
|
1609 | + * * etag - A unique token that must change if the object changed. |
|
1610 | + * * size - The size of the object, in bytes. |
|
1611 | + * |
|
1612 | + * @param string $principalUri |
|
1613 | + * @param string $objectUri |
|
1614 | + * @return array |
|
1615 | + */ |
|
1616 | + function getSchedulingObject($principalUri, $objectUri) { |
|
1617 | + $query = $this->db->getQueryBuilder(); |
|
1618 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1619 | + ->from('schedulingobjects') |
|
1620 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1621 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1622 | + ->execute(); |
|
1623 | + |
|
1624 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
1625 | + |
|
1626 | + if(!$row) { |
|
1627 | + return null; |
|
1628 | + } |
|
1629 | + |
|
1630 | + return [ |
|
1631 | + 'uri' => $row['uri'], |
|
1632 | + 'calendardata' => $row['calendardata'], |
|
1633 | + 'lastmodified' => $row['lastmodified'], |
|
1634 | + 'etag' => '"' . $row['etag'] . '"', |
|
1635 | + 'size' => (int)$row['size'], |
|
1636 | + ]; |
|
1637 | + } |
|
1638 | + |
|
1639 | + /** |
|
1640 | + * Returns all scheduling objects for the inbox collection. |
|
1641 | + * |
|
1642 | + * These objects should be returned as an array. Every item in the array |
|
1643 | + * should follow the same structure as returned from getSchedulingObject. |
|
1644 | + * |
|
1645 | + * The main difference is that 'calendardata' is optional. |
|
1646 | + * |
|
1647 | + * @param string $principalUri |
|
1648 | + * @return array |
|
1649 | + */ |
|
1650 | + function getSchedulingObjects($principalUri) { |
|
1651 | + $query = $this->db->getQueryBuilder(); |
|
1652 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1653 | + ->from('schedulingobjects') |
|
1654 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1655 | + ->execute(); |
|
1656 | + |
|
1657 | + $result = []; |
|
1658 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1659 | + $result[] = [ |
|
1660 | + 'calendardata' => $row['calendardata'], |
|
1661 | + 'uri' => $row['uri'], |
|
1662 | + 'lastmodified' => $row['lastmodified'], |
|
1663 | + 'etag' => '"' . $row['etag'] . '"', |
|
1664 | + 'size' => (int)$row['size'], |
|
1665 | + ]; |
|
1666 | + } |
|
1667 | + |
|
1668 | + return $result; |
|
1669 | + } |
|
1670 | + |
|
1671 | + /** |
|
1672 | + * Deletes a scheduling object from the inbox collection. |
|
1673 | + * |
|
1674 | + * @param string $principalUri |
|
1675 | + * @param string $objectUri |
|
1676 | + * @return void |
|
1677 | + */ |
|
1678 | + function deleteSchedulingObject($principalUri, $objectUri) { |
|
1679 | + $query = $this->db->getQueryBuilder(); |
|
1680 | + $query->delete('schedulingobjects') |
|
1681 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1682 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1683 | + ->execute(); |
|
1684 | + } |
|
1685 | + |
|
1686 | + /** |
|
1687 | + * Creates a new scheduling object. This should land in a users' inbox. |
|
1688 | + * |
|
1689 | + * @param string $principalUri |
|
1690 | + * @param string $objectUri |
|
1691 | + * @param string $objectData |
|
1692 | + * @return void |
|
1693 | + */ |
|
1694 | + function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
1695 | + $query = $this->db->getQueryBuilder(); |
|
1696 | + $query->insert('schedulingobjects') |
|
1697 | + ->values([ |
|
1698 | + 'principaluri' => $query->createNamedParameter($principalUri), |
|
1699 | + 'calendardata' => $query->createNamedParameter($objectData), |
|
1700 | + 'uri' => $query->createNamedParameter($objectUri), |
|
1701 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
1702 | + 'etag' => $query->createNamedParameter(md5($objectData)), |
|
1703 | + 'size' => $query->createNamedParameter(strlen($objectData)) |
|
1704 | + ]) |
|
1705 | + ->execute(); |
|
1706 | + } |
|
1707 | + |
|
1708 | + /** |
|
1709 | + * Adds a change record to the calendarchanges table. |
|
1710 | + * |
|
1711 | + * @param mixed $calendarId |
|
1712 | + * @param string $objectUri |
|
1713 | + * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
1714 | + * @return void |
|
1715 | + */ |
|
1716 | + protected function addChange($calendarId, $objectUri, $operation) { |
|
1717 | + |
|
1718 | + $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1719 | + $stmt->execute([ |
|
1720 | + $objectUri, |
|
1721 | + $calendarId, |
|
1722 | + $operation, |
|
1723 | + $calendarId |
|
1724 | + ]); |
|
1725 | + $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
1726 | + $stmt->execute([ |
|
1727 | + $calendarId |
|
1728 | + ]); |
|
1729 | + |
|
1730 | + } |
|
1731 | + |
|
1732 | + /** |
|
1733 | + * Parses some information from calendar objects, used for optimized |
|
1734 | + * calendar-queries. |
|
1735 | + * |
|
1736 | + * Returns an array with the following keys: |
|
1737 | + * * etag - An md5 checksum of the object without the quotes. |
|
1738 | + * * size - Size of the object in bytes |
|
1739 | + * * componentType - VEVENT, VTODO or VJOURNAL |
|
1740 | + * * firstOccurence |
|
1741 | + * * lastOccurence |
|
1742 | + * * uid - value of the UID property |
|
1743 | + * |
|
1744 | + * @param string $calendarData |
|
1745 | + * @return array |
|
1746 | + */ |
|
1747 | + public function getDenormalizedData($calendarData) { |
|
1748 | + |
|
1749 | + $vObject = Reader::read($calendarData); |
|
1750 | + $componentType = null; |
|
1751 | + $component = null; |
|
1752 | + $firstOccurrence = null; |
|
1753 | + $lastOccurrence = null; |
|
1754 | + $uid = null; |
|
1755 | + $classification = self::CLASSIFICATION_PUBLIC; |
|
1756 | + foreach($vObject->getComponents() as $component) { |
|
1757 | + if ($component->name!=='VTIMEZONE') { |
|
1758 | + $componentType = $component->name; |
|
1759 | + $uid = (string)$component->UID; |
|
1760 | + break; |
|
1761 | + } |
|
1762 | + } |
|
1763 | + if (!$componentType) { |
|
1764 | + throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
1765 | + } |
|
1766 | + if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
1767 | + $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
1768 | + // Finding the last occurrence is a bit harder |
|
1769 | + if (!isset($component->RRULE)) { |
|
1770 | + if (isset($component->DTEND)) { |
|
1771 | + $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
1772 | + } elseif (isset($component->DURATION)) { |
|
1773 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
1774 | + $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
1775 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
1776 | + } elseif (!$component->DTSTART->hasTime()) { |
|
1777 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
1778 | + $endDate->modify('+1 day'); |
|
1779 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
1780 | + } else { |
|
1781 | + $lastOccurrence = $firstOccurrence; |
|
1782 | + } |
|
1783 | + } else { |
|
1784 | + $it = new EventIterator($vObject, (string)$component->UID); |
|
1785 | + $maxDate = new \DateTime(self::MAX_DATE); |
|
1786 | + if ($it->isInfinite()) { |
|
1787 | + $lastOccurrence = $maxDate->getTimestamp(); |
|
1788 | + } else { |
|
1789 | + $end = $it->getDtEnd(); |
|
1790 | + while($it->valid() && $end < $maxDate) { |
|
1791 | + $end = $it->getDtEnd(); |
|
1792 | + $it->next(); |
|
1793 | + |
|
1794 | + } |
|
1795 | + $lastOccurrence = $end->getTimestamp(); |
|
1796 | + } |
|
1797 | + |
|
1798 | + } |
|
1799 | + } |
|
1800 | + |
|
1801 | + if ($component->CLASS) { |
|
1802 | + $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
1803 | + switch ($component->CLASS->getValue()) { |
|
1804 | + case 'PUBLIC': |
|
1805 | + $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
1806 | + break; |
|
1807 | + case 'CONFIDENTIAL': |
|
1808 | + $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
1809 | + break; |
|
1810 | + } |
|
1811 | + } |
|
1812 | + return [ |
|
1813 | + 'etag' => md5($calendarData), |
|
1814 | + 'size' => strlen($calendarData), |
|
1815 | + 'componentType' => $componentType, |
|
1816 | + 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
1817 | + 'lastOccurence' => $lastOccurrence, |
|
1818 | + 'uid' => $uid, |
|
1819 | + 'classification' => $classification |
|
1820 | + ]; |
|
1821 | + |
|
1822 | + } |
|
1823 | + |
|
1824 | + private function readBlob($cardData) { |
|
1825 | + if (is_resource($cardData)) { |
|
1826 | + return stream_get_contents($cardData); |
|
1827 | + } |
|
1828 | + |
|
1829 | + return $cardData; |
|
1830 | + } |
|
1831 | + |
|
1832 | + /** |
|
1833 | + * @param IShareable $shareable |
|
1834 | + * @param array $add |
|
1835 | + * @param array $remove |
|
1836 | + */ |
|
1837 | + public function updateShares($shareable, $add, $remove) { |
|
1838 | + $calendarId = $shareable->getResourceId(); |
|
1839 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
1840 | + '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
1841 | + [ |
|
1842 | + 'calendarId' => $calendarId, |
|
1843 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1844 | + 'shares' => $this->getShares($calendarId), |
|
1845 | + 'add' => $add, |
|
1846 | + 'remove' => $remove, |
|
1847 | + ])); |
|
1848 | + $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
1849 | + } |
|
1850 | + |
|
1851 | + /** |
|
1852 | + * @param int $resourceId |
|
1853 | + * @return array |
|
1854 | + */ |
|
1855 | + public function getShares($resourceId) { |
|
1856 | + return $this->sharingBackend->getShares($resourceId); |
|
1857 | + } |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * @param boolean $value |
|
1861 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1862 | + * @return string|null |
|
1863 | + */ |
|
1864 | + public function setPublishStatus($value, $calendar) { |
|
1865 | + $query = $this->db->getQueryBuilder(); |
|
1866 | + if ($value) { |
|
1867 | + $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
1868 | + $query->insert('dav_shares') |
|
1869 | + ->values([ |
|
1870 | + 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
1871 | + 'type' => $query->createNamedParameter('calendar'), |
|
1872 | + 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
1873 | + 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
1874 | + 'publicuri' => $query->createNamedParameter($publicUri) |
|
1875 | + ]); |
|
1876 | + $query->execute(); |
|
1877 | + return $publicUri; |
|
1878 | + } |
|
1879 | + $query->delete('dav_shares') |
|
1880 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1881 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
1882 | + $query->execute(); |
|
1883 | + return null; |
|
1884 | + } |
|
1885 | + |
|
1886 | + /** |
|
1887 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1888 | + * @return mixed |
|
1889 | + */ |
|
1890 | + public function getPublishStatus($calendar) { |
|
1891 | + $query = $this->db->getQueryBuilder(); |
|
1892 | + $result = $query->select('publicuri') |
|
1893 | + ->from('dav_shares') |
|
1894 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1895 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
1896 | + ->execute(); |
|
1897 | + |
|
1898 | + $row = $result->fetch(); |
|
1899 | + $result->closeCursor(); |
|
1900 | + return $row ? reset($row) : false; |
|
1901 | + } |
|
1902 | + |
|
1903 | + /** |
|
1904 | + * @param int $resourceId |
|
1905 | + * @param array $acl |
|
1906 | + * @return array |
|
1907 | + */ |
|
1908 | + public function applyShareAcl($resourceId, $acl) { |
|
1909 | + return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
1910 | + } |
|
1911 | + |
|
1912 | + private function convertPrincipal($principalUri, $toV2) { |
|
1913 | + if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
1914 | + list(, $name) = URLUtil::splitPath($principalUri); |
|
1915 | + if ($toV2 === true) { |
|
1916 | + return "principals/users/$name"; |
|
1917 | + } |
|
1918 | + return "principals/$name"; |
|
1919 | + } |
|
1920 | + return $principalUri; |
|
1921 | + } |
|
1922 | 1922 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
180 | 180 | } |
181 | 181 | |
182 | - return (int)$query->execute()->fetchColumn(); |
|
182 | + return (int) $query->execute()->fetchColumn(); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -226,25 +226,25 @@ discard block |
||
226 | 226 | $stmt = $query->execute(); |
227 | 227 | |
228 | 228 | $calendars = []; |
229 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
229 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | 230 | |
231 | 231 | $components = []; |
232 | 232 | if ($row['components']) { |
233 | - $components = explode(',',$row['components']); |
|
233 | + $components = explode(',', $row['components']); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | $calendar = [ |
237 | 237 | 'id' => $row['id'], |
238 | 238 | 'uri' => $row['uri'], |
239 | 239 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
240 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
240 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
241 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
242 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
244 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | 245 | ]; |
246 | 246 | |
247 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
247 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
248 | 248 | $calendar[$xmlName] = $row[$dbName]; |
249 | 249 | } |
250 | 250 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | |
258 | 258 | // query for shared calendars |
259 | 259 | $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
260 | - $principals[]= $principalUri; |
|
260 | + $principals[] = $principalUri; |
|
261 | 261 | |
262 | 262 | $fields = array_values($this->propertyMap); |
263 | 263 | $fields[] = 'a.id'; |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
278 | 278 | ->execute(); |
279 | 279 | |
280 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
281 | - while($row = $result->fetch()) { |
|
280 | + $readOnlyPropertyName = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only'; |
|
281 | + while ($row = $result->fetch()) { |
|
282 | 282 | $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
283 | 283 | if (isset($calendars[$row['id']])) { |
284 | 284 | if ($readOnly) { |
@@ -293,25 +293,25 @@ discard block |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
296 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
297 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
296 | + $uri = $row['uri'].'_shared_by_'.$name; |
|
297 | + $row['displayname'] = $row['displayname'].' ('.$this->getUserDisplayName($name).')'; |
|
298 | 298 | $components = []; |
299 | 299 | if ($row['components']) { |
300 | - $components = explode(',',$row['components']); |
|
300 | + $components = explode(',', $row['components']); |
|
301 | 301 | } |
302 | 302 | $calendar = [ |
303 | 303 | 'id' => $row['id'], |
304 | 304 | 'uri' => $uri, |
305 | 305 | 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
306 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
307 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
308 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
309 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
310 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
306 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
307 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
308 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
309 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
310 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
311 | 311 | $readOnlyPropertyName => $readOnly, |
312 | 312 | ]; |
313 | 313 | |
314 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
314 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
315 | 315 | $calendar[$xmlName] = $row[$dbName]; |
316 | 316 | } |
317 | 317 | |
@@ -338,21 +338,21 @@ discard block |
||
338 | 338 | ->orderBy('calendarorder', 'ASC'); |
339 | 339 | $stmt = $query->execute(); |
340 | 340 | $calendars = []; |
341 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
341 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
342 | 342 | $components = []; |
343 | 343 | if ($row['components']) { |
344 | - $components = explode(',',$row['components']); |
|
344 | + $components = explode(',', $row['components']); |
|
345 | 345 | } |
346 | 346 | $calendar = [ |
347 | 347 | 'id' => $row['id'], |
348 | 348 | 'uri' => $row['uri'], |
349 | 349 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
350 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
351 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
352 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
353 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
350 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
351 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
352 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
353 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
354 | 354 | ]; |
355 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
355 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
356 | 356 | $calendar[$xmlName] = $row[$dbName]; |
357 | 357 | } |
358 | 358 | if (!isset($calendars[$calendar['id']])) { |
@@ -400,27 +400,27 @@ discard block |
||
400 | 400 | ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
401 | 401 | ->execute(); |
402 | 402 | |
403 | - while($row = $result->fetch()) { |
|
403 | + while ($row = $result->fetch()) { |
|
404 | 404 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
405 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
405 | + $row['displayname'] = $row['displayname']."($name)"; |
|
406 | 406 | $components = []; |
407 | 407 | if ($row['components']) { |
408 | - $components = explode(',',$row['components']); |
|
408 | + $components = explode(',', $row['components']); |
|
409 | 409 | } |
410 | 410 | $calendar = [ |
411 | 411 | 'id' => $row['id'], |
412 | 412 | 'uri' => $row['publicuri'], |
413 | 413 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
414 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
415 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
416 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
417 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
418 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
419 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
420 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
414 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
415 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
416 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
417 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
418 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
419 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
420 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
421 | 421 | ]; |
422 | 422 | |
423 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
423 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
424 | 424 | $calendar[$xmlName] = $row[$dbName]; |
425 | 425 | } |
426 | 426 | |
@@ -462,29 +462,29 @@ discard block |
||
462 | 462 | $result->closeCursor(); |
463 | 463 | |
464 | 464 | if ($row === false) { |
465 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
465 | + throw new NotFound('Node with name \''.$uri.'\' could not be found'); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
469 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
469 | + $row['displayname'] = $row['displayname'].' '."($name)"; |
|
470 | 470 | $components = []; |
471 | 471 | if ($row['components']) { |
472 | - $components = explode(',',$row['components']); |
|
472 | + $components = explode(',', $row['components']); |
|
473 | 473 | } |
474 | 474 | $calendar = [ |
475 | 475 | 'id' => $row['id'], |
476 | 476 | 'uri' => $row['publicuri'], |
477 | 477 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
478 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
479 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
480 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
481 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
482 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
483 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
484 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
478 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
479 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
480 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
481 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
482 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
483 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
484 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
485 | 485 | ]; |
486 | 486 | |
487 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
487 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
488 | 488 | $calendar[$xmlName] = $row[$dbName]; |
489 | 489 | } |
490 | 490 | |
@@ -522,20 +522,20 @@ discard block |
||
522 | 522 | |
523 | 523 | $components = []; |
524 | 524 | if ($row['components']) { |
525 | - $components = explode(',',$row['components']); |
|
525 | + $components = explode(',', $row['components']); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | $calendar = [ |
529 | 529 | 'id' => $row['id'], |
530 | 530 | 'uri' => $row['uri'], |
531 | 531 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
532 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
533 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
534 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
535 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
532 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
533 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
534 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
535 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
536 | 536 | ]; |
537 | 537 | |
538 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
538 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
539 | 539 | $calendar[$xmlName] = $row[$dbName]; |
540 | 540 | } |
541 | 541 | |
@@ -566,20 +566,20 @@ discard block |
||
566 | 566 | |
567 | 567 | $components = []; |
568 | 568 | if ($row['components']) { |
569 | - $components = explode(',',$row['components']); |
|
569 | + $components = explode(',', $row['components']); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | $calendar = [ |
573 | 573 | 'id' => $row['id'], |
574 | 574 | 'uri' => $row['uri'], |
575 | 575 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
576 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
577 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
578 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
579 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
576 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
577 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
578 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
579 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
580 | 580 | ]; |
581 | 581 | |
582 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
582 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
583 | 583 | $calendar[$xmlName] = $row[$dbName]; |
584 | 584 | } |
585 | 585 | |
@@ -611,16 +611,16 @@ discard block |
||
611 | 611 | $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
612 | 612 | if (isset($properties[$sccs])) { |
613 | 613 | if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
614 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
614 | + throw new DAV\Exception('The '.$sccs.' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
615 | 615 | } |
616 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
616 | + $values['components'] = implode(',', $properties[$sccs]->getValue()); |
|
617 | 617 | } |
618 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
618 | + $transp = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
619 | 619 | if (isset($properties[$transp])) { |
620 | - $values['transparent'] = $properties[$transp]->getValue()==='transparent'; |
|
620 | + $values['transparent'] = $properties[$transp]->getValue() === 'transparent'; |
|
621 | 621 | } |
622 | 622 | |
623 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
623 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
624 | 624 | if (isset($properties[$xmlName])) { |
625 | 625 | $values[$dbName] = $properties[$xmlName]; |
626 | 626 | } |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | |
629 | 629 | $query = $this->db->getQueryBuilder(); |
630 | 630 | $query->insert('calendars'); |
631 | - foreach($values as $column => $value) { |
|
631 | + foreach ($values as $column => $value) { |
|
632 | 632 | $query->setValue($column, $query->createNamedParameter($value)); |
633 | 633 | } |
634 | 634 | $query->execute(); |
@@ -661,14 +661,14 @@ discard block |
||
661 | 661 | */ |
662 | 662 | function updateCalendar($calendarId, PropPatch $propPatch) { |
663 | 663 | $supportedProperties = array_keys($this->propertyMap); |
664 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
664 | + $supportedProperties[] = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
665 | 665 | |
666 | 666 | $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
667 | 667 | $newValues = []; |
668 | 668 | foreach ($mutations as $propertyName => $propertyValue) { |
669 | 669 | |
670 | 670 | switch ($propertyName) { |
671 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
671 | + case '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' : |
|
672 | 672 | $fieldName = 'transparent'; |
673 | 673 | $newValues[$fieldName] = $propertyValue->getValue() === 'transparent'; |
674 | 674 | break; |
@@ -778,16 +778,16 @@ discard block |
||
778 | 778 | $stmt = $query->execute(); |
779 | 779 | |
780 | 780 | $result = []; |
781 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
781 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
782 | 782 | $result[] = [ |
783 | 783 | 'id' => $row['id'], |
784 | 784 | 'uri' => $row['uri'], |
785 | 785 | 'lastmodified' => $row['lastmodified'], |
786 | - 'etag' => '"' . $row['etag'] . '"', |
|
786 | + 'etag' => '"'.$row['etag'].'"', |
|
787 | 787 | 'calendarid' => $row['calendarid'], |
788 | - 'size' => (int)$row['size'], |
|
788 | + 'size' => (int) $row['size'], |
|
789 | 789 | 'component' => strtolower($row['componenttype']), |
790 | - 'classification'=> (int)$row['classification'] |
|
790 | + 'classification'=> (int) $row['classification'] |
|
791 | 791 | ]; |
792 | 792 | } |
793 | 793 | |
@@ -820,18 +820,18 @@ discard block |
||
820 | 820 | $stmt = $query->execute(); |
821 | 821 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
822 | 822 | |
823 | - if(!$row) return null; |
|
823 | + if (!$row) return null; |
|
824 | 824 | |
825 | 825 | return [ |
826 | 826 | 'id' => $row['id'], |
827 | 827 | 'uri' => $row['uri'], |
828 | 828 | 'lastmodified' => $row['lastmodified'], |
829 | - 'etag' => '"' . $row['etag'] . '"', |
|
829 | + 'etag' => '"'.$row['etag'].'"', |
|
830 | 830 | 'calendarid' => $row['calendarid'], |
831 | - 'size' => (int)$row['size'], |
|
831 | + 'size' => (int) $row['size'], |
|
832 | 832 | 'calendardata' => $this->readBlob($row['calendardata']), |
833 | 833 | 'component' => strtolower($row['componenttype']), |
834 | - 'classification'=> (int)$row['classification'] |
|
834 | + 'classification'=> (int) $row['classification'] |
|
835 | 835 | ]; |
836 | 836 | } |
837 | 837 | |
@@ -870,12 +870,12 @@ discard block |
||
870 | 870 | 'id' => $row['id'], |
871 | 871 | 'uri' => $row['uri'], |
872 | 872 | 'lastmodified' => $row['lastmodified'], |
873 | - 'etag' => '"' . $row['etag'] . '"', |
|
873 | + 'etag' => '"'.$row['etag'].'"', |
|
874 | 874 | 'calendarid' => $row['calendarid'], |
875 | - 'size' => (int)$row['size'], |
|
875 | + 'size' => (int) $row['size'], |
|
876 | 876 | 'calendardata' => $this->readBlob($row['calendardata']), |
877 | 877 | 'component' => strtolower($row['componenttype']), |
878 | - 'classification' => (int)$row['classification'] |
|
878 | + 'classification' => (int) $row['classification'] |
|
879 | 879 | ]; |
880 | 880 | } |
881 | 881 | $result->closeCursor(); |
@@ -932,7 +932,7 @@ discard block |
||
932 | 932 | )); |
933 | 933 | $this->addChange($calendarId, $objectUri, 1); |
934 | 934 | |
935 | - return '"' . $extraData['etag'] . '"'; |
|
935 | + return '"'.$extraData['etag'].'"'; |
|
936 | 936 | } |
937 | 937 | |
938 | 938 | /** |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | } |
986 | 986 | $this->addChange($calendarId, $objectUri, 2); |
987 | 987 | |
988 | - return '"' . $extraData['etag'] . '"'; |
|
988 | + return '"'.$extraData['etag'].'"'; |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | /** |
@@ -1136,7 +1136,7 @@ discard block |
||
1136 | 1136 | $stmt = $query->execute(); |
1137 | 1137 | |
1138 | 1138 | $result = []; |
1139 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1139 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1140 | 1140 | if ($requirePostFilter) { |
1141 | 1141 | if (!$this->validateFilterForObject($row, $filters)) { |
1142 | 1142 | continue; |
@@ -1157,14 +1157,14 @@ discard block |
||
1157 | 1157 | * @param integer|null $offset |
1158 | 1158 | * @return array |
1159 | 1159 | */ |
1160 | - public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1160 | + public function calendarSearch($principalUri, array $filters, $limit = null, $offset = null) { |
|
1161 | 1161 | $calendars = $this->getCalendarsForUser($principalUri); |
1162 | 1162 | $ownCalendars = []; |
1163 | 1163 | $sharedCalendars = []; |
1164 | 1164 | |
1165 | 1165 | $uriMapper = []; |
1166 | 1166 | |
1167 | - foreach($calendars as $calendar) { |
|
1167 | + foreach ($calendars as $calendar) { |
|
1168 | 1168 | if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
1169 | 1169 | $ownCalendars[] = $calendar['id']; |
1170 | 1170 | } else { |
@@ -1180,11 +1180,11 @@ discard block |
||
1180 | 1180 | |
1181 | 1181 | // Calendar id expressions |
1182 | 1182 | $calendarExpressions = []; |
1183 | - foreach($ownCalendars as $id) { |
|
1183 | + foreach ($ownCalendars as $id) { |
|
1184 | 1184 | $calendarExpressions[] = $query->expr() |
1185 | 1185 | ->eq('calendarid', $query->createNamedParameter($id)); |
1186 | 1186 | } |
1187 | - foreach($sharedCalendars as $id) { |
|
1187 | + foreach ($sharedCalendars as $id) { |
|
1188 | 1188 | $calendarExpressions[] = $query->expr()->andX( |
1189 | 1189 | $query->expr()->eq('calendarid', |
1190 | 1190 | $query->createNamedParameter($id)), |
@@ -1201,7 +1201,7 @@ discard block |
||
1201 | 1201 | |
1202 | 1202 | // Component expressions |
1203 | 1203 | $compExpressions = []; |
1204 | - foreach($filters['comps'] as $comp) { |
|
1204 | + foreach ($filters['comps'] as $comp) { |
|
1205 | 1205 | $compExpressions[] = $query->expr() |
1206 | 1206 | ->eq('componenttype', $query->createNamedParameter($comp)); |
1207 | 1207 | } |
@@ -1214,7 +1214,7 @@ discard block |
||
1214 | 1214 | |
1215 | 1215 | // property and filter expression |
1216 | 1216 | $searchTermFilter = $query->expr()->like('calendardata', |
1217 | - $query->createNamedParameter('%' . $this->db->escapeLikeParameter($filters['search-term']) . '%')); |
|
1217 | + $query->createNamedParameter('%'.$this->db->escapeLikeParameter($filters['search-term']).'%')); |
|
1218 | 1218 | |
1219 | 1219 | $query->select(['calendarid', 'uri', 'calendardata']) |
1220 | 1220 | ->from('calendarobjects') |
@@ -1225,12 +1225,12 @@ discard block |
||
1225 | 1225 | $stmt = $query->execute(); |
1226 | 1226 | |
1227 | 1227 | $result = []; |
1228 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1228 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1229 | 1229 | if (!$this->validateFilterForCalendarSearch($row, $filters)) { |
1230 | 1230 | continue; |
1231 | 1231 | } |
1232 | 1232 | |
1233 | - $result[] = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1233 | + $result[] = $uriMapper[$row['calendarid']].'/'.$row['uri']; |
|
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | return $result; |
@@ -1287,7 +1287,7 @@ discard block |
||
1287 | 1287 | $stmt = $query->execute(); |
1288 | 1288 | |
1289 | 1289 | if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
1290 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1290 | + return $row['calendaruri'].'/'.$row['objecturi']; |
|
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 | return null; |
@@ -1352,7 +1352,7 @@ discard block |
||
1352 | 1352 | function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
1353 | 1353 | // Current synctoken |
1354 | 1354 | $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
1355 | - $stmt->execute([ $calendarId ]); |
|
1355 | + $stmt->execute([$calendarId]); |
|
1356 | 1356 | $currentToken = $stmt->fetchColumn(0); |
1357 | 1357 | |
1358 | 1358 | if (is_null($currentToken)) { |
@@ -1369,8 +1369,8 @@ discard block |
||
1369 | 1369 | if ($syncToken) { |
1370 | 1370 | |
1371 | 1371 | $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
1372 | - if ($limit>0) { |
|
1373 | - $query.= " `LIMIT` " . (int)$limit; |
|
1372 | + if ($limit > 0) { |
|
1373 | + $query .= " `LIMIT` ".(int) $limit; |
|
1374 | 1374 | } |
1375 | 1375 | |
1376 | 1376 | // Fetching all changes |
@@ -1381,15 +1381,15 @@ discard block |
||
1381 | 1381 | |
1382 | 1382 | // This loop ensures that any duplicates are overwritten, only the |
1383 | 1383 | // last change on a node is relevant. |
1384 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1384 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1385 | 1385 | |
1386 | 1386 | $changes[$row['uri']] = $row['operation']; |
1387 | 1387 | |
1388 | 1388 | } |
1389 | 1389 | |
1390 | - foreach($changes as $uri => $operation) { |
|
1390 | + foreach ($changes as $uri => $operation) { |
|
1391 | 1391 | |
1392 | - switch($operation) { |
|
1392 | + switch ($operation) { |
|
1393 | 1393 | case 1 : |
1394 | 1394 | $result['added'][] = $uri; |
1395 | 1395 | break; |
@@ -1459,10 +1459,10 @@ discard block |
||
1459 | 1459 | ->from('calendarsubscriptions') |
1460 | 1460 | ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
1461 | 1461 | ->orderBy('calendarorder', 'asc'); |
1462 | - $stmt =$query->execute(); |
|
1462 | + $stmt = $query->execute(); |
|
1463 | 1463 | |
1464 | 1464 | $subscriptions = []; |
1465 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1465 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1466 | 1466 | |
1467 | 1467 | $subscription = [ |
1468 | 1468 | 'id' => $row['id'], |
@@ -1471,10 +1471,10 @@ discard block |
||
1471 | 1471 | 'source' => $row['source'], |
1472 | 1472 | 'lastmodified' => $row['lastmodified'], |
1473 | 1473 | |
1474 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1474 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1475 | 1475 | ]; |
1476 | 1476 | |
1477 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1477 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1478 | 1478 | if (!is_null($row[$dbName])) { |
1479 | 1479 | $subscription[$xmlName] = $row[$dbName]; |
1480 | 1480 | } |
@@ -1513,7 +1513,7 @@ discard block |
||
1513 | 1513 | |
1514 | 1514 | $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
1515 | 1515 | |
1516 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1516 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1517 | 1517 | if (array_key_exists($xmlName, $properties)) { |
1518 | 1518 | $values[$dbName] = $properties[$xmlName]; |
1519 | 1519 | if (in_array($dbName, $propertiesBoolean)) { |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | |
1562 | 1562 | $newValues = []; |
1563 | 1563 | |
1564 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
1564 | + foreach ($mutations as $propertyName=>$propertyValue) { |
|
1565 | 1565 | if ($propertyName === '{http://calendarserver.org/ns/}source') { |
1566 | 1566 | $newValues['source'] = $propertyValue->getHref(); |
1567 | 1567 | } else { |
@@ -1573,7 +1573,7 @@ discard block |
||
1573 | 1573 | $query = $this->db->getQueryBuilder(); |
1574 | 1574 | $query->update('calendarsubscriptions') |
1575 | 1575 | ->set('lastmodified', $query->createNamedParameter(time())); |
1576 | - foreach($newValues as $fieldName=>$value) { |
|
1576 | + foreach ($newValues as $fieldName=>$value) { |
|
1577 | 1577 | $query->set($fieldName, $query->createNamedParameter($value)); |
1578 | 1578 | } |
1579 | 1579 | $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
@@ -1623,7 +1623,7 @@ discard block |
||
1623 | 1623 | |
1624 | 1624 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
1625 | 1625 | |
1626 | - if(!$row) { |
|
1626 | + if (!$row) { |
|
1627 | 1627 | return null; |
1628 | 1628 | } |
1629 | 1629 | |
@@ -1631,8 +1631,8 @@ discard block |
||
1631 | 1631 | 'uri' => $row['uri'], |
1632 | 1632 | 'calendardata' => $row['calendardata'], |
1633 | 1633 | 'lastmodified' => $row['lastmodified'], |
1634 | - 'etag' => '"' . $row['etag'] . '"', |
|
1635 | - 'size' => (int)$row['size'], |
|
1634 | + 'etag' => '"'.$row['etag'].'"', |
|
1635 | + 'size' => (int) $row['size'], |
|
1636 | 1636 | ]; |
1637 | 1637 | } |
1638 | 1638 | |
@@ -1655,13 +1655,13 @@ discard block |
||
1655 | 1655 | ->execute(); |
1656 | 1656 | |
1657 | 1657 | $result = []; |
1658 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1658 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1659 | 1659 | $result[] = [ |
1660 | 1660 | 'calendardata' => $row['calendardata'], |
1661 | 1661 | 'uri' => $row['uri'], |
1662 | 1662 | 'lastmodified' => $row['lastmodified'], |
1663 | - 'etag' => '"' . $row['etag'] . '"', |
|
1664 | - 'size' => (int)$row['size'], |
|
1663 | + 'etag' => '"'.$row['etag'].'"', |
|
1664 | + 'size' => (int) $row['size'], |
|
1665 | 1665 | ]; |
1666 | 1666 | } |
1667 | 1667 | |
@@ -1753,10 +1753,10 @@ discard block |
||
1753 | 1753 | $lastOccurrence = null; |
1754 | 1754 | $uid = null; |
1755 | 1755 | $classification = self::CLASSIFICATION_PUBLIC; |
1756 | - foreach($vObject->getComponents() as $component) { |
|
1757 | - if ($component->name!=='VTIMEZONE') { |
|
1756 | + foreach ($vObject->getComponents() as $component) { |
|
1757 | + if ($component->name !== 'VTIMEZONE') { |
|
1758 | 1758 | $componentType = $component->name; |
1759 | - $uid = (string)$component->UID; |
|
1759 | + $uid = (string) $component->UID; |
|
1760 | 1760 | break; |
1761 | 1761 | } |
1762 | 1762 | } |
@@ -1781,13 +1781,13 @@ discard block |
||
1781 | 1781 | $lastOccurrence = $firstOccurrence; |
1782 | 1782 | } |
1783 | 1783 | } else { |
1784 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
1784 | + $it = new EventIterator($vObject, (string) $component->UID); |
|
1785 | 1785 | $maxDate = new \DateTime(self::MAX_DATE); |
1786 | 1786 | if ($it->isInfinite()) { |
1787 | 1787 | $lastOccurrence = $maxDate->getTimestamp(); |
1788 | 1788 | } else { |
1789 | 1789 | $end = $it->getDtEnd(); |
1790 | - while($it->valid() && $end < $maxDate) { |
|
1790 | + while ($it->valid() && $end < $maxDate) { |
|
1791 | 1791 | $end = $it->getDtEnd(); |
1792 | 1792 | $it->next(); |
1793 | 1793 |
@@ -24,79 +24,79 @@ |
||
24 | 24 | |
25 | 25 | class CalendarSearchValidator { |
26 | 26 | |
27 | - /** |
|
28 | - * Verify if a list of filters applies to the calendar data object |
|
29 | - * |
|
30 | - * The list of filters must be formatted as parsed by Xml\Request\CalendarSearchReport |
|
31 | - * |
|
32 | - * @param VObject\Component\VCalendar $vObject |
|
33 | - * @param array $filters |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - function validate(VObject\Component\VCalendar $vObject, array $filters) { |
|
37 | - $comps = $vObject->getComponents(); |
|
38 | - $filters['comps'][] = 'VTIMEZONE'; |
|
27 | + /** |
|
28 | + * Verify if a list of filters applies to the calendar data object |
|
29 | + * |
|
30 | + * The list of filters must be formatted as parsed by Xml\Request\CalendarSearchReport |
|
31 | + * |
|
32 | + * @param VObject\Component\VCalendar $vObject |
|
33 | + * @param array $filters |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + function validate(VObject\Component\VCalendar $vObject, array $filters) { |
|
37 | + $comps = $vObject->getComponents(); |
|
38 | + $filters['comps'][] = 'VTIMEZONE'; |
|
39 | 39 | |
40 | - $matches = false; |
|
41 | - foreach($comps as $comp) { |
|
42 | - if ($comp->name === 'VTIMEZONE') { |
|
43 | - continue; |
|
44 | - } |
|
45 | - if ($matches) { |
|
46 | - break; |
|
47 | - } |
|
40 | + $matches = false; |
|
41 | + foreach($comps as $comp) { |
|
42 | + if ($comp->name === 'VTIMEZONE') { |
|
43 | + continue; |
|
44 | + } |
|
45 | + if ($matches) { |
|
46 | + break; |
|
47 | + } |
|
48 | 48 | |
49 | - // check comps |
|
50 | - if (!in_array($comp->name, $filters['comps'])) { |
|
51 | - return false; |
|
52 | - } |
|
49 | + // check comps |
|
50 | + if (!in_array($comp->name, $filters['comps'])) { |
|
51 | + return false; |
|
52 | + } |
|
53 | 53 | |
54 | - $children = $comp->children(); |
|
55 | - foreach($children as $child) { |
|
56 | - if (!($child instanceof VObject\Property)) { |
|
57 | - continue; |
|
58 | - } |
|
59 | - if ($matches) { |
|
60 | - break; |
|
61 | - } |
|
54 | + $children = $comp->children(); |
|
55 | + foreach($children as $child) { |
|
56 | + if (!($child instanceof VObject\Property)) { |
|
57 | + continue; |
|
58 | + } |
|
59 | + if ($matches) { |
|
60 | + break; |
|
61 | + } |
|
62 | 62 | |
63 | - foreach($filters['props'] as $prop) { |
|
64 | - if ($child->name !== $prop) { |
|
65 | - continue; |
|
66 | - } |
|
63 | + foreach($filters['props'] as $prop) { |
|
64 | + if ($child->name !== $prop) { |
|
65 | + continue; |
|
66 | + } |
|
67 | 67 | |
68 | - $value = $child->getValue(); |
|
69 | - if (substr_count($value, $filters['search-term'])) { |
|
70 | - $matches = true; |
|
71 | - break; |
|
72 | - } |
|
73 | - } |
|
68 | + $value = $child->getValue(); |
|
69 | + if (substr_count($value, $filters['search-term'])) { |
|
70 | + $matches = true; |
|
71 | + break; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - foreach($filters['params'] as $param) { |
|
76 | - $propName = $param['property']; |
|
77 | - $paramName = $param['parameter']; |
|
75 | + foreach($filters['params'] as $param) { |
|
76 | + $propName = $param['property']; |
|
77 | + $paramName = $param['parameter']; |
|
78 | 78 | |
79 | - if ($child->name !== $propName) { |
|
80 | - continue; |
|
81 | - } |
|
82 | - if ($matches) { |
|
83 | - break; |
|
84 | - } |
|
79 | + if ($child->name !== $propName) { |
|
80 | + continue; |
|
81 | + } |
|
82 | + if ($matches) { |
|
83 | + break; |
|
84 | + } |
|
85 | 85 | |
86 | - $parameters = $child->parameters(); |
|
87 | - foreach ($parameters as $key => $value) { |
|
88 | - if ($paramName !== $key) { |
|
89 | - continue; |
|
90 | - } |
|
91 | - if (substr_count($value, $filters['search-term'])) { |
|
92 | - $matches = true; |
|
93 | - break; |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
86 | + $parameters = $child->parameters(); |
|
87 | + foreach ($parameters as $key => $value) { |
|
88 | + if ($paramName !== $key) { |
|
89 | + continue; |
|
90 | + } |
|
91 | + if (substr_count($value, $filters['search-term'])) { |
|
92 | + $matches = true; |
|
93 | + break; |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - return $matches; |
|
101 | - } |
|
100 | + return $matches; |
|
101 | + } |
|
102 | 102 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $filters['comps'][] = 'VTIMEZONE'; |
39 | 39 | |
40 | 40 | $matches = false; |
41 | - foreach($comps as $comp) { |
|
41 | + foreach ($comps as $comp) { |
|
42 | 42 | if ($comp->name === 'VTIMEZONE') { |
43 | 43 | continue; |
44 | 44 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | $children = $comp->children(); |
55 | - foreach($children as $child) { |
|
55 | + foreach ($children as $child) { |
|
56 | 56 | if (!($child instanceof VObject\Property)) { |
57 | 57 | continue; |
58 | 58 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | break; |
61 | 61 | } |
62 | 62 | |
63 | - foreach($filters['props'] as $prop) { |
|
63 | + foreach ($filters['props'] as $prop) { |
|
64 | 64 | if ($child->name !== $prop) { |
65 | 65 | continue; |
66 | 66 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - foreach($filters['params'] as $param) { |
|
75 | + foreach ($filters['params'] as $param) { |
|
76 | 76 | $propName = $param['property']; |
77 | 77 | $paramName = $param['parameter']; |
78 | 78 |
@@ -27,21 +27,21 @@ |
||
27 | 27 | |
28 | 28 | class CompFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $att = $reader->parseAttributes(); |
|
37 | - $componentName = $att['name']; |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $att = $reader->parseAttributes(); |
|
37 | + $componentName = $att['name']; |
|
38 | 38 | |
39 | - $reader->parseInnerTree(); |
|
39 | + $reader->parseInnerTree(); |
|
40 | 40 | |
41 | - if (!is_string($componentName)) { |
|
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
43 | - } |
|
41 | + if (!is_string($componentName)) { |
|
42 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
43 | + } |
|
44 | 44 | |
45 | - return $componentName; |
|
46 | - } |
|
45 | + return $componentName; |
|
46 | + } |
|
47 | 47 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | $reader->parseInnerTree(); |
40 | 40 | |
41 | 41 | if (!is_string($componentName)) { |
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
42 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}comp-filter requires a valid name attribute'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | return $componentName; |
@@ -27,17 +27,17 @@ |
||
27 | 27 | |
28 | 28 | class LimitFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return int |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $value = $reader->parseInnerTree(); |
|
37 | - if (!is_int($value) && !is_string($value)) { |
|
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}limit has illegal value'); |
|
39 | - } |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return int |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $value = $reader->parseInnerTree(); |
|
37 | + if (!is_int($value) && !is_string($value)) { |
|
38 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}limit has illegal value'); |
|
39 | + } |
|
40 | 40 | |
41 | - return intval($value); |
|
42 | - } |
|
41 | + return intval($value); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -35,7 +35,7 @@ |
||
35 | 35 | static function xmlDeserialize(Reader $reader) { |
36 | 36 | $value = $reader->parseInnerTree(); |
37 | 37 | if (!is_int($value) && !is_string($value)) { |
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}limit has illegal value'); |
|
38 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}limit has illegal value'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return intval($value); |
@@ -27,17 +27,17 @@ |
||
27 | 27 | |
28 | 28 | class SearchTermFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $value = $reader->parseInnerTree(); |
|
37 | - if (!is_string($value)) { |
|
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
39 | - } |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $value = $reader->parseInnerTree(); |
|
37 | + if (!is_string($value)) { |
|
38 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
39 | + } |
|
40 | 40 | |
41 | - return $value; |
|
42 | - } |
|
41 | + return $value; |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -35,7 +35,7 @@ |
||
35 | 35 | static function xmlDeserialize(Reader $reader) { |
36 | 36 | $value = $reader->parseInnerTree(); |
37 | 37 | if (!is_string($value)) { |
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
38 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}search-term has illegal value'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return $value; |
@@ -27,17 +27,17 @@ |
||
27 | 27 | |
28 | 28 | class OffsetFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return int |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $value = $reader->parseInnerTree(); |
|
37 | - if (!is_int($value) && !is_string($value)) { |
|
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}offset has illegal value'); |
|
39 | - } |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return int |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $value = $reader->parseInnerTree(); |
|
37 | + if (!is_int($value) && !is_string($value)) { |
|
38 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}offset has illegal value'); |
|
39 | + } |
|
40 | 40 | |
41 | - return intval($value); |
|
42 | - } |
|
41 | + return intval($value); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -35,7 +35,7 @@ |
||
35 | 35 | static function xmlDeserialize(Reader $reader) { |
36 | 36 | $value = $reader->parseInnerTree(); |
37 | 37 | if (!is_int($value) && !is_string($value)) { |
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}offset has illegal value'); |
|
38 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}offset has illegal value'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return intval($value); |
@@ -27,21 +27,21 @@ |
||
27 | 27 | |
28 | 28 | class PropFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $att = $reader->parseAttributes(); |
|
37 | - $componentName = $att['name']; |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $att = $reader->parseAttributes(); |
|
37 | + $componentName = $att['name']; |
|
38 | 38 | |
39 | - $reader->parseInnerTree(); |
|
39 | + $reader->parseInnerTree(); |
|
40 | 40 | |
41 | - if (!is_string($componentName)) { |
|
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
43 | - } |
|
41 | + if (!is_string($componentName)) { |
|
42 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
43 | + } |
|
44 | 44 | |
45 | - return $componentName; |
|
46 | - } |
|
45 | + return $componentName; |
|
46 | + } |
|
47 | 47 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | $reader->parseInnerTree(); |
40 | 40 | |
41 | 41 | if (!is_string($componentName)) { |
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
42 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}prop-filter requires a valid name attribute'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | return $componentName; |