1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
chatindex.php
См. документацию.
1<?php
2namespace Bitrix\Im\Model;
3
4use Bitrix\Main,
5 Bitrix\Main\Application,
6 Bitrix\Main\Entity,
7 Bitrix\Main\Error,
8 Bitrix\Main\DB\SqlExpression
9;
10
11
36
37class ChatIndexTable extends Main\Entity\DataManager
38{
39 use Main\ORM\Data\Internal\DeleteByFilterTrait;
40
46 public static function getTableName()
47 {
48 return 'b_im_chat_index';
49 }
50
56 public static function getMap()
57 {
58 return array(
59 'CHAT_ID' => array(
60 'data_type' => 'integer',
61 'primary' => true,
62 ),
63 'SEARCH_TITLE' => array(
64 'data_type' => 'string',
65 'validation' => array(__CLASS__, 'validateTitle'),
66 ),
67 'SEARCH_CONTENT' => array(
68 'data_type' => 'text',
69 ),
70 );
71 }
72
73 public static function validateTitle()
74 {
75 return array(
76 new Entity\Validator\Length(null, 255),
77 );
78 }
79
80 protected static function getMergeFields()
81 {
82 return array('CHAT_ID');
83 }
84
85 public static function merge(array $data)
86 {
87 $result = new Entity\AddResult();
88
89 $helper = Application::getConnection()->getSqlHelper();
90 $insertData = $data;
91 $updateData = $data;
92 $mergeFields = static::getMergeFields();
93
94 foreach ($mergeFields as $field)
95 {
96 unset($updateData[$field]);
97 }
98
99 $versionMain = \Bitrix\Main\ModuleManager::getVersion('main');
100 $isPgCompatible = (version_compare($versionMain, '24.0.0') >= 0);//todo: Remove it in future version
101
102 if (isset($updateData['SEARCH_CONTENT']))
103 {
104 if ($isPgCompatible)
105 {
106 $field = new SqlExpression('?v', 'SEARCH_CONTENT');
107 }
108 else
109 {
110 $field = 'SEARCH_CONTENT';
111 }
112 $updateData['SEARCH_CONTENT'] = new SqlExpression($helper->getConditionalAssignment($field, $updateData['SEARCH_CONTENT']));
113 }
114
115 if (isset($updateData['SEARCH_TITLE']))
116 {
117 if ($isPgCompatible)
118 {
119 $field = new SqlExpression('?v', 'SEARCH_TITLE');
120 }
121 else
122 {
123 $field = 'SEARCH_TITLE';
124 }
125 $updateData['SEARCH_TITLE'] = new SqlExpression($helper->getConditionalAssignment($field, $updateData['SEARCH_TITLE']));
126 }
127
128 $merge = $helper->prepareMerge(
129 static::getTableName(),
130 static::getMergeFields(),
131 $insertData,
132 $updateData
133 );
134
135 if ($merge[0] != "")
136 {
137 Application::getConnection()->query($merge[0]);
138 $id = Application::getConnection()->getInsertedId();
139 $result->setId($id);
140 $result->setData($data);
141 }
142 else
143 {
144 $result->addError(new Error('Error constructing query'));
145 }
146
147 return $result;
148 }
149
150 public static function updateIndex($id, $primaryField, array $updateData): Main\ORM\Data\UpdateResult
151 {
153 $helper = Application::getConnection()->getSqlHelper();
154
155 if (isset($updateData[$primaryField]))
156 {
157 unset($updateData[$primaryField]);
158 }
159
160 if (isset($updateData['SEARCH_CONTENT']))
161 {
162 $updateData['SEARCH_CONTENT'] = new SqlExpression($helper->getConditionalAssignment('SEARCH_CONTENT', $updateData['SEARCH_CONTENT']));
163 }
164
165 if (isset($updateData['SEARCH_TITLE']))
166 {
167 $updateData['SEARCH_TITLE'] = new SqlExpression($helper->getConditionalAssignment('SEARCH_TITLE', $updateData['SEARCH_TITLE']));
168 }
169
170 $update = $helper->prepareUpdate(
171 static::getTableName(),
172 $updateData
173 );
174
175 if ($update[0] !== '')
176 {
177 $sql = "UPDATE " . static::getTableName() . " SET " . $update[0] . " WHERE " . $primaryField . " = " . $id;
178 self::safeUpdateIndex($sql);
179 }
180
181 return $result;
182 }
183
184 private static function safeUpdateIndex(string $sql): void
185 {
186 try
187 {
188 Application::getConnection()->query($sql);
189 }
190 catch (Main\DB\SqlQueryException $exception)
191 {
192 if (str_starts_with($exception->getMessage(), "Mysql query error: (1022) Can't write;"))
193 {
194 Application::getConnection()->query($sql);
195
196 return;
197 }
198
199 throw $exception;
200 }
201 }
202}
static getMap()
Определения chatindex.php:56
static getMergeFields()
Определения chatindex.php:80
static validateTitle()
Определения chatindex.php:73
static updateIndex($id, $primaryField, array $updateData)
Определения chatindex.php:150
static merge(array $data)
Определения chatindex.php:85
static getTableName()
Определения chatindex.php:46
Определения error.php:15
static getVersion($moduleName)
Определения modulemanager.php:89
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
Определения arrayresult.php:2
Определения aliases.php:105
Определения ufield.php:9