3namespace Bitrix\Calendar\Sync\Icloud;
5use Bitrix\Calendar\Core;
6use Bitrix\Calendar\Integration\Pull\PushCommand;
7use Bitrix\Calendar\Sync\Builders\BuilderConnectionFromArray;
8use Bitrix\Calendar\Sync\Builders\BuilderConnectionFromDM;
9use Bitrix\Calendar\Sync\Managers;
10use Bitrix\Calendar\Util;
11use Bitrix\Main\ArgumentException;
12use Bitrix\Main\DI\ServiceLocator;
13use Bitrix\Calendar\Sync\Managers\NotificationManager;
14use Bitrix\Main\ObjectPropertyException;
15use Bitrix\Main\SystemException;
19 private const STATUS_ERROR =
'error';
20 private const STATUS_SUCCESS =
'success';
34 $this->helper =
new Helper();
35 $this->mapperFactory = ServiceLocator::getInstance()->get(
'calendar.service.mappers.factory');
52 $userId = \CCalendar::GetUserId();
53 $connection = $this->mapperFactory->getConnection()->getById($connectionId);
58 'status' => self::STATUS_ERROR,
59 'message' =>
'Connection not found',
66 'status' => self::STATUS_ERROR,
67 'message' =>
'Access Denied',
75 'status' => self::STATUS_ERROR,
76 'message' =>
'Error while trying to import events',
81 PushCommand::ProcessSyncConnection,
84 'vendorName' => $this->helper::ACCOUNT_TYPE,
85 'stage' =>
'import_finished',
86 'accountName' =>
$connection->getServer()->getUserName(),
94 'status' => self::STATUS_ERROR,
95 'message' =>
'Error while trying to export events',
100 PushCommand::ProcessSyncConnection,
103 'vendorName' => $this->helper::ACCOUNT_TYPE,
104 'stage' =>
'export_finished',
105 'accountName' =>
$connection->getServer()->getUserName(),
109 NotificationManager::addFinishedSyncNotificationAgent(
111 $this->helper::ACCOUNT_TYPE
115 'status' => self::STATUS_SUCCESS
130 'ENTITY_ID' => \CCalendar::GetCurUserId(),
132 'SERVER_HOST' => $this->helper::SERVER_PATH,
133 'SERVER_USERNAME' => $appleId,
134 'SERVER_PASSWORD' => $appPassword,
135 'NAME' => str_replace(
'#NAME#', $appleId, $this->helper::CONNECTION_NAME)
139 $calendarPath = $this->getSyncService()->getCalendarServerPath(
$params);
142 $this->error =
'Error while trying to get calendars path';
148 $connections = $connectionManager->getConnectionsData($owner, [Helper::ACCOUNT_TYPE]);
149 $connectionManager->deactivateConnections($connections);
150 foreach ($connections as
$con)
152 $existPath =
$con->getServerScheme()
154 .
$con->getServerHost()
156 .
$con->getServerPort()
157 .
$con->getServerPath()
159 if ($existPath === $calendarPath)
169 $connection->getServer()->setPassword($appPassword);
190 'ACCOUNT_TYPE' => $this->helper::ACCOUNT_TYPE,
193 'SERVER_USERNAME' =>
$connection[
'SERVER_USERNAME'],
194 'SERVER_PASSWORD' =>
$connection[
'SERVER_PASSWORD']
197 $connectionId = \CDavConnection::Add(
$fields);
201 return $connectionId;
204 $this->error =
'Error while trying to save connection';
211 if (!$this->syncService)
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getRole(int $id, string $type)
syncIcloudConnection(int $connectionId)
VendorSyncService $syncService
initConnection(string $appleId, string $appPassword)
addConnection(array $connection, string $calendarPath)
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)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']