From f6ef779f97c2abf0543184e58dd27b39aa0ea3bc Mon Sep 17 00:00:00 2001 From: Tobia De Koninck Date: Sat, 16 Sep 2017 13:42:46 +0200 Subject: [PATCH 1/3] Make ContactsStore a public API Signed-off-by: Tobia De Koninck --- apps/dav/appinfo/app.php | 2 ++ apps/dav/lib/AppInfo/Application.php | 10 +++++++ apps/dav/lib/CardDAV/ContactsManager.php | 8 ++++++ .../Contacts/ContactsMenu/ContactsStore.php | 3 ++- lib/private/Server.php | 10 +++++++ .../Contacts/ContactsMenu/IContactsStore.php | 26 +++++++++++++++++++ 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 lib/public/Contacts/ContactsMenu/IContactsStore.php diff --git a/apps/dav/appinfo/app.php b/apps/dav/appinfo/app.php index 8a534a75970cb..4f4fbe6e12624 100644 --- a/apps/dav/appinfo/app.php +++ b/apps/dav/appinfo/app.php @@ -53,6 +53,8 @@ function(GenericEvent $event) use ($app) { $user = \OC::$server->getUserSession()->getUser(); if (!is_null($user)) { $app->setupContactsProvider($cm, $user->getUID()); + } else { + $app->setupSystemContactsProvider($cm); } }); diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index b38f38044f309..a557128635492 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -75,6 +75,16 @@ public function setupContactsProvider(IContactsManager $contactsManager, $userID $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); } + /** + * @param IManager $contactsManager + */ + public function setupSystemContactsProvider(IContactsManager $contactsManager) { + /** @var ContactsManager $cm */ + $cm = $this->getContainer()->query(ContactsManager::class); + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); + $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); + } + /** * @param ICalendarManager $calendarManager * @param string $userId diff --git a/apps/dav/lib/CardDAV/ContactsManager.php b/apps/dav/lib/CardDAV/ContactsManager.php index ad02d4ba427f2..67e3ef2c72c38 100644 --- a/apps/dav/lib/CardDAV/ContactsManager.php +++ b/apps/dav/lib/CardDAV/ContactsManager.php @@ -55,6 +55,14 @@ public function __construct(CardDavBackend $backend, IL10N $l10n) { public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) { $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId"); $this->register($cm, $addressBooks, $urlGenerator); + $this->setupSystemContactsProvider($cm, $urlGenerator); + } + + /** + * @param IManager $cm + * @param IURLGenerator $urlGenerator + */ + public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) { $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system"); $this->register($cm, $addressBooks, $urlGenerator); } diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index 108ff0d49893d..43600470e1ff7 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -35,8 +35,9 @@ use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\Contacts\ContactsMenu\IContactsStore; -class ContactsStore { +class ContactsStore implements IContactsStore { /** @var IManager */ private $contactsManager; diff --git a/lib/private/Server.php b/lib/private/Server.php index 0dfbcbb75ecfd..09128f33bfbf6 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -63,6 +63,7 @@ use OC\Collaboration\Collaborators\UserPlugin; use OC\Command\CronBus; use OC\Contacts\ContactsMenu\ActionFactory; +use OC\Contacts\ContactsMenu\ContactsStore; use OC\Diagnostics\EventLogger; use OC\Diagnostics\QueryLogger; use OC\Federation\CloudIdManager; @@ -1129,6 +1130,15 @@ public function __construct($webRoot, \OC\Config $config) { return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); }); + $this->registerService(\OCP\Contacts\ContactsMenu\IContactsStore::class, function(Server $c) { + return new ContactsStore( + $c->getContactsManager(), + $c->getConfig(), + $c->getUserManager(), + $c->getGroupManager() + ); + }); + $this->connectDispatcher(); } diff --git a/lib/public/Contacts/ContactsMenu/IContactsStore.php b/lib/public/Contacts/ContactsMenu/IContactsStore.php new file mode 100644 index 0000000000000..415c450072d01 --- /dev/null +++ b/lib/public/Contacts/ContactsMenu/IContactsStore.php @@ -0,0 +1,26 @@ + Date: Sun, 1 Oct 2017 09:15:30 +0200 Subject: [PATCH 2/3] Add @since annotation and add missing new line Signed-off-by: Tobia De Koninck --- lib/public/Contacts/ContactsMenu/IContactsStore.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/public/Contacts/ContactsMenu/IContactsStore.php b/lib/public/Contacts/ContactsMenu/IContactsStore.php index 415c450072d01..78b2b29c574a4 100644 --- a/lib/public/Contacts/ContactsMenu/IContactsStore.php +++ b/lib/public/Contacts/ContactsMenu/IContactsStore.php @@ -4,6 +4,9 @@ use OCP\IUser; +/** + * @since 13.0.0 + */ interface IContactsStore { @@ -11,6 +14,7 @@ interface IContactsStore { * @param IUser $user * @param $filter * @return IEntry[] + * @since 13.0.0 */ public function getContacts(IUser $user, $filter); @@ -20,7 +24,8 @@ public function getContacts(IUser $user, $filter); * @param integer $shareType * @param string $shareWith * @return IEntry|null + * @since 13.0.0 */ public function findOne(IUser $user, $shareType, $shareWith); -} \ No newline at end of file +} From cecfc28ebd63b80904b57b23b0e0c30b02960330 Mon Sep 17 00:00:00 2001 From: Tobia De Koninck Date: Sun, 10 Dec 2017 11:58:33 +0100 Subject: [PATCH 3/3] Register ContactsStore using alias + run autoloaderchecker.sh Signed-off-by: Tobia De Koninck --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Server.php | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index b3fb04ff6d96b..c91e4989d718c 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -93,6 +93,7 @@ 'OCP\\Contacts' => $baseDir . '/lib/public/Contacts.php', 'OCP\\Contacts\\ContactsMenu\\IAction' => $baseDir . '/lib/public/Contacts/ContactsMenu/IAction.php', 'OCP\\Contacts\\ContactsMenu\\IActionFactory' => $baseDir . '/lib/public/Contacts/ContactsMenu/IActionFactory.php', + 'OCP\\Contacts\\ContactsMenu\\IContactsStore' => $baseDir . '/lib/public/Contacts/ContactsMenu/IContactsStore.php', 'OCP\\Contacts\\ContactsMenu\\IEntry' => $baseDir . '/lib/public/Contacts/ContactsMenu/IEntry.php', 'OCP\\Contacts\\ContactsMenu\\ILinkAction' => $baseDir . '/lib/public/Contacts/ContactsMenu/ILinkAction.php', 'OCP\\Contacts\\ContactsMenu\\IProvider' => $baseDir . '/lib/public/Contacts/ContactsMenu/IProvider.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index a905134ce9fee..3a7d7674fa07b 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -123,6 +123,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Contacts' => __DIR__ . '/../../..' . '/lib/public/Contacts.php', 'OCP\\Contacts\\ContactsMenu\\IAction' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IAction.php', 'OCP\\Contacts\\ContactsMenu\\IActionFactory' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IActionFactory.php', + 'OCP\\Contacts\\ContactsMenu\\IContactsStore' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IContactsStore.php', 'OCP\\Contacts\\ContactsMenu\\IEntry' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IEntry.php', 'OCP\\Contacts\\ContactsMenu\\ILinkAction' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/ILinkAction.php', 'OCP\\Contacts\\ContactsMenu\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IProvider.php', diff --git a/lib/private/Server.php b/lib/private/Server.php index 09128f33bfbf6..8a5fb0fa96cfd 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -115,6 +115,7 @@ use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Collaboration\AutoComplete\IManager; +use OCP\Contacts\ContactsMenu\IContactsStore; use OCP\Defaults; use OCA\Theming\Util; use OCP\Federation\ICloudIdManager; @@ -1130,7 +1131,7 @@ public function __construct($webRoot, \OC\Config $config) { return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); }); - $this->registerService(\OCP\Contacts\ContactsMenu\IContactsStore::class, function(Server $c) { + $this->registerService(IContactsStore::class, function(Server $c) { return new ContactsStore( $c->getContactsManager(), $c->getConfig(), @@ -1138,6 +1139,7 @@ public function __construct($webRoot, \OC\Config $config) { $c->getGroupManager() ); }); + $this->registerAlias(IContactsStore::class, ContactsStore::class); $this->connectDispatcher(); }