Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agent.php
1<?php
3
6
12class Agent
13{
15 private static $date;
16
22 public static function send(): void
23 {
24 self::$date = new Main\Type\DateTime();
25
26 foreach (self::getProviders() as $provider)
27 {
28 $providerCode = $provider::getCode();
29 $payload = Storage::getPayloadByCode($providerCode, self::$date);
30
31 $sender = new Sender($providerCode, $payload);
32 if ($sender->send())
33 {
34 static::onSuccessfullySent($providerCode, self::$date);
35 }
36 }
37
38 static::createAgent(static::getNextExecutionAgentDate());
39 }
40
45 protected static function createAgent(Main\Type\DateTime $nextExecutionAgentDate): void
46 {
47 \CAgent::Add([
48 'NAME' => '\\'.static::class.'::send();',
49 'MODULE_ID' => 'sale',
50 'ACTIVE' => 'Y',
51 'AGENT_INTERVAL' => 86400,
52 'IS_PERIOD' => 'Y',
53 'NEXT_EXEC' => $nextExecutionAgentDate,
54 ]);
55 }
56
60 protected static function getNextExecutionAgentDate(): Main\Type\DateTime
61 {
62 $date = new \DateTime();
63 $currentMonth = $date->format('n');
64
65 $date->modify('+1 day');
66 $modifiedMonth = $date->format('n');
67
68 if ($modifiedMonth > $currentMonth)
69 {
70 $nextDate =
71 $date
72 ->modify('first day of '.$date->format('F'))
73 ->format(Main\Type\DateTime::getFormat())
74 ;
75 }
76 else
77 {
78 $nextDate = $date->format(Main\Type\DateTime::getFormat());
79 }
80
81 return new Main\Type\DateTime($nextDate);
82 }
83
87 protected static function onSuccessfullySent(string $providerCode, Main\Type\DateTime $dateTo): void
88 {
89 Storage::clean($providerCode, $dateTo);
90 }
91
95 private static function getProviders(): array
96 {
97 return [
98 Sale\PaySystem\Internals\Analytics\Provider::class,
99 Sale\Delivery\Internals\Analytics\Provider::class,
100 Sale\Cashbox\Internals\Analytics\Provider::class,
101 Sale\Internals\Analytics\Events\Provider::class,
102 ];
103 }
104}
static getFormat(Context\Culture $culture=null)
Definition date.php:261
static onSuccessfullySent(string $providerCode, Main\Type\DateTime $dateTo)
Definition agent.php:87
static createAgent(Main\Type\DateTime $nextExecutionAgentDate)
Definition agent.php:45
static getPayloadByCode(string $code, Main\Type\DateTime $dateTo)
Definition storage.php:43
static clean(string $providerCode, Main\Type\DateTime $dateTo)
Definition storage.php:75