Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
norelationpermission.php
1<?php
2namespace Bitrix\Im\Disk;
3
5use \Bitrix\Main\Type\DateTime,
7
8use \Bitrix\Im\Model\RelationTable;
9
11{
12 const ACCESS_TIME = 86400;
13 const CACHE_TIME = 864000;
14
15 public static function add($chatId, $userId)
16 {
17 $result = false;
18
19 $rowRelation = RelationTable::getRow(array(
20 'select' => array('ID'),
21 'filter' => array(
22 '=CHAT_ID' => $chatId,
23 '=USER_ID' => $userId
24 ),
25 'cache'=>array('ttl'=>self::CACHE_TIME)
26 ));
27 if(empty($rowRelation))
28 {
29 $provider = new ChatAuthProvider();
30 if ($provider->isCodeAlreadyExists($chatId, $userId))
31 {
32 return $result;
33 }
34
35 if(\CIMDisk::ChangeFolderMembers($chatId, $userId))
36 {
38 'select' => array('ID'),
39 'filter' => array('=CHAT_ID' => $chatId, '=USER_ID' => $userId),
40 'cache'=>array('ttl'=>self::CACHE_TIME)
41 ));
42
43 $count = 0;
44 while ($row = $raw->fetch())
45 {
46 $count++;
47
48 if($count>1)
49 {
51 }
52 else
53 {
54 $updateRaw = NoRelationPermissionDiskTable::update($row['ID'], array(
55 'ACTIVE_TO' => DateTime::createFromTimestamp(time() + self::ACCESS_TIME)
56 ));
57
58 if($updateRaw->isSuccess())
59 $result = true;
60 }
61 }
62
63 if($count === 0)
64 {
66 'CHAT_ID' => $chatId,
67 'USER_ID' => $userId,
68 'ACTIVE_TO' => DateTime::createFromTimestamp(time() + self::ACCESS_TIME)
69 ));
70
71 if($addRaw->isSuccess())
72 $result = true;
73 }
74 }
75 }
76
77 return $result;
78 }
79
80 public static function delete($chatId, $userId, $permissionDisk = true)
81 {
82 $result = false;
83
84 if($permissionDisk)
85 {
86 $rowRelation = RelationTable::getRow(array(
87 'select' => array('ID'),
88 'filter' => array(
89 '=CHAT_ID' => $chatId,
90 '=USER_ID' => $userId
91 ),
92 'cache'=>array('ttl'=>self::CACHE_TIME)
93 ));
94 if(empty($rowRelation))
95 {
96 if(\CIMDisk::ChangeFolderMembers($chatId, $userId, false))
97 $result = true;
98 }
99 }
100
102 'select' => array('ID'),
103 'filter' => array('=CHAT_ID' => $chatId, '=USER_ID' => $userId),
104 'cache'=>array('ttl'=>self::CACHE_TIME)
105 ));
106
107 while ($row = $raw->fetch())
108 {
109 if(NoRelationPermissionDiskTable::delete($row['ID'])->isSuccess())
110 $result = true;
111 }
112
113 return $result;
114 }
115
116 public static function cleaningAgent(): string
117 {
118 if (!\Bitrix\Main\ModuleManager::isModuleInstalled('disk'))
119 {
120 return __METHOD__.'();';
121 }
122
123 $connection = \Bitrix\Main\Application::getInstance()->getConnection();
124
125 $relationTbl = RelationTable::getTableName();
126 $noRelationPermTbl = NoRelationPermissionDiskTable::getTableName();
127
128 $connection->queryExecute("
129 DELETE
130 FROM
131 {$noRelationPermTbl}
132 WHERE (CHAT_ID, USER_ID) in (
133 select CHAT_ID, USER_ID FROM {$relationTbl}
134 )
135 ");
136
138 'select' => ['CHAT_ID', 'USER_ID'],
139 'filter' => [
140 '<=ACTIVE_TO' => DateTime::createFromTimestamp(time())
141 ]
142 ]);
143 $pseudoRelation = [];
144 while($row = $result->fetch())
145 {
146 $pseudoRelation[$row['CHAT_ID']][$row['USER_ID']] = $row['USER_ID'];
147 }
148
149 $connection->queryExecute("DELETE FROM {$noRelationPermTbl} WHERE ACTIVE_TO <= now()");
150
151 foreach ($pseudoRelation as $chatId => $userDelete)
152 {
153 \CIMDisk::changeFolderMembers($chatId, $userDelete, false);
154 }
155
156 return __METHOD__.'();';
157 }
158}
static isModuleInstalled($moduleName)
static getList(array $parameters=array())
static update($primary, array $data)
static createFromTimestamp($timestamp)
Definition datetime.php:246