17 return get_called_class();
24 if (!Loader::includeModule(
"calendar") && !Loader::includeModule(
"dav"))
29 $pushEnabled = \CCalendar::IsBitrix24() || \COption::GetOptionString(
'calendar',
'sync_by_push',
false);
35 $lastId = Option::get(
'calendar',
'initLocalDataToGoogleLastId', 0);
37 $connections = $this->getNotSyncLocalConnection((
int)$lastId);
40 CAgent::RemoveAgent(
"CCalendarSync::doSync();",
"calendar");
41 foreach ($connections as $connection)
43 $connection = $this->stopChannels($connection);
45 $lastId = $connection[
'ID'];
49 Option::set(
'calendar',
'initLocalDataToGoogleLastId', (
string)$lastId);
50 CAgent::AddAgent(
"CCalendarSync::doSync();",
"calendar",
"N", 120);
62 private function getNotSyncLocalConnection(
int $lastId): array
67 $strSql =
"SELECT DISTINCT c.*, GROUP_CONCAT(s.ID) as SECTION_LIST"
68 .
" FROM b_dav_connections c"
69 .
" INNER JOIN b_calendar_section s ON s.OWNER_ID = c.ENTITY_ID"
70 .
" WHERE (s.EXTERNAL_TYPE = 'local' OR s.EXTERNAL_TYPE = 'google') AND c.ACCOUNT_TYPE = 'google_api_oauth' AND c.ID > " . $lastId
75 $connectionsDb = $DB->Query($strSql);
77 while ($connection = $connectionsDb->Fetch())
79 $connections[] = $connection;
91 private function stopChannels($connection)
93 GoogleApiPush::stopChannel(GoogleApiPush::getPush(GoogleApiPush::TYPE_CONNECTION, (
int)$connection[
'ID']));
94 if (isset($connection[
'SECTION_LIST']) && is_string($connection[
'SECTION_LIST']))
96 foreach (explode(
',', $connection[
'SECTION_LIST']) as $sectionId)
98 GoogleApiPush::stopChannel(GoogleApiPush::getPush(GoogleApiPush::TYPE_SECTION, $sectionId));