Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ecrmpropertyupdate.php
1<?
3
9
11{
12 protected static $moduleId = "lists";
13 protected $deleteFile = false;
14
15 public function execute(array &$result)
16 {
17 if(!Loader::includeModule("lists"))
18 return false;
19
20 $className = get_class($this);
21 $option = Option::get("lists", $className, 0);
22 $result["steps"] = $option;
23
24 $limit = 20;
25 $result["steps"] = (int)($result["steps"] ?? 0);
26
27 $queryObject = PropertyTable::getList(array(
28 "select" => array("ID", "IBLOCK_ID", "USER_TYPE_SETTINGS"),
29 "filter" => array("=USER_TYPE" => "ECrm")
30 ));
31 $listIblockId = array();
32 $listPropertyId = array();
33 while($property = $queryObject->fetch())
34 {
35 if(is_string($property["USER_TYPE_SETTINGS"]) && CheckSerializedData($property["USER_TYPE_SETTINGS"]))
36 {
37 $property["USER_TYPE_SETTINGS"] = unserialize($property["USER_TYPE_SETTINGS"], ['allowed_classes' => false]);
38 }
39 if(is_array($property["USER_TYPE_SETTINGS"]))
40 {
41 if(array_key_exists("VISIBLE", $property["USER_TYPE_SETTINGS"]))
42 unset($property["USER_TYPE_SETTINGS"]["VISIBLE"]);
43 $tmpArray = array_filter($property["USER_TYPE_SETTINGS"], function($mark) { return $mark == "Y"; });
44 if(count($tmpArray) == 1)
45 {
46 $listIblockId[] = intval($property["IBLOCK_ID"]);
47 $listPropertyId[$property["IBLOCK_ID"]][] = intval($property["ID"]);
48 }
49 }
50 }
51
52 $connection = Application::getInstance()->getConnection();
53 $listIblockIdS = implode(",", $listIblockId);
54 if(empty($listIblockIdS))
55 {
56 return false;
57 }
58
59 $sqlString = "SELECT ID, IBLOCK_ID FROM b_iblock_element WHERE IBLOCK_ID IN (".$listIblockIdS
60 .") ORDER BY ID ASC LIMIT ".$limit." OFFSET ".$result["steps"];
61 $queryObject = $connection->query($sqlString);
62 $listElement = $queryObject->fetchAll();
63 $selectedRowsCount = $queryObject->getSelectedRowsCount();
64 $listElementData = array();
65 foreach($listElement as $element)
66 {
67 $listElementData[$element["IBLOCK_ID"]][] = $element["ID"];
68 }
69
70 foreach($listElementData as $iblockId => $listElementId)
71 {
72 $queryObject = \CIblockElement::getPropertyValues(
73 $iblockId, array("ID" => $listElementId), false, array("ID" => $listPropertyId[$iblockId]));
74 while($propertyValues = $queryObject->fetch())
75 {
76
77 foreach($propertyValues as $propertyId => $propertyValue)
78 {
79 if($propertyId == "IBLOCK_ELEMENT_ID" || empty($propertyValue))
80 continue;
81
82 $isDamaged = false;
83 if(is_array($propertyValue))
84 {
85 $listPropertyValues = array();
86 foreach ($propertyValue as $value)
87 {
88 if(!intval($value))
89 {
90 $explode = explode('_', $value);
91 $listPropertyValues[] = intval($explode[1]);
92 $isDamaged = true;
93 }
94 }
95 $propertyValue = $listPropertyValues;
96 }
97 else
98 {
99 if(!intval($propertyValue))
100 {
101 $explode = explode('_', $propertyValue);
102 $propertyValue = intval($explode[1]);
103 $isDamaged = true;
104 }
105 }
106 if($isDamaged && $propertyId)
107 {
108 \CIBlockElement::setPropertyValues(
109 $propertyValues["IBLOCK_ELEMENT_ID"], $iblockId, $propertyValue, $propertyId);
110 }
111 }
112 }
113 }
114
115 if($selectedRowsCount < $limit)
116 {
117 Option::delete("lists", array("name" => $className));
118 return false;
119 }
120 else
121 {
122 $result["steps"] = $result["steps"] + $selectedRowsCount;
123 $option = $result["steps"];
124 Option::set("lists", $className, $option);
125 return true;
126 }
127 }
128}