1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
messageinternaldatehandler.php
См. документацию.
1<?php
2
4
11
13{
14 public static function getStartInternalDateForDir(
15 $mailboxId,
16 ?string $dirPath = null,
17 ?string $dirMd5 = null,
18 ): ?DateTime
19 {
20 $filter = [
21 '=MAILBOX_ID' => $mailboxId,
22 ];
23
24 if (!is_null($dirPath))
25 {
26 $filter['=PATH'] = Emoji::encode($dirPath);
27 }
28 else if (!is_null($dirMd5))
29 {
30 $filter['=DIR_MD5'] = $dirMd5;
31 }
32
33 $startInternalData =
34 MailboxDirectoryTable::query()
35 ->setSelect(['ID', 'INTERNAL_START_DATE', 'IS_DATE_CACHED'])
36 ->setFilter($filter)
37 ->setLimit(1)
38 ->fetch()
39 ;
40
41 if (empty($startInternalData['ID'] ?? null))
42 {
43 return null;
44 }
45
46 if (!$startInternalData['IS_DATE_CACHED'])
47 {
48 $firstSyncMessage = self::getFirstSyncMessageFromMailMessageTable((int)$mailboxId, $dirPath, $dirMd5) ?? [];
49 $startInternalData = array_merge($startInternalData, $firstSyncMessage);
50 self::setStartInternalDateForDir($startInternalData);
51 }
52
53 return $startInternalData['INTERNAL_START_DATE'] ?? null;
54 }
55
56 public static function setStartInternalDateForDir(
57 array $startInternalDate
58 ): void
59 {
60 MailboxDirectoryTable::update($startInternalDate['ID'], [
61 'INTERNAL_START_DATE' => $startInternalDate['INTERNAL_START_DATE'] ?? null,
62 'IS_DATE_CACHED' => true,
63 ]);
64 }
65
66 private static function getFirstSyncMessageFromMailMessageTable(
67 int $mailboxId,
68 ?string $dirPath,
69 ?string $dirMd5 = null,
70 ): ?array
71 {
72
73 if (is_null($dirMd5) && !is_null($dirPath))
74 {
75 $dirMd5 = md5(Emoji::encode($dirPath));
76 }
77
78 $filter = [
79 '=MESSAGE_UID.DELETE_TIME' => 0,
80 '!@MESSAGE_UID.IS_OLD' => MailMessageUidTable::EXCLUDED_COUNTER_STATUSES,
81 ];
82
83 $firstSyncMessage = MailMessageTable::getList(
84 [
85 'runtime' => [
87 'MESSAGE_UID', MailMessageUidTable::class, [
88 '=this.MAILBOX_ID' => 'ref.MAILBOX_ID',
89 '=this.ID' => 'ref.MESSAGE_ID',
90 ], [
91 'join_type' => 'INNER',
92 ]
93 ),
94 ],
95 'select' => [
96 'INTERNAL_START_DATE' => 'MESSAGE_UID.INTERNALDATE',
97 ],
98 'filter' => array_merge(
99 [
100 '=MAILBOX_ID' => $mailboxId,
101 '=MESSAGE_UID.DIR_MD5' => $dirMd5,
102 ],
103 $filter
104 ),
105 'order' => [
106 'FIELD_DATE' => 'ASC',
107 ],
108 'limit' => 1,
109 ]
110 )->fetchAll();
111
112 return $firstSyncMessage[0] ?? null;
113 }
114
115 public static function clearStartInternalDate(?int $mailboxId = null, ?string $dirMd5 = null): ORM\Data\UpdateResult
116 {
117 $filter['=IS_DATE_CACHED'] = true;
118 if ($mailboxId !== null)
119 {
120 $filter['=MAILBOX_ID'] = $mailboxId;
121
122 if($dirMd5 !== null)
123 {
124 $filter['=DIR_MD5'] = $dirMd5;
125 }
126 }
127
128 $directoryRows = MailboxDirectoryTable::getList([
129 'select' => ['ID'],
130 'filter' => $filter,
131 ]);
132
134 $ids = array_column($directoryRows->fetchAll(), 'ID');
135 if (empty($ids))
136 {
137 return $result;
138 }
139
140 return MailboxDirectoryTable::updateMulti(
141 $ids,
142 [
143 'IS_DATE_CACHED' => false,
144 'INTERNAL_START_DATE' => null,
145 ],
146 true
147 );
148 }
149}
static getStartInternalDateForDir( $mailboxId, ?string $dirPath=null, ?string $dirMd5=null,)
Определения messageinternaldatehandler.php:14
static clearStartInternalDate(?int $mailboxId=null, ?string $dirMd5=null)
Определения messageinternaldatehandler.php:115
static setStartInternalDateForDir(array $startInternalDate)
Определения messageinternaldatehandler.php:56
const EXCLUDED_COUNTER_STATUSES
Определения mailmessageuid.php:42
Определения emoji.php:10
</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
$filter
Определения iblock_catalog_list.php:54
Определения aliases.php:105