Loading lib/Command/MigrateWebmailAddressbooks.php +10 −6 Original line number Diff line number Diff line Loading @@ -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 ); Loading Loading @@ -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); Loading lib/Db/WebmailMapper.php +14 −6 Original line number Diff line number Diff line Loading @@ -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)) { Loading Loading @@ -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 { Loading Loading
lib/Command/MigrateWebmailAddressbooks.php +10 −6 Original line number Diff line number Diff line Loading @@ -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 ); Loading Loading @@ -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); Loading
lib/Db/WebmailMapper.php +14 −6 Original line number Diff line number Diff line Loading @@ -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)) { Loading Loading @@ -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 { Loading