Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
storage.php
1<?php
2
4
6
13final class Storage
14{
16 private $provider;
17
21 public function __construct(Provider $provider)
22 {
23 $this->provider = $provider;
24 }
25
29 public function save(): void
30 {
31 $providerData = $this->provider->getData();
32 if ($providerData)
33 {
34 $this->savePayload($providerData);
35 }
36 }
37
43 public static function getPayloadByCode(string $code, Main\Type\DateTime $dateTo): array
44 {
45 if (empty($code))
46 {
47 return [];
48 }
49
50 $result = [];
51
52 $analyticsIterator = AnalyticsTable::getList([
53 'select' => ['ID', 'PAYLOAD'],
54 'filter' => [
55 '=CODE' => $code,
56 '<=CREATED_AT' => $dateTo,
57 ],
58 ]);
59 while ($analyticsData = $analyticsIterator->fetch())
60 {
61 $result[] = [
62 'data' => $analyticsData['PAYLOAD'],
63 'hash' => self::calculateHash($analyticsData),
64 ];
65 }
66
67 return $result;
68 }
69
75 public static function clean(string $providerCode, Main\Type\DateTime $dateTo): void
76 {
77 if (empty($providerCode))
78 {
79 return;
80 }
81
82 AnalyticsTable::deleteByCodeAndDate($providerCode, $dateTo);
83 }
84
85 private function savePayload(array $data): void
86 {
87 AnalyticsTable::add([
88 'CODE' => $this->provider::getCode(),
89 'PAYLOAD' => $data,
90 ]);
91 }
92
97 private static function calculateHash(array $data): string
98 {
99 if (self::isB24())
100 {
101 $uniqParam = BX24_HOST_NAME;
102 }
103 else
104 {
105 $uniqParam = Main\Analytics\Counter::getPrivateKey();
106 }
107
108 return md5(serialize($data) . $uniqParam);
109 }
110
114 private static function isB24(): bool
115 {
116 return Main\Loader::includeModule('bitrix24');
117 }
118
124 public static function cleanUpAgent(): string
125 {
126 $dateTo = new Main\Type\DateTime();
127 $dateTo->add('-30D');
128
129 AnalyticsTable::deleteByDate($dateTo);
130
131 return '\Bitrix\Sale\Internals\Analytics\Storage::cleanUpAgent();';
132 }
133}
static getPayloadByCode(string $code, Main\Type\DateTime $dateTo)
Definition storage.php:43
static clean(string $providerCode, Main\Type\DateTime $dateTo)
Definition storage.php:75