mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
wip: synchro
This commit is contained in:
@@ -3,48 +3,49 @@
|
||||
namespace Chill\CalendarBundle\Command;
|
||||
|
||||
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MachineTokenStorage;
|
||||
use Chill\CalendarBundle\Synchro\Connector\MSGraph\MapCalendarToUser;
|
||||
use Chill\CalendarBundle\Synchro\Connector\MSGraphRemoteCalendarConnector;
|
||||
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 MSGraphRemoteCalendarConnector $remoteCalendarConnector;
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private MapCalendarToUser $mapCalendarToUser;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(MSGraphRemoteCalendarConnector $remoteCalendarConnector)
|
||||
public function __construct(EntityManagerInterface $em, MapCalendarToUser $mapCalendarToUser, UserRepository $userRepository)
|
||||
{
|
||||
parent::__construct('chill:calendar:map-user');
|
||||
|
||||
$this->remoteCalendarConnector = $remoteCalendarConnector;
|
||||
$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);
|
||||
|
||||
do {
|
||||
$users = $this->userRepository->findByNotHavingAttribute('ms:graph', $limit);
|
||||
while ($offset < $total) {
|
||||
$users = $this->userRepository->findByNotHavingAttribute(MapCalendarToUser::METADATA_KEY, $limit, $offset);
|
||||
|
||||
foreach ($users as $user) {
|
||||
$usersData = $this->remoteCalendarConnector->getUserByEmail($user->getEmailCanonical());
|
||||
|
||||
$defaultCalendar
|
||||
|
||||
$user->setAttributes(['ms:graph' => [
|
||||
|
||||
]]);
|
||||
$this->mapCalendarToUser->writeMetadata($user);
|
||||
$offset++;
|
||||
}
|
||||
|
||||
} while (count($users) === $limit);
|
||||
|
||||
|
||||
$this->em->flush();
|
||||
$this->em->clear();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user