mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-29 15:14:34 +00:00
Add support for remote_calendar_dsn configuration to handle multiple calendar connector types
- Introduced `remote_calendar_dsn` in configuration to manage different connectors (e.g., MS Graph, Zimbra, Null). - Deprecated `microsoft_graph` configuration. - Enhanced `RemoteCalendarCompilerPass` to dynamically determine and configure the appropriate connector based on DSN. - Removed unnecessary Microsoft Graph services when using Zimbra or Null connectors. - Improved service alias and removed unsupported service definitions for invalid schemes.
This commit is contained in:
@@ -47,6 +47,8 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
|
||||
} else {
|
||||
$container->setParameter('chill_calendar.short_messages', null);
|
||||
}
|
||||
|
||||
$container->setParameter('chill_calendar.remote_calendar_dsn', $config['remote_calendar_dsn']);
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
|
||||
@@ -32,9 +32,10 @@ class Configuration implements ConfigurationInterface
|
||||
->canBeDisabled()
|
||||
->children()->end()
|
||||
->end() // end for short_messages
|
||||
->scalarNode('remote_calendar_dsn')->defaultValue('null://null')->cannotBeEmpty()->end()
|
||||
->arrayNode('remote_calendars_sync')->canBeEnabled()
|
||||
->children()
|
||||
->arrayNode('microsoft_graph')->canBeEnabled()
|
||||
->arrayNode('microsoft_graph')->canBeEnabled()->setDeprecated('chill-project/chill-bundles', '4.7.0', 'The child node %node% at path %path% is deprecated: use remote_calendar_dsn instead, with a "msgraph://default" value')
|
||||
->children()
|
||||
->end() // end of machine_access_token
|
||||
->end() // end of microsoft_graph children
|
||||
|
||||
@@ -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