Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
searchhelper.php
1<?
10
13
14//use Bitrix\Sale\Location;
18
19Loc::loadMessages(__FILE__);
20
21final class SearchHelper
22{
23 const INDEX_RECHECK_COUNTER_OPT = 'sale.location.index_recheck_counter';
24 const INDEX_VALID_OPT = 'sale.location.db_index_valid';
26
27 protected static function setCounter($value)
28 {
29 Option::set('sale', self::INDEX_RECHECK_COUNTER_OPT, $value, '');
30 }
31
32 protected static function getCounter()
33 {
34 return intval(Option::get('sale', self::INDEX_RECHECK_COUNTER_OPT, '', ''));
35 }
36
37 protected static function showSearchNotification()
38 {
39 $reindexUrl = Helper::getReindexUrl();
40 global $adminSidePanelHelper;
41 $reindexUrl = $adminSidePanelHelper->editUrlToPublicPage($reindexUrl);
42 $params = array('MESSAGE' => Loc::getMessage(
43 'SALE_LOCATION_ADMIN_SEARCH_HELPER_ENTITY_INVALID_SINDEX',
44 array('#ANCHOR_INDEX_RESTORE#' => '<a href="'.$reindexUrl.'" target="_blank">', "#ANCHOR_END#" => '</a>')
45 ), 'type' => 'ERROR', 'HTML' => true);
46 if (defined('PUBLIC_MODE') && PUBLIC_MODE == 1)
47 {
48 $params["SKIP_PUBLIC_MODE"] = true;
49 }
50 \CAdminMessage::ShowMessage($params);
51 }
52
53 public static function checkIndexValid()
54 {
55 return Option::get('sale', self::INDEX_VALID_OPT, '', '') != 'N';
56 }
57
58 public static function setIndexValid()
59 {
60 Option::set('sale', self::INDEX_VALID_OPT, 'Y', '');
61 }
62
63 public static function setIndexInvalid()
64 {
65 Option::set('sale', self::INDEX_VALID_OPT, 'N', '');
66 }
67
68 protected static function showDBIndexNotification()
69 {
70 $importUrl = Helper::getImportUrl();
71 global $adminSidePanelHelper;
72 $importUrl = $adminSidePanelHelper->editUrlToPublicPage($importUrl);
73 $params = array('MESSAGE' => Loc::getMessage(
74 'SALE_LOCATION_ADMIN_SEARCH_HELPER_ENTITY_INVALID_DBINDEX',
75 array('#ANCHOR_INDEX_RESTORE#' => '<a href="'.$importUrl.'" target="_blank">', "#ANCHOR_END#" => '</a>')
76 ), 'type' => 'ERROR', 'HTML' => true);
77 if (defined('PUBLIC_MODE') && PUBLIC_MODE == 1)
78 {
79 $params["SKIP_PUBLIC_MODE"] = true;
80 }
81 \CAdminMessage::ShowMessage($params);
82 }
83
84 public static function checkIndexesValid()
85 {
87 static::showSearchNotification();
88
89 $cnt = static::getCounter();
90
91 if($cnt > static::HITS_BETWEEN_RECHECKS || !static::checkIndexValid())
92 {
93 $allOk = true;
95 if(is_array($map))
96 {
97 foreach($map as $ixName => $ixInfo)
98 {
99 $ixInfo['DROP_ONLY'] ??= false;
100 if(!$ixInfo['DROP_ONLY'] && !DB\Helper::checkIndexNameExists($ixName, $ixInfo['TABLE']))
101 {
102 $allOk = false;
103 break;
104 }
105 }
106 }
107 else
108 $allOk = false;
109
110 if($allOk)
111 static::setIndexValid();
112 else
113 static::setIndexInvalid();
114
115 static::setCounter(0);
116 }
117 else
118 static::setCounter($cnt + 1);
119
120 if(!static::checkIndexValid())
121 static::showDBIndexNotification();
122 }
123}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29