Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
check.php
1<?php
3
4use \Bitrix\Main\Update\Stepper;
5use \Bitrix\Main\Config\Option;
6
7class Check extends Stepper
8{
13 protected static $moduleId = 'landing';
14
18 const STEPPER_COUNT = 1;
19
25 public function execute(array &$result)
26 {
27 $lastId = Option::get('landing', 'update_domain_check', 0);
28 $result['count'] = 0;
29 if (!isset($result['steps']))
30 {
31 $result['steps'] = 0;
32 }
33 $forUpdate = [];
34
35 // gets all domains by condition
36 $resDomain = \Bitrix\Landing\Domain::getList([
37 'select' => [
38 'ID', 'DOMAIN'
39 ],
40 'order' => [
41 'ID' => 'asc'
42 ]
43 ]);
44 while ($domain = $resDomain->fetch())
45 {
46 $resSite = \Bitrix\Landing\Site::getList([
47 'select' => [
48 'ID'
49 ],
50 'filter' => [
51 'DOMAIN_ID' => $domain['ID'],
52 'CHECK_PERMISSIONS' => 'N'
53 ]
54 ]);
55 if (!$resSite->fetch())
56 {
57 $result['count']++;
58 if ($domain['ID'] > $lastId)
59 {
60 if (count($forUpdate) < self::STEPPER_COUNT)
61 {
62 $forUpdate[$domain['ID']] = $domain['DOMAIN'];
63 }
64 }
65 }
66 }
67
68 if (!empty($forUpdate))
69 {
70 $class = \Bitrix\Landing\Manager::getExternalSiteController();
71 foreach ($forUpdate as $id => $domain)
72 {
73 $lastId = $id;
74 $result['steps']++;
75 \Bitrix\Landing\Domain::delete($id);
76 $class::deleteDomain($domain);
77 }
78 Option::set('landing', 'update_domain_check', $lastId);
79 return true;
80 }
81 else
82 {
83 Option::delete('landing', array('name' => 'update_domain_check'));
84 return false;
85 }
86 }
87
88}