Passed
Push — master ( 222d9e...5d29a9 )
by Christoph
23:13 queued 05:51
created
apps/dav/lib/CalDAV/AppCalendar/CalendarObject.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -36,118 +36,118 @@
 block discarded – undo
36 36
 use Sabre\VObject\Property\ICalendar\DateTime;
37 37
 
38 38
 class CalendarObject implements ICalendarObject, IACL {
39
-	private VCalendar $vobject;
40
-	private AppCalendar $calendar;
41
-	private ICalendar|ICreateFromString $backend;
42
-
43
-	public function __construct(AppCalendar $calendar, ICalendar $backend, VCalendar $vobject) {
44
-		$this->backend = $backend;
45
-		$this->calendar = $calendar;
46
-		$this->vobject = $vobject;
47
-	}
48
-
49
-	public function getOwner() {
50
-		return $this->calendar->getOwner();
51
-	}
52
-
53
-	public function getGroup() {
54
-		return $this->calendar->getGroup();
55
-	}
56
-
57
-	public function getACL(): array {
58
-		$acl = [
59
-			[
60
-				'privilege' => '{DAV:}read',
61
-				'principal' => $this->getOwner(),
62
-				'protected' => true,
63
-			]
64
-		];
65
-		if ($this->calendar->getPermissions() & Constants::PERMISSION_UPDATE) {
66
-			$acl[] = [
67
-				'privilege' => '{DAV:}write-content',
68
-				'principal' => $this->getOwner(),
69
-				'protected' => true,
70
-			];
71
-		}
72
-		return $acl;
73
-	}
74
-
75
-	public function setACL(array $acl): void {
76
-		throw new Forbidden('Setting ACL is not supported on this node');
77
-	}
78
-
79
-	public function getSupportedPrivilegeSet(): ?array {
80
-		return null;
81
-	}
82
-
83
-	public function put($data): void {
84
-		if ($this->backend instanceof ICreateFromString && $this->calendar->getPermissions() & Constants::PERMISSION_UPDATE) {
85
-			if (is_resource($data)) {
86
-				$data = stream_get_contents($data) ?: '';
87
-			}
88
-			$this->backend->createFromString($this->getName(), $data);
89
-		} else {
90
-			throw new Forbidden('This calendar-object is read-only');
91
-		}
92
-	}
93
-
94
-	public function get(): string {
95
-		return $this->vobject->serialize();
96
-	}
97
-
98
-	public function getContentType(): string {
99
-		return 'text/calendar; charset=utf-8';
100
-	}
101
-
102
-	public function getETag(): ?string {
103
-		return null;
104
-	}
105
-
106
-	public function getSize() {
107
-		return mb_strlen($this->vobject->serialize());
108
-	}
109
-
110
-	public function delete(): void {
111
-		if ($this->backend instanceof ICreateFromString && $this->calendar->getPermissions() & Constants::PERMISSION_DELETE) {
112
-			/** @var \Sabre\VObject\Component[] */
113
-			$components = $this->vobject->getBaseComponents();
114
-			foreach ($components as $key => $component) {
115
-				$components[$key]->STATUS = 'CANCELLED';
116
-				$components[$key]->SEQUENCE = isset($component->SEQUENCE) ? ((int)$component->SEQUENCE->getValue()) + 1 : 1;
117
-				if ($component->name === 'VEVENT') {
118
-					$components[$key]->METHOD = 'CANCEL';
119
-				}
120
-			}
121
-			$this->backend->createFromString($this->getName(), (new VCalendar($components))->serialize());
122
-		} else {
123
-			throw new Forbidden('This calendar-object is read-only');
124
-		}
125
-	}
126
-
127
-	public function getName(): string {
128
-		// Every object is required to have an UID
129
-		$base = $this->vobject->getBaseComponent();
130
-		// This should never happen except the app provides invalid calendars (VEvent, VTodo... all require UID to be present)
131
-		if ($base === null) {
132
-			throw new NotFound('Invalid node');
133
-		}
134
-		if (isset($base->{'X-FILENAME'})) {
135
-			return (string)$base->{'X-FILENAME'};
136
-		}
137
-		return (string)$base->UID . '.ics';
138
-	}
139
-
140
-	public function setName($name): void {
141
-		throw new Forbidden('This calendar-object is read-only');
142
-	}
143
-
144
-	public function getLastModified(): ?int {
145
-		$base = $this->vobject->getBaseComponent();
146
-		if ($base !== null && $this->vobject->getBaseComponent()->{'LAST-MODIFIED'}) {
147
-			/** @var DateTime */
148
-			$lastModified = $this->vobject->getBaseComponent()->{'LAST-MODIFIED'};
149
-			return $lastModified->getDateTime()->getTimestamp();
150
-		}
151
-		return null;
152
-	}
39
+    private VCalendar $vobject;
40
+    private AppCalendar $calendar;
41
+    private ICalendar|ICreateFromString $backend;
42
+
43
+    public function __construct(AppCalendar $calendar, ICalendar $backend, VCalendar $vobject) {
44
+        $this->backend = $backend;
45
+        $this->calendar = $calendar;
46
+        $this->vobject = $vobject;
47
+    }
48
+
49
+    public function getOwner() {
50
+        return $this->calendar->getOwner();
51
+    }
52
+
53
+    public function getGroup() {
54
+        return $this->calendar->getGroup();
55
+    }
56
+
57
+    public function getACL(): array {
58
+        $acl = [
59
+            [
60
+                'privilege' => '{DAV:}read',
61
+                'principal' => $this->getOwner(),
62
+                'protected' => true,
63
+            ]
64
+        ];
65
+        if ($this->calendar->getPermissions() & Constants::PERMISSION_UPDATE) {
66
+            $acl[] = [
67
+                'privilege' => '{DAV:}write-content',
68
+                'principal' => $this->getOwner(),
69
+                'protected' => true,
70
+            ];
71
+        }
72
+        return $acl;
73
+    }
74
+
75
+    public function setACL(array $acl): void {
76
+        throw new Forbidden('Setting ACL is not supported on this node');
77
+    }
78
+
79
+    public function getSupportedPrivilegeSet(): ?array {
80
+        return null;
81
+    }
82
+
83
+    public function put($data): void {
84
+        if ($this->backend instanceof ICreateFromString && $this->calendar->getPermissions() & Constants::PERMISSION_UPDATE) {
85
+            if (is_resource($data)) {
86
+                $data = stream_get_contents($data) ?: '';
87
+            }
88
+            $this->backend->createFromString($this->getName(), $data);
89
+        } else {
90
+            throw new Forbidden('This calendar-object is read-only');
91
+        }
92
+    }
93
+
94
+    public function get(): string {
95
+        return $this->vobject->serialize();
96
+    }
97
+
98
+    public function getContentType(): string {
99
+        return 'text/calendar; charset=utf-8';
100
+    }
101
+
102
+    public function getETag(): ?string {
103
+        return null;
104
+    }
105
+
106
+    public function getSize() {
107
+        return mb_strlen($this->vobject->serialize());
108
+    }
109
+
110
+    public function delete(): void {
111
+        if ($this->backend instanceof ICreateFromString && $this->calendar->getPermissions() & Constants::PERMISSION_DELETE) {
112
+            /** @var \Sabre\VObject\Component[] */
113
+            $components = $this->vobject->getBaseComponents();
114
+            foreach ($components as $key => $component) {
115
+                $components[$key]->STATUS = 'CANCELLED';
116
+                $components[$key]->SEQUENCE = isset($component->SEQUENCE) ? ((int)$component->SEQUENCE->getValue()) + 1 : 1;
117
+                if ($component->name === 'VEVENT') {
118
+                    $components[$key]->METHOD = 'CANCEL';
119
+                }
120
+            }
121
+            $this->backend->createFromString($this->getName(), (new VCalendar($components))->serialize());
122
+        } else {
123
+            throw new Forbidden('This calendar-object is read-only');
124
+        }
125
+    }
126
+
127
+    public function getName(): string {
128
+        // Every object is required to have an UID
129
+        $base = $this->vobject->getBaseComponent();
130
+        // This should never happen except the app provides invalid calendars (VEvent, VTodo... all require UID to be present)
131
+        if ($base === null) {
132
+            throw new NotFound('Invalid node');
133
+        }
134
+        if (isset($base->{'X-FILENAME'})) {
135
+            return (string)$base->{'X-FILENAME'};
136
+        }
137
+        return (string)$base->UID . '.ics';
138
+    }
139
+
140
+    public function setName($name): void {
141
+        throw new Forbidden('This calendar-object is read-only');
142
+    }
143
+
144
+    public function getLastModified(): ?int {
145
+        $base = $this->vobject->getBaseComponent();
146
+        if ($base !== null && $this->vobject->getBaseComponent()->{'LAST-MODIFIED'}) {
147
+            /** @var DateTime */
148
+            $lastModified = $this->vobject->getBaseComponent()->{'LAST-MODIFIED'};
149
+            return $lastModified->getDateTime()->getTimestamp();
150
+        }
151
+        return null;
152
+    }
153 153
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/AppCalendar/AppCalendar.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -40,169 +40,169 @@
 block discarded – undo
40 40
 use Sabre\VObject\Reader;
41 41
 
42 42
 class AppCalendar extends ExternalCalendar {
43
-	protected string $principal;
44
-	protected ICalendar $calendar;
45
-
46
-	public function __construct(string $appId, ICalendar $calendar, string $principal) {
47
-		parent::__construct($appId, $calendar->getUri());
48
-		$this->principal = $principal;
49
-		$this->calendar = $calendar;
50
-	}
51
-
52
-	/**
53
-	 * Return permissions supported by the backend calendar
54
-	 * @return int Permissions based on \OCP\Constants
55
-	 */
56
-	public function getPermissions(): int {
57
-		// Make sure to only promote write support if the backend implement the correct interface
58
-		if ($this->calendar instanceof ICreateFromString) {
59
-			return $this->calendar->getPermissions();
60
-		}
61
-		return Constants::PERMISSION_READ;
62
-	}
63
-
64
-	public function getOwner(): ?string {
65
-		return $this->principal;
66
-	}
67
-
68
-	public function getGroup(): ?string {
69
-		return null;
70
-	}
71
-
72
-	public function getACL(): array {
73
-		$acl = [
74
-			[
75
-				'privilege' => '{DAV:}read',
76
-				'principal' => $this->getOwner(),
77
-				'protected' => true,
78
-			],
79
-			[
80
-				'privilege' => '{DAV:}write-properties',
81
-				'principal' => $this->getOwner(),
82
-				'protected' => true,
83
-			]
84
-		];
85
-		if ($this->getPermissions() & Constants::PERMISSION_CREATE) {
86
-			$acl[] = [
87
-				'privilege' => '{DAV:}write',
88
-				'principal' => $this->getOwner(),
89
-				'protected' => true,
90
-			];
91
-		}
92
-		return $acl;
93
-	}
94
-
95
-	public function setACL(array $acl): void {
96
-		throw new Forbidden('Setting ACL is not supported on this node');
97
-	}
98
-
99
-	public function getSupportedPrivilegeSet(): ?array {
100
-		// Use the default one
101
-		return null;
102
-	}
103
-
104
-	public function getLastModified(): ?int {
105
-		// unknown
106
-		return null;
107
-	}
108
-
109
-	public function delete(): void {
110
-		// No method for deleting a calendar in OCP\Calendar\ICalendar
111
-		throw new Forbidden('Deleting an entry is not implemented');
112
-	}
113
-
114
-	public function createFile($name, $data = null) {
115
-		if ($this->calendar instanceof ICreateFromString) {
116
-			if (is_resource($data)) {
117
-				$data = stream_get_contents($data) ?: null;
118
-			}
119
-			$this->calendar->createFromString($name, is_null($data) ? '' : $data);
120
-			return null;
121
-		} else {
122
-			throw new Forbidden('Creating a new entry is not allowed');
123
-		}
124
-	}
125
-
126
-	public function getProperties($properties) {
127
-		return [
128
-			'{DAV:}displayname' => $this->calendar->getDisplayName() ?: $this->calendar->getKey(),
129
-			'{http://apple.com/ns/ical/}calendar-color' => $this->calendar->getDisplayColor() ?: '#0082c9',
130
-			'{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VEVENT', 'VJOURNAL', 'VTODO']),
131
-		];
132
-	}
133
-
134
-	public function calendarQuery(array $filters) {
135
-		$result = [];
136
-		$objects = $this->getChildren();
137
-
138
-		foreach ($objects as $object) {
139
-			if ($this->validateFilterForObject($object, $filters)) {
140
-				$result[] = $object->getName();
141
-			}
142
-		}
143
-
144
-		return $result;
145
-	}
146
-
147
-	protected function validateFilterForObject(ICalendarObject $object, array $filters): bool {
148
-		/** @var \Sabre\VObject\Component\VCalendar */
149
-		$vObject = Reader::read($object->get());
150
-
151
-		$validator = new CalendarQueryValidator();
152
-		$result = $validator->validate($vObject, $filters);
153
-
154
-		// Destroy circular references so PHP will GC the object.
155
-		$vObject->destroy();
156
-
157
-		return $result;
158
-	}
159
-
160
-	public function childExists($name): bool {
161
-		try {
162
-			$this->getChild($name);
163
-			return true;
164
-		} catch (NotFound $error) {
165
-			return false;
166
-		}
167
-	}
168
-
169
-	public function getChild($name) {
170
-		// Try to get calendar by filename
171
-		$children = $this->calendar->search($name, ['X-FILENAME']);
172
-		if (count($children) === 0) {
173
-			// If nothing found try to get by UID from filename
174
-			$pos = strrpos($name, '.ics');
175
-			$children = $this->calendar->search(substr($name, 0, $pos ?: null), ['UID']);
176
-		}
177
-
178
-		if (count($children) > 0) {
179
-			return new CalendarObject($this, $this->calendar, new VCalendar($children));
180
-		}
181
-
182
-		throw new NotFound('Node not found');
183
-	}
184
-
185
-	/**
186
-	 * @return ICalendarObject[]
187
-	 */
188
-	public function getChildren(): array {
189
-		$objects = $this->calendar->search('');
190
-		// We need to group by UID (actually by filename but we do not have that information)
191
-		$result = [];
192
-		foreach ($objects as $object) {
193
-			$uid = (string)$object['UID'] ?: uniqid();
194
-			if (!isset($result[$uid])) {
195
-				$result[$uid] = [];
196
-			}
197
-			$result[$uid][] = $object;
198
-		}
199
-
200
-		return array_map(function (array $children) {
201
-			return new CalendarObject($this, $this->calendar, new VCalendar($children));
202
-		}, $result);
203
-	}
204
-
205
-	public function propPatch(PropPatch $propPatch): void {
206
-		// no setDisplayColor or setDisplayName in \OCP\Calendar\ICalendar
207
-	}
43
+    protected string $principal;
44
+    protected ICalendar $calendar;
45
+
46
+    public function __construct(string $appId, ICalendar $calendar, string $principal) {
47
+        parent::__construct($appId, $calendar->getUri());
48
+        $this->principal = $principal;
49
+        $this->calendar = $calendar;
50
+    }
51
+
52
+    /**
53
+     * Return permissions supported by the backend calendar
54
+     * @return int Permissions based on \OCP\Constants
55
+     */
56
+    public function getPermissions(): int {
57
+        // Make sure to only promote write support if the backend implement the correct interface
58
+        if ($this->calendar instanceof ICreateFromString) {
59
+            return $this->calendar->getPermissions();
60
+        }
61
+        return Constants::PERMISSION_READ;
62
+    }
63
+
64
+    public function getOwner(): ?string {
65
+        return $this->principal;
66
+    }
67
+
68
+    public function getGroup(): ?string {
69
+        return null;
70
+    }
71
+
72
+    public function getACL(): array {
73
+        $acl = [
74
+            [
75
+                'privilege' => '{DAV:}read',
76
+                'principal' => $this->getOwner(),
77
+                'protected' => true,
78
+            ],
79
+            [
80
+                'privilege' => '{DAV:}write-properties',
81
+                'principal' => $this->getOwner(),
82
+                'protected' => true,
83
+            ]
84
+        ];
85
+        if ($this->getPermissions() & Constants::PERMISSION_CREATE) {
86
+            $acl[] = [
87
+                'privilege' => '{DAV:}write',
88
+                'principal' => $this->getOwner(),
89
+                'protected' => true,
90
+            ];
91
+        }
92
+        return $acl;
93
+    }
94
+
95
+    public function setACL(array $acl): void {
96
+        throw new Forbidden('Setting ACL is not supported on this node');
97
+    }
98
+
99
+    public function getSupportedPrivilegeSet(): ?array {
100
+        // Use the default one
101
+        return null;
102
+    }
103
+
104
+    public function getLastModified(): ?int {
105
+        // unknown
106
+        return null;
107
+    }
108
+
109
+    public function delete(): void {
110
+        // No method for deleting a calendar in OCP\Calendar\ICalendar
111
+        throw new Forbidden('Deleting an entry is not implemented');
112
+    }
113
+
114
+    public function createFile($name, $data = null) {
115
+        if ($this->calendar instanceof ICreateFromString) {
116
+            if (is_resource($data)) {
117
+                $data = stream_get_contents($data) ?: null;
118
+            }
119
+            $this->calendar->createFromString($name, is_null($data) ? '' : $data);
120
+            return null;
121
+        } else {
122
+            throw new Forbidden('Creating a new entry is not allowed');
123
+        }
124
+    }
125
+
126
+    public function getProperties($properties) {
127
+        return [
128
+            '{DAV:}displayname' => $this->calendar->getDisplayName() ?: $this->calendar->getKey(),
129
+            '{http://apple.com/ns/ical/}calendar-color' => $this->calendar->getDisplayColor() ?: '#0082c9',
130
+            '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VEVENT', 'VJOURNAL', 'VTODO']),
131
+        ];
132
+    }
133
+
134
+    public function calendarQuery(array $filters) {
135
+        $result = [];
136
+        $objects = $this->getChildren();
137
+
138
+        foreach ($objects as $object) {
139
+            if ($this->validateFilterForObject($object, $filters)) {
140
+                $result[] = $object->getName();
141
+            }
142
+        }
143
+
144
+        return $result;
145
+    }
146
+
147
+    protected function validateFilterForObject(ICalendarObject $object, array $filters): bool {
148
+        /** @var \Sabre\VObject\Component\VCalendar */
149
+        $vObject = Reader::read($object->get());
150
+
151
+        $validator = new CalendarQueryValidator();
152
+        $result = $validator->validate($vObject, $filters);
153
+
154
+        // Destroy circular references so PHP will GC the object.
155
+        $vObject->destroy();
156
+
157
+        return $result;
158
+    }
159
+
160
+    public function childExists($name): bool {
161
+        try {
162
+            $this->getChild($name);
163
+            return true;
164
+        } catch (NotFound $error) {
165
+            return false;
166
+        }
167
+    }
168
+
169
+    public function getChild($name) {
170
+        // Try to get calendar by filename
171
+        $children = $this->calendar->search($name, ['X-FILENAME']);
172
+        if (count($children) === 0) {
173
+            // If nothing found try to get by UID from filename
174
+            $pos = strrpos($name, '.ics');
175
+            $children = $this->calendar->search(substr($name, 0, $pos ?: null), ['UID']);
176
+        }
177
+
178
+        if (count($children) > 0) {
179
+            return new CalendarObject($this, $this->calendar, new VCalendar($children));
180
+        }
181
+
182
+        throw new NotFound('Node not found');
183
+    }
184
+
185
+    /**
186
+     * @return ICalendarObject[]
187
+     */
188
+    public function getChildren(): array {
189
+        $objects = $this->calendar->search('');
190
+        // We need to group by UID (actually by filename but we do not have that information)
191
+        $result = [];
192
+        foreach ($objects as $object) {
193
+            $uid = (string)$object['UID'] ?: uniqid();
194
+            if (!isset($result[$uid])) {
195
+                $result[$uid] = [];
196
+            }
197
+            $result[$uid][] = $object;
198
+        }
199
+
200
+        return array_map(function (array $children) {
201
+            return new CalendarObject($this, $this->calendar, new VCalendar($children));
202
+        }, $result);
203
+    }
204
+
205
+    public function propPatch(PropPatch $propPatch): void {
206
+        // no setDisplayColor or setDisplayName in \OCP\Calendar\ICalendar
207
+    }
208 208
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/AppCalendar/AppCalendarPlugin.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -32,43 +32,43 @@
 block discarded – undo
32 32
 
33 33
 /* Plugin for wrapping application generated calendars registered in nextcloud core (OCP\Calendar\ICalendarProvider) */
34 34
 class AppCalendarPlugin implements ICalendarProvider {
35
-	protected IManager $manager;
36
-	protected LoggerInterface $logger;
35
+    protected IManager $manager;
36
+    protected LoggerInterface $logger;
37 37
 
38
-	public function __construct(IManager $manager, LoggerInterface $logger) {
39
-		$this->manager = $manager;
40
-		$this->logger = $logger;
41
-	}
38
+    public function __construct(IManager $manager, LoggerInterface $logger) {
39
+        $this->manager = $manager;
40
+        $this->logger = $logger;
41
+    }
42 42
 
43
-	public function getAppID(): string {
44
-		return 'dav-wrapper';
45
-	}
43
+    public function getAppID(): string {
44
+        return 'dav-wrapper';
45
+    }
46 46
 
47
-	public function fetchAllForCalendarHome(string $principalUri): array {
48
-		return array_map(function ($calendar) use (&$principalUri) {
49
-			return new AppCalendar($this->getAppID(), $calendar, $principalUri);
50
-		}, $this->getWrappedCalendars($principalUri));
51
-	}
47
+    public function fetchAllForCalendarHome(string $principalUri): array {
48
+        return array_map(function ($calendar) use (&$principalUri) {
49
+            return new AppCalendar($this->getAppID(), $calendar, $principalUri);
50
+        }, $this->getWrappedCalendars($principalUri));
51
+    }
52 52
 
53
-	public function hasCalendarInCalendarHome(string $principalUri, string $calendarUri): bool {
54
-		return count($this->getWrappedCalendars($principalUri, [ $calendarUri ])) > 0;
55
-	}
53
+    public function hasCalendarInCalendarHome(string $principalUri, string $calendarUri): bool {
54
+        return count($this->getWrappedCalendars($principalUri, [ $calendarUri ])) > 0;
55
+    }
56 56
 
57
-	public function getCalendarInCalendarHome(string $principalUri, string $calendarUri): ?ExternalCalendar {
58
-		$calendars = $this->getWrappedCalendars($principalUri, [ $calendarUri ]);
59
-		if (count($calendars) > 0) {
60
-			return new AppCalendar($this->getAppID(), $calendars[0], $principalUri);
61
-		}
57
+    public function getCalendarInCalendarHome(string $principalUri, string $calendarUri): ?ExternalCalendar {
58
+        $calendars = $this->getWrappedCalendars($principalUri, [ $calendarUri ]);
59
+        if (count($calendars) > 0) {
60
+            return new AppCalendar($this->getAppID(), $calendars[0], $principalUri);
61
+        }
62 62
 
63
-		return null;
64
-	}
63
+        return null;
64
+    }
65 65
 
66
-	protected function getWrappedCalendars(string $principalUri, array $calendarUris = []): array {
67
-		return array_values(
68
-			array_filter($this->manager->getCalendarsForPrincipal($principalUri, $calendarUris), function ($c) {
69
-				// We must not provide a wrapper for DAV calendars
70
-				return ! ($c instanceof \OCA\DAV\CalDAV\CalendarImpl);
71
-			})
72
-		);
73
-	}
66
+    protected function getWrappedCalendars(string $principalUri, array $calendarUris = []): array {
67
+        return array_values(
68
+            array_filter($this->manager->getCalendarsForPrincipal($principalUri, $calendarUris), function ($c) {
69
+                // We must not provide a wrapper for DAV calendars
70
+                return ! ($c instanceof \OCA\DAV\CalDAV\CalendarImpl);
71
+            })
72
+        );
73
+    }
74 74
 }
Please login to merge, or discard this patch.
apps/dav/lib/AppInfo/PluginManager.php 1 patch
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -46,281 +46,281 @@
 block discarded – undo
46 46
  */
47 47
 class PluginManager {
48 48
 
49
-	/**
50
-	 * @var ServerContainer
51
-	 */
52
-	private $container;
53
-
54
-	/**
55
-	 * @var IAppManager
56
-	 */
57
-	private $appManager;
58
-
59
-	/**
60
-	 * App plugins
61
-	 *
62
-	 * @var ServerPlugin[]
63
-	 */
64
-	private $plugins = [];
65
-
66
-	/**
67
-	 * App collections
68
-	 *
69
-	 * @var Collection[]
70
-	 */
71
-	private $collections = [];
72
-
73
-	/**
74
-	 * Address book plugins
75
-	 *
76
-	 * @var IAddressBookProvider[]
77
-	 */
78
-	private $addressBookPlugins = [];
79
-
80
-	/**
81
-	 * Calendar plugins
82
-	 *
83
-	 * @var ICalendarProvider[]
84
-	 */
85
-	private $calendarPlugins = [];
86
-
87
-	/** @var bool */
88
-	private $populated = false;
89
-
90
-	/**
91
-	 * Contstruct a PluginManager
92
-	 *
93
-	 * @param ServerContainer $container server container for resolving plugin classes
94
-	 * @param IAppManager $appManager app manager to loading apps and their info
95
-	 */
96
-	public function __construct(ServerContainer $container, IAppManager $appManager) {
97
-		$this->container = $container;
98
-		$this->appManager = $appManager;
99
-	}
100
-
101
-	/**
102
-	 * Returns an array of app-registered plugins
103
-	 *
104
-	 * @return ServerPlugin[]
105
-	 */
106
-	public function getAppPlugins() {
107
-		$this->populate();
108
-		return $this->plugins;
109
-	}
110
-
111
-	/**
112
-	 * Returns an array of app-registered collections
113
-	 *
114
-	 * @return array
115
-	 */
116
-	public function getAppCollections() {
117
-		$this->populate();
118
-		return $this->collections;
119
-	}
120
-
121
-	/**
122
-	 * @return IAddressBookProvider[]
123
-	 */
124
-	public function getAddressBookPlugins(): array {
125
-		$this->populate();
126
-		return $this->addressBookPlugins;
127
-	}
128
-
129
-	/**
130
-	 * Returns an array of app-registered calendar plugins
131
-	 *
132
-	 * @return ICalendarProvider[]
133
-	 */
134
-	public function getCalendarPlugins():array {
135
-		$this->populate();
136
-		return $this->calendarPlugins;
137
-	}
138
-
139
-	/**
140
-	 * Retrieve plugin and collection list and populate attributes
141
-	 */
142
-	private function populate(): void {
143
-		if ($this->populated) {
144
-			return;
145
-		}
146
-		$this->populated = true;
147
-
148
-		$this->calendarPlugins[] = $this->container->get(AppCalendarPlugin::class);
149
-
150
-		foreach ($this->appManager->getInstalledApps() as $app) {
151
-			// load plugins and collections from info.xml
152
-			$info = $this->appManager->getAppInfo($app);
153
-			if (!isset($info['types']) || !in_array('dav', $info['types'], true)) {
154
-				continue;
155
-			}
156
-			$plugins = $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info));
157
-			foreach ($plugins as $plugin) {
158
-				$this->plugins[] = $plugin;
159
-			}
160
-
161
-			$collections = $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info));
162
-			foreach ($collections as $collection) {
163
-				$this->collections[] = $collection;
164
-			}
165
-
166
-			$addresbookPlugins = $this->loadSabreAddressBookPluginsFromInfoXml($this->extractAddressBookPluginList($info));
167
-			foreach ($addresbookPlugins as $addresbookPlugin) {
168
-				$this->addressBookPlugins[] = $addresbookPlugin;
169
-			}
170
-
171
-			$calendarPlugins = $this->loadSabreCalendarPluginsFromInfoXml($this->extractCalendarPluginList($info));
172
-			foreach ($calendarPlugins as $calendarPlugin) {
173
-				$this->calendarPlugins[] = $calendarPlugin;
174
-			}
175
-		}
176
-	}
177
-
178
-	/**
179
-	 * @param array $array
180
-	 * @return string[]
181
-	 */
182
-	private function extractPluginList(array $array): array {
183
-		if (isset($array['sabre']) && is_array($array['sabre'])) {
184
-			if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) {
185
-				if (isset($array['sabre']['plugins']['plugin'])) {
186
-					$items = $array['sabre']['plugins']['plugin'];
187
-					if (!is_array($items)) {
188
-						$items = [$items];
189
-					}
190
-					return $items;
191
-				}
192
-			}
193
-		}
194
-		return [];
195
-	}
196
-
197
-	/**
198
-	 * @param array $array
199
-	 * @return string[]
200
-	 */
201
-	private function extractCollectionList(array $array): array {
202
-		if (isset($array['sabre']) && is_array($array['sabre'])) {
203
-			if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) {
204
-				if (isset($array['sabre']['collections']['collection'])) {
205
-					$items = $array['sabre']['collections']['collection'];
206
-					if (!is_array($items)) {
207
-						$items = [$items];
208
-					}
209
-					return $items;
210
-				}
211
-			}
212
-		}
213
-		return [];
214
-	}
215
-
216
-	/**
217
-	 * @param array $array
218
-	 * @return string[]
219
-	 */
220
-	private function extractAddressBookPluginList(array $array): array {
221
-		if (!isset($array['sabre']) || !is_array($array['sabre'])) {
222
-			return [];
223
-		}
224
-		if (!isset($array['sabre']['address-book-plugins']) || !is_array($array['sabre']['address-book-plugins'])) {
225
-			return [];
226
-		}
227
-		if (!isset($array['sabre']['address-book-plugins']['plugin'])) {
228
-			return [];
229
-		}
230
-
231
-		$items = $array['sabre']['address-book-plugins']['plugin'];
232
-		if (!is_array($items)) {
233
-			$items = [$items];
234
-		}
235
-		return $items;
236
-	}
237
-
238
-	/**
239
-	 * @param array $array
240
-	 * @return string[]
241
-	 */
242
-	private function extractCalendarPluginList(array $array): array {
243
-		if (isset($array['sabre']) && is_array($array['sabre'])) {
244
-			if (isset($array['sabre']['calendar-plugins']) && is_array($array['sabre']['calendar-plugins'])) {
245
-				if (isset($array['sabre']['calendar-plugins']['plugin'])) {
246
-					$items = $array['sabre']['calendar-plugins']['plugin'];
247
-					if (!is_array($items)) {
248
-						$items = [$items];
249
-					}
250
-					return $items;
251
-				}
252
-			}
253
-		}
254
-		return [];
255
-	}
256
-
257
-	private function createClass(string $className): object {
258
-		try {
259
-			return $this->container->get($className);
260
-		} catch (QueryException $e) {
261
-			if (class_exists($className)) {
262
-				return new $className();
263
-			}
264
-		}
265
-
266
-		throw new \Exception('Could not load ' . $className, 0, $e);
267
-	}
268
-
269
-
270
-	/**
271
-	 * @param string[] $classes
272
-	 * @return ServerPlugin[]
273
-	 * @throws \Exception
274
-	 */
275
-	private function loadSabrePluginsFromInfoXml(array $classes): array {
276
-		return array_map(function (string $className): ServerPlugin {
277
-			$instance = $this->createClass($className);
278
-			if (!($instance instanceof ServerPlugin)) {
279
-				throw new \Exception('Sabre server plugin ' . $className . ' does not implement the ' . ServerPlugin::class . ' interface');
280
-			}
281
-			return $instance;
282
-		}, $classes);
283
-	}
284
-
285
-	/**
286
-	 * @param string[] $classes
287
-	 * @return Collection[]
288
-	 */
289
-	private function loadSabreCollectionsFromInfoXml(array $classes): array {
290
-		return array_map(function (string $className): Collection {
291
-			$instance = $this->createClass($className);
292
-			if (!($instance instanceof Collection)) {
293
-				throw new \Exception('Sabre collection plugin ' . $className . ' does not implement the ' . Collection::class . ' interface');
294
-			}
295
-			return $instance;
296
-		}, $classes);
297
-	}
298
-
299
-	/**
300
-	 * @param string[] $classes
301
-	 * @return IAddressBookProvider[]
302
-	 */
303
-	private function loadSabreAddressBookPluginsFromInfoXml(array $classes): array {
304
-		return array_map(function (string $className): IAddressBookProvider {
305
-			$instance = $this->createClass($className);
306
-			if (!($instance instanceof IAddressBookProvider)) {
307
-				throw new \Exception('Sabre address book plugin class ' . $className . ' does not implement the ' . IAddressBookProvider::class . ' interface');
308
-			}
309
-			return $instance;
310
-		}, $classes);
311
-	}
312
-
313
-	/**
314
-	 * @param string[] $classes
315
-	 * @return ICalendarProvider[]
316
-	 */
317
-	private function loadSabreCalendarPluginsFromInfoXml(array $classes): array {
318
-		return array_map(function (string $className): ICalendarProvider {
319
-			$instance = $this->createClass($className);
320
-			if (!($instance instanceof ICalendarProvider)) {
321
-				throw new \Exception('Sabre calendar plugin class ' . $className . ' does not implement the ' . ICalendarProvider::class . ' interface');
322
-			}
323
-			return $instance;
324
-		}, $classes);
325
-	}
49
+    /**
50
+     * @var ServerContainer
51
+     */
52
+    private $container;
53
+
54
+    /**
55
+     * @var IAppManager
56
+     */
57
+    private $appManager;
58
+
59
+    /**
60
+     * App plugins
61
+     *
62
+     * @var ServerPlugin[]
63
+     */
64
+    private $plugins = [];
65
+
66
+    /**
67
+     * App collections
68
+     *
69
+     * @var Collection[]
70
+     */
71
+    private $collections = [];
72
+
73
+    /**
74
+     * Address book plugins
75
+     *
76
+     * @var IAddressBookProvider[]
77
+     */
78
+    private $addressBookPlugins = [];
79
+
80
+    /**
81
+     * Calendar plugins
82
+     *
83
+     * @var ICalendarProvider[]
84
+     */
85
+    private $calendarPlugins = [];
86
+
87
+    /** @var bool */
88
+    private $populated = false;
89
+
90
+    /**
91
+     * Contstruct a PluginManager
92
+     *
93
+     * @param ServerContainer $container server container for resolving plugin classes
94
+     * @param IAppManager $appManager app manager to loading apps and their info
95
+     */
96
+    public function __construct(ServerContainer $container, IAppManager $appManager) {
97
+        $this->container = $container;
98
+        $this->appManager = $appManager;
99
+    }
100
+
101
+    /**
102
+     * Returns an array of app-registered plugins
103
+     *
104
+     * @return ServerPlugin[]
105
+     */
106
+    public function getAppPlugins() {
107
+        $this->populate();
108
+        return $this->plugins;
109
+    }
110
+
111
+    /**
112
+     * Returns an array of app-registered collections
113
+     *
114
+     * @return array
115
+     */
116
+    public function getAppCollections() {
117
+        $this->populate();
118
+        return $this->collections;
119
+    }
120
+
121
+    /**
122
+     * @return IAddressBookProvider[]
123
+     */
124
+    public function getAddressBookPlugins(): array {
125
+        $this->populate();
126
+        return $this->addressBookPlugins;
127
+    }
128
+
129
+    /**
130
+     * Returns an array of app-registered calendar plugins
131
+     *
132
+     * @return ICalendarProvider[]
133
+     */
134
+    public function getCalendarPlugins():array {
135
+        $this->populate();
136
+        return $this->calendarPlugins;
137
+    }
138
+
139
+    /**
140
+     * Retrieve plugin and collection list and populate attributes
141
+     */
142
+    private function populate(): void {
143
+        if ($this->populated) {
144
+            return;
145
+        }
146
+        $this->populated = true;
147
+
148
+        $this->calendarPlugins[] = $this->container->get(AppCalendarPlugin::class);
149
+
150
+        foreach ($this->appManager->getInstalledApps() as $app) {
151
+            // load plugins and collections from info.xml
152
+            $info = $this->appManager->getAppInfo($app);
153
+            if (!isset($info['types']) || !in_array('dav', $info['types'], true)) {
154
+                continue;
155
+            }
156
+            $plugins = $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info));
157
+            foreach ($plugins as $plugin) {
158
+                $this->plugins[] = $plugin;
159
+            }
160
+
161
+            $collections = $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info));
162
+            foreach ($collections as $collection) {
163
+                $this->collections[] = $collection;
164
+            }
165
+
166
+            $addresbookPlugins = $this->loadSabreAddressBookPluginsFromInfoXml($this->extractAddressBookPluginList($info));
167
+            foreach ($addresbookPlugins as $addresbookPlugin) {
168
+                $this->addressBookPlugins[] = $addresbookPlugin;
169
+            }
170
+
171
+            $calendarPlugins = $this->loadSabreCalendarPluginsFromInfoXml($this->extractCalendarPluginList($info));
172
+            foreach ($calendarPlugins as $calendarPlugin) {
173
+                $this->calendarPlugins[] = $calendarPlugin;
174
+            }
175
+        }
176
+    }
177
+
178
+    /**
179
+     * @param array $array
180
+     * @return string[]
181
+     */
182
+    private function extractPluginList(array $array): array {
183
+        if (isset($array['sabre']) && is_array($array['sabre'])) {
184
+            if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) {
185
+                if (isset($array['sabre']['plugins']['plugin'])) {
186
+                    $items = $array['sabre']['plugins']['plugin'];
187
+                    if (!is_array($items)) {
188
+                        $items = [$items];
189
+                    }
190
+                    return $items;
191
+                }
192
+            }
193
+        }
194
+        return [];
195
+    }
196
+
197
+    /**
198
+     * @param array $array
199
+     * @return string[]
200
+     */
201
+    private function extractCollectionList(array $array): array {
202
+        if (isset($array['sabre']) && is_array($array['sabre'])) {
203
+            if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) {
204
+                if (isset($array['sabre']['collections']['collection'])) {
205
+                    $items = $array['sabre']['collections']['collection'];
206
+                    if (!is_array($items)) {
207
+                        $items = [$items];
208
+                    }
209
+                    return $items;
210
+                }
211
+            }
212
+        }
213
+        return [];
214
+    }
215
+
216
+    /**
217
+     * @param array $array
218
+     * @return string[]
219
+     */
220
+    private function extractAddressBookPluginList(array $array): array {
221
+        if (!isset($array['sabre']) || !is_array($array['sabre'])) {
222
+            return [];
223
+        }
224
+        if (!isset($array['sabre']['address-book-plugins']) || !is_array($array['sabre']['address-book-plugins'])) {
225
+            return [];
226
+        }
227
+        if (!isset($array['sabre']['address-book-plugins']['plugin'])) {
228
+            return [];
229
+        }
230
+
231
+        $items = $array['sabre']['address-book-plugins']['plugin'];
232
+        if (!is_array($items)) {
233
+            $items = [$items];
234
+        }
235
+        return $items;
236
+    }
237
+
238
+    /**
239
+     * @param array $array
240
+     * @return string[]
241
+     */
242
+    private function extractCalendarPluginList(array $array): array {
243
+        if (isset($array['sabre']) && is_array($array['sabre'])) {
244
+            if (isset($array['sabre']['calendar-plugins']) && is_array($array['sabre']['calendar-plugins'])) {
245
+                if (isset($array['sabre']['calendar-plugins']['plugin'])) {
246
+                    $items = $array['sabre']['calendar-plugins']['plugin'];
247
+                    if (!is_array($items)) {
248
+                        $items = [$items];
249
+                    }
250
+                    return $items;
251
+                }
252
+            }
253
+        }
254
+        return [];
255
+    }
256
+
257
+    private function createClass(string $className): object {
258
+        try {
259
+            return $this->container->get($className);
260
+        } catch (QueryException $e) {
261
+            if (class_exists($className)) {
262
+                return new $className();
263
+            }
264
+        }
265
+
266
+        throw new \Exception('Could not load ' . $className, 0, $e);
267
+    }
268
+
269
+
270
+    /**
271
+     * @param string[] $classes
272
+     * @return ServerPlugin[]
273
+     * @throws \Exception
274
+     */
275
+    private function loadSabrePluginsFromInfoXml(array $classes): array {
276
+        return array_map(function (string $className): ServerPlugin {
277
+            $instance = $this->createClass($className);
278
+            if (!($instance instanceof ServerPlugin)) {
279
+                throw new \Exception('Sabre server plugin ' . $className . ' does not implement the ' . ServerPlugin::class . ' interface');
280
+            }
281
+            return $instance;
282
+        }, $classes);
283
+    }
284
+
285
+    /**
286
+     * @param string[] $classes
287
+     * @return Collection[]
288
+     */
289
+    private function loadSabreCollectionsFromInfoXml(array $classes): array {
290
+        return array_map(function (string $className): Collection {
291
+            $instance = $this->createClass($className);
292
+            if (!($instance instanceof Collection)) {
293
+                throw new \Exception('Sabre collection plugin ' . $className . ' does not implement the ' . Collection::class . ' interface');
294
+            }
295
+            return $instance;
296
+        }, $classes);
297
+    }
298
+
299
+    /**
300
+     * @param string[] $classes
301
+     * @return IAddressBookProvider[]
302
+     */
303
+    private function loadSabreAddressBookPluginsFromInfoXml(array $classes): array {
304
+        return array_map(function (string $className): IAddressBookProvider {
305
+            $instance = $this->createClass($className);
306
+            if (!($instance instanceof IAddressBookProvider)) {
307
+                throw new \Exception('Sabre address book plugin class ' . $className . ' does not implement the ' . IAddressBookProvider::class . ' interface');
308
+            }
309
+            return $instance;
310
+        }, $classes);
311
+    }
312
+
313
+    /**
314
+     * @param string[] $classes
315
+     * @return ICalendarProvider[]
316
+     */
317
+    private function loadSabreCalendarPluginsFromInfoXml(array $classes): array {
318
+        return array_map(function (string $className): ICalendarProvider {
319
+            $instance = $this->createClass($className);
320
+            if (!($instance instanceof ICalendarProvider)) {
321
+                throw new \Exception('Sabre calendar plugin class ' . $className . ' does not implement the ' . ICalendarProvider::class . ' interface');
322
+            }
323
+            return $instance;
324
+        }, $classes);
325
+    }
326 326
 }
Please login to merge, or discard this patch.
apps/dav/lib/AppInfo/Application.php 1 patch
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -111,211 +111,211 @@
 block discarded – undo
111 111
 use function is_null;
112 112
 
113 113
 class Application extends App implements IBootstrap {
114
-	public const APP_ID = 'dav';
115
-
116
-	public function __construct() {
117
-		parent::__construct(self::APP_ID);
118
-	}
119
-
120
-	public function register(IRegistrationContext $context): void {
121
-		$context->registerServiceAlias('CardDAVSyncService', SyncService::class);
122
-		$context->registerService(PhotoCache::class, function (ContainerInterface $c) {
123
-			return new PhotoCache(
124
-				$c->get(IAppDataFactory::class)->get('dav-photocache'),
125
-				$c->get(LoggerInterface::class)
126
-			);
127
-		});
128
-		$context->registerService(AppCalendarPlugin::class, function(ContainerInterface $c) {
129
-			return new AppCalendarPlugin(
130
-			  $c->get(ICalendarManager::class),
131
-			  $c->get(LoggerInterface::class)
132
-			);
133
-		  });
134
-
135
-		/*
114
+    public const APP_ID = 'dav';
115
+
116
+    public function __construct() {
117
+        parent::__construct(self::APP_ID);
118
+    }
119
+
120
+    public function register(IRegistrationContext $context): void {
121
+        $context->registerServiceAlias('CardDAVSyncService', SyncService::class);
122
+        $context->registerService(PhotoCache::class, function (ContainerInterface $c) {
123
+            return new PhotoCache(
124
+                $c->get(IAppDataFactory::class)->get('dav-photocache'),
125
+                $c->get(LoggerInterface::class)
126
+            );
127
+        });
128
+        $context->registerService(AppCalendarPlugin::class, function(ContainerInterface $c) {
129
+            return new AppCalendarPlugin(
130
+                $c->get(ICalendarManager::class),
131
+                $c->get(LoggerInterface::class)
132
+            );
133
+            });
134
+
135
+        /*
136 136
 		 * Register capabilities
137 137
 		 */
138
-		$context->registerCapability(Capabilities::class);
138
+        $context->registerCapability(Capabilities::class);
139 139
 
140
-		/*
140
+        /*
141 141
 		 * Register Search Providers
142 142
 		 */
143
-		$context->registerSearchProvider(ContactsSearchProvider::class);
144
-		$context->registerSearchProvider(EventsSearchProvider::class);
145
-		$context->registerSearchProvider(TasksSearchProvider::class);
146
-
147
-		/**
148
-		 * Register event listeners
149
-		 */
150
-		$context->registerEventListener(CalendarCreatedEvent::class, ActivityUpdaterListener::class);
151
-		$context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class);
152
-		$context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
153
-		$context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionDefaultUpdaterListener::class);
154
-		$context->registerEventListener(CalendarMovedToTrashEvent::class, ActivityUpdaterListener::class);
155
-		$context->registerEventListener(CalendarMovedToTrashEvent::class, CalendarObjectReminderUpdaterListener::class);
156
-		$context->registerEventListener(CalendarUpdatedEvent::class, ActivityUpdaterListener::class);
157
-		$context->registerEventListener(CalendarRestoredEvent::class, ActivityUpdaterListener::class);
158
-		$context->registerEventListener(CalendarRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
159
-		$context->registerEventListener(CalendarObjectCreatedEvent::class, ActivityUpdaterListener::class);
160
-		$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class);
161
-		$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectReminderUpdaterListener::class);
162
-		$context->registerEventListener(CalendarObjectUpdatedEvent::class, ActivityUpdaterListener::class);
163
-		$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarContactInteractionListener::class);
164
-		$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarObjectReminderUpdaterListener::class);
165
-		$context->registerEventListener(CalendarObjectDeletedEvent::class, ActivityUpdaterListener::class);
166
-		$context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
167
-		$context->registerEventListener(CalendarObjectMovedEvent::class, ActivityUpdaterListener::class);
168
-		$context->registerEventListener(CalendarObjectMovedEvent::class, CalendarObjectReminderUpdaterListener::class);
169
-		$context->registerEventListener(CalendarObjectMovedToTrashEvent::class, ActivityUpdaterListener::class);
170
-		$context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectReminderUpdaterListener::class);
171
-		$context->registerEventListener(CalendarObjectRestoredEvent::class, ActivityUpdaterListener::class);
172
-		$context->registerEventListener(CalendarObjectRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
173
-		$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class);
174
-		$context->registerEventListener(CalendarPublishedEvent::class, CalendarPublicationListener::class);
175
-		$context->registerEventListener(CalendarUnpublishedEvent::class, CalendarPublicationListener::class);
176
-		$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarShareUpdateListener::class);
177
-
178
-		$context->registerEventListener(SubscriptionCreatedEvent::class, SubscriptionListener::class);
179
-		$context->registerEventListener(SubscriptionDeletedEvent::class, SubscriptionListener::class);
180
-
181
-
182
-		$context->registerEventListener(AddressBookCreatedEvent::class, AddressbookListener::class);
183
-		$context->registerEventListener(AddressBookDeletedEvent::class, AddressbookListener::class);
184
-		$context->registerEventListener(AddressBookUpdatedEvent::class, AddressbookListener::class);
185
-		$context->registerEventListener(AddressBookShareUpdatedEvent::class, AddressbookListener::class);
186
-		$context->registerEventListener(CardCreatedEvent::class, CardListener::class);
187
-		$context->registerEventListener(CardDeletedEvent::class, CardListener::class);
188
-		$context->registerEventListener(CardUpdatedEvent::class, CardListener::class);
189
-		$context->registerEventListener(CardCreatedEvent::class, BirthdayListener::class);
190
-		$context->registerEventListener(CardDeletedEvent::class, BirthdayListener::class);
191
-		$context->registerEventListener(CardUpdatedEvent::class, BirthdayListener::class);
192
-		$context->registerEventListener(CardDeletedEvent::class, ClearPhotoCacheListener::class);
193
-		$context->registerEventListener(CardUpdatedEvent::class, ClearPhotoCacheListener::class);
194
-		$context->registerEventListener(TrustedServerRemovedEvent::class, TrustedServerRemovedListener::class);
195
-
196
-		$context->registerEventListener(BeforePreferenceDeletedEvent::class, UserPreferenceListener::class);
197
-		$context->registerEventListener(BeforePreferenceSetEvent::class, UserPreferenceListener::class);
198
-
199
-		$context->registerNotifierService(Notifier::class);
200
-
201
-		$context->registerCalendarProvider(CalendarProvider::class);
202
-
203
-		$context->registerUserMigrator(CalendarMigrator::class);
204
-		$context->registerUserMigrator(ContactsMigrator::class);
205
-	}
206
-
207
-	public function boot(IBootContext $context): void {
208
-		// Load all dav apps
209
-		\OC_App::loadApps(['dav']);
210
-
211
-		$context->injectFn([$this, 'registerHooks']);
212
-		$context->injectFn([$this, 'registerContactsManager']);
213
-		$context->injectFn([$this, 'registerCalendarManager']);
214
-		$context->injectFn([$this, 'registerCalendarReminders']);
215
-	}
216
-
217
-	public function registerHooks(HookManager $hm,
218
-								   EventDispatcherInterface $dispatcher,
219
-								   IAppContainer $container,
220
-								   IServerContainer $serverContainer) {
221
-		$hm->setup();
222
-
223
-		// first time login event setup
224
-		$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
225
-			if ($event instanceof GenericEvent) {
226
-				$hm->firstLogin($event->getSubject());
227
-			}
228
-		});
229
-
230
-		$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) {
231
-			$user = $event->getSubject();
232
-			/** @var SyncService $syncService */
233
-			$syncService = $container->query(SyncService::class);
234
-			$syncService->updateUser($user);
235
-		});
236
-
237
-
238
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) {
239
-			/** @var Backend $backend */
240
-			$backend = $container->query(Backend::class);
241
-			$backend->onCalendarUpdateShares(
242
-				$event->getArgument('calendarData'),
243
-				$event->getArgument('shares'),
244
-				$event->getArgument('add'),
245
-				$event->getArgument('remove')
246
-			);
247
-
248
-			// Here we should recalculate if reminders should be sent to new or old sharees
249
-		});
250
-
251
-		$eventHandler = function () use ($container, $serverContainer): void {
252
-			try {
253
-				/** @var UpdateCalendarResourcesRoomsBackgroundJob $job */
254
-				$job = $container->query(UpdateCalendarResourcesRoomsBackgroundJob::class);
255
-				$job->run([]);
256
-				$serverContainer->getJobList()->setLastRun($job);
257
-			} catch (Exception $ex) {
258
-				$serverContainer->get(LoggerInterface::class)->error($ex->getMessage(), ['exception' => $ex]);
259
-			}
260
-		};
261
-
262
-		$dispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler);
263
-		$dispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler);
264
-	}
265
-
266
-	public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void {
267
-		$cm->register(function () use ($container, $cm): void {
268
-			$user = \OC::$server->getUserSession()->getUser();
269
-			if (!is_null($user)) {
270
-				$this->setupContactsProvider($cm, $container, $user->getUID());
271
-			} else {
272
-				$this->setupSystemContactsProvider($cm, $container);
273
-			}
274
-		});
275
-	}
276
-
277
-	private function setupContactsProvider(IContactsManager $contactsManager,
278
-										   IAppContainer $container,
279
-										   string $userID): void {
280
-		/** @var ContactsManager $cm */
281
-		$cm = $container->query(ContactsManager::class);
282
-		$urlGenerator = $container->getServer()->getURLGenerator();
283
-		$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
284
-	}
285
-
286
-	private function setupSystemContactsProvider(IContactsManager $contactsManager,
287
-												 IAppContainer $container): void {
288
-		/** @var ContactsManager $cm */
289
-		$cm = $container->query(ContactsManager::class);
290
-		$urlGenerator = $container->getServer()->getURLGenerator();
291
-		$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
292
-	}
293
-
294
-	public function registerCalendarManager(ICalendarManager $calendarManager,
295
-											 IAppContainer $container): void {
296
-		$calendarManager->register(function () use ($container, $calendarManager) {
297
-			$user = \OC::$server->getUserSession()->getUser();
298
-			if ($user !== null) {
299
-				$this->setupCalendarProvider($calendarManager, $container, $user->getUID());
300
-			}
301
-		});
302
-	}
303
-
304
-	private function setupCalendarProvider(ICalendarManager $calendarManager,
305
-										   IAppContainer $container,
306
-										   $userId) {
307
-		$cm = $container->query(CalendarManager::class);
308
-		$cm->setupCalendarProvider($calendarManager, $userId);
309
-	}
310
-
311
-	public function registerCalendarReminders(NotificationProviderManager $manager,
312
-											   LoggerInterface $logger): void {
313
-		try {
314
-			$manager->registerProvider(AudioProvider::class);
315
-			$manager->registerProvider(EmailProvider::class);
316
-			$manager->registerProvider(PushProvider::class);
317
-		} catch (Throwable $ex) {
318
-			$logger->error($ex->getMessage(), ['exception' => $ex]);
319
-		}
320
-	}
143
+        $context->registerSearchProvider(ContactsSearchProvider::class);
144
+        $context->registerSearchProvider(EventsSearchProvider::class);
145
+        $context->registerSearchProvider(TasksSearchProvider::class);
146
+
147
+        /**
148
+         * Register event listeners
149
+         */
150
+        $context->registerEventListener(CalendarCreatedEvent::class, ActivityUpdaterListener::class);
151
+        $context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class);
152
+        $context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
153
+        $context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionDefaultUpdaterListener::class);
154
+        $context->registerEventListener(CalendarMovedToTrashEvent::class, ActivityUpdaterListener::class);
155
+        $context->registerEventListener(CalendarMovedToTrashEvent::class, CalendarObjectReminderUpdaterListener::class);
156
+        $context->registerEventListener(CalendarUpdatedEvent::class, ActivityUpdaterListener::class);
157
+        $context->registerEventListener(CalendarRestoredEvent::class, ActivityUpdaterListener::class);
158
+        $context->registerEventListener(CalendarRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
159
+        $context->registerEventListener(CalendarObjectCreatedEvent::class, ActivityUpdaterListener::class);
160
+        $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class);
161
+        $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectReminderUpdaterListener::class);
162
+        $context->registerEventListener(CalendarObjectUpdatedEvent::class, ActivityUpdaterListener::class);
163
+        $context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarContactInteractionListener::class);
164
+        $context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarObjectReminderUpdaterListener::class);
165
+        $context->registerEventListener(CalendarObjectDeletedEvent::class, ActivityUpdaterListener::class);
166
+        $context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
167
+        $context->registerEventListener(CalendarObjectMovedEvent::class, ActivityUpdaterListener::class);
168
+        $context->registerEventListener(CalendarObjectMovedEvent::class, CalendarObjectReminderUpdaterListener::class);
169
+        $context->registerEventListener(CalendarObjectMovedToTrashEvent::class, ActivityUpdaterListener::class);
170
+        $context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectReminderUpdaterListener::class);
171
+        $context->registerEventListener(CalendarObjectRestoredEvent::class, ActivityUpdaterListener::class);
172
+        $context->registerEventListener(CalendarObjectRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
173
+        $context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class);
174
+        $context->registerEventListener(CalendarPublishedEvent::class, CalendarPublicationListener::class);
175
+        $context->registerEventListener(CalendarUnpublishedEvent::class, CalendarPublicationListener::class);
176
+        $context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarShareUpdateListener::class);
177
+
178
+        $context->registerEventListener(SubscriptionCreatedEvent::class, SubscriptionListener::class);
179
+        $context->registerEventListener(SubscriptionDeletedEvent::class, SubscriptionListener::class);
180
+
181
+
182
+        $context->registerEventListener(AddressBookCreatedEvent::class, AddressbookListener::class);
183
+        $context->registerEventListener(AddressBookDeletedEvent::class, AddressbookListener::class);
184
+        $context->registerEventListener(AddressBookUpdatedEvent::class, AddressbookListener::class);
185
+        $context->registerEventListener(AddressBookShareUpdatedEvent::class, AddressbookListener::class);
186
+        $context->registerEventListener(CardCreatedEvent::class, CardListener::class);
187
+        $context->registerEventListener(CardDeletedEvent::class, CardListener::class);
188
+        $context->registerEventListener(CardUpdatedEvent::class, CardListener::class);
189
+        $context->registerEventListener(CardCreatedEvent::class, BirthdayListener::class);
190
+        $context->registerEventListener(CardDeletedEvent::class, BirthdayListener::class);
191
+        $context->registerEventListener(CardUpdatedEvent::class, BirthdayListener::class);
192
+        $context->registerEventListener(CardDeletedEvent::class, ClearPhotoCacheListener::class);
193
+        $context->registerEventListener(CardUpdatedEvent::class, ClearPhotoCacheListener::class);
194
+        $context->registerEventListener(TrustedServerRemovedEvent::class, TrustedServerRemovedListener::class);
195
+
196
+        $context->registerEventListener(BeforePreferenceDeletedEvent::class, UserPreferenceListener::class);
197
+        $context->registerEventListener(BeforePreferenceSetEvent::class, UserPreferenceListener::class);
198
+
199
+        $context->registerNotifierService(Notifier::class);
200
+
201
+        $context->registerCalendarProvider(CalendarProvider::class);
202
+
203
+        $context->registerUserMigrator(CalendarMigrator::class);
204
+        $context->registerUserMigrator(ContactsMigrator::class);
205
+    }
206
+
207
+    public function boot(IBootContext $context): void {
208
+        // Load all dav apps
209
+        \OC_App::loadApps(['dav']);
210
+
211
+        $context->injectFn([$this, 'registerHooks']);
212
+        $context->injectFn([$this, 'registerContactsManager']);
213
+        $context->injectFn([$this, 'registerCalendarManager']);
214
+        $context->injectFn([$this, 'registerCalendarReminders']);
215
+    }
216
+
217
+    public function registerHooks(HookManager $hm,
218
+                                    EventDispatcherInterface $dispatcher,
219
+                                    IAppContainer $container,
220
+                                    IServerContainer $serverContainer) {
221
+        $hm->setup();
222
+
223
+        // first time login event setup
224
+        $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
225
+            if ($event instanceof GenericEvent) {
226
+                $hm->firstLogin($event->getSubject());
227
+            }
228
+        });
229
+
230
+        $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) {
231
+            $user = $event->getSubject();
232
+            /** @var SyncService $syncService */
233
+            $syncService = $container->query(SyncService::class);
234
+            $syncService->updateUser($user);
235
+        });
236
+
237
+
238
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) {
239
+            /** @var Backend $backend */
240
+            $backend = $container->query(Backend::class);
241
+            $backend->onCalendarUpdateShares(
242
+                $event->getArgument('calendarData'),
243
+                $event->getArgument('shares'),
244
+                $event->getArgument('add'),
245
+                $event->getArgument('remove')
246
+            );
247
+
248
+            // Here we should recalculate if reminders should be sent to new or old sharees
249
+        });
250
+
251
+        $eventHandler = function () use ($container, $serverContainer): void {
252
+            try {
253
+                /** @var UpdateCalendarResourcesRoomsBackgroundJob $job */
254
+                $job = $container->query(UpdateCalendarResourcesRoomsBackgroundJob::class);
255
+                $job->run([]);
256
+                $serverContainer->getJobList()->setLastRun($job);
257
+            } catch (Exception $ex) {
258
+                $serverContainer->get(LoggerInterface::class)->error($ex->getMessage(), ['exception' => $ex]);
259
+            }
260
+        };
261
+
262
+        $dispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler);
263
+        $dispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler);
264
+    }
265
+
266
+    public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void {
267
+        $cm->register(function () use ($container, $cm): void {
268
+            $user = \OC::$server->getUserSession()->getUser();
269
+            if (!is_null($user)) {
270
+                $this->setupContactsProvider($cm, $container, $user->getUID());
271
+            } else {
272
+                $this->setupSystemContactsProvider($cm, $container);
273
+            }
274
+        });
275
+    }
276
+
277
+    private function setupContactsProvider(IContactsManager $contactsManager,
278
+                                            IAppContainer $container,
279
+                                            string $userID): void {
280
+        /** @var ContactsManager $cm */
281
+        $cm = $container->query(ContactsManager::class);
282
+        $urlGenerator = $container->getServer()->getURLGenerator();
283
+        $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
284
+    }
285
+
286
+    private function setupSystemContactsProvider(IContactsManager $contactsManager,
287
+                                                    IAppContainer $container): void {
288
+        /** @var ContactsManager $cm */
289
+        $cm = $container->query(ContactsManager::class);
290
+        $urlGenerator = $container->getServer()->getURLGenerator();
291
+        $cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
292
+    }
293
+
294
+    public function registerCalendarManager(ICalendarManager $calendarManager,
295
+                                                IAppContainer $container): void {
296
+        $calendarManager->register(function () use ($container, $calendarManager) {
297
+            $user = \OC::$server->getUserSession()->getUser();
298
+            if ($user !== null) {
299
+                $this->setupCalendarProvider($calendarManager, $container, $user->getUID());
300
+            }
301
+        });
302
+    }
303
+
304
+    private function setupCalendarProvider(ICalendarManager $calendarManager,
305
+                                            IAppContainer $container,
306
+                                            $userId) {
307
+        $cm = $container->query(CalendarManager::class);
308
+        $cm->setupCalendarProvider($calendarManager, $userId);
309
+    }
310
+
311
+    public function registerCalendarReminders(NotificationProviderManager $manager,
312
+                                                LoggerInterface $logger): void {
313
+        try {
314
+            $manager->registerProvider(AudioProvider::class);
315
+            $manager->registerProvider(EmailProvider::class);
316
+            $manager->registerProvider(PushProvider::class);
317
+        } catch (Throwable $ex) {
318
+            $logger->error($ex->getMessage(), ['exception' => $ex]);
319
+        }
320
+    }
321 321
 }
Please login to merge, or discard this patch.