diff --git a/lib/Command/MigrateWebmailAddressbooks.php b/lib/Command/MigrateWebmailAddressbooks.php index 4f089fb80d9340920eea7c72e80143d5f444227e..7a866223e56827e35016d9962f04f011668c35ca 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', - 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); diff --git a/lib/Db/WebmailMapper.php b/lib/Db/WebmailMapper.php index 1c524cbfe1d0c9aefff5d4d894f6da46ceb2211e..614d13eab370a8309913e9d014c05496b9e0c026 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)) { @@ -142,13 +142,21 @@ 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']); } - $this->createCloudAddressBook($contacts, $user['email']); } }