Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
messageclosurestepper.php
1<?php
2
3namespace Bitrix\Mail\Helper;
4
8
10{
11 protected static $moduleId = 'mail';
12
13 public function execute(array &$option)
14 {
15 global $DB, $pPERIOD;
16
17 $pPERIOD = 10;
18
19 $option['count'] = Mail\MailMessageTable::getCount();
20 $option['steps'] = Mail\Internals\MessageClosureTable::getList(array(
21 'select' => array(
22 new Main\Entity\ExpressionField('CNT', 'COUNT(DISTINCT %s)', 'MESSAGE_ID')
23 ),
24 ))->fetch()['CNT'];
25
26 if ($option['steps'] < $option['count'])
27 {
28 if (!($option['mailboxId'] > 0) || $option['stage'] < 1)
29 {
30 $option['mailboxId'] = $DB->query(
31 'SELECT MAILBOX_ID FROM b_mail_message M WHERE NOT EXISTS (
32 SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = M.ID
33 ) LIMIT 1'
34 )->fetch()['MAILBOX_ID'];
35
36 $option['stage'] = 1;
37 }
38 }
39 else
40 {
41 $option['mailboxId'] = false;
42
43 $option['stage'] = 3;
44 }
45
46 if ($option['mailboxId'] > 0 && 1 == $option['stage'])
47 {
49 'SELECT M.ID, M.ID FROM b_mail_message M
50 WHERE M.MAILBOX_ID = %u AND (
51 M.IN_REPLY_TO IS NULL OR M.IN_REPLY_TO = \'\' OR M.IN_REPLY_TO = M.MSG_ID OR NOT EXISTS (
52 SELECT 1 FROM b_mail_message WHERE MAILBOX_ID = M.MAILBOX_ID AND MSG_ID = M.IN_REPLY_TO
53 )
54 ) AND NOT EXISTS (SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = M.ID)
55 LIMIT 40000',
56 (int)$option['mailboxId']
57 ));
58
59 $option['stage'] = $res < 40000 ? 2 : 1;
60 $option['steps'] += $res;
61
63 }
64
65 if ($option['mailboxId'] > 0 && 2 == $option['stage'])
66 {
68 'SELECT DISTINCT M.ID, C.PARENT_ID
69 FROM b_mail_message M
70 LEFT JOIN b_mail_message R ON M.MAILBOX_ID = R.MAILBOX_ID AND M.IN_REPLY_TO = R.MSG_ID
71 LEFT JOIN b_mail_message_closure C ON R.ID = C.MESSAGE_ID
72 WHERE M.MAILBOX_ID = %u
73 AND EXISTS (SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = R.ID)
74 AND NOT EXISTS (SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = M.ID)',
75 (int)$option['mailboxId']
76 ));
77
78 $option['stage'] = $res > 0 ? 3 : 4;
79
81 }
82
83 if (3 == $option['stage'])
84 {
86 'SELECT DISTINCT C.MESSAGE_ID, C.MESSAGE_ID
87 FROM b_mail_message_closure C
88 WHERE NOT EXISTS (SELECT 1 FROM b_mail_message_closure WHERE PARENT_ID = C.MESSAGE_ID)'
89 );
90
91 $option['stage'] = $res > 0 ? 2 : 4;
92 }
93
94 if (4 == $option['stage'])
95 {
97 'SELECT M.ID, M.ID FROM b_mail_message M
98 WHERE M.MAILBOX_ID = %u
99 AND NOT EXISTS (SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = M.ID)
100 ORDER BY FIELD_DATE ASC LIMIT 1',
101 (int)$option['mailboxId']
102 ));
103
104 $option['stage'] = $res > 0 ? 2 : 0;
105 }
106
107 return $option['mailboxId'] > 0 ? self::CONTINUE_EXECUTION : self::FINISH_EXECUTION;
108 }
109
110}
static insertIgnoreFromSelect(string $fromSelect)