summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-02-16 08:29:54 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-02-16 08:29:54 +0100
commit9942263409dfb7e542bd468b9f8ab895b6b35a38 (patch)
treedc281e17f2a4fabdcaff9165e6ca6e90a9b96d7e
parente5641247a3c4b4ea83f0a77fedef28ae5e7ab78e (diff)
parent722809c2bd9810365497c48dfb40dd40c512868e (diff)
downloadnextcloud-server-9942263409dfb7e542bd468b9f8ab895b6b35a38.tar.gz
nextcloud-server-9942263409dfb7e542bd468b9f8ab895b6b35a38.zip
Merge pull request #22392 from owncloud/create-default-calendar-and-addressbook
On login we create a default calendar and a default addressbook for t…
-rw-r--r--apps/dav/appinfo/application.php4
-rw-r--r--apps/dav/lib/hookmanager.php42
2 files changed, 44 insertions, 2 deletions
diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php
index 11ab384d75d..28b9a833456 100644
--- a/apps/dav/appinfo/application.php
+++ b/apps/dav/appinfo/application.php
@@ -57,7 +57,9 @@ class Application extends App {
/** @var IAppContainer $c */
return new HookManager(
$c->getServer()->getUserManager(),
- $c->query('SyncService')
+ $c->query('SyncService'),
+ $c->query('CalDavBackend'),
+ $c->query('CardDavBackend')
);
});
diff --git a/apps/dav/lib/hookmanager.php b/apps/dav/lib/hookmanager.php
index d2199bec598..c3d68a3ee2a 100644
--- a/apps/dav/lib/hookmanager.php
+++ b/apps/dav/lib/hookmanager.php
@@ -20,6 +20,8 @@
*/
namespace OCA\DAV;
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\SyncService;
use OCP\IUser;
use OCP\IUserManager;
@@ -36,9 +38,20 @@ class HookManager {
/** @var IUser[] */
private $usersToDelete;
- public function __construct(IUserManager $userManager, SyncService $syncService) {
+ /** @var CalDavBackend */
+ private $calDav;
+
+ /** @var CardDavBackend */
+ private $cardDav;
+
+ public function __construct(IUserManager $userManager,
+ SyncService $syncService,
+ CalDavBackend $calDav,
+ CardDavBackend $cardDav) {
$this->userManager = $userManager;
$this->syncService = $syncService;
+ $this->calDav = $calDav;
+ $this->cardDav = $cardDav;
}
public function setup() {
@@ -58,6 +71,10 @@ class HookManager {
'changeUser',
$this,
'changeUser');
+ Util::connectHook('OC_User',
+ 'post_login',
+ $this,
+ 'postLogin');
}
public function postCreateUser($params) {
@@ -80,4 +97,27 @@ class HookManager {
$user = $params['user'];
$this->syncService->updateUser($user);
}
+
+ public function postLogin($params) {
+ $user = $this->userManager->get($params['uid']);
+
+ $principal = 'principals/users/' . $user->getUID();
+ $calendars = $this->calDav->getCalendarsForUser($principal);
+ if (empty($calendars)) {
+ try {
+ $this->calDav->createCalendar($principal, 'default', []);
+ } catch (\Exception $ex) {
+ \OC::$server->getLogger()->logException($ex);
+ }
+ }
+ $books = $this->cardDav->getAddressBooksForUser($principal);
+ if (empty($books)) {
+ try {
+ $this->cardDav->createAddressBook($principal, 'default', []);
+ } catch (\Exception $ex) {
+ \OC::$server->getLogger()->logException($ex);
+ }
+ }
+
+ }
}