1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mailboxdirectory.php
См. документацию.
1<?php
2
3namespace Bitrix\Mail;
4
5use Bitrix\Mail\Helper\Mailbox;
6use Bitrix\Mail\Internals\MailboxDirectoryTable;
7use Bitrix\Main\Entity\ExpressionField;
8use Bitrix\Main\Entity\Query;
9use Bitrix\Main\Result;
10
12{
13 public static function fetchAllDirsTypes($mailboxId)
14 {
16 'filter' => [
17 'LOGIC' => 'AND',
18 '=MAILBOX_ID' => $mailboxId,
19 [
20 'LOGIC' => 'OR',
21 '=IS_OUTCOME' => MailboxDirectoryTable::ACTIVE,
22 '=IS_TRASH' => MailboxDirectoryTable::ACTIVE,
24 ]
25 ],
26 'select' => ['*'],
27 'order' => ['LEVEL' => 'ASC']
28 ])->fetchCollection();
29 }
30
31 public static function fetchOneLevelByParentId($mailboxId, $id, $level)
32 {
34 'filter' => [
35 'LOGIC' => 'AND',
36 '=MAILBOX_ID' => $mailboxId,
37 '=PARENT_ID' => $id,
38 '=LEVEL' => $level,
39 ],
40 'select' => ['*']
41 ]);
42
43 $result = [];
44
45 while ($row = $query->fetchObject())
46 {
47 $result[$row->getPath()] = $row;
48 }
49
50 return $result;
51 }
52
53 public static function fetchAllLevelByParentId($mailboxId, $path, $level)
54 {
56 'filter' => [
57 'LOGIC' => 'AND',
58 '=MAILBOX_ID' => $mailboxId,
59 '%=PATH' => $path,
60 '>=LEVEL' => $level,
61 ],
62 'select' => ['*'],
63 'order' => ['LEVEL' => 'ASC']
64 ]);
65
66 $result = [];
67
68 while ($row = $query->fetchObject())
69 {
70 $result[$row->getPath()] = $row;
71 }
72
73 return $result;
74 }
75
76 public static function fetchOneByMailboxIdAndHash($mailboxId, $hash)
77 {
79 'filter' => [
80 '=MAILBOX_ID' => $mailboxId,
81 '=DIR_MD5' => $hash
82 ]
83 ])->fetchObject();
84 }
85
86 public static function fetchOneOutcome($mailboxId)
87 {
89 'filter' => [
90 '=MAILBOX_ID' => $mailboxId,
91 '=IS_OUTCOME' => MailboxDirectoryTable::ACTIVE
92 ]
93 ])->fetchObject();
94 }
95
96 public static function fetchTrashAndSpamHash($mailboxId)
97 {
99 'filter' => [
100 'LOGIC' => 'AND',
101 '=MAILBOX_ID' => $mailboxId,
102 [
103 'LOGIC' => 'OR',
104 '=IS_TRASH' => MailboxDirectoryTable::ACTIVE,
105 '=IS_SPAM' => MailboxDirectoryTable::ACTIVE,
106 ]
107 ]
108 ]);
109
110 $result = [];
111
112 while ($row = $query->fetch())
113 {
114 $result[] = $row['DIR_MD5'];
115 }
116
117 return $result;
118 }
119
120 public static function fetchOneById($id)
121 {
123 'filter' => [
124 '=ID' => $id
125 ]
126 ])->fetchObject();
127 }
128
129 public static function fetchOneByHash($mailboxId, $hash)
130 {
132 'filter' => [
133 '=MAILBOX_ID' => $mailboxId,
134 '=DIR_MD5' => $hash
135 ]
136 ])->fetchObject();
137 }
138
139 public static function updateSync($id, $val)
140 {
142 $id,
143 [
144 'IS_SYNC' => $val
145 ]
146 );
147 }
148
149 public static function resetDirsTypes($mailboxId, $type)
150 {
152 $connection = $entity->getConnection();
153
154 $query = sprintf(
155 'UPDATE %s SET %s WHERE %s',
156 $connection->getSqlHelper()->quote($entity->getDbTableName()),
157 $connection->getSqlHelper()->prepareUpdate($entity->getDbTableName(), [
159 ])[0],
160 Query::buildFilterSql(
161 $entity,
162 [
163 'MAILBOX_ID' => $mailboxId,
165 ]
166 )
167 );
168
169 return $connection->query($query);
170 }
171
172 public static function update($id, $data)
173 {
175 }
176
177 public static function add(array $data)
178 {
180 }
181
182 public static function addMulti($rows, $ignoreEvents = false)
183 {
184 return MailboxDirectoryTable::addMulti($rows, $ignoreEvents);
185 }
186
187 public static function deleteList(array $filter)
188 {
190 $connection = $entity->getConnection();
191
192 return $connection->query(sprintf(
193 'DELETE FROM %s WHERE %s',
194 $connection->getSqlHelper()->quote($entity->getDbTableName()),
195 Query::buildFilterSql($entity, $filter)
196 ));
197 }
198
199 public static function updateSyncDirs(array $values, $val, $mailboxId)
200 {
202 $connection = $entity->getConnection();
203
204 $totalValues = count($values);
205 $batchSize = 100;
206 $offset = 0;
207
208 while ($offset < $totalValues)
209 {
210 $batchValues = array_slice($values, $offset, $batchSize);
211 $offset += $batchSize;
212
213 $result = $connection->query(sprintf(
214 "UPDATE %s SET %s WHERE %s",
215 $connection->getSqlHelper()->quote($entity->getDbTableName()),
216 $connection->getSqlHelper()->prepareUpdate($entity->getDbTableName(), [
217 'IS_SYNC' => $val,
218 ])[0],
219 Query::buildFilterSql(
220 $entity,
221 [
222 '=MAILBOX_ID' => $mailboxId,
223 '@DIR_MD5' => $batchValues,
224 'IS_DISABLED' => MailboxDirectoryTable::INACTIVE,
225 ]
226 )
227 ));
228 }
229
230 return $result ?? new Result();
231 }
232
233 public static function fetchAll(int $mailboxId)
234 {
235 static $mailboxDirs = [];
236
237 if (!isset($mailboxDirs[$mailboxId]))
238 {
240 'filter' => [
241 '=MAILBOX_ID' => $mailboxId
242 ],
243 'select' => ['*'],
244 /*
245 When assembling directories, we look for their parents.
246 Sorting ensures that for a directories that parents are processed first,
247 and for children, matching parents are always found from those processed.
248 */
249 'order' => ['LEVEL' => 'ASC']
250 ]);
251
252 $result = [];
253
254 while ($row = $query->fetchObject())
255 {
256 $result[$row->getPath()] = $row;
257 }
258
259 $mailboxDirs[$mailboxId] = $result;
260 }
261
262 return $mailboxDirs[$mailboxId];
263 }
264
265 public static function fetchAllSyncDirs($mailboxId)
266 {
268 'filter' => [
269 '=MAILBOX_ID' => $mailboxId,
270 '=IS_SYNC' => MailboxDirectoryTable::ACTIVE,
271 '=IS_DISABLED' => MailboxDirectoryTable::INACTIVE
272 ],
273 'select' => ['*'],
274 'order' => ['LEVEL' => 'ASC']
275 ])->fetchCollection();
276 }
277
278 public static function fetchAllDisabledDirs($mailboxId)
279 {
281 'filter' => [
282 '=MAILBOX_ID' => $mailboxId,
283 '=IS_DISABLED' => MailboxDirectoryTable::ACTIVE
284 ],
285 'select' => ['*'],
286 'order' => ['ID' => 'ASC']
287 ])->fetchCollection();
288 }
289
290 public static function countMessagesSyncDirs($mailboxId)
291 {
293 'filter' => [
294 '=MAILBOX_ID' => $mailboxId,
295 '=IS_SYNC' => MailboxDirectoryTable::ACTIVE,
296 '=IS_DISABLED' => MailboxDirectoryTable::INACTIVE
297 ],
298 'select' => ['CNT'],
299 'runtime' => [
300 new ExpressionField('CNT', 'SUM(%s)', 'MESSAGE_COUNT'),
301 ]
302 ])->fetch();
303
304 return (int)$counter['CNT'];
305 }
306
307 public static function getMinSyncTime($mailboxId)
308 {
310 'filter' => [
311 '=MAILBOX_ID' => $mailboxId,
312 '=IS_SYNC' => MailboxDirectoryTable::ACTIVE,
313 ],
314 'select' => ['MIN_SYNC_TIME'],
315 'runtime' => [
316 new ExpressionField('MIN_SYNC_TIME', 'MIN(COALESCE(%s, 0))', 'SYNC_TIME'),
317 ]
318 ])->fetch();
319
320 return (int)$res['MIN_SYNC_TIME'];
321 }
322
323 public static function countSyncDirs($mailboxId)
324 {
326 'filter' => [
327 '=MAILBOX_ID' => $mailboxId,
328 '=IS_SYNC' => MailboxDirectoryTable::ACTIVE,
329 '=IS_DISABLED' => MailboxDirectoryTable::INACTIVE
330 ],
331 'select' => ['CNT'],
332 'runtime' => [
333 new ExpressionField('CNT', 'COUNT(*)'),
334 ]
335 ])->fetch();
336
337 return (int)$counter['CNT'];
338 }
339
340 public static function updateMessageCount($id, $val)
341 {
343 $id,
344 [
345 'MESSAGE_COUNT' => $val
346 ]
347 );
348 }
349
350 public static function updateFlags($id, $flags)
351 {
353 $id,
354 [
355 'FLAGS' => $flags
356 ]
357 );
358 }
359
360 public static function updateSyncTime($id, $val)
361 {
363 $id,
364 [
365 'SYNC_TIME' => $val
366 ]
367 );
368 }
369
370 public static function setSyncLock(int $id, int $time)
371 {
373 $connection = $entity->getConnection();
374
375 $query = sprintf(
376 "UPDATE %s SET %s WHERE %s",
377 $connection->getSqlHelper()->quote($entity->getDbTableName()),
378 $connection->getSqlHelper()->prepareUpdate($entity->getDbTableName(), [
379 'SYNC_LOCK' => $time,
380 ])[0],
381 Query::buildFilterSql(
382 $entity,
383 [
384 '=ID' => $id,
385 [
386 'LOGIC' => 'OR',
387 '=SYNC_LOCK' => 'IS NULL',
388 '<SYNC_LOCK' => time() - Mailbox::getTimeout(),
389 ]
390 ]
391 )
392 );
393
394 $connection->query($query);
395 $count = $connection->getAffectedRowsCount();
396
397 return $count;
398 }
399}
$path
Определения access_edit.php:21
$connection
Определения actionsdefinitions.php:38
$count
Определения admin_tab.php:4
$hash
Определения ajax_redirector.php:8
$type
Определения options.php:106
static fetchOneOutcome($mailboxId)
Определения mailboxdirectory.php:86
static fetchAllLevelByParentId($mailboxId, $path, $level)
Определения mailboxdirectory.php:53
static fetchAll(int $mailboxId)
Определения mailboxdirectory.php:233
static getMinSyncTime($mailboxId)
Определения mailboxdirectory.php:307
static deleteList(array $filter)
Определения mailboxdirectory.php:187
static fetchTrashAndSpamHash($mailboxId)
Определения mailboxdirectory.php:96
static updateSync($id, $val)
Определения mailboxdirectory.php:139
static fetchOneByHash($mailboxId, $hash)
Определения mailboxdirectory.php:129
static resetDirsTypes($mailboxId, $type)
Определения mailboxdirectory.php:149
static updateMessageCount($id, $val)
Определения mailboxdirectory.php:340
static updateFlags($id, $flags)
Определения mailboxdirectory.php:350
static addMulti($rows, $ignoreEvents=false)
Определения mailboxdirectory.php:182
static fetchAllDisabledDirs($mailboxId)
Определения mailboxdirectory.php:278
static countMessagesSyncDirs($mailboxId)
Определения mailboxdirectory.php:290
static fetchAllSyncDirs($mailboxId)
Определения mailboxdirectory.php:265
static fetchOneLevelByParentId($mailboxId, $id, $level)
Определения mailboxdirectory.php:31
static fetchAllDirsTypes($mailboxId)
Определения mailboxdirectory.php:13
static add(array $data)
Определения mailboxdirectory.php:177
static updateSyncDirs(array $values, $val, $mailboxId)
Определения mailboxdirectory.php:199
static setSyncLock(int $id, int $time)
Определения mailboxdirectory.php:370
static countSyncDirs($mailboxId)
Определения mailboxdirectory.php:323
static fetchOneById($id)
Определения mailboxdirectory.php:120
static updateSyncTime($id, $val)
Определения mailboxdirectory.php:360
static update($id, $data)
Определения mailboxdirectory.php:172
static fetchOneByMailboxIdAndHash($mailboxId, $hash)
Определения mailboxdirectory.php:76
Определения result.php:20
static getEntity()
Определения datamanager.php:65
static getList(array $parameters=array())
Определения datamanager.php:431
static addMulti($rows, $ignoreEvents=false)
Определения datamanager.php:1041
static add(array $data)
Определения datamanager.php:877
static update($primary, array $data)
Определения datamanager.php:1256
$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
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$entity
$filter
Определения iblock_catalog_list.php:54
$time
Определения payment.php:61
$counter
Определения options.php:5
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$val
Определения options.php:1793
$rows
Определения options.php:264