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

Commit 750ce93d authored by Akhil's avatar Akhil 🙂
Browse files

Merge branch 'dev/webmail-migrate-logs' into 'main'

Add more logging to the migrate command

See merge request !74
parents 573939c1 2809e8b0
Loading
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -30,21 +30,21 @@ class MigrateWebmailAddressbooks extends Command {
			->addOption(
				'users',
				null,
				InputOption::VALUE_OPTIONAL,
				InputOption::VALUE_REQUIRED,
				'comma separated list of users',
				''
			)
			->addOption(
				'limit',
				null,
				InputOption::VALUE_OPTIONAL,
				InputOption::VALUE_REQUIRED,
				'Limit of users to migrate',
				null
				0
			)
			->addOption(
				'offset',
				null,
				InputOption::VALUE_OPTIONAL,
				InputOption::VALUE_REQUIRED,
				'Offset',
				0
			);
@@ -88,12 +88,16 @@ class MigrateWebmailAddressbooks extends Command {
				$emails[] = $email;
			}

			
			if ($limit === 0) {
				$this->commandOutput->writeln('Migrating all users starting at ' . $offset);
			} else {
				$this->commandOutput->writeln('Migrating ' . $limit . ' users starting at ' . $offset);
			}
			$users = $this->webmailMapper->getUsers($limit, $offset, $emails);
			if (empty($users)) {
				return;
			}
			$this->webmailMapper->migrateContacts($users);
			$this->webmailMapper->migrateContacts($users, $this->commandOutput);
			return;
		}
		$users = $this->webmailMapper->getUsers($limit, $offset);
+14 −6
Original line number Diff line number Diff line
@@ -52,12 +52,12 @@ class WebmailMapper {
	}


	public function getUsers(int $limit, int $offset = 0, array $emails = []) : array {
	public function getUsers(int $limit = 0, int $offset = 0, array $emails = []) : array {
		$qb = $this->conn->createQueryBuilder();
		$qb->select('rl_email, id_user')
			->from(self::USERS_TABLE, 'u')
			->setFirstResult($offset);
		if ($limit) {
		if ($limit > 0) {
			$qb->setMaxResults($limit);
		}
		if (!empty($emails)) {
@@ -142,15 +142,23 @@ class WebmailMapper {
		}
	}

	public function migrateContacts(array $users) {
	public function migrateContacts(array $users, $commandOutput = null) {
		$userCount = 0;
		foreach ($users as $user) {
			$userCount += 1;
			if ($commandOutput) {
				$commandOutput->writeln('Migrating user ' . $userCount . ' with email: '.  $user['email']);
			}
			$contacts = $this->getUserContacts($user['id']);
			if (!count($contacts)) {
				return;
			$numberOfContacts = count($contacts);
			if ($commandOutput) {
				$commandOutput->writeln('Number of contacts for ' . $user['email'] . ':' . $numberOfContacts);
			}
			if ($numberOfContacts > 0) {
				$this->createCloudAddressBook($contacts, $user['email']);
			}
		}
	}


	private function initConnection() : void {