- Модуль: calendar
- Путь к файлу: ~/bitrix/modules/calendar/lib/sync/googleapipush.php
- Класс: BitrixCalendarSyncGoogleApiPush
- Вызов: GoogleApiPush::checkSectionsPush
static function checkSectionsPush($localSections, $userId, $connectionId)
{
$googleApiConnection = new GoogleApiSync($userId, $connectionId);
//Create new channels and refresh old push channels for sections of current connection
$sectionIds = self::getNotVirtualSectionIds($localSections);
$pushChannels = PushTable::getList([
'filter' => [
'=ENTITY_TYPE' => self::TYPE_SECTION,
'=ENTITY_ID' => $sectionIds,
]
]);
$inactiveSections = array_flip($sectionIds);
while($row = $pushChannels->fetch())
{
$now = time();
$tsExpires = strtotime($row['EXPIRES']);
if ($now > $tsExpires)
{
self::deletePushChannel($row);
continue;
}
if (($tsExpires - $now) > GoogleApiSync::ONE_DAY
|| self::isAuthError(self::getLastResultBySectionId((int)$row['ENTITY_ID']))
)
{
unset($inactiveSections[$row['ENTITY_ID']]);
continue;
}
$googleApiConnection->stopChannel($row['CHANNEL_ID'], $row['RESOURCE_ID']);
self::deletePushChannel($row);
unset($inactiveSections[$row['ENTITY_ID']]);
$localCalendarIndex = array_search($row['ENTITY_ID'], array_column($localSections, 'ID'));
if ($localCalendarIndex !== false)
{
$channelInfo = $googleApiConnection->startWatchCalendarList($localSections[$localCalendarIndex]['GAPI_CALENDAR_ID']);
if ($channelInfo)
{
PushTable::update(
[
'ENTITY_TYPE' => $row['ENTITY_TYPE'],
'ENTITY_ID' => $row['ENTITY_ID']
],
[
'CHANNEL_ID' => $channelInfo['id'],
'RESOURCE_ID' => $channelInfo['resourceId'],
'EXPIRES' => $channelInfo['expiration'],
'NOT_PROCESSED' => 'N'
]
);
}
}
}
if (is_array($localSections) && is_array($inactiveSections) && $googleApiConnection instanceof GoogleApiSync)
{
self::startChannelForInActiveSections($localSections, $inactiveSections, $googleApiConnection);
}
return false;
}