14 private const WEEK_TIME_SLICE = 650000;
15 private const SYNC_CONNECTIONS = [
34 (
new self())->cleanConnections();
36 return "\\Bitrix\\Calendar\\Sync\\Util\\CleanConnectionAgent::cleanAgent();";
48 private function cleanConnections(): void
50 if (!Loader::includeModule(
'dav') || !Loader::includeModule(
'calendar'))
55 $deletedUsersConnections = $this->getDeletedUsersConnection();
57 $deletedUsersConnectionsIds = array_map(
static function($deletedConnection){
58 return (
int)$deletedConnection[
'ID'];
59 }, $deletedUsersConnections);
61 if ($deletedUsersConnectionsIds)
63 $this->cleanTables($deletedUsersConnectionsIds);
74 private function getDeletedConnections(): array
76 return DavConnectionTable::query()
77 ->setSelect([
'ID',
'ACCOUNT_TYPE'])
78 ->where(
'IS_DELETED',
'Y')
79 ->where(
'SYNCHRONIZED',
'<',
new Date(\CCalendar::Date(time() - self::WEEK_TIME_SLICE)))
80 ->whereIn(
'ACCOUNT_TYPE', self::SYNC_CONNECTIONS)
89 private function getDeletedUsersConnection(): array
91 return DavConnectionTable::query()
92 ->setSelect([
'ID',
'ACCOUNT_TYPE'])
93 ->registerRuntimeField(
97 [
'=this.ENTITY_ID' =>
'ref.ID'],
98 [
'join_type' =>
'INNER']
101 ->where(
'USER.ACTIVE',
'N')
102 ->whereIn(
'ACCOUNT_TYPE', self::SYNC_CONNECTIONS)
113 private function cleanTables(array $id): void
116 $id = implode(
',', $id);
118 DELETE FROM b_calendar_event_connection
119 WHERE CONNECTION_ID IN ( " . $id .
");"
123 DELETE FROM b_calendar_section_connection
124 WHERE CONNECTION_ID IN (" . $id .
");"
128 DELETE FROM b_dav_connections
129 WHERE ID IN (" . $id .
");"