Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pagemanager.php
1<?
3
7
9{
10 public static function register($cacheKey, array $params = array())
11 {
12 $options = Helper::getOptions();
13 if ($options["WRITE_STATISTIC"] === "N")
14 {
15 return null;
16 }
17
18 if (!is_string($cacheKey) || mb_strlen($cacheKey) < 1)
19 {
20 return null;
21 }
22
23 $pageTitle = $params["TITLE"] ?? $GLOBALS["APPLICATION"]->GetTitle();
24 $pageTitle = mb_substr($pageTitle, 0, 250);
25
26 $pageHost = isset($params["HOST"]) && mb_strlen($params["HOST"]) ? $params["HOST"] : Helper::getHttpHost();
27 $pageHost = mb_substr($pageHost, 0, 100);
28
29 $pageUri = isset($params["URI"]) && mb_strlen($params["URI"]) ? $params["URI"] : Helper::getRequestUri();
30 $pageUri = mb_substr($pageUri, 0, 2000);
31
32 $pageSize = isset($params["SIZE"]) ? intval($params["SIZE"]) : 0;
33
34 $data = array(
35 "TITLE" => $pageTitle,
36 "URI" => $pageUri,
37 "HOST" => $pageHost
38 );
39
40 $GLOBALS["DB"]->StartUsingMasterOnly();
41
42 $page = static::getByCacheKey($cacheKey);
43 $result = null;
44 if ($page)
45 {
46 $data["LAST_VIEWED"] = new DateTime();
47 $data["VIEWS"] = $page["VIEWS"] + 1;
48
49 if (isset($params["CHANGED"]) && $params["CHANGED"] === true)
50 {
51 $data["CHANGED"] = new DateTime();
52 $data["REWRITES"] = $page["REWRITES"] + 1;
53 $data["SIZE"] = $pageSize;
54 }
55
56 $result = PageTable::update($page["ID"], $data);
57 }
58 else
59 {
60 $data["SIZE"] = $pageSize;
61 $data["CACHE_KEY"] = $cacheKey;
62 $result = PageTable::add($data);
63 }
64
65 $GLOBALS["DB"]->StopUsingMasterOnly();
66
67 return $result !== null ? $result->getId() : null;
68 }
69
70 public static function getByCacheKey($cacheKey)
71 {
72 $records = PageTable::getList(array(
73 "filter" => array(
74 "=CACHE_KEY" => $cacheKey
75 ),
76 "order" => array(
77 "ID" => "ASC"
78 )
79 ));
80
81 $result = null;
82 while ($record = $records->fetch())
83 {
84 if ($result === null)
85 {
86 $result = $record;
87 }
88 else
89 {
90 //delete duplicate records just in case
91 PageTable::delete($record["ID"]);
92 }
93 }
94
95 return $result;
96 }
97
98 public static function deleteByCacheKey($cacheKey)
99 {
100 $records = PageTable::getList(array(
101 "select" => array("ID"),
102 "filter" => array(
103 "=CACHE_KEY" => $cacheKey
104 )
105 ));
106
107 $result = null;
108 while ($record = $records->fetch())
109 {
110 $result = PageTable::delete($record["ID"]);
111 }
112
113 return $result;
114 }
115}
static getHttpHost($host=null)
Definition helper.php:41
$GLOBALS['____1444769544']
Definition license.php:1