1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
syncrequest.php
См. документацию.
1<?php
2
3namespace Bitrix\Mail\Integration;
4
5use Bitrix\Mail\Helper\Mailbox\MailboxSyncManager;
6use Bitrix\Main\Event;
7use Bitrix\Mail\Helper;
8use Bitrix\Main\LoaderException;
9use Bitrix\Main\Loader;
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}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static onRequestSyncMail(Event $event)
Определения syncrequest.php:18
static getInstance()
Определения application.php:98
Определения event.php:5
</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
global $USER
Определения csv_new_run.php:40
$event
Определения prolog_after.php:141
const SITE_ID
Определения sonet_set_content_view.php:12