1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
groupqueueservice.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Sender\Service;
4
5
use Bitrix\Main\ArgumentException;
6
use Bitrix\Main\Type\DateTime;
7
use Bitrix\Sender\GroupTable;
8
use Bitrix\Sender\Internals\Model\GroupQueueTable;
9
use Bitrix\Sender\Posting\Locker;
10
11
class
GroupQueueService
implements
GroupQueueServiceInterface
12
{
13
private
const
LOCK_KEY =
'group_queue'
;
14
private
const
LIFETIME = 9800;
15
23
public
function
addToDB
(
int
$type
,
int
$entityId
,
int
$groupId)
24
{
25
if
(!in_array(
$type
,
GroupQueueTable::TYPE
))
26
{
27
return
;
28
}
29
if
(!Locker::lock(self::LOCK_KEY,
$entityId
))
30
{
31
return
;
32
}
33
34
$current = $this->getCurrentRow(
$type
,
$entityId
, $groupId);
35
if
(isset($current[
'ID'
]) || isset($current[0][
'ID'
]))
36
{
37
Locker::unlock(self::LOCK_KEY,
$entityId
);
38
return
;
39
}
40
41
GroupQueueTable::add([
42
'TYPE'
=>
$type
,
43
'ENTITY_ID'
=>
$entityId
,
44
'GROUP_ID'
=> $groupId,
45
'DATE_INSERT'
=> (
new
DateTime
())->disableUserTime(),
46
]);
47
48
Locker::unlock(self::LOCK_KEY,
$entityId
);
49
}
50
58
public
function
releaseGroup
(
int
$type
,
int
$entityId
,
int
$groupId)
59
{
60
$current = $this->getCurrentRow(
$type
,
$entityId
, $groupId)[0];
61
if
(!isset($current[
'ID'
]))
62
{
63
return
;
64
}
65
66
GroupQueueTable::delete($current[
'ID'
]);
67
68
$this->
isReleased
($groupId);
69
}
70
79
public
function
isReleased
(
int
$groupId): bool
80
{
81
$dateTime = (
new
DateTime
())
82
->disableUserTime()
83
->getTimestamp();
84
85
$entitiesToDelete = GroupQueueTable::getList([
86
'select'
=> [
'ID'
,
'DATE_INSERT'
],
87
'filter'
=> [
88
'GROUP_ID'
=> $groupId,
89
[
90
'LOGIC'
=>
'OR'
,
91
[
'DATE_INSERT'
=>
false
],
92
[
'<DATE_INSERT'
=> DateTime::createFromTimestamp($dateTime - self::LIFETIME)],
93
],
94
],
95
])->fetchAll();
96
97
foreach
($entitiesToDelete as
$entity
)
98
{
99
try
100
{
101
GroupQueueTable::delete(
$entity
[
'ID'
]);
102
}
103
catch
(\
Exception
$e)
104
{}
105
}
106
107
$remainingRecords = GroupQueueTable::query()
108
->setSelect([
'ID'
])
109
->where(
'GROUP_ID'
, $groupId)
110
->exec()
111
->fetch()
112
;
113
114
if
(!$remainingRecords)
115
{
116
GroupTable::update
(
117
$groupId,
118
[
119
'fields'
=> [
'STATUS'
=>
GroupTable::STATUS_DONE
],
120
],
121
);
122
}
123
124
return
!$remainingRecords;
125
}
126
127
private
function
getCurrentRow(
int
$type
,
int
$entityId
,
int
$groupId):
array
128
{
129
return
GroupQueueTable::query()
130
->setSelect([
'ID'
])
131
->where(
'TYPE'
,
$type
)
132
->where(
'ENTITY_ID'
,
$entityId
)
133
->where(
'GROUP_ID'
, $groupId)
134
->exec()
135
->fetchAll();
136
}
137
138
public
function
isEntityProcessed
(
int
$type
,
int
$entityId
)
139
{
140
return
GroupQueueTable::query()
141
->setSelect([
142
'ID'
,
143
'DATE_INSERT'
,
144
])
145
->where(
'ENTITY_ID'
,
$entityId
)
146
->where(
'TYPE'
,
$type
)
147
->exec()
148
->fetch();
149
}
150
}
$type
$type
Определения
options.php:106
Bitrix\Main\ORM\Data\DataManager\update
static update($primary, array $data)
Определения
datamanager.php:1256
Bitrix\Main\Type\DateTime
Определения
datetime.php:9
Bitrix\Sender\GroupTable\STATUS_DONE
const STATUS_DONE
Определения
group.php:26
Bitrix\Sender\Internals\Model\GroupQueueTable\TYPE
const TYPE
Определения
groupqueue.php:33
Bitrix\Sender\Service\GroupQueueService
Определения
groupqueueservice.php:12
Bitrix\Sender\Service\GroupQueueService\isReleased
isReleased(int $groupId)
Определения
groupqueueservice.php:79
Bitrix\Sender\Service\GroupQueueService\releaseGroup
releaseGroup(int $type, int $entityId, int $groupId)
Определения
groupqueueservice.php:58
Bitrix\Sender\Service\GroupQueueService\addToDB
addToDB(int $type, int $entityId, int $groupId)
Определения
groupqueueservice.php:23
Bitrix\Sender\Service\GroupQueueService\isEntityProcessed
isEntityProcessed(int $type, int $entityId)
Определения
groupqueueservice.php:138
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$entity
$entity
Определения
group_bizproc_workflow_delete.php:17
Bitrix\Sender\Service\GroupQueueServiceInterface
Определения
groupqueueserviceinterface.php:6
Bitrix\Main\DI\Exception
Определения
circulardependencyexception.php:3
$entityId
$entityId
Определения
payment.php:4
bitrix
modules
sender
lib
service
groupqueueservice.php
Создано системой
1.14.0