3namespace Bitrix\Calendar\Sync\Google;
5use Bitrix\Calendar\Sync\Connection\Connection;
6use Bitrix\Calendar\Sync\Connection\SectionConnection;
7use Bitrix\Calendar\Sync\GoogleApiSync;
8use Bitrix\Calendar\Sync\Managers\PushManagerInterface;
9use Bitrix\Calendar\Sync\Push\Push;
10use Bitrix\Calendar\Sync\Util\Result;
11use Bitrix\Main\ArgumentException;
12use Bitrix\Main\Config\Option;
13use Bitrix\Main\Context;
15use Bitrix\Main\LoaderException;
16use Bitrix\Main\ObjectException;
17use Bitrix\Main\Type\DateTime;
33 if ($this->isVirtualCalendar($link))
35 return $result->addError(
new Error(
'This type of calendar doesnt support push.', 415));
38 $calendarId = $link->getVendorSectionId();
43 $this->httpClient->query(
44 Web\HttpClient::HTTP_POST,
45 $this->connection->getVendor()->getServer()->getFullPath()
46 .
'/calendars/' . urlencode($calendarId) .
'/events/watch',
47 Web\Json::encode(
$params, JSON_UNESCAPED_SLASHES)
50 if ($this->httpClient->getStatus() === 200)
54 'CHANNEL_ID' =>
$data[
'id'],
55 'RESOURCE_ID' =>
$data[
'resourceId'],
59 else if ($this->httpClient->getStatus() === 401)
61 $this->handleUnauthorize($this->connection);
63 $result->addError(
new Error(
'Unauthorized', $this->httpClient->getStatus()));
67 $result->addError(
new Error(
'Error of create channel', $this->httpClient->getStatus()));
89 $this->httpClient->query(
90 Web\HttpClient::HTTP_POST,
91 $this->connection->getVendor()->getServer()->getFullPath() .
'/channels/stop',
95 ], JSON_UNESCAPED_SLASHES)
98 if ($this->httpClient->getStatus() !== 200)
100 $result->addError(
new Error(
'Error of stopping push channel.', $this->httpClient->getStatus()));
120 $this->httpClient->query(
121 Web\HttpClient::HTTP_POST,
122 $this->connection->getVendor()->getServer()->getFullPath() .
'/users/me/calendarList/watch',
123 Web\Json::encode($channelInfo, JSON_UNESCAPED_SLASHES)
126 if ($this->isRequestSuccess())
130 'CHANNEL_ID' =>
$data[
'id'],
131 'RESOURCE_ID' =>
$data[
'resourceId'],
135 else if ($this->httpClient->getStatus() === 401)
137 $this->handleUnauthorize($this->connection);
139 $result->addError(
new Error(
'Unauthorized', $this->httpClient->getStatus()));
143 $result->addError(
new Error(
'Error of create channel', $this->httpClient->getStatus()));
155 private function makeChannelParams($uniqId,
string $type):
array
157 if (defined(
'BX24_HOST_NAME') && BX24_HOST_NAME)
163 $request = Context::getCurrent()->getRequest();
164 if (defined(
'SITE_SERVER_NAME') && SITE_SERVER_NAME)
166 $host = SITE_SERVER_NAME;
170 $host = Option::get(
'main',
'server_name',
$request->getHttpHost());
173 $externalUrl =
'https://' .
$host .
'/bitrix/tools/calendar/push.php';
177 'id' =>
$type .
'_' . $this->userId.
'_'.md5($uniqId. time()),
178 'type' =>
'web_hook',
179 'address' => $externalUrl,
189 private function isVirtualCalendar(SectionConnection $link): bool
191 return (strpos($link->getVendorSectionId(),
'holiday.calendar.google.com'))
192 || (strpos($link->getVendorSectionId(),
'group.v.calendar.google.com'))
193 || (strpos($link->getVendorSectionId(),
'@virtual'))
194 || (strpos($link->getSection()->getExternalType(),
'_readonly'))
195 || (strpos($link->getSection()->getExternalType(),
'_freebusy'))
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
renewPush(Push $pushChannel)
addSectionPush(SectionConnection $link)
addConnectionPush(Connection $connection)
deletePush(Push $pushChannel)
const CONNECTION_CHANNEL_TYPE
</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']