mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-02-28 02:59:40 +00:00
Create a connector to synchronize with zimbra calendars
This commit is contained in:
@@ -35,25 +35,46 @@ use TheNetworg\OAuth2\Client\Provider\Azure;
|
||||
|
||||
class RemoteCalendarCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
private const ZIMBRA_CONNECTOR = 'Chill\ZimbraBundle\Calendar\Connector\ZimbraConnector';
|
||||
|
||||
private const MS_GRAPH_SERVICES_TO_REMOVE = [
|
||||
MapAndSubscribeUserCalendarCommand::class,
|
||||
AzureGrantAdminConsentAndAcquireToken::class,
|
||||
RemoteCalendarConnectAzureController::class,
|
||||
MachineTokenStorage::class,
|
||||
MachineHttpClient::class,
|
||||
MSGraphRemoteCalendarConnector::class,
|
||||
MSUserAbsenceReaderInterface::class,
|
||||
MSUserAbsenceSync::class,
|
||||
];
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$config = $container->getParameter('chill_calendar');
|
||||
$config = $container->getParameter('chill_calendar.remote_calendar_dsn');
|
||||
if (true === $container->getParameter('chill_calendar')['remote_calendars_sync']['microsoft_graph']['enabled']) {
|
||||
$dsn = 'msgraph://default';
|
||||
} else {
|
||||
$dsn = $config;
|
||||
}
|
||||
|
||||
if (true === $config['remote_calendars_sync']['microsoft_graph']['enabled']) {
|
||||
$scheme = parse_url($dsn, PHP_URL_SCHEME);
|
||||
|
||||
if ('msgraph' === $scheme) {
|
||||
$connector = MSGraphRemoteCalendarConnector::class;
|
||||
|
||||
$container->setAlias(HttpClientInterface::class.' $machineHttpClient', MachineHttpClient::class);
|
||||
} else {
|
||||
} elseif ('zimbra+http' === $scheme || 'zimbra+https' === $scheme) {
|
||||
$connector = self::ZIMBRA_CONNECTOR;
|
||||
foreach (self::MS_GRAPH_SERVICES_TO_REMOVE as $serviceId) {
|
||||
$container->removeDefinition($serviceId);
|
||||
}
|
||||
} elseif ('null' === $scheme) {
|
||||
$connector = NullRemoteCalendarConnector::class;
|
||||
// remove services which cannot be loaded
|
||||
$container->removeDefinition(MapAndSubscribeUserCalendarCommand::class);
|
||||
$container->removeDefinition(AzureGrantAdminConsentAndAcquireToken::class);
|
||||
$container->removeDefinition(RemoteCalendarConnectAzureController::class);
|
||||
$container->removeDefinition(MachineTokenStorage::class);
|
||||
$container->removeDefinition(MachineHttpClient::class);
|
||||
$container->removeDefinition(MSGraphRemoteCalendarConnector::class);
|
||||
$container->removeDefinition(MSUserAbsenceReaderInterface::class);
|
||||
$container->removeDefinition(MSUserAbsenceSync::class);
|
||||
foreach (self::MS_GRAPH_SERVICES_TO_REMOVE as $serviceId) {
|
||||
$container->removeDefinition($serviceId);
|
||||
}
|
||||
} else {
|
||||
throw new \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('Unsupported remote calendar scheme: '.$scheme);
|
||||
}
|
||||
|
||||
if (!$container->hasAlias(Azure::class) && $container->hasDefinition('knpu.oauth2.client.azure')) {
|
||||
@@ -62,7 +83,9 @@ class RemoteCalendarCompilerPass implements CompilerPassInterface
|
||||
|
||||
foreach ([
|
||||
NullRemoteCalendarConnector::class,
|
||||
MSGraphRemoteCalendarConnector::class, ] as $serviceId) {
|
||||
MSGraphRemoteCalendarConnector::class,
|
||||
self::ZIMBRA_CONNECTOR,
|
||||
] as $serviceId) {
|
||||
if ($connector === $serviceId) {
|
||||
$container->getDefinition($serviceId)
|
||||
->setDecoratedService(RemoteCalendarConnectorInterface::class);
|
||||
|
||||
Reference in New Issue
Block a user