Passed
Push — master ( b57115...23df94 )
by Blizzz
16:17 queued 12s
created
apps/dav/lib/CalDAV/CalendarImpl.php 1 patch
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -46,193 +46,193 @@
 block discarded – undo
46 46
 
47 47
 class CalendarImpl implements ICreateFromString {
48 48
 
49
-	private CalDavBackend $backend;
50
-	private Calendar $calendar;
51
-	/** @var array<string, mixed> */
52
-	private array $calendarInfo;
53
-
54
-	public function __construct(Calendar $calendar,
55
-								array $calendarInfo,
56
-								CalDavBackend $backend) {
57
-		$this->calendar = $calendar;
58
-		$this->calendarInfo = $calendarInfo;
59
-		$this->backend = $backend;
60
-	}
61
-
62
-	/**
63
-	 * @return string defining the technical unique key
64
-	 * @since 13.0.0
65
-	 */
66
-	public function getKey(): string {
67
-		return (string) $this->calendarInfo['id'];
68
-	}
69
-
70
-	/**
71
-	 * {@inheritDoc}
72
-	 */
73
-	public function getUri(): string {
74
-		return $this->calendarInfo['uri'];
75
-	}
76
-
77
-	/**
78
-	 * In comparison to getKey() this function returns a human readable (maybe translated) name
79
-	 * @since 13.0.0
80
-	 */
81
-	public function getDisplayName(): ?string {
82
-		return $this->calendarInfo['{DAV:}displayname'];
83
-	}
84
-
85
-	/**
86
-	 * Calendar color
87
-	 * @since 13.0.0
88
-	 */
89
-	public function getDisplayColor(): ?string {
90
-		return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color'];
91
-	}
92
-
93
-	/**
94
-	 * @param string $pattern which should match within the $searchProperties
95
-	 * @param array $searchProperties defines the properties within the query pattern should match
96
-	 * @param array $options - optional parameters:
97
-	 * 	['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
98
-	 * @param int|null $limit - limit number of search results
99
-	 * @param int|null $offset - offset for paging of search results
100
-	 * @return array an array of events/journals/todos which are arrays of key-value-pairs
101
-	 * @since 13.0.0
102
-	 */
103
-	public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array {
104
-		return $this->backend->search($this->calendarInfo, $pattern,
105
-			$searchProperties, $options, $limit, $offset);
106
-	}
107
-
108
-	/**
109
-	 * @return int build up using \OCP\Constants
110
-	 * @since 13.0.0
111
-	 */
112
-	public function getPermissions(): int {
113
-		$permissions = $this->calendar->getACL();
114
-		$result = 0;
115
-		foreach ($permissions as $permission) {
116
-			switch ($permission['privilege']) {
117
-				case '{DAV:}read':
118
-					$result |= Constants::PERMISSION_READ;
119
-					break;
120
-				case '{DAV:}write':
121
-					$result |= Constants::PERMISSION_CREATE;
122
-					$result |= Constants::PERMISSION_UPDATE;
123
-					break;
124
-				case '{DAV:}all':
125
-					$result |= Constants::PERMISSION_ALL;
126
-					break;
127
-			}
128
-		}
129
-
130
-		return $result;
131
-	}
132
-
133
-	/**
134
-	 * @since 26.0.0
135
-	 */
136
-	public function isDeleted(): bool {
137
-		return $this->calendar->isDeleted();
138
-	}
139
-
140
-	/**
141
-	 * Create a new calendar event for this calendar
142
-	 * by way of an ICS string
143
-	 *
144
-	 * @param string $name the file name - needs to contain the .ics ending
145
-	 * @param string $calendarData a string containing a valid VEVENT ics
146
-	 *
147
-	 * @throws CalendarException
148
-	 */
149
-	public function createFromString(string $name, string $calendarData): void {
150
-		$server = new InvitationResponseServer(false);
151
-
152
-		/** @var CustomPrincipalPlugin $plugin */
153
-		$plugin = $server->server->getPlugin('auth');
154
-		// we're working around the previous implementation
155
-		// that only allowed the public system principal to be used
156
-		// so set the custom principal here
157
-		$plugin->setCurrentPrincipal($this->calendar->getPrincipalURI());
158
-
159
-		if (empty($this->calendarInfo['uri'])) {
160
-			throw new CalendarException('Could not write to calendar as URI parameter is missing');
161
-		}
162
-
163
-		// Build full calendar path
164
-		[, $user] = uriSplit($this->calendar->getPrincipalURI());
165
-		$fullCalendarFilename = sprintf('calendars/%s/%s/%s', $user, $this->calendarInfo['uri'], $name);
166
-
167
-		// Force calendar change URI
168
-		/** @var Schedule\Plugin $schedulingPlugin */
169
-		$schedulingPlugin = $server->server->getPlugin('caldav-schedule');
170
-		$schedulingPlugin->setPathOfCalendarObjectChange($fullCalendarFilename);
171
-
172
-		$stream = fopen('php://memory', 'rb+');
173
-		fwrite($stream, $calendarData);
174
-		rewind($stream);
175
-		try {
176
-			$server->server->createFile($fullCalendarFilename, $stream);
177
-		} catch (Conflict $e) {
178
-			throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e);
179
-		} finally {
180
-			fclose($stream);
181
-		}
182
-	}
183
-
184
-	/**
185
-	 * @throws CalendarException
186
-	 */
187
-	public function handleIMipMessage(string $name, string $calendarData): void {
188
-		$server = new InvitationResponseServer(false);
189
-
190
-		/** @var CustomPrincipalPlugin $plugin */
191
-		$plugin = $server->server->getPlugin('auth');
192
-		// we're working around the previous implementation
193
-		// that only allowed the public system principal to be used
194
-		// so set the custom principal here
195
-		$plugin->setCurrentPrincipal($this->calendar->getPrincipalURI());
196
-
197
-		if (empty($this->calendarInfo['uri'])) {
198
-			throw new CalendarException('Could not write to calendar as URI parameter is missing');
199
-		}
200
-		// Force calendar change URI
201
-		/** @var Schedule\Plugin $schedulingPlugin */
202
-		$schedulingPlugin = $server->server->getPlugin('caldav-schedule');
203
-		// Let sabre handle the rest
204
-		$iTipMessage = new Message();
205
-		/** @var VCalendar $vObject */
206
-		$vObject = Reader::read($calendarData);
207
-		/** @var VEvent $vEvent */
208
-		$vEvent = $vObject->{'VEVENT'};
209
-
210
-		if($vObject->{'METHOD'} === null) {
211
-			throw new CalendarException('No Method provided for scheduling data. Could not process message');
212
-		}
213
-
214
-		if(!isset($vEvent->{'ORGANIZER'}) || !isset($vEvent->{'ATTENDEE'})) {
215
-			throw new CalendarException('Could not process scheduling data, neccessary data missing from ICAL');
216
-		}
217
-		$orgaizer = $vEvent->{'ORGANIZER'}->getValue();
218
-		$attendee = $vEvent->{'ATTENDEE'}->getValue();
219
-
220
-		$iTipMessage->method = $vObject->{'METHOD'}->getValue();
221
-		if($iTipMessage->method === 'REPLY') {
222
-			if ($server->isExternalAttendee($vEvent->{'ATTENDEE'}->getValue())) {
223
-				$iTipMessage->recipient = $orgaizer;
224
-			} else {
225
-				$iTipMessage->recipient = $attendee;
226
-			}
227
-			$iTipMessage->sender = $attendee;
228
-		} else if($iTipMessage->method === 'CANCEL') {
229
-			$iTipMessage->recipient = $attendee;
230
-			$iTipMessage->sender = $orgaizer;
231
-		}
232
-		$iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : '';
233
-		$iTipMessage->component = 'VEVENT';
234
-		$iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0;
235
-		$iTipMessage->message = $vObject;
236
-		$schedulingPlugin->scheduleLocalDelivery($iTipMessage);
237
-	}
49
+    private CalDavBackend $backend;
50
+    private Calendar $calendar;
51
+    /** @var array<string, mixed> */
52
+    private array $calendarInfo;
53
+
54
+    public function __construct(Calendar $calendar,
55
+                                array $calendarInfo,
56
+                                CalDavBackend $backend) {
57
+        $this->calendar = $calendar;
58
+        $this->calendarInfo = $calendarInfo;
59
+        $this->backend = $backend;
60
+    }
61
+
62
+    /**
63
+     * @return string defining the technical unique key
64
+     * @since 13.0.0
65
+     */
66
+    public function getKey(): string {
67
+        return (string) $this->calendarInfo['id'];
68
+    }
69
+
70
+    /**
71
+     * {@inheritDoc}
72
+     */
73
+    public function getUri(): string {
74
+        return $this->calendarInfo['uri'];
75
+    }
76
+
77
+    /**
78
+     * In comparison to getKey() this function returns a human readable (maybe translated) name
79
+     * @since 13.0.0
80
+     */
81
+    public function getDisplayName(): ?string {
82
+        return $this->calendarInfo['{DAV:}displayname'];
83
+    }
84
+
85
+    /**
86
+     * Calendar color
87
+     * @since 13.0.0
88
+     */
89
+    public function getDisplayColor(): ?string {
90
+        return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color'];
91
+    }
92
+
93
+    /**
94
+     * @param string $pattern which should match within the $searchProperties
95
+     * @param array $searchProperties defines the properties within the query pattern should match
96
+     * @param array $options - optional parameters:
97
+     * 	['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
98
+     * @param int|null $limit - limit number of search results
99
+     * @param int|null $offset - offset for paging of search results
100
+     * @return array an array of events/journals/todos which are arrays of key-value-pairs
101
+     * @since 13.0.0
102
+     */
103
+    public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array {
104
+        return $this->backend->search($this->calendarInfo, $pattern,
105
+            $searchProperties, $options, $limit, $offset);
106
+    }
107
+
108
+    /**
109
+     * @return int build up using \OCP\Constants
110
+     * @since 13.0.0
111
+     */
112
+    public function getPermissions(): int {
113
+        $permissions = $this->calendar->getACL();
114
+        $result = 0;
115
+        foreach ($permissions as $permission) {
116
+            switch ($permission['privilege']) {
117
+                case '{DAV:}read':
118
+                    $result |= Constants::PERMISSION_READ;
119
+                    break;
120
+                case '{DAV:}write':
121
+                    $result |= Constants::PERMISSION_CREATE;
122
+                    $result |= Constants::PERMISSION_UPDATE;
123
+                    break;
124
+                case '{DAV:}all':
125
+                    $result |= Constants::PERMISSION_ALL;
126
+                    break;
127
+            }
128
+        }
129
+
130
+        return $result;
131
+    }
132
+
133
+    /**
134
+     * @since 26.0.0
135
+     */
136
+    public function isDeleted(): bool {
137
+        return $this->calendar->isDeleted();
138
+    }
139
+
140
+    /**
141
+     * Create a new calendar event for this calendar
142
+     * by way of an ICS string
143
+     *
144
+     * @param string $name the file name - needs to contain the .ics ending
145
+     * @param string $calendarData a string containing a valid VEVENT ics
146
+     *
147
+     * @throws CalendarException
148
+     */
149
+    public function createFromString(string $name, string $calendarData): void {
150
+        $server = new InvitationResponseServer(false);
151
+
152
+        /** @var CustomPrincipalPlugin $plugin */
153
+        $plugin = $server->server->getPlugin('auth');
154
+        // we're working around the previous implementation
155
+        // that only allowed the public system principal to be used
156
+        // so set the custom principal here
157
+        $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI());
158
+
159
+        if (empty($this->calendarInfo['uri'])) {
160
+            throw new CalendarException('Could not write to calendar as URI parameter is missing');
161
+        }
162
+
163
+        // Build full calendar path
164
+        [, $user] = uriSplit($this->calendar->getPrincipalURI());
165
+        $fullCalendarFilename = sprintf('calendars/%s/%s/%s', $user, $this->calendarInfo['uri'], $name);
166
+
167
+        // Force calendar change URI
168
+        /** @var Schedule\Plugin $schedulingPlugin */
169
+        $schedulingPlugin = $server->server->getPlugin('caldav-schedule');
170
+        $schedulingPlugin->setPathOfCalendarObjectChange($fullCalendarFilename);
171
+
172
+        $stream = fopen('php://memory', 'rb+');
173
+        fwrite($stream, $calendarData);
174
+        rewind($stream);
175
+        try {
176
+            $server->server->createFile($fullCalendarFilename, $stream);
177
+        } catch (Conflict $e) {
178
+            throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e);
179
+        } finally {
180
+            fclose($stream);
181
+        }
182
+    }
183
+
184
+    /**
185
+     * @throws CalendarException
186
+     */
187
+    public function handleIMipMessage(string $name, string $calendarData): void {
188
+        $server = new InvitationResponseServer(false);
189
+
190
+        /** @var CustomPrincipalPlugin $plugin */
191
+        $plugin = $server->server->getPlugin('auth');
192
+        // we're working around the previous implementation
193
+        // that only allowed the public system principal to be used
194
+        // so set the custom principal here
195
+        $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI());
196
+
197
+        if (empty($this->calendarInfo['uri'])) {
198
+            throw new CalendarException('Could not write to calendar as URI parameter is missing');
199
+        }
200
+        // Force calendar change URI
201
+        /** @var Schedule\Plugin $schedulingPlugin */
202
+        $schedulingPlugin = $server->server->getPlugin('caldav-schedule');
203
+        // Let sabre handle the rest
204
+        $iTipMessage = new Message();
205
+        /** @var VCalendar $vObject */
206
+        $vObject = Reader::read($calendarData);
207
+        /** @var VEvent $vEvent */
208
+        $vEvent = $vObject->{'VEVENT'};
209
+
210
+        if($vObject->{'METHOD'} === null) {
211
+            throw new CalendarException('No Method provided for scheduling data. Could not process message');
212
+        }
213
+
214
+        if(!isset($vEvent->{'ORGANIZER'}) || !isset($vEvent->{'ATTENDEE'})) {
215
+            throw new CalendarException('Could not process scheduling data, neccessary data missing from ICAL');
216
+        }
217
+        $orgaizer = $vEvent->{'ORGANIZER'}->getValue();
218
+        $attendee = $vEvent->{'ATTENDEE'}->getValue();
219
+
220
+        $iTipMessage->method = $vObject->{'METHOD'}->getValue();
221
+        if($iTipMessage->method === 'REPLY') {
222
+            if ($server->isExternalAttendee($vEvent->{'ATTENDEE'}->getValue())) {
223
+                $iTipMessage->recipient = $orgaizer;
224
+            } else {
225
+                $iTipMessage->recipient = $attendee;
226
+            }
227
+            $iTipMessage->sender = $attendee;
228
+        } else if($iTipMessage->method === 'CANCEL') {
229
+            $iTipMessage->recipient = $attendee;
230
+            $iTipMessage->sender = $orgaizer;
231
+        }
232
+        $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : '';
233
+        $iTipMessage->component = 'VEVENT';
234
+        $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0;
235
+        $iTipMessage->message = $vObject;
236
+        $schedulingPlugin->scheduleLocalDelivery($iTipMessage);
237
+    }
238 238
 }
Please login to merge, or discard this patch.
lib/public/Calendar/ICalendar.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -33,52 +33,52 @@
 block discarded – undo
33 33
  */
34 34
 interface ICalendar {
35 35
 
36
-	/**
37
-	 * @return string defining the technical unique key
38
-	 * @since 13.0.0
39
-	 */
40
-	public function getKey(): string;
36
+    /**
37
+     * @return string defining the technical unique key
38
+     * @since 13.0.0
39
+     */
40
+    public function getKey(): string;
41 41
 
42
-	/**
43
-	 * @since 24.0.0
44
-	 */
45
-	public function getUri(): string;
42
+    /**
43
+     * @since 24.0.0
44
+     */
45
+    public function getUri(): string;
46 46
 
47
-	/**
48
-	 * In comparison to getKey() this function returns a human readable (maybe translated) name
49
-	 * @return null|string
50
-	 * @since 13.0.0
51
-	 */
52
-	public function getDisplayName(): ?string;
47
+    /**
48
+     * In comparison to getKey() this function returns a human readable (maybe translated) name
49
+     * @return null|string
50
+     * @since 13.0.0
51
+     */
52
+    public function getDisplayName(): ?string;
53 53
 
54
-	/**
55
-	 * Calendar color
56
-	 * @return null|string
57
-	 * @since 13.0.0
58
-	 */
59
-	public function getDisplayColor(): ?string;
54
+    /**
55
+     * Calendar color
56
+     * @return null|string
57
+     * @since 13.0.0
58
+     */
59
+    public function getDisplayColor(): ?string;
60 60
 
61
-	/**
62
-	 * @param string $pattern which should match within the $searchProperties
63
-	 * @param array $searchProperties defines the properties within the query pattern should match
64
-	 * @param array $options - optional parameters:
65
-	 * 	['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
66
-	 * @param int|null $limit - limit number of search results
67
-	 * @param int|null $offset - offset for paging of search results
68
-	 * @return array an array of events/journals/todos which are arrays of key-value-pairs
69
-	 * @since 13.0.0
70
-	 */
71
-	public function search(string $pattern, array $searchProperties = [], array $options = [], ?int $limit = null, ?int $offset = null): array;
61
+    /**
62
+     * @param string $pattern which should match within the $searchProperties
63
+     * @param array $searchProperties defines the properties within the query pattern should match
64
+     * @param array $options - optional parameters:
65
+     * 	['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
66
+     * @param int|null $limit - limit number of search results
67
+     * @param int|null $offset - offset for paging of search results
68
+     * @return array an array of events/journals/todos which are arrays of key-value-pairs
69
+     * @since 13.0.0
70
+     */
71
+    public function search(string $pattern, array $searchProperties = [], array $options = [], ?int $limit = null, ?int $offset = null): array;
72 72
 
73
-	/**
74
-	 * @return int build up using \OCP\Constants
75
-	 * @since 13.0.0
76
-	 */
77
-	public function getPermissions(): int;
73
+    /**
74
+     * @return int build up using \OCP\Constants
75
+     * @since 13.0.0
76
+     */
77
+    public function getPermissions(): int;
78 78
 
79
-	/**
80
-	 * Whether the calendar is deleted
81
-	 * @since 26.0.0
82
-	 */
83
-	public function isDeleted(): bool;
79
+    /**
80
+     * Whether the calendar is deleted
81
+     * @since 26.0.0
82
+     */
83
+    public function isDeleted(): bool;
84 84
 }
Please login to merge, or discard this patch.