aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/AppInfo
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2020-01-27 13:21:57 +0100
committerGeorg Ehrke <developer@georgehrke.com>2020-02-18 14:35:14 +0100
commitb46e5cb270b1730a6e6d4a98e52ca672eafebd39 (patch)
treea67f62762d13273c5b0037078443dc081f61744d /apps/dav/lib/AppInfo
parenta1fc233fcb30d9181415ad24a4141f0285b6899a (diff)
downloadnextcloud-server-b46e5cb270b1730a6e6d4a98e52ca672eafebd39.tar.gz
nextcloud-server-b46e5cb270b1730a6e6d4a98e52ca672eafebd39.zip
Allow apps to provide Calendars in user's calendarHome
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/lib/AppInfo')
-rw-r--r--apps/dav/lib/AppInfo/PluginManager.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/apps/dav/lib/AppInfo/PluginManager.php b/apps/dav/lib/AppInfo/PluginManager.php
index 7063a150b4d..6a44332ddb2 100644
--- a/apps/dav/lib/AppInfo/PluginManager.php
+++ b/apps/dav/lib/AppInfo/PluginManager.php
@@ -25,6 +25,7 @@
namespace OCA\DAV\AppInfo;
use OC\ServerContainer;
+use OCA\DAV\CalDAV\Integration\ICalendarProvider;
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
@@ -59,6 +60,13 @@ class PluginManager {
private $collections = null;
/**
+ * Calendar plugins
+ *
+ * @var array
+ */
+ private $calendarPlugins = null;
+
+ /**
* Contstruct a PluginManager
*
* @param ServerContainer $container server container for resolving plugin classes
@@ -94,10 +102,23 @@ class PluginManager {
}
/**
+ * Returns an array of app-registered calendar plugins
+ *
+ * @return array
+ */
+ public function getCalendarPlugins():array {
+ if (null === $this->calendarPlugins) {
+ $this->populate();
+ }
+ return $this->calendarPlugins;
+ }
+
+ /**
* Retrieve plugin and collection list and populate attributes
*/
private function populate() {
$this->plugins = [];
+ $this->calendarPlugins = [];
$this->collections = [];
foreach ($this->appManager->getInstalledApps() as $app) {
// load plugins and collections from info.xml
@@ -107,6 +128,7 @@ class PluginManager {
}
$this->loadSabrePluginsFromInfoXml($this->extractPluginList($info));
$this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info));
+ $this->loadSabreCalendarPluginsFromInfoXml($this->extractCalendarPluginList($info));
}
}
@@ -140,6 +162,21 @@ class PluginManager {
return [];
}
+ private function extractCalendarPluginList(array $array):array {
+ if (isset($array['sabre']) && is_array($array['sabre'])) {
+ if (isset($array['sabre']['calendar-plugins']) && is_array($array['sabre']['calendar-plugins'])) {
+ if (isset($array['sabre']['calendar-plugins']['plugin'])) {
+ $items = $array['sabre']['calendar-plugins']['plugin'];
+ if (!is_array($items)) {
+ $items = [$items];
+ }
+ return $items;
+ }
+ }
+ }
+ return [];
+ }
+
private function loadSabrePluginsFromInfoXml(array $plugins) {
foreach ($plugins as $plugin) {
try {
@@ -168,4 +205,24 @@ class PluginManager {
}
}
+ private function loadSabreCalendarPluginsFromInfoXml(array $calendarPlugins):void {
+ foreach ($calendarPlugins as $calendarPlugin) {
+ try {
+ $instantiatedCalendarPlugin = $this->container->query($calendarPlugin);
+ } catch (QueryException $e) {
+ if (class_exists($calendarPlugin)) {
+ $instantiatedCalendarPlugin = new $calendarPlugin();
+ } else {
+ throw new \Exception("Sabre calendar-plugin class '$calendarPlugin' is unknown and could not be loaded");
+ }
+ }
+
+ if (!($instantiatedCalendarPlugin instanceof ICalendarProvider)) {
+ throw new \Exception("Sabre calendar-plugin class '$calendarPlugin' does not implement ICalendarProvider interface");
+ }
+
+ $this->calendarPlugins[] = $instantiatedCalendarPlugin;
+ }
+ }
+
}