wip: synchro

This commit is contained in:
2022-05-07 02:22:28 +02:00
parent 9935af0497
commit 811798e23f
14 changed files with 315 additions and 43 deletions

View File

@@ -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;
}
}