Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logindex.php
1<?php
2
10
15
32class LogIndexTable extends Entity\DataManager
33{
34 public const ITEM_TYPE_LOG = 'L';
35 public const ITEM_TYPE_COMMENT = 'LC';
36
37 public static function getItemTypes(): array
38 {
39 return [
42 ];
43 }
44
45 public static function getTableName(): string
46 {
47 return 'b_sonet_log_index';
48 }
49
50 public static function getMap(): array
51 {
52 return [
53 'LOG_ID' => [
54 'data_type' => 'integer',
55 ],
56 'LOG_UPDATE' => [
57 'data_type' => 'datetime',
58 ],
59 'DATE_CREATE' => [
60 'data_type' => 'datetime',
61 ],
62 'ITEM_TYPE' => [
63 'data_type' => 'string',
64 'primary' => true,
65 ],
66 'ITEM_ID' => [
67 'data_type' => 'integer',
68 'primary' => true,
69 ],
70 'CONTENT' => [
71 'data_type' => 'text',
72 ],
73 ];
74 }
75
76 public static function set($params = []): bool
77 {
78 $itemType = ($params['itemType'] ?? self::ITEM_TYPE_LOG);
79 $itemId = (int)($params['itemId'] ?? 0);
80 $logId = (int)($params['logId'] ?? 0);
81 $content = trim(($params['content'] ?? ''));
82
83 if (
84 !in_array($itemType, self::getItemTypes())
85 || $itemId <= 0
86 || $logId <= 0
87 || empty($content)
88 )
89 {
90 return false;
91 }
92
93 $connection = Application::getConnection();
94 $helper = $connection->getSqlHelper();
95
96 $value = $helper->forSql($content);
97 $encryptedValue = sha1($content);
98
99 $insertFields = [
100 'ITEM_TYPE' => $helper->forSql($itemType),
101 'ITEM_ID' => $itemId,
102 'LOG_ID' => $logId,
103 'CONTENT' => $value,
104 ];
105
106 $updateFields = [
107 'CONTENT' => new SqlExpression("IF(SHA1(CONTENT) = '{$encryptedValue}', CONTENT, '{$value}')"),
108 ];
109
110 if (
111 isset($params['logDateUpdate'])
112 && $params['logDateUpdate'] instanceof DateTime
113 )
114 {
115 $insertFields['LOG_UPDATE'] = $params['logDateUpdate'];
116 $updateFields['LOG_UPDATE'] = $params['logDateUpdate'];
117 }
118
119 if (
120 isset($params['dateCreate'])
121 && $params['dateCreate'] instanceof DateTime
122 )
123 {
124 $insertFields['DATE_CREATE'] = $params['dateCreate'];
125 $updateFields['DATE_CREATE'] = $params['dateCreate'];
126 }
127
128 $merge = $helper->prepareMerge(
129 static::getTableName(),
130 [ 'ITEM_TYPE', 'ITEM_ID' ],
131 $insertFields,
132 $updateFields
133 );
134
135 if ($merge[0] != '')
136 {
137 $connection->query($merge[0]);
138 }
139
140 return true;
141 }
142
143 public static function setLogUpdate($params = []): bool
144 {
145 $logId = (int)($params['logId'] ?? 0);
146 $value = (!empty($params['value']) ? $params['value'] : false);
147
148 if ($logId <= 0)
149 {
150 return false;
151 }
152
153 $connection = Application::getConnection();
154 $helper = $connection->getSqlHelper();
155
156 $now = $connection->getSqlHelper()->getCurrentDateTimeFunction();
157 if (
158 !$value
159 || mb_strtolower($value) == mb_strtolower($now)
160 )
161 {
162 $value = new SqlExpression($now);
163 }
164
165 $updateFields = [
166 "LOG_UPDATE" => $value,
167 ];
168
169 $tableName = self::getTableName();
170 list($prefix, $values) = $helper->prepareUpdate($tableName, $updateFields);
171 $connection->queryExecute("UPDATE {$tableName} SET {$prefix} WHERE LOG_ID = " . $logId);
172
173 return true;
174 }
175}
static getConnection($name="")
static setLogUpdate($params=[])
Definition logindex.php:143