Completed
Pull Request — master (#9609)
by Georg
16:43 queued 01:44
created
apps/dav/lib/CalDAV/Schedule/Plugin.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -38,131 +38,131 @@
 block discarded – undo
38 38
 
39 39
 class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
40 40
 
41
-	/**
42
-	 * Initializes the plugin
43
-	 *
44
-	 * @param Server $server
45
-	 * @return void
46
-	 */
47
-	function initialize(Server $server) {
48
-		parent::initialize($server);
49
-		$server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
50
-	}
51
-
52
-	/**
53
-	 * Returns a list of addresses that are associated with a principal.
54
-	 *
55
-	 * @param string $principal
56
-	 * @return array
57
-	 */
58
-	protected function getAddressesForPrincipal($principal) {
59
-		$result = parent::getAddressesForPrincipal($principal);
60
-
61
-		if ($result === null) {
62
-			$result = [];
63
-		}
64
-
65
-		return $result;
66
-	}
67
-
68
-	/**
69
-	 * Always use the personal calendar as target for scheduled events
70
-	 *
71
-	 * @param PropFind $propFind
72
-	 * @param INode $node
73
-	 * @return void
74
-	 */
75
-	function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
76
-		if ($node instanceof IPrincipal) {
77
-			$propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
78
-				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
79
-				$caldavPlugin = $this->server->getPlugin('caldav');
80
-				$principalUrl = $node->getPrincipalUrl();
81
-
82
-				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
83
-
84
-				if (!$calendarHomePath) {
85
-					return null;
86
-				}
87
-
88
-				/** @var CalendarHome $calendarHome */
89
-				$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
90
-				if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
91
-					$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
92
-						'{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
93
-					]);
94
-				}
95
-
96
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
97
-				if (empty($result)) {
98
-					return null;
99
-				}
100
-
101
-				return new LocalHref($result[0]['href']);
102
-			});
103
-		}
104
-	}
105
-
106
-	/**
107
-	 * This method is triggered whenever there was a calendar object gets
108
-	 * created or updated.
109
-	 *
110
-	 * Basically just a copy of parent::calendarObjectChange, with the change
111
-	 * from:
112
-	 * $addresses = $this->getAddressesForPrincipal($calendarNode->getOwner());
113
-	 * to:
114
-	 * $addresses = $this->getAddressesForPrincipal($calendarNode->getPrincipalURI());
115
-	 *
116
-	 * @param RequestInterface $request HTTP request
117
-	 * @param ResponseInterface $response HTTP Response
118
-	 * @param VCalendar $vCal Parsed iCalendar object
119
-	 * @param mixed $calendarPath Path to calendar collection
120
-	 * @param mixed $modified The iCalendar object has been touched.
121
-	 * @param mixed $isNew Whether this was a new item or we're updating one
122
-	 * @return void
123
-	 */
124
-	function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
125
-
126
-		if (!$this->scheduleReply($this->server->httpRequest)) {
127
-			return;
128
-		}
129
-
130
-		$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
131
-
132
-		$addresses = $this->getAddressesForPrincipal(
133
-			$calendarNode->getPrincipalURI()
134
-		);
135
-
136
-		if (!$isNew) {
137
-			$node = $this->server->tree->getNodeForPath($request->getPath());
138
-			$oldObj = Reader::read($node->get());
139
-		} else {
140
-			$oldObj = null;
141
-		}
142
-
143
-		$this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
144
-
145
-		if ($oldObj) {
146
-			// Destroy circular references so PHP will GC the object.
147
-			$oldObj->destroy();
148
-		}
149
-
150
-	}
151
-
152
-	/**
153
-	 * This method checks the 'Schedule-Reply' header
154
-	 * and returns false if it's 'F', otherwise true.
155
-	 *
156
-	 * Copied from Sabre/DAV's Schedule plugin, because it's
157
-	 * private for whatever reason
158
-	 *
159
-	 * @param RequestInterface $request
160
-	 * @return bool
161
-	 */
162
-	private function scheduleReply(RequestInterface $request) {
163
-
164
-		$scheduleReply = $request->getHeader('Schedule-Reply');
165
-		return $scheduleReply !== 'F';
166
-
167
-	}
41
+    /**
42
+     * Initializes the plugin
43
+     *
44
+     * @param Server $server
45
+     * @return void
46
+     */
47
+    function initialize(Server $server) {
48
+        parent::initialize($server);
49
+        $server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
50
+    }
51
+
52
+    /**
53
+     * Returns a list of addresses that are associated with a principal.
54
+     *
55
+     * @param string $principal
56
+     * @return array
57
+     */
58
+    protected function getAddressesForPrincipal($principal) {
59
+        $result = parent::getAddressesForPrincipal($principal);
60
+
61
+        if ($result === null) {
62
+            $result = [];
63
+        }
64
+
65
+        return $result;
66
+    }
67
+
68
+    /**
69
+     * Always use the personal calendar as target for scheduled events
70
+     *
71
+     * @param PropFind $propFind
72
+     * @param INode $node
73
+     * @return void
74
+     */
75
+    function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
76
+        if ($node instanceof IPrincipal) {
77
+            $propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
78
+                /** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
79
+                $caldavPlugin = $this->server->getPlugin('caldav');
80
+                $principalUrl = $node->getPrincipalUrl();
81
+
82
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
83
+
84
+                if (!$calendarHomePath) {
85
+                    return null;
86
+                }
87
+
88
+                /** @var CalendarHome $calendarHome */
89
+                $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
90
+                if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
91
+                    $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
92
+                        '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
93
+                    ]);
94
+                }
95
+
96
+                $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
97
+                if (empty($result)) {
98
+                    return null;
99
+                }
100
+
101
+                return new LocalHref($result[0]['href']);
102
+            });
103
+        }
104
+    }
105
+
106
+    /**
107
+     * This method is triggered whenever there was a calendar object gets
108
+     * created or updated.
109
+     *
110
+     * Basically just a copy of parent::calendarObjectChange, with the change
111
+     * from:
112
+     * $addresses = $this->getAddressesForPrincipal($calendarNode->getOwner());
113
+     * to:
114
+     * $addresses = $this->getAddressesForPrincipal($calendarNode->getPrincipalURI());
115
+     *
116
+     * @param RequestInterface $request HTTP request
117
+     * @param ResponseInterface $response HTTP Response
118
+     * @param VCalendar $vCal Parsed iCalendar object
119
+     * @param mixed $calendarPath Path to calendar collection
120
+     * @param mixed $modified The iCalendar object has been touched.
121
+     * @param mixed $isNew Whether this was a new item or we're updating one
122
+     * @return void
123
+     */
124
+    function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
125
+
126
+        if (!$this->scheduleReply($this->server->httpRequest)) {
127
+            return;
128
+        }
129
+
130
+        $calendarNode = $this->server->tree->getNodeForPath($calendarPath);
131
+
132
+        $addresses = $this->getAddressesForPrincipal(
133
+            $calendarNode->getPrincipalURI()
134
+        );
135
+
136
+        if (!$isNew) {
137
+            $node = $this->server->tree->getNodeForPath($request->getPath());
138
+            $oldObj = Reader::read($node->get());
139
+        } else {
140
+            $oldObj = null;
141
+        }
142
+
143
+        $this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
144
+
145
+        if ($oldObj) {
146
+            // Destroy circular references so PHP will GC the object.
147
+            $oldObj->destroy();
148
+        }
149
+
150
+    }
151
+
152
+    /**
153
+     * This method checks the 'Schedule-Reply' header
154
+     * and returns false if it's 'F', otherwise true.
155
+     *
156
+     * Copied from Sabre/DAV's Schedule plugin, because it's
157
+     * private for whatever reason
158
+     *
159
+     * @param RequestInterface $request
160
+     * @return bool
161
+     */
162
+    private function scheduleReply(RequestInterface $request) {
163
+
164
+        $scheduleReply = $request->getHeader('Schedule-Reply');
165
+        return $scheduleReply !== 'F';
166
+
167
+    }
168 168
 }
Please login to merge, or discard this patch.