From e5b44d29fbf89a220a5343a4659d9f0bbeafee38 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 5 Sep 2023 16:35:28 +0530 Subject: [PATCH 1/4] Add more logging to the command --- lib/Command/MigrateWebmailAddressbooks.php | 4 ++-- lib/Db/WebmailMapper.php | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Command/MigrateWebmailAddressbooks.php b/lib/Command/MigrateWebmailAddressbooks.php index 4f089fb8..2d1ddf28 100644 --- a/lib/Command/MigrateWebmailAddressbooks.php +++ b/lib/Command/MigrateWebmailAddressbooks.php @@ -88,12 +88,12 @@ class MigrateWebmailAddressbooks extends Command { $emails[] = $email; } - + $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); diff --git a/lib/Db/WebmailMapper.php b/lib/Db/WebmailMapper.php index 1c524cbf..757ceac9 100644 --- a/lib/Db/WebmailMapper.php +++ b/lib/Db/WebmailMapper.php @@ -142,9 +142,15 @@ 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']); + $commandOutput->writeln('Number of contacts for ' . $user['email'] . ':' . count($contacts)); if (!count($contacts)) { return; } -- GitLab From 79e3fd5311df3585be01fbebb38e3c3dacf558b3 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 5 Sep 2023 16:41:59 +0530 Subject: [PATCH 2/4] Fix default value of limit --- lib/Command/MigrateWebmailAddressbooks.php | 8 ++++++-- lib/Db/WebmailMapper.php | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Command/MigrateWebmailAddressbooks.php b/lib/Command/MigrateWebmailAddressbooks.php index 2d1ddf28..5396fd9d 100644 --- a/lib/Command/MigrateWebmailAddressbooks.php +++ b/lib/Command/MigrateWebmailAddressbooks.php @@ -39,7 +39,7 @@ class MigrateWebmailAddressbooks extends Command { null, InputOption::VALUE_OPTIONAL, 'Limit of users to migrate', - null + 0 ) ->addOption( 'offset', @@ -88,7 +88,11 @@ class MigrateWebmailAddressbooks extends Command { $emails[] = $email; } - $this->commandOutput->writeln('Migrating ' . $limit . ' users starting at ' . $offset); + 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; diff --git a/lib/Db/WebmailMapper.php b/lib/Db/WebmailMapper.php index 757ceac9..ae235229 100644 --- a/lib/Db/WebmailMapper.php +++ b/lib/Db/WebmailMapper.php @@ -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)) { -- GitLab From 1490380196d9134866f4ff2ddcb45e2a419dc6f8 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 5 Sep 2023 16:43:19 +0530 Subject: [PATCH 3/4] VALUE_REQUIRED not optional --- lib/Command/MigrateWebmailAddressbooks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Command/MigrateWebmailAddressbooks.php b/lib/Command/MigrateWebmailAddressbooks.php index 5396fd9d..7a866223 100644 --- a/lib/Command/MigrateWebmailAddressbooks.php +++ b/lib/Command/MigrateWebmailAddressbooks.php @@ -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', 0 ) ->addOption( 'offset', null, - InputOption::VALUE_OPTIONAL, + InputOption::VALUE_REQUIRED, 'Offset', 0 ); -- GitLab From ecac068b430d1cd3de4fdccfbdb3e91f2ee54986 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 5 Sep 2023 16:45:10 +0530 Subject: [PATCH 4/4] Migrate only if number of contacts greater than 0 --- lib/Db/WebmailMapper.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Db/WebmailMapper.php b/lib/Db/WebmailMapper.php index ae235229..614d13ea 100644 --- a/lib/Db/WebmailMapper.php +++ b/lib/Db/WebmailMapper.php @@ -150,11 +150,13 @@ class WebmailMapper { $commandOutput->writeln('Migrating user ' . $userCount . ' with email: '. $user['email']); } $contacts = $this->getUserContacts($user['id']); - $commandOutput->writeln('Number of contacts for ' . $user['email'] . ':' . count($contacts)); - 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']); } - $this->createCloudAddressBook($contacts, $user['email']); } } -- GitLab