Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
searchcontent.php
1<?php
3
4use \Bitrix\Landing\Block;
5use \Bitrix\Landing\Internals\BlockTable;
6use \Bitrix\Main\Update\Stepper;
7use \Bitrix\Main\Config\Option;
8
9class SearchContent extends Stepper
10{
14 const OPTION_CODE = 'update_block_search_content';
15
20 protected static $moduleId = 'landing';
21
27 public function execute(array &$result)
28 {
29 $lastId = Option::get('landing', self::OPTION_CODE, 0);
30
31 $finished = true;
32
33 // gets common quantity
34 $res = BlockTable::getList([
35 'select' => [
37 'CNT', 'COUNT(*)'
38 )
39 ]
40 ]);
41 if ($row = $res->fetch())
42 {
43 $result['count'] = $row['CNT'];
44 }
45
46 // gets group of blocks for update
47 $res = BlockTable::getList([
48 'select' => [
49 'ID',
50 'SORT',
51 'CODE',
52 'ANCHOR',
53 'ACTIVE',
54 'PUBLIC',
55 'DELETED',
56 'CONTENT',
57 'LID',
58 'SITE_ID' => 'LANDING.SITE_ID',
59 ],
60 'filter' => [
61 '>ID' => $lastId
62 ],
63 'order' => [
64 'ID' => 'ASC'
65 ],
66 'limit' => 20
67 ]);
68 while ($row = $res->fetch())
69 {
70 $lastId = $row['ID'];
71 $result['steps']++;
72
73 $block = new Block($row['ID'], $row);
74 $searchContent = $block->getSearchContent();
75
76 if ($searchContent)
77 {
78 BlockTable::update($row['ID'], [
79 'SEARCH_CONTENT' => $searchContent
80 ]);
81 }
82
83 $finished = false;
84 }
85
86 if (!$finished)
87 {
88 Option::set('landing', self::OPTION_CODE, $lastId);
89 return true;
90 }
91 else
92 {
93 Option::delete('landing', ['name' => self::OPTION_CODE]);
94 return false;
95 }
96 }
97}