Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
syncrequest.php
1<?php
2
4
10use Bitrix\Main;
11use Exception;
12
14{
18 public static function onRequestSyncMail(Event $event): void
19 {
20 global $USER;
21 if (Loader::includeModule('mail') && is_object($USER) && $USER->IsAuthorized())
22 {
23 $userId = $USER->GetID();
24 $urgent = $event->getParameter('urgent');
25 if ($urgent || (new MailboxSyncManager($userId))->isMailNeedsToBeSynced())
26 {
27 Main\Application::getInstance()->addBackgroundJob(function () {
29 }, []);
30 }
31 }
32 }
33
38 public static function syncMail(): array
39 {
40 global $USER;
41 $result = [
42 'lastFailedToSyncMailboxId' => 0,
43 'hasSuccessSync' => false,
44 'unseen' => 0,
45 ];
46
47 if (Loader::includeModule('mail') && is_object($USER) && $USER->IsAuthorized())
48 {
49 $userId = $USER->GetID();
50 $mailboxesSyncManager = new MailboxSyncManager($userId);
51 $mailboxesReadyToSync = $mailboxesSyncManager->getNeedToBeSyncedMailboxes();
52
53 if (!empty($mailboxesReadyToSync))
54 {
55 foreach ($mailboxesReadyToSync as $mailboxId => $lastMailCheckData)
56 {
57 $mailboxHelper = Helper\Mailbox::createInstance($mailboxId, false);
58 if (!empty($mailboxHelper))
59 {
60 if ($mailboxHelper->sync() === false)
61 {
62 $result['lastFailedToSyncMailboxId'] = $mailboxId;
63 }
64 else
65 {
66 $result['hasSuccessSync'] = true;
67 }
68 if ($mailboxHelper->getMailbox()['SYNC_LOCK'] >= 0)
69 {
70 break;
71 }
72 }
73 }
74 $unseen = max(Helper\Message::getCountersForUserMailboxes($userId, true), 0);
75 $result['unseen'] = $unseen;
76 \CUserCounter::set($userId, 'mail_unseen', $unseen, SITE_ID);
77 }
78 }
79 return $result;
80 }
81
82}
static onRequestSyncMail(Event $event)
getParameter($key)
Definition event.php:80