9namespace Bitrix\Sender\Internals;
11use Bitrix\Main\Application;
12use Bitrix\Main\Config\Option;
13use Bitrix\Sender\Runtime;
14use Bitrix\Sender\Internals\Model;
18 private static $optionName =
'~update_counters_16';
20 private static $startTime =
null;
21 private static $stages =
array(
22 'RECIPIENT_READ' =>
'1',
23 'RECIPIENT_CLICK' =>
'2',
24 'RECIPIENT_UNSUB' =>
'3',
25 'POSTING_STATUS' =>
'4',
26 'POSTING_READ' =>
'5',
27 'POSTING_CLICK' =>
'6',
28 'POSTING_UNSUB' =>
'7',
29 'MAILING_SUBSCRIPTION' =>
'8',
30 'CONTACT_EMAIL_REGISTER' =>
'9',
36 $currentValue = Option::get(
'sender', self::$optionName,
'');
37 $stageValue = self::$stages[$stageCode];
39 if($currentValue ===
'')
41 $currentValue =
'100';
43 if($stageValue ===
'')
48 if(intval($currentValue) >= intval($stageValue))
60 Option::set(
'sender', self::$optionName, self::$stages[$stageCode]);
65 $currentValue = Option::get(
'sender', self::$optionName,
'');
66 if($currentValue ===
'')
68 $currentValue =
count(self::$stages);
70 $currentValue = intval($currentValue);
72 return array(
'CURRENT' => $currentValue,
'ALL' =>
count(self::$stages));
75 private static function isTimeUp()
77 if(self::$startTime ===
null)
79 self::$startTime = microtime(
true);
82 if(self::$maxExecutionTime > 0 && (microtime(
true) - self::$startTime) > self::$maxExecutionTime)
100 return microtime(
true) - self::$startTime;
106 if(self::wasCompleted())
114 foreach(
array(
'READ',
'CLICK',
'UNSUB') as
$type)
116 if($haveData || self::wasCompleted(
'RECIPIENT_' .
$type))
129 if(!$haveData && !self::wasCompleted(
'POSTING_STATUS'))
139 foreach(
array(
'READ',
'CLICK',
'UNSUB') as
$type)
141 if($haveData || self::wasCompleted(
'POSTING_' .
$type))
154 if(!$haveData && !self::wasCompleted(
'MAILING_SUBSCRIPTION'))
164 if(!$haveData && !self::wasCompleted(
'CONTACT_EMAIL_REGISTER'))
185 'select' =>
array(
'RECIPIENT_ID'),
189 'Bitrix\Sender\PostingRecipientTable',
190 array(
'=this.RECIPIENT_ID' =>
'ref.ID')
194 '!UPDATE_RECIPIENT.ID' =>
null,
195 '=UPDATE_RECIPIENT.IS_' .
$type =>
'N',
197 'group' =>
array(
'RECIPIENT_ID')
218 while($item = $dataDb->fetch())
225 Model\Posting\RecipientTable::update($item[
'RECIPIENT_ID'], [
'IS_' .
$type =>
'Y']);
233 $lastPostingId =
null;
237 'select' =>
array(
'POSTING_ID',
'STATUS',
'CALC_COUNT'),
239 '!UPDATE_POSTING.ID' =>
null,
241 '=UPDATE_POSTING.COUNT_SEND_ALL' => 0,
248 'Bitrix\Sender\PostingTable',
249 array(
'=this.POSTING_ID' =>
'ref.ID'),
250 array(
'join_type' =>
'INNER')
253 'order' =>
array(
'CALC_COUNT' =>
'DESC',
'POSTING_ID' =>
'ASC'),
263 $data = $resultDb->fetch();
266 if(!
$data || $lastPostingId !=
$data[
'POSTING_ID'])
269 $updateFields = self::getPostingStatusUpdateFields($lastPostingId,
$statusList);
272 Model\PostingTable::update($lastPostingId, $updateFields);
281 $lastPostingId =
$data[
'POSTING_ID'];
305 '=UPDATE_POSTING.COUNT_' .
$type => 0,
307 '=IS_' .
$type =>
'Y'
312 'Bitrix\Sender\PostingTable',
313 array(
'=this.POSTING_ID' =>
'ref.ID'),
314 array(
'join_type' =>
'INNER')
318 'order' =>
array(
'CNT' =>
'DESC',
'POSTING_ID' =>
'ASC'),
321 while($item = $dataDb->fetch())
328 Model\PostingTable::update($item[
'POSTING_ID'],
array(
'COUNT_' .
$type => $item[
'CNT']));
338 'CONTACT_ID' =>
'POSTING_RECIPIENT.CONTACT_ID',
339 'MAILING_ID' =>
'POSTING.MAILING_ID',
342 'order' =>
array(
'ID' =>
'ASC'),
344 while(
$data = $dataDb->fetch())
351 $primary =
array(
'MAILING_ID' =>
$data[
'MAILING_ID'],
'CONTACT_ID' =>
$data[
'CONTACT_ID']);
370 $query =
"SELECT ID FROM b_sender_contact WHERE TYPE_ID=1 AND CODE LIKE '%[A-Z]%' COLLATE Latin1_General_BIN";
373 $query =
"SELECT ID FROM b_sender_contact WHERE TYPE_ID=1 AND CODE REGEXP BINARY '[A-Z]'";
376 $query =
"SELECT ID FROM b_sender_contact WHERE TYPE_ID=1 AND REGEXP_LIKE(CODE, '[A-Z]')";
380 $query =
"SELECT ID FROM b_sender_contact WHERE TYPE_ID=1 AND {$helper->getRegexpOperator('CODE', "'[A-Z]'")}";
384 while ($senderContact = $senderContactDb->fetch())
386 if (self::isTimeUp())
391 $connection->Query(
"UPDATE b_sender_contact SET CODE = LOWER(CODE) WHERE TYPE_ID=1 AND ID = " . intval($senderContact[
'ID']));
397 private static function getPostingStatusUpdateFields($postingId,
$statusList)
404 $postingUpdateFields =
array(
'COUNT_SEND_ALL' => 0);
407 foreach(
$map as $recipientStatus => $postingFieldName)
409 if(!array_key_exists($recipientStatus,
$statusList))
415 $postingCountFieldValue =
$statusList[$recipientStatus];
418 $postingUpdateFields[
'COUNT_SEND_ALL'] += $postingCountFieldValue;
419 $postingUpdateFields[$postingFieldName] = $postingCountFieldValue;
422 if($postingUpdateFields[
'COUNT_SEND_ALL'] == 0)
427 return $postingUpdateFields;
437 $conn = Application::getConnection();
440 if ($conn->isTableExists(
'b_sender_posting_rcpnt_old'))
444 while (!$timer->isElapsed())
447 $sql =
"INSERT IGNORE
448 INTO b_sender_posting_recipient
490 b_sender_posting_rcpnt_old ro
498 ro2.POSTING_ID = p.ID
500 and c.CODE = ro2.EMAIL
504 $conn->query(
"delete from b_sender_posting_rcpnt_old order by ID asc limit $limit");
505 if (!$conn->query(
'select ID from b_sender_posting_rcpnt_old limit 1')->fetch())
515 Application::getConnection()->query(
516 "DROP TABLE IF EXISTS b_sender_posting_rcpnt_old"
523 return '\Bitrix\Sender\Internals\CounterCalculation::updateRecipientsAgent();';
static getConnection($name="")
static getRowById($id, array $parameters=[])
static getList(array $parameters=array())
static updateMailingSubscription()
static wasCompleted($stageCode='FINISH')
static updateRecipientsAgent()
static getExecutionTime()
static setCompleted($stageCode='FINISH')
static updatePostingReadCounters($type)
static updateRecipientReadCounters($type)
static updateContactEmailRegister()
static getCompletedPercent()
static updatePostingStatusCounters()
static getRecipientStatusToPostingFieldMap()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
if( $guestStatuses !=='') if(!is_array($guestStatuses)) $statusList