3namespace Bitrix\Calendar\Sync\Google;
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Core\Base\Result;
7use Bitrix\Calendar\Core\Mappers;
8use Bitrix\Calendar\Core\Role\Helper;
9use Bitrix\Calendar\Core\Role\Role;
10use Bitrix\Calendar\Core\Role\User;
11use Bitrix\Calendar\Integration\Pull\PushCommand;
12use Bitrix\Calendar\Sync\Managers\NotificationManager;
13use Bitrix\Calendar\Sync\Util\HandleStatusTrait;
14use Bitrix\Calendar\Sync\Connection\Connection;
15use Bitrix\Calendar\Sync\Factories\SyncSectionFactory;
16use Bitrix\Calendar\Sync\Handlers\MasterPushHandler;
17use Bitrix\Calendar\Sync\Managers;
18use Bitrix\Calendar\Sync\Managers\OutgoingManager;
19use Bitrix\Calendar\Sync\Managers\StartSynchronization;
20use Bitrix\Calendar\Sync\Managers\VendorDataExchangeManager;
21use Bitrix\Calendar\Util;
22use Bitrix\Main\ArgumentException;
23use Bitrix\Main\DI\ServiceLocator;
24use Bitrix\Main\ObjectException;
25use Bitrix\Main\ObjectNotFoundException;
26use Bitrix\Main\ObjectPropertyException;
27use Bitrix\Main\SystemException;
29use Psr\Container\NotFoundExceptionInterface;
33 use HandleStatusTrait;
41 private static array $outgoingManagersCache = [];
55 $this->mapperFactory = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
68 'message' =>
'Could not finish sync.',
71 $owner = Helper::getRole(\CCalendar::GetUserId(), User::TYPE);
72 $pusher =
static function (
$result) use ($owner)
75 PushCommand::ProcessSyncConnection,
80 if (
$result[
'stage'] ===
'export_finished')
82 NotificationManager::addFinishedSyncNotificationAgent(
91 if ($connection = $this->addStatusHandler($pusher)->
start())
94 'status' =>
'success',
95 'message' =>
'CONNECTION_CREATED',
96 'connectionId' => $connection->getId(),
114 $this->connection = $connection = $this->createConnection($this->mapperFactory->getConnection());
115 $this->sendResult(MasterPushHandler::MASTER_STAGE[0]);
117 $factory =
new Factory($this->connection);
123 ->addStatusHandlerList($this->getStatusHandlerList())
128 $this->sendResult(MasterPushHandler::MASTER_STAGE[2]);
129 $this->sendResult(MasterPushHandler::MASTER_STAGE[3]);
148 $connectionManager->deactivateConnections($connections);
153 $nameResult = $factory->getImportManager()->requestConnectionId();
155 if (!$nameResult->isSuccess() || empty($nameResult->getData()[
'id']))
160 $name = $nameResult->getData()[
'id'];
161 $connectionMap = $mapper->getMap([
162 '%=NAME' =>
'%'.
$name .
'%',
163 '=ENTITY_ID' => $this->user->getId(),
165 ],
null, [
'ID' =>
'ASC']);
167 $currentConnection = $connectionMap->fetch();
169 if ($currentConnection && $duplicatedConnection = $connectionMap->fetch())
171 $this->deleteConnectionData($duplicatedConnection->getId());
176 if ($currentConnection)
182 $mapper->update($currentConnection);
184 return $currentConnection;
197 (
new MasterPushHandler($this->user,
'google', $connection->getName()))(MasterPushHandler::MASTER_STAGE[0]);
205 private function sendResult(
string $stage): void
208 'vendorName' =>
'google',
209 'accountName' => $this->connection->getName(),
226 $links = $this->mapperFactory->getSectionConnection()->getMap([
227 '=CONNECTION_ID' => $connection->getId(),
231 $manager = $this->getOutgoingManager($connection);
232 foreach ($links as $link)
249 if (empty(static::$outgoingManagersCache[
$connection->getId()]))
254 return static::$outgoingManagersCache[
$connection->getId()];
262 private function deleteConnectionData(
int $connectionId): void
266 DELETE FROM b_calendar_event_connection
267 WHERE CONNECTION_ID = " . $connectionId .
";"
271 DELETE FROM b_calendar_section_connection
272 WHERE CONNECTION_ID = " . $connectionId .
";"
276 DELETE FROM b_dav_connections
277 WHERE ID = " . $connectionId .
";"
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getUserRole(int $id)
sendPushNotification(Connection $connection)
initSubscription(Connection $connection)
static addPullEvent(PushCommand $command, int $userId, array $params=[])
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)