Completed
Pull Request — master (#9609)
by Georg
15:31
created
apps/dav/lib/CalDAV/Schedule/Plugin.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -38,125 +38,125 @@
 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
-	 * @param RequestInterface $request HTTP request
111
-	 * @param ResponseInterface $response HTTP Response
112
-	 * @param VCalendar $vCal Parsed iCalendar object
113
-	 * @param mixed $calendarPath Path to calendar collection
114
-	 * @param mixed $modified The iCalendar object has been touched.
115
-	 * @param mixed $isNew Whether this was a new item or we're updating one
116
-	 * @return void
117
-	 */
118
-	function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
119
-
120
-		if (!$this->scheduleReply($this->server->httpRequest)) {
121
-			return;
122
-		}
123
-
124
-		$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
125
-
126
-		$addresses = $this->getAddressesForPrincipal(
127
-			$calendarNode->getPrincipalURI()
128
-		);
129
-
130
-		if (!$isNew) {
131
-			$node = $this->server->tree->getNodeForPath($request->getPath());
132
-			$oldObj = Reader::read($node->get());
133
-		} else {
134
-			$oldObj = null;
135
-		}
136
-
137
-		$this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
138
-
139
-		if ($oldObj) {
140
-			// Destroy circular references so PHP will GC the object.
141
-			$oldObj->destroy();
142
-		}
143
-
144
-	}
145
-
146
-	/**
147
-	 * This method checks the 'Schedule-Reply' header
148
-	 * and returns false if it's 'F', otherwise true.
149
-	 *
150
-	 * Copied from Sabre/DAV's Schedule plugin, because it's
151
-	 * private for whatever reason
152
-	 *
153
-	 * @param RequestInterface $request
154
-	 * @return bool
155
-	 */
156
-	private function scheduleReply(RequestInterface $request) {
157
-
158
-		$scheduleReply = $request->getHeader('Schedule-Reply');
159
-		return $scheduleReply !== 'F';
160
-
161
-	}
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
+     * @param RequestInterface $request HTTP request
111
+     * @param ResponseInterface $response HTTP Response
112
+     * @param VCalendar $vCal Parsed iCalendar object
113
+     * @param mixed $calendarPath Path to calendar collection
114
+     * @param mixed $modified The iCalendar object has been touched.
115
+     * @param mixed $isNew Whether this was a new item or we're updating one
116
+     * @return void
117
+     */
118
+    function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
119
+
120
+        if (!$this->scheduleReply($this->server->httpRequest)) {
121
+            return;
122
+        }
123
+
124
+        $calendarNode = $this->server->tree->getNodeForPath($calendarPath);
125
+
126
+        $addresses = $this->getAddressesForPrincipal(
127
+            $calendarNode->getPrincipalURI()
128
+        );
129
+
130
+        if (!$isNew) {
131
+            $node = $this->server->tree->getNodeForPath($request->getPath());
132
+            $oldObj = Reader::read($node->get());
133
+        } else {
134
+            $oldObj = null;
135
+        }
136
+
137
+        $this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
138
+
139
+        if ($oldObj) {
140
+            // Destroy circular references so PHP will GC the object.
141
+            $oldObj->destroy();
142
+        }
143
+
144
+    }
145
+
146
+    /**
147
+     * This method checks the 'Schedule-Reply' header
148
+     * and returns false if it's 'F', otherwise true.
149
+     *
150
+     * Copied from Sabre/DAV's Schedule plugin, because it's
151
+     * private for whatever reason
152
+     *
153
+     * @param RequestInterface $request
154
+     * @return bool
155
+     */
156
+    private function scheduleReply(RequestInterface $request) {
157
+
158
+        $scheduleReply = $request->getHeader('Schedule-Reply');
159
+        return $scheduleReply !== 'F';
160
+
161
+    }
162 162
 }
Please login to merge, or discard this patch.