Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add example contact on first login #50156

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions apps/dav/lib/HookManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\SyncService;
use OCP\App\IAppManager;
use OCP\Defaults;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Uid\Factory\UlidFactory;
use OCP\Util;
use Psr\Log\LoggerInterface;

Expand All @@ -36,6 +38,8 @@
private CalDavBackend $calDav,
private CardDavBackend $cardDav,
private Defaults $themingDefaults,
private IAppManager $appManager,
private UlidFactory $Uidfactory
) {
}

Expand Down Expand Up @@ -128,6 +132,7 @@
* @return void
*/
public function firstLogin(?IUser $user = null) {
\OC::$server->get(LoggerInterface::class)->error("First login");
if (!is_null($user)) {
$principal = 'principals/users/' . $user->getUID();
if ($this->calDav->getCalendarsForUserCount($principal) === 0) {
Expand All @@ -150,6 +155,31 @@
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
}
}
$defaultAddressBook = $this->cardDav->getAddressBooksByUri($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI);
\OC::$server->get(LoggerInterface::class)->error("default ab",[ 'defaultAddressBook' => $defaultAddressBook]);

if($defaultAddressBook != null) {
\OC::$server->get(LoggerInterface::class)->error("I'm here");
$cardData = 'BEGIN:VCARD' . PHP_EOL .
'VERSION:3.0' . PHP_EOL .
'PRODID:-//Nextcloud Contacts v' . $this->appManager->getAppVersion('contacts') . PHP_EOL .
'UID:'. $this->Uidfactory->create() . PHP_EOL .
'ADR;TYPE=HOME:;;123 Street Street;City;State;;Country' . PHP_EOL .
'EMAIL;TYPE=WORK:[email protected]' . PHP_EOL .
'TEL;TYPE=HOME,VOICE:+999999999999' . PHP_EOL .
'TITLE:Manager' . PHP_EOL .
'ORG:Company' . PHP_EOL .
'BDAY;VALUE=DATE:20000101' . PHP_EOL .
'URL;VALUE=URI:https://example.com/' . PHP_EOL .
'REV;VALUE=DATE-AND-OR-TIME:20241227T144820Z' . PHP_EOL .
'END:VCARD';
try{
$this->cardDav->createCard($defaultAddressBook['id'], 'Jane', $cardData,false);
}
catch(Exception $e){

Check failure on line 179 in apps/dav/lib/HookManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedClass

apps/dav/lib/HookManager.php:179:11: UndefinedClass: Class, interface or enum named OCA\DAV\Exception does not exist (see https://psalm.dev/019)
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);

Check failure on line 180 in apps/dav/lib/HookManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedClass

apps/dav/lib/HookManager.php:180:55: UndefinedClass: Class, interface or enum named OCA\DAV\Exception does not exist (see https://psalm.dev/019)
}
}
}
}
}
Loading