46 public static function addField($entityName, $orderId, $field, $oldValue =
null, $value =
null, $id =
null, $entity =
null, array $fields = array())
51 if ($value !==
null && static::isDate($value))
53 $value = $value->toString();
56 if ($oldValue !==
null && static::isDate($oldValue))
58 $oldValue = $oldValue->toString();
63 foreach($fields as $fieldName => $fieldValue)
65 if (static::isDate($fieldValue))
67 $fields[$fieldName] = $fieldValue->toString();
72 static::$pool[$entityName][$orderId][$id][$field][] = array(
73 'RECORD_TYPE' => static::SALE_ORDER_HISTORY_RECORD_TYPE_FIELD,
74 'ENTITY_NAME' => $entityName,
76 'ORDER_ID' => $orderId,
79 'OLD_VALUE' => $oldValue,
97 public static function addAction($entityName, $orderId, $type, $id =
null, $entity =
null, array $fields = array(), $level =
null)
101 $level = static::SALE_ORDER_HISTORY_ACTION_LOG_LEVEL_0;
104 if (!static::checkActionLogLevel($level))
107 static::$pool[$entityName][$orderId][$id][$type][] = array(
108 'RECORD_TYPE' => static::SALE_ORDER_HISTORY_RECORD_TYPE_ACTION,
109 'ENTITY_NAME' => $entityName,
125 if (!$poolEntity = static::getPoolByEntity($entityName, $orderId))
133 foreach ($poolEntity as $entityId => $fieldValue)
135 if ($entityId == $id)
146 foreach ($poolEntity as $entityId => $fieldValue)
148 if ($id !==
null && $entityId != $id)
153 $dataFields = array();
154 $oldFields = array();
157 foreach ($fieldValue as $dataList)
159 foreach ($dataList as $key => $data)
161 if ($data[
'RECORD_TYPE'] == static::SALE_ORDER_HISTORY_RECORD_TYPE_ACTION
162 || $data[
'RECORD_TYPE'] == static::SALE_ORDER_HISTORY_RECORD_TYPE_DEBUG)
170 static::prepareDataForAdd($entityName, $data[
'TYPE'], $data[
'ENTITY'], $data[
'DATA'])
172 unset(static::$pool[$entityName][$orderId][$data[
'ID']][$data[
'TYPE']][$key]);
174 if (empty(static::$pool[$entityName][$orderId][$data[
'ID']][$data[
'TYPE']]))
175 unset(static::$pool[$entityName][$orderId][$data[
'ID']][$data[
'TYPE']]);
180 $value = $data[
'VALUE'];
181 $oldValue = $data[
'OLD_VALUE'];
183 if (static::isDate($value))
184 $value = static::convertDateField($value);
186 if (static::isDate($oldValue))
187 $oldValue = static::convertDateField($oldValue);
189 $oldFields[$data[
'NAME']] = $oldValue;
190 $fields[$data[
'NAME']] = $value;
192 if (!empty($data[
'DATA']) && is_array($data[
'DATA']))
194 $dataFields = array_merge($dataFields, $data[
'DATA']);
197 $dataType = static::FIELD_TYPE_TYPE;
198 if (isset($data[
'RECORD_TYPE']) && $data[
'RECORD_TYPE'] == static::SALE_ORDER_HISTORY_RECORD_TYPE_FIELD)
200 $dataType = static::FIELD_TYPE_NAME;
203 if (isset($data[$dataType]))
205 unset(static::$pool[$entityName][$orderId][$data[
'ID']][$data[$dataType]][$key]);
207 if (empty(static::$pool[$entityName][$orderId][$data[
'ID']][$data[$dataType]]))
208 unset(static::$pool[$entityName][$orderId][$data[
'ID']][$data[$dataType]]);
211 if ($entity ===
null && array_key_exists(
'ENTITY', $data))
213 $entity = $data[
'ENTITY'];
220 if ($entityName ===
"")
222 if (isset($fields[
"ID"]))
223 unset($fields[
"ID"]);
226 foreach ($fields as $key => $val)
233 if (!array_key_exists($key, $oldFields)
235 array_key_exists($key, $oldFields)
236 && $val <>
'' && $val != $oldFields[$key]
240 $arRecord = \CSaleOrderChange::MakeRecordFromField($key, $dataFields, $entityName, $entity);
243 $result = $arRecord[
"DATA"];
244 foreach ($arRecord[
"DATA"] as $fieldKey => $fieldValue)
246 if (!isset($result[
'OLD_'.$fieldKey]) && isset($dataFields[
'OLD_'.$fieldKey]))
248 $result[
'OLD_'.$fieldKey] = TruncateText($dataFields[
'OLD_'.$key], 128);
258 static::prepareDataForAdd($entityName, $arRecord[
"TYPE"], $entity, $result)
264 if (empty(static::$pool[$entityName][$orderId][$entityId]))
265 unset(static::$pool[$entityName][$orderId][$entityId]);
268 if (empty(static::$pool[$entityName][$orderId]))
269 unset(static::$pool[$entityName][$orderId]);
271 if (empty(static::$pool[$entityName]))
272 unset(static::$pool[$entityName]);
301 protected static function prepareDataForAdd($entityName, $type, $entity =
null, array $data = array())
304 && ($operationType = static::getOperationType($entityName, $type))
305 && (!empty($operationType[
"DATA_FIELDS"]) && is_array($operationType[
"DATA_FIELDS"]))
308 foreach ($operationType[
"DATA_FIELDS"] as $fieldName)
310 if (!array_key_exists($fieldName, $data) && ($value = $entity->getField($fieldName)))
312 $data[$fieldName] = TruncateText($value, 128);
328 protected static function addRecord($entityName, $orderId, $type, $id =
null, $entity =
null, array $data = array())
331 $userId = (is_object($USER)) ? intval($USER->GetID()) : 0;
334 "ORDER_ID" => intval($orderId),
336 "DATA" => (is_array($data) ? serialize($data) : $data),
337 "USER_ID" => $userId,
338 "ENTITY" => $entityName,
342 static::addInternal($fields);
461 public static function addLog($entityName, $orderId, $type, $id =
null, $entity =
null, array $fields = array(), $level =
null)
465 $level = static::SALE_ORDER_HISTORY_LOG_LEVEL_0;
468 if (!static::checkLogLevel($level))
473 foreach($fields as $fieldName => $fieldValue)
475 if (static::isDate($fieldValue))
477 $fields[$fieldName] = $fieldValue->toString();
482 static::$pool[$entityName][$orderId][$id][$type][] = array(
483 'RECORD_TYPE' => static::SALE_ORDER_HISTORY_RECORD_TYPE_DEBUG,
484 'ENTITY_NAME' => $entityName,
583 $calledClass =
'\\'.static::class;
587 static::deleteOldInternal($days, $hitLimit);
592 $expired->add(
"-$days days");
593 $dbRes = static::getList(array(
594 'filter' => array(
'<DATE_CREATE' => $expired->toString()),
604 $interval = 24 * 60 * 60;
607 $agentsList = \CAgent::GetList(array(
"ID"=>
"DESC"), array(
608 "MODULE_ID" =>
"sale",
609 "NAME" => $calledClass.
"::deleteOldAgent(%"
611 if ($agent = $agentsList->Fetch())
613 \CAgent::Update($agent[
'ID'], array(
"AGENT_INTERVAL" => $interval));
617 return $calledClass.
"::deleteOldAgent(\"$days\", \"$hitLimit\");";