28 private const COUNT_CONNECTIONS_FOR_REGULAR_SYNC = 10;
37 $this->factories = $factories;
46 public static function markDeletedFailedConnection(
Connection $connection): void
49 $mapperFactory = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
65 public function exchange():
Result
68 foreach ($this->factories as $factory)
75 $exchangeManager =
new VendorDataExchangeManager($factory, self::getSyncSectionMap($factory));
76 $exchangeManager->exchange();
92 public function import(): Result
95 foreach ($this->factories as $factory)
97 $exchangeManager =
new VendorDataExchangeManager($factory, self::getSyncSectionMap($factory));
101 ->updateConnection($factory->getConnection())
107 $exchangeManager->renewSubscription($factory->getConnection());
109 catch (\Exception $e)
125 public static function importAgent(): string
127 if (!Loader::includeModule(
'calendar') || !Loader::includeModule(
'dav'))
129 return "\\Bitrix\\Calendar\\Sync\\Managers\\DataExchangeManager::importAgent();";
132 $connections = self::getConnections();
134 while ($connection = $connections->fetch())
136 if ($connection->getOwner() ===
null)
138 self::markDeletedFailedConnection($connection);
145 $factory = FactoriesCollection::createByConnection($connection)->fetch();
152 $exchangeManager =
new VendorDataExchangeManager($factory, self::getSyncSectionMap($factory));
156 ->updateConnection($factory->getConnection())
159 catch (RemoteAccountException $e)
161 self::markDeletedFailedConnection($connection);
163 catch (\Exception $e)
169 return "\\Bitrix\\Calendar\\Sync\\Managers\\DataExchangeManager::importAgent();";
178 private static function getConnections(): Core\Base\Map
181 $mapperFactory = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
183 return $mapperFactory->getConnection()->getMap(
186 Google\Helper::GOOGLE_ACCOUNT_TYPE_API,
187 Office365\Helper::ACCOUNT_TYPE
189 '=ENTITY_TYPE' => Core\Role\User::TYPE,
190 '=IS_DELETED' =>
'N',
192 self::COUNT_CONNECTIONS_FOR_REGULAR_SYNC,
193 [
'SYNCHRONIZED' =>
'ASC']
206 private static function getSyncSectionMap(FactoryBase $factory): SyncSectionMap
208 return (
new SyncSectionFactory())->getSyncSectionMapByFactory($factory);