Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
senderjob.php
1<?php
10
13
18class SenderJob extends Job
19{
21 protected $letterId;
22
24 protected $campaignId;
25
32 public function withCampaignId($campaignId)
33 {
34 $this->campaignId = $campaignId;
35 return $this;
36 }
37
44 public function withLetterId($letterId)
45 {
46 $this->letterId = $letterId;
47 return $this;
48 }
49
55 public function actualize()
56 {
57 $filter = [];
58 if ($this->campaignId)
59 {
60 $filter['=CAMPAIGN_ID'] = $this->campaignId;
61 }
62 if ($this->letterId)
63 {
64 $filter['=ID'] = $this->letterId;
65 }
66
67 $list = LetterTable::getList(array(
68 'select' => ['ID', 'POSTING_ID', 'STATUS', 'AUTO_SEND_TIME', 'CAMPAIGN_ACTIVE' => 'CAMPAIGN.ACTIVE'],
69 'filter' => $filter
70 ));
71
72 $data = [];
73
74 foreach ($list as $row)
75 {
76 $data[] = $row;
77 }
78
79 foreach ($data as $row)
80 {
81 $agentName = static::getAgentName($row['ID']);
82 if (!$agentName)
83 {
84 continue;
85 }
86
87 self::removeAgent($agentName);
88
90 {
91 continue;
92 }
93
94 if (empty($row['AUTO_SEND_TIME']))
95 {
96 continue;
97 }
98
99 if ($row['CAMPAIGN_ACTIVE'] !== 'Y')
100 {
101 continue;
102 }
103
104 $allowedStatuses = [LetterTable::STATUS_SEND, LetterTable::STATUS_PLAN];
105 if (!in_array($row['STATUS'], $allowedStatuses))
106 {
107 continue;
108 }
109
110 $interval = Option::get('sender', 'auto_agent_interval');
111 self::addAgent($agentName, $interval, $row['AUTO_SEND_TIME']);
112 }
113
114 return $this;
115 }
116
125 public static function getAgentName($letterId, $threadId = false)
126 {
127 $letterId = (int) $letterId;
128 if (!$letterId)
129 {
130 return '';
131 }
132
133 return '\Bitrix\Sender\MailingManager::chainSend('. $letterId. ');';
134 }
135}
static isSenderJobCron()
Definition env.php:28
addAgent($agentName, $interval=60, $nextDateExec='')
Definition job.php:50
removeAgent($agentName)
Definition job.php:69
static getAgentName($letterId, $threadId=false)