mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\CalendarBundle\Command;
|
|
|
|
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MapCalendarToUser;
|
|
use Chill\MainBundle\Repository\UserRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class MapUserCalendarCommand extends Command
|
|
{
|
|
private EntityManagerInterface $em;
|
|
|
|
private MapCalendarToUser $mapCalendarToUser;
|
|
|
|
private UserRepository $userRepository;
|
|
|
|
public function __construct(EntityManagerInterface $em, MapCalendarToUser $mapCalendarToUser, UserRepository $userRepository)
|
|
{
|
|
parent::__construct('chill:calendar:map-user');
|
|
|
|
$this->em = $em;
|
|
$this->mapCalendarToUser = $mapCalendarToUser;
|
|
$this->userRepository = $userRepository;
|
|
}
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$limit = 2;
|
|
$offset = 0;
|
|
$total = $this->userRepository->countByNotHavingAttribute(MapCalendarToUser::METADATA_KEY);
|
|
|
|
while ($offset < $total) {
|
|
$users = $this->userRepository->findByNotHavingAttribute(MapCalendarToUser::METADATA_KEY, $limit, $offset);
|
|
|
|
foreach ($users as $user) {
|
|
$this->mapCalendarToUser->writeMetadata($user);
|
|
++$offset;
|
|
}
|
|
|
|
$this->em->flush();
|
|
$this->em->clear();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|