Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Iblock.php
1<?php
2
4
11
12class Iblock
13{
17 public static function __callStatic($name, $arguments)
18 {
19 $name = mb_strtoupper($name);
20 switch ($name)
21 {
22 case 'ADDELEMENT':
23 case 'ADDSECTION':
24
25 $fields = $arguments[0];
26 if (
27 $fields["ID"] > 0
28 && $fields['IBLOCK_ID'] > 0
29 && (
30 !isset($fields['ACTIVE']) || $fields['ACTIVE'] == 'Y'
31 )
32 )
33 {
34 self::processIblock($fields['IBLOCK_ID']);
35 }
36 break;
37
38 case 'DELETEELEMENT':
39 case 'DELETESECTION':
40 case 'UPDATEELEMENT':
41 case 'UPDATESECTION':
42
43 $fields = $arguments[0];
44 if (is_array($fields) && $fields['ID'] > 0 && $fields['IBLOCK_ID'] > 0)
45 {
46 if (!isset($fields['RESULT']) || $fields['RESULT'] !== false)
47 {
48 self::processIblock($fields['IBLOCK_ID']);
49 }
50 }
51
52 break;
53 }
54 }
55
56 protected static function processIblock(int $iblockId): void
57 {
58 $iblocksForSitemap = IblockTable::query()
59 ->setSelect(['SITEMAP_ID'])
60 ->where('IBLOCK_ID', $iblockId)
61 ->exec()
62 ;
63
64 foreach ($iblocksForSitemap as $iblock)
65 {
66 Job::markToRegenerate($iblock['SITEMAP_ID']);
67 }
68 }
69
77 public static function prepareUrlToReplace($url, $siteId = null)
78 {
79 // REMOVE PROTOCOL - we put them later, based on user settings
80 $url = str_replace(['http://', 'https://'], '', $url);
81
82 // REMOVE SERVER_NAME from start position, because we put server_url later
83 if (mb_substr($url, 0, mb_strlen('#SERVER_NAME#')) == '#SERVER_NAME#')
84 {
85 $url = mb_substr($url, mb_strlen('#SERVER_NAME#'));
86 }
87
88 // get correct SERVER_URL
89 if ($siteId)
90 {
91 $filter = ['=LID' => $siteId];
92 $dbSite = SiteTable::getList(array(
93 'filter' => $filter,
94 'select' => array('LID', 'DIR', 'SERVER_NAME'),
95 ));
96 $currentSite = $dbSite->fetch();
97 $serverName = $currentSite['SERVER_NAME'];
98 $url = str_replace('#SERVER_NAME#', $serverName, $url);
99 }
100
101 return $url;
102 }
103}
static markToRegenerate(int $sitemapId)
Definition Job.php:199
static processIblock(int $iblockId)
Definition Iblock.php:56
static __callStatic($name, $arguments)
Definition Iblock.php:17
static prepareUrlToReplace($url, $siteId=null)
Definition Iblock.php:77