Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit f6f4162b authored by Akhil's avatar Akhil
Browse files

Add exception handling

parent 3b57d6b3
Loading
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use OCA\EcloudAccounts\Db\WebmailMapper;
use OCP\IUserManager;
use OCP\IUser;

class MigrateWebmailAddressbooks extends Command {
	private OutputInterface $commandOutput;
@@ -78,10 +79,20 @@ class MigrateWebmailAddressbooks extends Command {
			$emails = [];
			foreach ($usernames as $username) {
				$user = $this->userManager->get($username);
				if (!$user instanceof IUser) {
					$this->commandOutput->writeln('User ' . $username . ' does not exist!');
					continue;
				}

				$email = $user->getEMailAddress();
				$emails[] = $email;
			}

			
			$users = $this->webmailMapper->getUsers($limit, $offset, $emails);
			if (empty($users)) {
				return;
			}
			$this->webmailMapper->migrateContacts($users);
			return;
		}
+29 −15
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ use OCP\IUserManager;
use OCP\IUser;
use OCA\DAV\CardDAV\CardDavBackend;
use OCP\DB\QueryBuilder\IQueryBuilder;
use Throwable;

class WebmailMapper {
	private IConfig $config;
@@ -107,16 +108,26 @@ class WebmailMapper {

		$principalUri = 'principals/users/'. $username;
		$addressbookUri = 'webmail'; // some unique identifier
		try {
			$alreadyImported = $this->cardDavBackend->getAddressBooksByUri($principalUri, $addressbookUri);

			if ($alreadyImported) {
				return;
			}

		$addressBookId = $this->cardDavBackend->createAddressBook($principalUri, $addressbookUri, ['{DAV:}displayname' => 'Webmail',
			'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'Contacts imported from snappymail']);

			$addressBookId = $this->cardDavBackend->createAddressBook(
				$principalUri, 
				$addressbookUri, 
				[
					'{DAV:}displayname' => 'Webmail',
					'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'Contacts imported from snappymail'
				]
			);
		} catch (Throwable $e) {
			$this->logger->error('Error creating address book for user: ' . $username . ' ' . $e->getMessage());
		}
		foreach ($contacts as $contact) {
			try {
				$contact->PRODID = '-//IDN murena.io//Migrated contact//EN';

				$this->cardDavBackend->createCard(
@@ -125,6 +136,9 @@ class WebmailMapper {
					$contact->serialize(),
					true
				);
			} catch (Throwable $e) {
				$this->logger->error('Error inserting contact for user: ' . $username . ' contact: ' . $contact->serialize() . ' ' . $e->getMessage());
			}
		}
	}

+1 −1

File changed.

Contains only whitespace changes.

+6 −6

File changed.

Contains only whitespace changes.