Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
pushmanager.php
1
<?php
2
3
namespace
Bitrix\Calendar\Sync\Office365
;
4
5
use
Bitrix\Calendar\Core\Base\BaseException
;
6
use
Bitrix\Calendar\Core\Base\Date
;
7
use
Bitrix\Calendar\Sync\Connection\Connection
;
8
use
Bitrix\Calendar\Sync\Connection\SectionConnection
;
9
use
Bitrix\Calendar\Sync\Exceptions\ApiException
;
10
use
Bitrix\Calendar\Sync\Exceptions\AuthException
;
11
use
Bitrix\Calendar\Sync\Exceptions\ConflictException
;
12
use
Bitrix\Calendar\Sync\Exceptions\NotFoundException
;
13
use
Bitrix\Calendar\Sync\Exceptions\RemoteAccountException
;
14
use Bitrix\Calendar\Sync\Internals\HasContextTrait;
15
use
Bitrix\Calendar\Sync\Managers\PushManagerInterface
;
16
use
Bitrix\Calendar\Sync\Push\Push
;
17
use
Bitrix\Calendar\Sync\Util\Result
;
18
use
Bitrix\Main\ArgumentException
;
19
use
Bitrix\Main\ArgumentNullException
;
20
use
Bitrix\Main\Error
;
21
use
Bitrix\Main\LoaderException
;
22
use
Bitrix\Main\ObjectException
;
23
use
Bitrix\Main\Type\DateTime
;
24
use Exception;
25
26
class
PushManager
extends
AbstractManager
implements
PushManagerInterface
27
{
28
use HasContextTrait;
29
30
public
function
__construct
(
Office365Context
$context)
31
{
32
$this->context = $context;
33
parent::__construct($context->
getConnection
());
34
}
35
44
public
function
renewPush
(
Push
$pushChannel):
Result
45
{
46
$result =
new
Result
();
47
try
48
{
49
if
($data = $this->context->getVendorSyncService()->resubscribe($pushChannel->
getResourceId
()))
50
{
51
if
(empty($data[
'expirationDateTime'
]))
52
{
53
$time = time() + 70 * 60 * 60;
54
$data[
'expirationDateTime'
] = date(
'c'
, $time);
55
}
56
57
$pushChannel->
setExpireDate
(
new
Date
($this->convertToDateTime($data[
'expirationDateTime'
])));
58
$result->setData([
59
'CHANNEL_ID'
=> $pushChannel->
getChannelId
(),
60
'RESOURCE_ID'
=> $data[
'id'
],
61
'EXPIRES'
=> $this->convertToDateTime($data[
'expirationDateTime'
]),
62
]);
63
}
64
else
65
{
66
$result->addError(
new
Error
(
'Error of renew push channel'
));
67
}
68
}
69
catch
(
ApiException
$e)
70
{
71
$result->addError(
new
Error
(
'Error of MS Graph API'
, $e->getCode(), $e->getMessage()));
72
}
73
74
return
$result;
75
}
76
84
private
function
convertToDateTime(
string
$time):
DateTime
85
{
86
$phpDateTime = new \DateTime($time);
87
88
return
DateTime::createFromPhp
($phpDateTime);
89
}
90
98
public
function
addSectionPush
(
SectionConnection
$link):
Result
99
{
100
$result =
new
Result
();
101
try
102
{
103
$data = $this->context->getVendorSyncService()->subscribeSection($link);
104
105
if
($data && !empty($data[
'channelId'
]))
106
{
107
$result->setData([
108
'CHANNEL_ID'
=> $data[
'channelId'
],
109
'RESOURCE_ID'
=> $data[
'id'
],
110
'EXPIRES'
=> $this->convertToDateTime($data[
'expirationDateTime'
] ?? date(
'c'
)),
111
]);
112
}
113
else
114
{
115
$result->addError(
new
Error
(
'Error of create subscription.'
));
116
}
117
}
118
catch
(
ApiException
$e)
119
{
120
$result->addError(
new
Error
(
'Error of Push subscribing. Vendor returned error.'
, $e->getCode()));
121
}
122
catch
(
AuthException
$e)
123
{
124
$result->addError(
new
Error
(
'No authentication data'
, $e->getCode()));
125
}
126
127
return
$result;
128
}
129
145
public
function
deletePush
(
Push
$pushChannel):
Result
146
{
147
$result =
new
Result
();
148
149
try
150
{
151
if
($data = $this->context->getVendorSyncService()->unsubscribe($pushChannel->
getResourceId
()))
152
{
153
$result->setData($data);
154
}
155
156
return
$result;
157
}
158
catch
(
RemoteAccountException
|
AuthException
$exception)
159
{
160
return
$result;
161
}
162
}
163
179
public
function
clearAllSubscriptions
(): void
180
{
181
$apiResponse = $this->context->getApiClient()->get(
'subscriptions'
);
182
if
(!empty($apiResponse[
'value'
]))
183
{
184
foreach
($apiResponse[
'value'
] as $subscription)
185
{
186
$this->context->getApiClient()->delete(
'subscriptions/'
. $subscription[
'id'
]);
187
}
188
}
189
}
190
196
public
function
addConnectionPush
(
Connection
$connection
):
Result
197
{
198
return
(
new
Result
())->
addError
(
new
Error
(
'Connection push unavailable for this service'
, 503));
199
}
200
}
Bitrix\Bizproc\Error
Definition
error.php:8
Bitrix\Calendar\Core\Base\BaseException
Definition
baseexception.php:8
Bitrix\Calendar\Core\Base\Date
Definition
date.php:10
Bitrix\Calendar\Sync\Connection\Connection
Definition
connection.php:13
Bitrix\Calendar\Sync\Connection\SectionConnection
Definition
sectionconnection.php:16
Bitrix\Calendar\Sync\Exceptions\ApiException
Definition
apiexception.php:6
Bitrix\Calendar\Sync\Exceptions\AuthException
Definition
authexception.php:6
Bitrix\Calendar\Sync\Exceptions\ConflictException
Definition
conflictexception.php:6
Bitrix\Calendar\Sync\Exceptions\NotFoundException
Definition
notfoundexception.php:6
Bitrix\Calendar\Sync\Exceptions\RemoteAccountException
Definition
remoteaccountexception.php:6
Bitrix\Calendar\Sync\Managers\ServiceBase\$connection
Connection $connection
Definition
servicebase.php:13
Bitrix\Calendar\Sync\Office365\AbstractManager
Definition
abstractmanager.php:9
Bitrix\Calendar\Sync\Office365\Office365Context
Definition
office365context.php:28
Bitrix\Calendar\Sync\Office365\Office365Context\getConnection
getConnection()
Definition
office365context.php:171
Bitrix\Calendar\Sync\Office365\PushManager
Definition
pushmanager.php:27
Bitrix\Calendar\Sync\Office365\PushManager\__construct
__construct(Office365Context $context)
Definition
pushmanager.php:30
Bitrix\Calendar\Sync\Office365\PushManager\renewPush
renewPush(Push $pushChannel)
Definition
pushmanager.php:44
Bitrix\Calendar\Sync\Office365\PushManager\addSectionPush
addSectionPush(SectionConnection $link)
Definition
pushmanager.php:98
Bitrix\Calendar\Sync\Office365\PushManager\addConnectionPush
addConnectionPush(Connection $connection)
Definition
pushmanager.php:196
Bitrix\Calendar\Sync\Office365\PushManager\clearAllSubscriptions
clearAllSubscriptions()
Definition
pushmanager.php:179
Bitrix\Calendar\Sync\Office365\PushManager\deletePush
deletePush(Push $pushChannel)
Definition
pushmanager.php:145
Bitrix\Calendar\Sync\Push\Push
Definition
push.php:9
Bitrix\Calendar\Sync\Push\Push\getResourceId
getResourceId()
Definition
push.php:96
Bitrix\Calendar\Sync\Push\Push\getChannelId
getChannelId()
Definition
push.php:78
Bitrix\Calendar\Sync\Push\Push\setExpireDate
setExpireDate(Date $expireDate)
Definition
push.php:123
Bitrix\Calendar\Sync\Util\Result
Definition
result.php:6
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\ArgumentNullException
Definition
exception.php:54
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\LoaderException
Definition
loader.php:582
Bitrix\Main\ObjectException
Definition
exception.php:192
Bitrix\Main\Result\addError
addError(Error $error)
Definition
result.php:50
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Main\Type\DateTime\createFromPhp
static createFromPhp(\DateTime $datetime)
Definition
datetime.php:232
Bitrix\Calendar\Sync\Managers\PushManagerInterface
Definition
pushmanagerinterface.php:11
Bitrix\Calendar\Sync\Office365
Definition
abstractmanager.php:3
modules
calendar
lib
sync
office365
pushmanager.php
Создано системой
1.10.0