3namespace Bitrix\Calendar\Sync\Office365;
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Core\Base\Date;
7use Bitrix\Calendar\Sync\Connection\Connection;
8use Bitrix\Calendar\Sync\Connection\SectionConnection;
9use Bitrix\Calendar\Sync\Exceptions\ApiException;
10use Bitrix\Calendar\Sync\Exceptions\AuthException;
11use Bitrix\Calendar\Sync\Exceptions\ConflictException;
12use Bitrix\Calendar\Sync\Exceptions\NotFoundException;
13use Bitrix\Calendar\Sync\Exceptions\RemoteAccountException;
14use Bitrix\Calendar\Sync\Internals\HasContextTrait;
15use Bitrix\Calendar\Sync\Managers\PushManagerInterface;
16use Bitrix\Calendar\Sync\Push\Push;
17use Bitrix\Calendar\Sync\Util\Result;
18use Bitrix\Main\ArgumentException;
19use Bitrix\Main\ArgumentNullException;
21use Bitrix\Main\LoaderException;
22use Bitrix\Main\ObjectException;
23use Bitrix\Main\Type\DateTime;
33 parent::__construct(
$context->getConnection());
49 if (
$data = $this->context->getVendorSyncService()->resubscribe($pushChannel->
getResourceId()))
51 if (empty(
$data[
'expirationDateTime']))
53 $time = time() + 70 * 60 * 60;
54 $data[
'expirationDateTime'] = date(
'c',
$time);
60 'RESOURCE_ID' =>
$data[
'id'],
61 'EXPIRES' => $this->convertToDateTime(
$data[
'expirationDateTime']),
66 $result->addError(
new Error(
'Error of renew push channel'));
71 $result->addError(
new Error(
'Error of MS Graph API', $e->getCode(), $e->getMessage()));
86 $phpDateTime = new \DateTime(
$time);
88 return DateTime::createFromPhp($phpDateTime);
103 $data = $this->context->getVendorSyncService()->subscribeSection($link);
108 'CHANNEL_ID' =>
$data[
'channelId'],
109 'RESOURCE_ID' =>
$data[
'id'],
110 'EXPIRES' => $this->convertToDateTime(
$data[
'expirationDateTime'] ?? date(
'c')),
115 $result->addError(
new Error(
'Error of create subscription.'));
120 $result->addError(
new Error(
'Error of Push subscribing. Vendor returned error.', $e->getCode()));
124 $result->addError(
new Error(
'No authentication data', $e->getCode()));
151 if (
$data = $this->context->getVendorSyncService()->unsubscribe($pushChannel->
getResourceId()))
181 $apiResponse = $this->context->getApiClient()->get(
'subscriptions');
182 if (!empty($apiResponse[
'value']))
184 foreach ($apiResponse[
'value'] as $subscription)
186 $this->context->getApiClient()->delete(
'subscriptions/' . $subscription[
'id']);
198 return (
new Result())->
addError(
new Error(
'Connection push unavailable for this service', 503));
__construct(Office365Context $context)
renewPush(Push $pushChannel)
addSectionPush(SectionConnection $link)
addConnectionPush(Connection $connection)
deletePush(Push $pushChannel)
setExpireDate(Date $expireDate)